Can Espruino program a ATMEGA168-20PU?

Posted on
  • I'm super duper new to robotics, but it seems like there needs to be some way to use the limited number of pins available on Espruino (or any other microcontroller) to control an unlimited number of pins if used recursively... I've been looking for ideas of how to do this and found this https://www.youtube.com/watch?v=exD4jzZF­YN0

    where the microcontroller was programmed with an Arduino... if you could pre-program a set of functions into a second or third microcontroller and have the original microcontroller first initiate a function in the second and then wait for signals indicating a certain state to either initiate the next function or to move on to some other process with another component or microcontroller, it would seem do-able, though I'm not sure how this can be done and was wondering if anybody could link me to tutorials or examples if this is possible?

    Would these external microcontrollers be programmed in Javascript if I use Espruino?

  • There are a few questions here:

    • Yes, it is possible to make the Espruino program an Arduino via either ICSP (over SPI) or using the serial bootloader. I don't think anyone's done this, but it's 100% possible. I toyed with the idea of an Espruino program that would let you flash .hex files off the SD card onto an Arduino. However, you can't compile the Arduino code on the Espruino - all you could do is compile sketches ahead of time, and have the Espruino load them onto the Atmel chip. This is useful for making a neat portable programmer for Arduinos, particularly if you need to flash the same thing onto a lot of them, but it's useless for what you're trying to do.

    • You cannot program a MCU in javascript unless it's running the Espruino firmware, which means an ARM32 chip, not an Atmel chip (an attempt was made to make it run on the mega, but it never worked, and nobody ever bothered to try fixing it).

    However - do not despair - there are ways to expand the IO available to an MCU board:

    • Shift Registers - typically these are 8 or 16 bits, and as you put bits into them over SPI, they spit out the bits they had in them on an output, so you can daisy-chain them - and each bit has an output pin associated with it. These also let you set when the outputs are latched, and let you tri-state the outputs if needed.

    • I/O expanders - I2C or SPI devices offering both input and output, with widely varying levels of sophistication. You'd have to write a javascript module to control it, since we don't have one ready for any I/O expanders (nobody's used on with the Espruino yet I don't think).

    • Program an Atmel MCU as an I2C slave, or have it listen on serial, etc, and have it do whatever you want. Of course, you'd have to program this in Arduino-C (or worse still, real C).

  • I think when you start doing stuff, you'd actually be quite surprised by how much you can get done with the pins on a single microcontroller - for instance you could have one servo motor per pin, and there are around 40 pins available.

    But as @DrAzzy says, there are lots of ways of getting more pins from a single microcontroller.

    As he hinted at, if you have lots of Espruinos you can chain them together very easily. For instance, you can connect pin A10 (Serial receive) of all the 'slave' Espruinos together, and can connect that to A9 (Serial transmit) of the 'master' Espruino.

    As long as each of the slaves has a variable called NAME that is unique, you can send JavaScript commands straight to any of the slaves. For instance on the 'master':

    Serial1.println("if (NAME=='bob') digitalWrite(LED1,1);");
    Serial1.println("if (NAME=='fred') digitalPulse(A0,1,100);");
    

    Then all devices will execute the code, but only the devices with the correct names will actually run the command after the if statement.

    Hope that helps!

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Can Espruino program a ATMEGA168-20PU?

Posted by Avatar for user52526 @user52526

Actions