Programming an Arduino via WiFi with the ESP8266


This is experimental and not exactly for beginners, something may be wrong. Proceed with caution or you can break something!

A (not so) brief introduction.

I’ve been working on a new robot called RoDI for a summer course at my Alma mater. RoDI is a low cost wireless robot to teach robotics and programming I started developing last year (reminder to self: I still need to post about it), but it wasn’t until a month ago that I started to work on it more often.

The first version used a HC-06 Bluetooth module to communicate with the computer. I wanted to to use WiFi, but the cost of the WiFi modules was a problem, since the idea was that the entire robot would cost less than 30 USD.

Then, I read about the ESP8266 WiFi modules on Hackaday, and started working on a new version of RoDI, this time with WiFi :D. I wanted to be able to flash the atmega328 inside the robot via WiFi because the robot doesn’t have a USB to Serial converter.

I found (again on HaD) a blog that showed how to flash an Arduino via WiFi with these modules, but it uses the ESP8266 to connect to a router, as we’re planning to have a few of this robots, and the student will take these robot and it doesn’t have another way of flashing the chip unless they have a programmer, so this method wouldn’t work for the robots. One thing that I learn from the blog was that I was going to need to use the transparent mode and, of course, use the module as an AP. Bad news, transparent mode is not available when using the module in server mode with the at_v0.20_on_SDKv0.9.3 version of the at command example. Time for hacking it!

After reading through the source code for the AT commands firmware I was able to enable transparent mode when using the module as a server. One security issue for this is that it supports up to 5 connections, so is not completely secure. I asked and got this response but wasn’t able to find that method (or variable?). I found another method that consist on configuring the AP using the wifi_softap_get_config method from the SDK, which lets us set the max_connection parameter. Yet another option is to add a password to the AP. But… we plan to use it only for robots in a summer course, so the security isn’t really important for now. ;)

Let’s get to work…

Connecting all together

CAUTION: This assumes you’re using a 3.3V Arduino. I’m not responsible for any broken Arduino or ESP8266 modules.

Simplified connection diagram

Simplified connection diagram


We need to do some modifications to the ESP8266 AT firmware, arduino bootloader and the programmer software in order to successfully use it to program the Arduino, here are the mods:

  1. I’ve added a new AT command called AT+RODI that set the module as an AP, starts the transparent server mode, configures the GPIO used for resetting the Arduino and starts a TCP server on port 1234. You can find the code on my esp8266_at fork on my github account. For a guide on how to install the toolchain, you can follow this guide. And for a script to build and program the ESP8266 you can take a look here. Note: to enter AT mode, send +++.
  2. Then I’ve modified Arduino’s bootloader to send the ” character so it can be picked up by the programmer script. You can find the modified code here. (I think this is not entirely necessary but made things easier for me) Update: After some testing, I found out that there is not necessary to modify the bootloader, you can omit this step.
  3. Lastly I’ve modified the python script programmer from sistemasorp to add support so it can work as a client connecting to the ESP8266 for programming. You can find the modified code here.

So, the steps needed are:

  1. Build modified AT firmware for the ESP8266.
  2. Program the new firmware onto the module.
  3. Compile the modified bootloader and flash it to the atmega using a programmer. I use the USBasp or the buspirate
  4. Connect via WiFi to the ESP8266’s AP. You should get an IP address like
  5. Run the following command specifying the the correct *.hex file
    ./ /tmp/build7763862112848895248.tmp/Blink.cpp.hex

Hope you found it useful!

Happy hacking!

Arduino using ATmega328p with internal 8MHz Crystal with Bus Pirate

I am working in a robotics project where keeping the cost low is crucial. So in order to reduce costs and make the robot easy to program and connect to various types of sensors easily, I choose to use an ATmega328p so I can use the Arduino enviroment but using the internal 8MHz clock.

Here are the steps I made to program the bootloader into the ATmega328p chip using the all-mighty Bus Pirate froam Dangerous Prototypes:

Connect the BP to the microcontroller according to this (add link) table.

in a terminal check the connection between the BP and the microcontroller using

avrdude -c buspirate -p m328p -v -P /dev/ttyUSB0

unlock bootloader section on the chip using

avrdude -c buspirate -p m328p -P /dev/ttyUSB0 -U lock:w:0x3f:m

go to the folder where you installed arduino with

$cd /whatever/arduino/hardware/arduino/bootloaders/atmega

and use this command to write the correct bootloader to the chip

avrdude -c buspirate -p m328p -P /dev/ttyUSB0 -U efuse:w:0x05:m -U hfuse:w:0xDA:m -U lfuse:w:0xE2:m -U flash:w:ATmegaBOOT_168_atmega328_pro_8MHz.hex

then lock again the bootloader section with

