Embedded Programming

Individual Assignment:

  • read a microcontroller data sheet
  • program your board to do something, with as many different programming languages and programming environments as possible

Group Assignment

  • compare the performance and development workflows for other architectures

Programming the hello board with an arduino as ISP - C++ arduino

Embedded programming, thats mean that I need to code something and put the "instruction" to an electronic device !

Then I need a IDE (integrated development environment). In it I will be able to type the code in different languages and add some plugins.

I'm using Visual studio code because of all of these functionalities that it provide ! Natively, there is git interface that allow you to manage your git files. But you can also add some plugins, in this part I will use platformIO (but you can install into other IDE like Atom), plateforIO is a very powerful tool for IoT development. That allow you to build code for different type of processor or microcontroler, and upload the code into them using a lot of different frameworks or upload protocols. With it you can create your own build and upload process but there is already some really good process that I will use in order to program an ATTINY44 with differents ISP programmer.

I have installed it directly in Vcode through the extension menu. When its done you can start a new pletformIO project ! In the src folder that will be created I put my C code, and now I will configure the plateforIO configuration file called platformIO.ini.

In a first time I will use an arduino as ISP. And all of the different configurations are here Then I will use the arduino as isp configuration.

arduino as isp plateforIO configuration

Now lets plug the hello board to the arduino with the ISP connection. On the arduino I will use the MISO, MOSI, SCK, VCC, GND and RST pins.

When the board is plugged I use the keyboard shortcuts : CTRL+ALT+U. This command will execute all of the building and upload process !

arduino as isp

And it works pretty well, the operation is a sucess and my led is blinking !

Programming the hello board with the FabISP - C++ arduino

Now let's try to upload the same code with the famous FabISP of the electronic production week !!

fabisp plateforIO configuration

In a first time we all get (every fabacademy students of the lab) different error when we tried to use it. In fact, the FabISP was properly detected by our computer as a TINY USB, but when we have tried to use it with differents way and differents OS always get an error... initialization error rc = -1 or bad device signature.

After a lot of researches, Adel find out the problem !! When you want to program your board with the FabISP you need to power the board from two way : through the ISP connect and also through the FTDI connector. But be careful the two different GND must be linked !

Here this is the setup :

fabisp tot wirefabisp power

As you can see I have used an arduino to be the second power source, and I have used the VCC and GND pin of it plug into the VCC and GND pin of my FTDI connector ! But the two device are connected to the same USB hub in order to link the two GND ! And its working pretty well !!

Programming a nodemcu 32s (ESP8266) with a serial connection - microPython

In this section I will explain how I have programed a nodemcu 32s board based on a microcontroler ESP8266 and using microPython !

The first that I have made is to install the esptool package. I have used pacman -S esptool. For OSX, windows or another Linux distribution you should check the way to install it.

When this is made I can now communicate with the board.

I have connected the board and my computer using a serial FTDI connection USB. At this state wha I want is to re-write the flash memory with the microPython firmware.

First I have to erase the flash. To do this I use esptool with this command :
esptool --port /dev/ttyACM0 erase_flash

erase flash

At first I get an error Failed to connect to Espressif device Invalid head of packet (0x00) In order to provide this, execute the command and then you have to hold on the GPIO0 button during a reset.

I have to flash the new microPython firmware. This firmware will interpret microPython codes put directly on the boards or through a REPL (Read–eval–print loop, also termed an interactive toplevel or language shell) I downloaded it from microPython download page and i took the last stable firmware for the ESP8266.

Now lI have tried to flash the esp8266 with this command : esptool --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 [firmware location] If you get an error it may be because of you OS architecure (some linux or mac OS) you can use this command : esptool --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect -fm dio 0 [firmware location].

write flash

Okayy now I can start an REPL in order to try some basics intruction.

To do this, I downloaded picocom with pacman -S picocom. But you can do the same with a software like screen or any other type of software that served as a low-tech serial communications program to allow access to all types of devices that provide serial consoles.

Then I used this command : picocom /dev/ttyUSB0 -b 115200 . A REPL is then loaded I can make first a "hello world" !!

hellow world

But let's try to put directly some code into the board. To this I need a tool to put the code in the board, I have choosed Ampy a Adafruit MicroPython Tool - Utility to interact with a CircuitPython or MicroPython board over a serial connection. But you can use other software like rshell (from dhylands) or webrepl (from paul & damien) (I will use webrepl in a second time ;) )

In order to install it have cloned the git repo with git clone https://github.com/pycampers/ampy . And in the repo I installed it with python3 setup.py install.

I have coded a little script that found all of the prime numbers beetwen two limits, let's put it on the board with ampy -p /dev/ttyUSB0 put main.py


If you get no error, that mean that the transfer was made properly ! But you can verify it. Let's launch a REPL using the same previous picocom command. And then use import uos and then uos.listdir() You should see something like this.


In my main.py file there is some functions, let's import it ! To do this I use this command from main import *

prime numbers

And then I can call my function that will calculate all of the prime numbers beetwen 0 and 100.

prime numbers

Programming a nodemcu 32s (ESP8266) with a Wifi connection - microPython

As I said earlier, instead of using picocom in order to communicate with your esp8266 through a serial connection, you can use webrepl and communicate wwith your esp8266 through a wifi connexion.

The esp8266 can turn on as a wifi hotspot. The method is to connect your computer (or other device) to it, then the webrepl is a webpage .html using python scripts and java scripts.

You can download it here or directly go on the microPython website who hosts a webrepl http://micropython.org/webrepl/ . But before you can connect you must turn on the wifi of the ESP8266.

