1

I have a few Arduino boards connected to my computer running firmata and I want the computer to be able to differentiate between them even when I unplug them and plug them back into a different USB port in a different sequence. My solution was to save and read a Unique I.D. into each Arduino's EEPROM, but I am not sure how to accomplish this using firmata?

I want to save a few bits of data to the Arduino UNO with EEPROM, but the Arduino has to be running code compatible with firmata. Is this possible?

  • What have you tried so far in you code? Have you tried using the adrunio eeprom write function with your arduino program -so once it knows the unique ID (in your arduino program) it writes it to the EEPROM using the command EEPROM.write(address, value) and the library EEPROM.h – qwerty10 Sep 2 '16 at 21:10
  • Which firmata sketch for the Arduino are you planning on using? – Mikael Patel Sep 3 '16 at 8:20
  • I am using Standard Firmata Plus for one board and Standard Firmata Wifi for the other. – Aaron Cofield Sep 3 '16 at 14:53
  • Currently, I've been putting a resistor in the first analog pin and Identifying the board based on that resistor value, I need a better way of doing this and I haven't been able to successfully find a method of saving to EEPROM via firmata. – Aaron Cofield Sep 3 '16 at 14:54
2

You have to edit the Firmata source code and add a few lines of code:

  1. add the EEPROM library
  2. include the library into the Firmata code
  3. in the setup() function use the EEPROM library to read the id from the EEPROM

How do you plan to write that data into your Arduino EEPROM? If you want to do that via serial connection than you also need to add that code. I have done something similar in an example for my VoltageReference library, specifically in EEPROMCalibration.ino

UPDATE

After a little investigation I understand there is the possibility to exchange generic messages and handle generic commands via Firmata: commands 0x00-0x0F are reserved for customization. On the Arduino side you can use:

void storeToEEPROM(int id) {
  ...
}

void readFromEEPROM() {
  char buf[12];
  Firmata.sendString(itoa(the_id, buf, 10));
}

void setup() {
  ...
  Firmata.attach(0x00, storeToEEPROM);
  Firmata.attach(0x01, readFromEEPROM);
  ...
}

That will allow you to write and read the id using those two custom commands.

  • Thank you for the response! Yes, that would allow the Arduino to have access to its ID stored in EEPROM, but I need to be able to read and write this data over Serial using the firmata protocol. – Aaron Cofield Sep 3 '16 at 17:01
  • Please find the updated response: you can use two of the 16 reserved commands (0x00-0x0F) and attach your EEPROM reading/writing functions. – Roberto Lo Giacco Sep 3 '16 at 22:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.