Welcome to weblogs.com.pk Sign in | Join | Help

Firmata

Microcontrollers are great; but in today’s ever changing and more demanding world; we often need an ability to upgrade the software; fixing bugs if any; adding and enhancing the functionality. There are well established mechanisms for upgrading software on computers (PCs, Tablets and Phones); but updating firmware on Microcontrollers can become challenging. The connected smart appliances with larger memories can be updated with Over The Air (OTA) updates; but it needs resources like connectivity, enough memory/storage and developing + testing appropriate update mechanism in the firmware; that are not often available in all the appliances. In addition to this; our IoT software might be either complex or depends on other resources like cloud connectivity, database or accessing files that cant be done directly “on” the microcontroller. Further the solution might comprise of many appliances and there is need to coordinate across the appliances, taking input from one appliance doing something on other. MQTT can be used for data passing but sometimes we need an ability to treat the appliance as a “dump gadget” connected to a “smarter software” running on a computer. This is where firmata comes in; its a protocol for communicating with microcontrollers from software on a computer. The protocol is implemented in firmware on microcontroller; Arduino and Spark.IO are supported officially and there exists client libraries for different languages and platforms, from Python, Perl and Ruby to Java, .NET and Javascript/Node and many other (including mobile/tablet platforms)

Firmata Llbrary for Arduino comes preinstalled in the IDE and we can use it with supported boards, Arduino or ESP8266.

firmata-sketch

  • For Arduino; we use StandardFirmata and for ESP8266 we use StandardFirmataWifi

For the “Blink” example; I am showing you Python and Node.js examples; we can program in any language / platform and can find required library

firmata-python

firmata-nodejs

  • For the Node.js; I am using firmata

If you are wondering; the code is not compiled and sent to microcontroller; instead microcontroller after firmata firmware is acting as a slave always listening to what’s being sent over the wire in the firmata protocol; you can watch the RX activity clearly on the Arduino board

firmata-rx-activity

In case of Arduino, the clear drawback is that we need serial connectivity between the board and the computer running the program. We can either use Ethernet or Wifi shield or ESP8266 where this serial cable connection is avoided and the program can connect to the microcontroller through Wifi. Simply use StandardFirmataWifi; edit the WifiConfig.h according to your Wifi settings, optionally uncomment SERIAL_DEBUG to view the debug logs in the Serial Monitor and you are good to go

firmata-esp8266

I connected an Analog Temperature Sensor to Analog Pin 0 and wrote this little Node.js program that retrieve the temperature value and send it to ThingsSpeak for further analysis / reporting.

I find this firmata approach intuitive and easier; given we can change / manage the program easily on the computer instead of reflashing microcontroller firmware, especially ESP8266 based IoT appliances works great in this way. The appliance can continue to be installed where it is; say Sonoff switch and you can change / update the program on the computer possibly even remotely; say Raspberry Pi by sushing it

ESP8266 comes in all sizes; check this video for inspiration; we can deploy sensors connected to ESP01 (that has two GPIOs) and solder/glue/pack the things to normal wall socket USB chargers (with required voltage regulation)

ESP8266 ESP-01
Published Wednesday, February 01, 2017 5:33 PM by khurram

Comments

No Comments

New Comments to this post are disabled