To do this, launch a repl with picocom and in it use import webrepl_setup. Then you just have to follow the configuration instructions.

webrepl setup

After the webrepl configuration the board must reboot. After that Im now able to connect my computer to the esp8266 wifi.

In my network mange I chose MicroPython-XXXXXX. The password is a generic password : micropythoN.


Now I am connected to the board, I launch the webrepl page with firefox webrepl.html. And I can unplug the serial connection, I just let the GND and VCC pin connected in order to power the board.


Okayy let's try to type a little loop instruction !


And with the same method, that I have explained previously, you can upload a .py file in the esp8266 and then use the different function of it !


Read a Datasheet

For my final project I want to use a little network of board controlling servo-motors in order to move lasers... To do this I want to use some ESP32 because they have a wifi connection ! Then I need to create my own esp32 based dev board. Let's read the datasheet of the esp32 !

In it we can learn that the esp32 must be powered in 3,3V. And many others informations about the differents pin, type of memory and many more things...

Basically when you are on the first page of the Datasheet you can read the details of all the features available on the esp32.

Wi-Fi Key Features

  • 802.11 b/g/n
  • 802.11 n (2.4 GHz), up to 150 Mbps
  • WMM
  • Immediate Block ACK
  • Defragmentation
  • Automatic Beacon monitoring (hardware TSF)
  • 4 x virtual Wi-Fi interfaces
  • Simultaneous support for Infrastructure Station, SoftAP, and Promiscuous modesNote that when ESP32 is in Station mode, performing a scan, the SoftAP channel will be changed
  • Antenna diversity
The wifi work with different norms. Depending on the standard, the flow rate, distance and different characteristics change. As we can see in the datasheet, the ESP32 support the 802.11 b/g/n that is very useful because every router or wifi device (smartphone, pc, etc..) doesn't work with the same norms. And the 802.11 b/g/n are the most used type of wifi !

CPU and Memory

  • Xtensa single-/dual-core 32-bit LX6 microprocessor(s), up to 600 MIPS (200 MIPS for ESP32-S0WD, 400MIPS for ESP32-D2WD)
  • 448 KB ROM
  • 520 KB SRAM
  • 16 KB SRAM in RTC
  • QSPI supports multiple flash/SRAM chips
Okay, here one of the things that are very useful is capacity of ROM, SRAM and SRAM in RTC. The ROM is a type of memory that can hold data without power, it contains some control code for the WiFi, the bootloader to start code from external ROM and some bits of code to form a rudimentary scheduler. The SRAM is a memory where we can store data and instructions. And one thing also very useful is the 16 KB of SRAM in RTC. The RTC (Real Time Clock) is a non volatile memory that store informations about the reboot of the esp32. When the chip is put in the deep sleep mode, the SRAM in RTC is not deleted. In comparison here some spec of the ATTINY84 :

  • 8KB ISP flash memory (Program memory size)
  • 512 Bytes SRAM
  • 521 bytes of Data EEPROM/HEF
And some of the ATMEGA 328 :

  • 32KB ISP flash memory (Program memory size)
  • 2,048 SRAM bytes
  • 1024 bytes of Data EEPROM/HEF
Yes that is much less...

Basically, this is most of the features that I will use. There is also a lot of bluetooth features but I will not detailled this here because I won't use them.

Pin Layout

datasheetpart0 Basically there is :
  • 34 x programmable GPIOs
  • 12-bit SAR ADC up to 18 channels
  • 2 x 8-bit DAC
  • 10 x touch sensors
  • 4 x SPI
  • 2 x I2S
  • 2 x I2C
  • 3 x UART
  • 1 host (SD/eMMC/SDIO)
  • 1 slave (SDIO/SPI)
  • Ethernet MAC interface with dedicated DMA and IEEE 1588 support
  • CAN 2.0
  • IR (TX/RX
  • Motor PWM
  • LED PWM up to 16 channels
The first thing that we can notice is the very huge number of GPIO programmable pins. 34 for the esp32 (12 for the ATTINY 84 and 23 for the ATMEGA 328). Also there is two features that I like very much is the different converter pins : DAC (Digital to Analog Converter) and ADC (Analog to Digital Converter). They are very useful when you want to manage the signal of different kind of captors. And them numbers are very interesting, for example in a ATTINY 85 there is 8-channel 10-bit A/D converter and no DAC. For the ATMEGA 328 there is 6-channel 10-bit A/D converter (8-channels in TQFP and QFN/MLF packages) and no DAC.

How to setup the strapping pins in order to make working the esp32 (power, reset, select the booting modes)

In my case what I need to know is to now what is the minimal circuit that board will be functional. Basicaly, One of the most import things to know is the differents mode of the board. Like the booting mode, the debugging mode or the type input voltage (1.8V or 3,3V). These modes allow you to upload codes and and flash the memory of the board.

In the datasheet it's explain that the choice of the differents modes passes by the strapping pins.

datasheetpart1 datasheetpart2

Then it's explained that we need to switch the states of differents pins from 1 to 0 or from 0 to 1 in order to switch modes.

For exemple if I want to put the board into the SPI boot mode I need to put the GPIO0 pin into 1.

What I have learned

In the last week I had the time to familiarize myself with ATMEL microcontrolers, how they work and how we program it. They are very cheap and very powerful for a lot uses. But I have principaly learned how works esp microcontrolers with microPython. MicroPython is programation language very pleasant. The syntaxe is really supple, and the memory operation are in my sens more readable and digestible.

I'm eager to do more experimentation with this type of microcontroller !

All the files

micropython firmware prime number python script blink C++ platformIO ini file