avrdude -c buspirate -p m328p -P /dev/ttyUSB0 -Ulock:w:0x0F:m

now test with a ftdi chip to program with the arduino IDE

Presentación de RODI

En este video se pueden observar las primeras pruebas con el robot RoDI (Robot Didáctico Inalámbrico) desarrollado por el Club de Robótica. El mismo utiliza el entorno de programación por bloques Turtlebots desarrollado por el grupo Butiá de Uruguay y basado en TurtleBlocks.

MMA7455L accelerometer breakout board Free PCB Build

After a few problems with the local post office, I finally received my free PCBs from Dangerous Prototypes. This time I received two MMA7455L accelerometer breakout boards. It has a Freescale’s MMA7455L accelerometer in a LGA-14 package. It was not difficult to solder using the right method (a lot of patience and flux).

After the assembly, I tested both boards using the Bus Pirate and this tutorial.

Thanks to Ian and the Dangerous Prototype’s crew for the free PCBs.

Microchip anounces new cross-platform MPLAB XC compilers

Microchip has announced that it will release new cross-platform MPLAB XC C compilers by the end of March. They come in 3 versions depending on PIC family: XC8 is for 8bit, XC16 for 16bit, and XC32 for 32bit microcontrollers.

Microchip is releasing MPLAB XC C compilers in the upcoming weeks. There will be three, one for each of the major Microchip logic architectures: MPLAB XC8, MPLAB XC16 and MPLAB XC32. By the end of March, we should have all three versions available. In the same open-platform spirit as MPLAB X IDE, MPLAB XC C Compilers will run on Windows, MAC and Linux. XC compilers will come with a new license manager to make installation and license management simple across platforms. Users will be able to install the compiler on any platform of choice.

Esto ya se venía viendo desde un tiempo atrás, cuando la gente de Microchip empezó a unificar varios aspectos del compilador Hitech, para hacerlo mas “parecido” al MPLAB C18.

Personalmente me parece una excelente decisión de parte de Microchip, ya que actualmente existen tres compiladores “oficiales” de microchip para la gama de 8 bits (Hitech for PIC10/12/16, Hitech for PIC18 y MPLAB C18).

Unificar estos tres facilitará enormemente la programación a los usuarios además de proveer mayor facilidad de portabilidad de código y librerías existentes entre los diferentes modelos de microcontroladores de 8 bits de Microchip.

Disabling Discrete GPU in Debian GNU/Linux Wheezy

I really like using GNU/Linux, especially Debian distributions (not Debian-based, just Debian). I was doing just fine until I bought a HP Pavilion dv7-4285dx laptop a few moths ago. It has a Intel Core i5 460 CPU, 6 GB of RAM and 640 GB HDD, another interesting feature is the switchable graphics system, that means, it has an integrated Intel GPU for low power / low performance and a discrete ATI Mobility Radeon HD6370 GPU for high power/ high performance. It’s a nice feature but the problem is I never use the discrete GPU, but in a fresh installed Debian, both cards are turned on, generating a lot of heat and consuming/wasting a lot of power and therefore battery. In Virus  Windows you can select which GPU to use with the ATI configuration utility.

I googled for solutions and many people could disable one of the GPUs using a module called vgaswitcheroo, which allows to select which GPU to use as well as turn the unused GPU off. I did everything the tutotials said but I couldn’t get it to work, for some odd reason whenever I tried to turn the discrete GPU off the OS gave some kind of weird errors  and warnings.

So I started looking for another solution, and googling again I found another method to disable the discrete GPU using the acpi_call module, which I’ll describe here.

  • First you need to install the acpi_call module. I did it using this method, which I copy here.

1. Install dkms and some useful packages:

sudo apt-get install dkms git build-essential
sudo apt-get install linux-headers-$(uname -r)

2. Clone the acpi_call repository from git and copy it to where dkms will look for it. We’ll call it version 0.0.1 for now:

git clone
mkdir /usr/src/acpi_call-0.0.1
cp -rp acpi_call/* /usr/src/acpi_call-0.0.1

3. Create a file dkms.conf for it:

sudo gedit /usr/src/acpi_call-0.0.1/dkms.conf

and paste this into it and save it:

CLEAN="make clean"
MAKE[0]="make IGNORE_CC_MISMATCH=1 KDIR=$kernel_source_dir PWD=$dkms_tree/acpi_call/0.0.1/build"

4. Edit the Makefile:

sudo gedit /usr/src/acpi_call-0.0.1/Makefile

and paste this into it and save it:

obj-m := acpi_call.o
 $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
 rm acpi_call.mod.o acpi_call.o acpi_call.ko

5. Add the module to dkms and build and install it:

sudo dkms add -m acpi_call -v 0.0.1
sudo dkms build -m acpi_call -v 0.0.1
sudo dkms install -m acpi_call -v 0.0.1

If all went well, you should now be able to load the module with:

sudo modprobe acpi_call

and this will give some information about it:

modinfo acpi_call
  • to try if it worked you should
sudo sh /usr/src/acpi_call-0.0.1/

and you should get something like this

Trying \_SB.PCI0.P0P1.VGA._OFF: failed
Trying \_SB.PCI0.P0P2.VGA._OFF: failed
Trying \_SB_.PCI0.OVGA.ATPX: failed
Trying \_SB_.PCI0.OVGA.XTPX: failed
Trying \_SB.PCI0.P0P3.PEGP._OFF: works!

now you should check if the GPU is disabled by doing

lspci | grep VGA

and you should get something like this

gary@HP-Debian:~$ lspci | grep VGA
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02)
01:00.0 VGA compatible controller: ATI Technologies Inc Robson CE [AMD Radeon HD 6300 Series] (rev ff)

notice the (rev ff) at the end, that means that the GPU is now disconnected

  • If you want to make these changes permanent you need to add acpi_call module to so it can load at startup

First you need to add add acpi_call to /etc/modules

sudo echo acpi_call >> /etc/modules

then create a script in /etc/init.d to run at startup

sudo nano /etc/init.d/script_name_you_want

and copy this into it and save it

#! /bin/bash
 # Provides: script_name_you_want
 # Required-Start: $remote_fs $syslog
 # Required-Stop: $remote_fs $syslog
 # Default-Start: 2 3 4 5
 # Default-Stop: 0 1 6
 # Short-Description: Start daemon at boot time
 # Description: Enable service provided by daemon.
 # /etc/init.d/script_name_you_want
 # Carry out specific functions when asked to by the system
 case "$1" in
 echo "Disabling Discrete VGA "
 cd /usr/src/acpi_call-0.0.1/
 echo "Usage: /etc/init.d/script_name_you_want {start}"
 exit 1
 exit 0

then add the appropriate symbolic links to cause the script to be executed

sudo update-rc.d script_name_you_want defaults

If you want to remove the symbolic links

sudo update-rc.d -f script_name_you_want remove

XIX Jornadas de Jóvenes Investigadores de la AUGM

Del 25 al 27 de noviembre pasado, se llevaron a cabo en Ciudad del Este las XIX Jornadas de Jóvenes Investigadores de la AUGM, para los que no conozcan acerca de esta, la AUGM es la Asociación de Universidades del Grupo Montevideo. Es una asociación de Universidades Nacionales Públicas de Argentina, Brasil, Uruguay, Paraguay, Bolivia y Chile, compuesta por 28 Universidades Miembro.

Desde su creación en 1991, la AUGM promueve la integración y cooperación educativa regional, en defensa de la Educación Pública Superior considerada como un derecho humano universal y un bien público social. Entre las principales actividades de esta asociación, podemos citar las Jornadas de Jóvenes Investigadores que es el espacio anual que reúne a cientos de jóvenes investigadores de las distintas Universidades miembro de la AUGM.

Estas Jornadas están orientadas a promover el temprano relacionamiento entre jóvenes científicos de los países de la región y a impulsar su integración en los trabajos que crean. Se desarrollan redes interpersonales y de carácter científico-académicas, cuyo entramado luego posibilita y fundamenta la constitución de grupos regionales de investigación científica.

Este año, fueron seleccionados 30 trabajos de las distintas facultades y centros de la Universidad Nacional de Asunción entre los cuales 2 pertenecían a la Facultad Politécnica, de la que soy estudiante.

Comitiva de Jóvenes Investigadores de la UNA

El trabajo de investigación denominado “Prototipo de un Transportador Personal con Sistema de Balance Automático”, del cual soy autor junto a mi compañero Luis Sandoval, fue seleccionado para ser presentado en 2 categorías, exposición de póster y presentación oral.

Durante la presentación de pósteres

Durante la presentación oral

Nuestro proyecto recibió menciones de honor en ambas categorías como mejor póster y mejor presentación oral en el eje temático “Ingeniería Mecánica y de la producción”, lo cual represento una gran felicidad para mi como para la comitiva de la UNA. Estas menciones son 2 de las 4 que recibió la Universidad Nacional de Asunción durante estas Jornadas.

Mención a mejor presentación oral

Mención a mejor presentación oral

Compartir con Investigadores de las demás facultades y centros y de otras Universidades y países fue una experiencia increíble! Agradezco a la Dra. Miki Saito por convencerme para participar en estas Jornadas y a todos los demás profesores que apoyaron este viaje. Y a todos los compañeros del viaje por la buena onda!

Comitiva de la UNA con los verdecitos

This slideshow requires JavaScript.


Get every new post delivered to your Inbox.

Join 555 other followers