Firmata - basic control of devices from PC over USB

To move off-topic from the Diana thread...

Firmata is a standard protocol for controlling MCU peripherals from host software over serial port. It has simple libraries available basically for any programming language GitHub - firmata/protocol: Documentation of the Firmata protocol. . Reading/writing to pins, reading ADC values, I2C communication, etc. is just a matter of one or a few lines of code in the host software, easy to add into any existing project.

Arduino Nano with on-board USB-serial chip costs < 2USD incl. shipping (e.g. Nano Mini USB Development Board Nano V3.0 Controller Board ATmega328P CH340G USB to TTL NANO 3.0 for Arduino with USB Cable-in Integrated Circuits from Electronic Components & Supplies on AliExpress ) . Powered by the USB host, it can read/control the existing device directly, or via some inexpensive galvanic isolators (solid state relays, optocouplers). The arduino is programmed directly from the Arduino IDE, just select the Standard Firmata sketch available directly in the IDE and burn via USB to arduino, a few minutes of work even for beginners, incl. download and installation of the Arduino IDE.

The default serial port runs at 57600 bps, the protocol is binary MIDI format, making communication reasonably fast. In my interpreted octave (i.e. slow) a call to digitalWrite(pin, value) takes about 1ms.

For nice design a panel-mounted USB female short adapter cable costs next to nothing Mini USB Male to Female connector Adapter extend Cable With Panel Mount Hole es | eBay .

IMO in many cases there is no need to add USB chips and program some firmware changes. Using arduino firmata and coding simple logic in the host PC directly may reach the goal much faster, cheaper and more flexibly.
 
Last edited:
Sorry for continuing being off-topic in Edmonds thread.

However, I would like to point out that instead of using the ATMega processor based boards a STM32 based board would be a better solution. STM32F103 based boards are also dirt cheap on Aliexpress. The board often referred to as the Blue-pill board would be a candidate and are also supported by the Arduino framework. So it shouldn't be that different from a programming point of view.

Although not as cheap there also is this board from ST's Nucleo series. It has an STM32L432 which also has USB connectivity, but also hardware floating point module if needed. NUCLEO-L432KC STMicroelectronics | Mouser Europe

Mogens

The blue/black pill is a great hardware, amazing performance for the price. There is even a fantastic RTOS developed directly by an STM employee ChibiOS free embedded RTOS - ChibiOS Homepage which offers preemptive thread scheduling, complete support for all STM peripherals, the guy provides incredibly responsive support. I played with it, using his pre-configured Eclipse IDE on windows it is possible to compile and upload his examples in a matter of an hour. I used blue pill/chibios/µGFX to control a 480x272 TFT, it had some 10fps refresh rate with no HW accelleration. Very powerful for the price.

If the Firmata arduino version really works on the blue pill (it should Firmata example * stm32duino/wiki Wiki * GitHub ) , it would definitely be a nice tool. I will try it, a few 2USD blue pills laying around.

The default firmata serial port speed is 56kbps, the performance is limited by this link. But STM32 offers faster USB-serial, could be an advantage in some situations.

Thanks for noting the STM32.
 
Last edited: