Sep 26

Connecting an Android Phone to an Arduino

Connecting an Android Phone to an Arduino could not be easier. All you need is an OTG cable. I wrote a previous post here about connecting and controlling an Arduino from your Android device. Previously, I had always connected real Arduinos. This time I tried connecting my DIY Arduino.


Connecting an Android Phone to an ArduinoConnecting an Android Phone to an Arduino




Pictured above is my Samsung S5 (G900H) connected to my DIY Arduino via an FTDI converter and a white OTG cable. The FTDI converter would normally be plugged into your Host PC USB port. With the OTG cable, the Android Phone functions as the host. From the screen shot of the phone, you can tell that the Arduino is loaded with the Minipirate sketch. The phone is running the USB Terminal app. Note: some Android phones do not support USB host mode. To check if yours does, I recommend this app.

When I first connected my Arduino to the Phone it did not recognize the connection. I found out that my FTDI chip was fake and had an incorrect product id. The product id was all zeros and needed to be 6001. There is a solution to fix this called ft232r_prog. This Linux command line program allows you to reconfigure the FTDI chip. It is a few years old and does not compile on my version of Fedora. It does however compile fine on an Ubuntu distro. I used YUMI to boot into a live Ubuntu image to compile and run it. Here are the commands to install the prerequisites, compile and change the product ID on an Ubuntu system:

Once you get the binary, it does run on Fedora. However, first, you need to run these commands to install the prerequisites and create a symlink for the FTDI library:

The program will run fine on Fedora after that:

Connecting an Android Phone to an Arduino allows you portability in the field. You will want a means of re-charging or replacing the phone battery as the Arduino connection does drain the battery faster than normal.

Sep 07

Flashrom and an Arduino at 3.3V

Flashrom is an amazing piece of software and a life-saver when you need it! If you’ve tried to update your BIOS before using manufacturer supplied software and something went wrong, then you know how valuable Flashrom can be. I’ve written about Flashrom and the BusPirate in a previous post HERE. However, I just found out how easy it is to use Flashrom and an Arduino at 3.3V to program (read, write and erase) various ‘flash’ chips.  All Flashrom needs is a programmer to interface with. The Arduino (or Atmega 328P) can very easily and economically be made into a Flashrom programmer.

Basically a program is loaded into the Arduino to let Flashrom program through it. I am using frser-duino which Flashrom sees as a ‘serprog’ programmer. Serprog uses the FTDI chip, the serial port and SPI interfaces to do its work. More information about Flashrom using the Serprog ‘programmer’ can be found HERE. You can get the source code for frser-duino HERE.

I am using Fedora (24 as of the date of this post). Here are the commands I used to install the prerequisites and the frser-duino code into my Arduino (a DIY UNO).

Notice that the documented commands are not what I used as they are for a ‘real’ Arduino UNO. Since I am using an external FTDI chip, it needs to specify 115200 BAUD to program the Arduino. However, once programmed, the larger BAUD/buffer rate of 2000000 can be used to flash with. Once the code is loaded via avrdude into the Arduino, you are ready to use it with Flashrom.

One of the ‘problems’ in flashing BIOS chips is that they are usually 3.3V whereas the Arduino is usually 5V. You could use level translation circuitry to reduce the voltage but it turns out there is a much simpler way. The DIY Arduino can be run at 3.3V using an FTDI USB to Serial converter. A DIY version of an Arduino UNO can be easily made on a breadboard, PCB or perfboard.

Here is an example of how an 8-pin Winbond BIOS chip is wired to the Arduino (download the Fritzing source HERE):


Flashrom and an Arduino at 3.3V


DIY ArduinoHere is a picture of my newest DIY Arduino. It is a bit different that other Arduinos I made in the past and wrote about HERE. You can see the 6 pin ICSP header on the side (to attach the FTDI USB to serial convertor). Two 14 pin female headers are soldered to the base for connectivity to any pin. There is a 4 pin header for power (left side) and a four pin header for ground (right side). This is basically a bare minimum circuit to run the ATMega 328P and function as an Arduino UNO. It runs at either 5V or 3.3V depending on the jumper of the FTDI USB to serial convertor.


6 pin dual female cableA 6 pin female-female cable is used to connect the FTDI converter to the 6 pin male ICSP header on the Arduino. The six pins are GND,CTS,PWR,TX,RX,DTR.




FTDI - USB Mini ConverterFTDI USB-Serial Convertor






The FTDI USB to Serial Converter I use has a jumper to switch between 3.3V and 5V. I got mine from also sells one HERE. I have the jumper on 5V when I load the Arduino with the frser-duino code. Then I switch the jumper to 3.3V when I use Flashrom to program chips that need 3.3V.

Here is a picture of everything wired together:

Arduino Flashrom Programmer

Flashrom and an Arduino at 3.3V

If the BIOS chip is not soldered on, it can be extracted and placed on a breadboard to flash. However, if the BIOS chip is not socketed (i.e. it is soldered on), you may need an SOIC Test Clip or IC Test Hooks.


SOIC 8-pin Test ClipIC Test Hooks










Sometimes it is hard to use the SOIC test clip due to other circuitry in the way so I prefer the IC Test Hooks. They have a tiny ‘claw’ which can be clamped onto the leg of the IC.
IC Test Hook Claw


Here is an example command to run Flashrom and save the contents of a BIOS chip to a file:

Here is an exmaple command to just identify the flash chip:

here are the results:

As a side note, the BIOS file to flash has to be in the proper format (ROM image). ASUS for example, distributes their BIOS files in CAP format.  The ROM image has to be extracted from the CAP file with a utility like UEFITool. Alternatively, and much easier, just strip the header off the CAP file with this Linux shell script:

Jun 27

TV Video Output from the Arduino

I made another circuit to display TV Video output from the Arduino.

It uses the TVOut library (documented at the TVOut Arduino Playground) which can be used to output an NTSC or PAL video signal. The circuit is actually just a means of adding three resistors to an RCA video cable. Instead of cutting a cable and soldering on the resistors, it is much cleaner to use this circuit. The circuit is very simple, consisting of an RCA jack, three resistors and a three pin PCB connector. Normally, only two resistors are used (a 1K ohm resistor to sync and a 470 ohm to video), however, some TV/video monitors need an additional 75 ohm resistor from video to ground. Therefore, I also added that 75 ohm resistor in my circuit. Here is a picture of the circuit and the Fritzing diagram showing how to hook it up to an Arduino Leonardo:


TVOut RCA Jack Circuit Top ViewTVOut Fritzing Graphic








If you want diagrams’ Fritzing source file, download it from here.

I tried the TV Video output from the Arduino at first with my Arduino of choice, a Leonardo, and found that it did not work when the Leonardo is powered from a USB cable attached to a PC. The screen flickered too much. When the Leonardo was powered from a wall plug or battery, it functioned perfectly. I found that other Arduinos (the Uno or Mega) work fine from a PC USB power connection. Depending on which arduino you use, you will need to adjust where the video and sync pins are connected. There is a handy chart on the TVOut Arduino Playground documenting the pins used for various arduinos.

For small projects and portability, an LCD is great to use to display output from an Arduino. However, if your next project needs to display data from an arduino so more people can see it (perhaps a large screen TV), you might consider using the TVOut library and this simple circuit.

The TVOut library has a sample NTSC demo sketch. Here are two of the captured TV screens it outputs:


TV Video Output from the Arduino TV Video Output from the Arduino

Jun 20

LM317 to output 3.3 Volts

I created a simple circuit using the LM317 to output 3.3 volts from a 5V or greater input voltage. Why? Because, a number of modules for the Arduino (or Pinguino) take 3.3 Volts. It’s true, some of the Arduinos do have a 3.3V voltage regulator (and thus a source of 3.3V), however, that might not have sufficient amperage. Also, if  you are a fan of the DIY (Do-It-Yourself)  Pinguinos (as I am), you will need a 3.3V source to accompany them since they do not have one.

So, it is quite handy to have a 3.3V power source around! Here is what the circuit looks like:

LM317 3.3 V Circuit Top ViewLM317 Circuit Side View

I save the foam pads, that came with PC motherboards I bought, and cut out pieces to place under the circuits I make to protect against short circuits. The pads are held in place with two-sided sticky tape.

Here Is the Fritzing circuit diagram:


LM317 3.3V Circuit Diagram

If you’d like the Fritzing source to the above diagram, download it from here.

The LM317 is an adjustable  linear voltage regulator. It can take an input voltage of 3-40 Volts DC and outputs a fixed voltage from 1.2 to 37 Volts DC. The output is controlled by resistors on the adjustment pin. Here is a handy calculator to calculate the resistance needed to obtain the desired output voltage. I use 545 Ohms (470 + 75) to output the desired 3.3V.

Notice that I have a two pin header or a power jack as input source (on the right of the pictures) and the output is a two pin header (on the left in the pictures).

I tested this circuit using the ESP8266 and the NL6621-Y1 modules that I wrote about in earlier articles. These modules require 3.3V and both worked fine.

I thought about integrating this circuit on the DIY Pinguino boards I made and might do that next time I get around to making more of them. However, I think the stand alone circuit is more flexible to use. For example, you can attach a USB to RS-232 cable (like this):

USB to Serial Cabledirectly to the circuit (5V Input and GND) and to the wireless module (Tx and Rcv from the cable, 3.3V and GND from the circuit)  and not even need an Arduino / Pinguino.

Jun 01

Serial Port Communication via Python

There are many Linux (and Windows) programs ‘out there’ that allow you to do serial port communications.  However, I needed some things that those programs did not provide (on my Linux system) so I came up with my Serial Port Communication via Python script. If you want something that you can learn from and/or customize further this script is for you (if you are using Linux that is). Here is the script:

                                Serial Port Communication via Python

It takes from zero to two parameters. Given no parameters, it defaults to 115200 BAUD and will search for ‘active’ serial ports with the name /dev/ttyUSB* or /dev/ttyACM* and use the first one it finds. If you want to override or specify either the serial port or BAUD rate just give it either or both parameters. If you give it both parameters, they can be in any order as the script can tell what is a port versus what is the rate. When running, the script will ‘echo’ any characters coming from the serial port to the console and ‘echo’ any characters typed in from the console to the serial port. Use a Ctrl-C to exit the script. Note that the comments tell you how to change certain features of the program.

With this script you have basic serial port communications (quite usable) and it can be easily added to for enhanced functionality.

Again, there are other serial communication programs/scripts (which run under Linux). Perhaps the most common one used is minicom. Another quite useful program is screen.  Although screen is primarily used as a terminal multiplexer (i.e. using virtual terminals in a login session), it can be used as a serial terminal communication program too. For example:

screen /dev/ttyUSB0 115200

Also note that the Arduino IDE has a built in serial monitor (the newer versions have a serial plotter too) so that serial communications with your Arduino is relatively easy during code development. The Pinguino IDE does not have a serial monitor built in so my script can be used for that sometimes needed functionality.

You may notice that this script is an updated version of one I wrote about before (here) which I used to communicate with the Arduino MiniPirate sketch.

If you do put my script to use or enhance it, i’d be interested to see what features you add. Leave a comment!

May 27

FS1000A Wireless RF433 Transmit and Receive Module Pair

I like experimenting with wireless devices, as you can tell from the many posts about them here! 😎 I am trying out an FS1000A Wireless RF433 Transmit and Receive Module pair this time.

They use use the RF 433Mhz  frequency with ASK modulation. (You can also get these with the 315Mz frequency instead.)  I got mine from  They look like this:

FS1000A Wireless RF433 Transmit and Receive Module Pair


FS1000A RF433 Transmit and Receive Module PairHere is a graphic on how they work together:

FS1000A Wireless RF433 Transmit and Receive Module PairBasically you can use one Arduino to control the Transmitter and one Arduino to control the Receiver. An Arduino RF library comes in handy for that. In the past, you’d use the VirtualWire library for controlling these modules, now however, there is a better library called RadioHead which supersedes it. Download it from HERE. Once you install it from the Arduino IDE (Sketch -> Include Library -> Add .ZIP Library) there will be a number of examples to choose from. You can use the File -> Examples -> RadioHead -> Ask -> ask_receiver and ask_transmitter sketches.

I modified them a bit as shown below.

Here is the sketch for the Arduino Receiver:

Here is the sketch for the Arduino Transmitter:

As you can tell from the comments in the code, they are very easy to hook up. Both use only three pins (VCC, GND and DATA). Here is the Fritzing Diagram showing how they are connected:

FS1000A RF433 Transmit and Receive ModulesYou can download the custom fritzing parts from here. If you want my fritzing diagram, download it from here.

May 24

NL6621-Y1 Wireless Module

There is a new kid on the block, the NL6621-Y1 Wireless Module from Nufront.  The NL6621 WiFi SOC is powered by a 160 MHz ARM Cortex-M3 (NL6621M). Everything is integrated in the NL6621M SOC including 448KB of RAM.

Here is what the NL6621-Y1 wireless module looks like:


The NL6621-Y1 wireless module Back Image The NL6621 wireless module Front Image The NL6621 wireless module PCB Layout





Supposedly it is much better than the ESP8266 from Expressif. However, the ESP8266 has a lot of code and documentation for it whereas there is very little information or code for the  NL6621-Y1 wireless module.  There is a dedicated forum for the NL6621 HERE but there does not seem to be much traffic on it yet.

Nufront does have several GitHub repositories for it here:

The common module (NL6621-Y1) seems to have the NL6621_SerialNet_SDK installed as that is what services the serial AT command set which allows the module to be configured via a serial interface.

I have the NL6621-Y1 wireless module from Elecrow and I wanted to see if I could get it working (attached to an Arduino Leonardo) similar to how I attached an ESP8266 in an earlier post.

Hooking it up, hardware wise, is a breeze. Attach the NL6621-Y1 3.3V pin to the Arduino 3.3V pin, GND to GND, NL6621-Y1 TXD to Arduino RXD and NL6621-Y1 RXD to Arduino TXD.

Arduino Leonardo connected to an NL6621The NL6621 Wireless ModuleAt first, I used the multiserial mega Arduino script (HERE) to experiment with the AT commands. That script basically takes characters you type in the serial console and sends them to the 2nd serial port and it echos any data coming from the 2nd serial port to the 1st.  I set both serial port BAUD rates to 115200. Sending “AT+HELP” will list all the supported AT commands.

Searching GOOGLE I could not find any information on the AT command set so I took a look at the SerialNet SDK source. Here is a chart showing what I gleaned from that code:

NL6621-Y1 Wireless Module AT commands

Example: Enter DataMODE



(then telnet to the IP address of the NL6621 on port 8101)

+++ (exits back to CMD Mode)


Example: Scan for Wireless APs



Example: Set NL6621-Y1 to be an AP

AT+WQSOPT=2,11,3,3,0                     //SOFTAP,11,ccmp,wpa2,disable
AT+WSCAP=nufront,123abcdef,0        //SSID,password,retries
AT+IPCONFIG                                      //Show IP configuration


Example: Set NL6621-Y1 to STATION mode and connect to an AP

AT+WQSOPT=0,11,3,3,0                                //Station,11,ccmp,wpa2,disable
AT+WSCAP=your_ap_ssid,yourpassword,5   //SSID,Password,retries
AT+IPCONFIG                                                 //Show IP configuration


Here is an Arduino sketch which sets the wireless options and connects the NL6621-Y1 wireless module to my TP-Link router. Note: If you use this code make sure to change the SSID and PASS variables to match your router!

The NL6621-Y1 Wireless Module Arduino Sketch

One thing I don’t like about the NL6621-Y1 is that it does not have a unique (i.e. official)  MAC address. When you send this:  AT+MAC  the result is +OK=MAC:00:01:02:03:04:05.

Anyway, it will be interesting to see what the open source community comes up with to do with this new wireless chip.

May 20

How to Power an LED (Arduino vs. Pinguino)

How to Power an LED (Arduino vs. Pinguino) might seem silly, however, if you take a look at the following graphic, you will hopefully notice something interesting. The Pinguino sources the power to the ‘user’ LED differently that does an Arduino. The Pinguino wiring is represented by the green LED and the Arduino wiring is represented by the red LED.


How to Power an LED (Arduino vs. Pinguino)

How to Power an LED (Arduino vs. Pinguino)

The Arduino powers the LED via a Pin connection versus the Pinguino which sources power to the LED from VCC. So when you write your code to turn on/off the LED notice also the differences. To turn on the Pinguino user LED the Pin is brought LOW via digitalWrite(USERLED,LOW) and turned off via digitalWrite(USERLED,HIGH). Notice this is the opposite to the Arduino code. To turn on the Arduino user LED (on Pin 13 usually) the Pin is brought HIGH via digitalWrite(13,HIGH) and turned off via digitalWrite(13,LOW).

The Pinguino IDE has a ‘built-in’ variable USERLED which references the pin for the user LED on the target Pinguino board. The Pinguino IDE also has a ‘built-in’ toggle() function:


to do basically the same as:

digitalWrite(USERLED, !digitalRead(USERLED));

If you code and run the standard ‘blink’ sketch or just toggle() you might not notice or care about the difference in wiring, as the LED blinks (regardless of whether it was on or off initially).

May 13

I2C Wire Chat Between Two Arduinos

Someone asked me the other day if it was possible to have a ‘chat’ between Arduinos using the I2C Wire library. I came up with  ‘proof of concept’ code called ‘I2C Wire Chat Between Two Arduinos’. Here is the sketch:

I2C Wire Chat Between Two Arduinos

Setup two Arduinos connected by a length of CAT5 cable (you really only need 3 wires). Connect Analog Pins 5 (SCL), 4 (SDA) and Ground as shown in this Fritzing diagram:

I2C Wire Chat Between Two Arduinos

I2C Wire Chat Between Two Arduinos

Make sure each serial port is set to 9600 BAUD and type: #s in one Arduino and #m in the other making sure that ‘New Line’ is sent as the end character. This will put one in slave mode and the other in master mode. Due to the design of the I2C Wire library one has to be master and one slave. Only the master can send data (the slave receives), so it is not simultaneous transmit/receive. Whatever is typed in the master serial console is sent to the slave which displays it on its serial console. To switch back and forth (master <=> slave) just alternate the #s and #m. So you can in essence have a ‘chat’ with the I2C Wire library.

It basically functions the same as a Walkie-talkie radio.

One could even take the sketch further to automatically switch the master to slave and slave to master. For example, when the master is finished it could send a # as the last character which could function as the toggle. I will leave it to the reader to implement this. 😎

Well.. OK.. just so you can see how the code develops, here is the final version with the ‘toggle’ master/slave being the ‘#’ as the last character in the transmission buffer:

I2C Wire Chat Between Two Arduinos  [Final Version]

Over and Out!

Older posts «