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!

Arduino as a Network Monitor

I have set up an Arduino as a Network monitor so I can be silently alerted if a WEB server on the LAN/Internet goes down. In a previous post, here, I show the relay circuit I am using in this sketch to flash a CFL lamp. This sketch also uses the same ENC28J60 module to connect to the LAN/Internet.

Arduino Leonardo and SPI Communications using the ENC28J60 ethernet moduleThe uniqueness of this code is that it uses PING against multiple servers. I tried and tried to get this function using the UIPEthernet library working without success. I finally switched to the EtherCard library and found the solution for PINGing multiple servers. The EtherCard library also solves the problem of the CS Pin on the Arduino Leonardo that I document here. (The EtherCard library allows the code to select which pin will be used for the CS pin.)

There are several interesting things to note about this sketch:

  1. It uses PROGMEM so the IP Addresses are preserved thru each PING loop
  2. The IP address for the ENC28J60 module is dynamically set (the comments show how to switch to a static IP)
  3. MAXCYCLES can be set to re-ping and not alert in case your LAN is not perfect (the device you are pinging might miss a few)
  4. Since this is wired as a temporary setup, I blink the light when the sketch first starts to make sure the wiring is correct
  5. An LCD is used to display the IP address and millisecond PING times (this same info is also displayed to the serial port)

Here is the sketch:

To use it in your environment, change the IP addresses to PING (and number of them) to suit your LAN. Also see the comments to use a static versus dynamic IP address for the monitor itself.

Emergency Phone Call Alert to an Arduino via an Asterisk PBX

Recently, I created this simple circuit (and corresponding code) which makes an emergency phone call alert to an Arduino via an Asterisk PBX.  This project was for someone who needed to be alerted (silently) if someone made an emergency phone call on their Asterisk PBX. By the way, the free and open source Asterisk PBX is a fantastic phone system which can be easily adapted (via custom scripting) to do amazing things!

For this project, the Asterisk dialing plan for the emergency number is set to invoke an AGI script (which in this case was written in python). The AGI python script reads the SIP configuration and creates an Asterisk call file for each SIP peer which puts them all in a conference room. The scenario for this is something like a condominium where there might not be a dedicated person to answer the emergency call, instead everyone in the building (so to speak) is called. The python script also accesses the WEB page of the server running on an Arduino which will rapidly flash an “emergency” light.

I created this simple relay circuit with an S108T02 solid state relay to control the light (CFL). Here is the Fritzing diagram:

S108T02 Relay Fritzing Diagram

You can download the Fritzing code for the circuit here and modify it for your needs. Here is what the circuit looks like when it is built:

S108T02 Relay CircuitEmergency Phone Call Alert to an Arduino via an Asterisk PBX Circuit


Note that the board is about double the size needed so I can add a second relay if future needs require.  🙄

The Arduino code uses the UIPEthernet library to basically create a WEB server. When it is 1st accessed the light is turned on. Access it again and it is turned off. It is a ‘toggle’ so it can be tested from a browser client.  The circuit is attached to an arduino via the pinToToggle value (and also +5V and GND). Additionally the Arduino is connected to an ENC28J60 module for LAN/Internet access. See my previous posts here and here for connecting an Arduino Leonardo to an ENC28J60.

Here is the Arduino code:

The python AGI script:

If you try this out make sure to change the IP addresses in both scripts to match that of your Arduino. Also note that the python AGI script emails someone that the call was made. Check out the bottom part of the AGI script and change the email address to the correct one. (Or comment out that part if you don’t want it to email anyone.)

Do-It-Yourself Pinguino PIC18F4550 Board

I just got a good deal on several PIC18F4550 chips. So, I decided to make a Do-It-Yourself Pinguino PIC18F4550 Board to test them out. The Pinguino boards are based on the same concept as an Arduino. However,  instead of Atmel chips, Microchip PIC® chips are used. All of the Pinguino boards use PIC® chips with on board USB, so the boards are quite easy to access/program. The goal of the Pinguino project is to bring the simplicity of Arduino language to the Microchip PIC® microcontrollers with built-in USB hardware. (Visit the Pinguino project WEB site here.)

The IDE for the Pinguino boards is similar to the Arduino IDE and sketches are also similar, so Arduino users should feel right at home.  Pinguino Hardware and Software, like the Arduino, is all Open Source.

Here is a schematic, a breadboard layout and the DIY Pinguino circuit board I created using the PIC18F4550 microcontroller chip:



Pinguino PIC18F4550 Fritzing Diagram



Do-It-Yourself Pinguino PIC18F4550 Board

Do-It-Yourself Pinguino PIC18F4550 Board

You might notice that in the circuit I built (although not shown in the schematic),  I added a 6-pin ICSP header so I could initially load the bootloader by attaching a PICkit 3 programmer:


The PICkit 3  plugs nicely into the 6 pin header. The graphic above shows how the ICSP pins of both the PICkit and PIC18F4550 are connected. The bootloader (Version 4) I used can be downloaded here.

Here are the top and back views of the board:


I soldered on  four 10-pin female headers so that connections can be easily made to any pin. I also plugged in two 10-pin male-male headers (un-plugable) so that I can use any jumper wire that I may have around.  The male header PINs between the LEDs are all wired to +5V and the male header PINs at the other end of the board are all wired to GND so there is easy and ample connection to either. I used a type B female USB connector (so it fit the USB printer cables I have so many of).

usb-B-pinout usb2-Bpinout-600



If you’d like the Fritzing diagram for this board you can download it here or the original SVG graphic here. For more information about the Pinguino project visit their Wiki.

Controlling and Monitoring an Arduino Galileo via Node.js

It is very handy to be able to control and monitor things with an Arduino. It is even more handy when you can control and monitor things remotely from wherever you are via the Internet. For arguments sake, lets say we want to both control specific devices we have attached to our Arduino and we want to know when certain events happen (that sensors attached to our Arduino can tell us about).

For the controlling part we could use a WEB application but the WEB is not good for monitoring. This is because the WEB is stateless, it is not a true two way communications system. If we really wanted to use WEB technology, we would need to keep polling (refreshing) from our page which is unnecessary overhead. Yes, we could use an XMLHttpRequest, better know as AJAX, however that too is not the right approach for event monitoring.

Event monitoring in the PC world is normally done via Simple Network Management Protocol (SNMP). That complexity is not needed for something we can implement much more simply. The Arduino Galileo runs Node.js (referred to as node) which makes it very handy and easy to implement a means of both controlling and monitoring events. This is because we can add the socket.io module to node and have true two way communications for both controlling and monitoring. The node server running on the Galileo can monitor for events we want to watch and notify any applications/devices connected to it. The node server can also handle any control requests.

For proof of concept, I coded a node server which uses the mraa module to interface with the Galileo GPIO pins. You can download it here.

Copy it to your Galielo, and extract it with:

tar -xvf galileo_node_server.tar

You will also need to install these node modules (via npm):

npm install http socket.io fs ip mraa

Then start the server via:

node galileo.js

The default port is 8888 which you can  override as an optional parameter if you need to. There is an index.html file that node will send to your browser if you browse to that IP and port. Here is what the WEB (node) page looks like.

Controlling and Monitoring an Arduino Galileo via Node.jsBasically it is a ‘chat’ session. Any commands entered will be sent to the node server and ‘echoed’ back to all applications/devices connected to the server. So you can actually use it as a ‘chat server’ too. Any commands that begin with ‘mraa’ are processed using the mraa module. Then syntax of the command is displayed in case of incorrect parameters.

Additionally, I have coded an Apache Cordova application that you can run on your Android smart phone. You can download it here. The complete Cordova source for the apk can be downloaded here in case you want to make changes. When you install and run the apk, it will first ask you the IP address and port where the node server is running. Then it will connect (via socket.io to the node server) and allow the two way ‘chat’. Here is what the Cordova apk looks like:

Controlling and Monitoring an Arduino Galileo via Node.jsControlling and Monitoring an Arduino Galileo via Node.jsThe next step I have planned is to add sensors for monitoring and add code to the node server to send the monitored data to connected applications/devices. It is interesting to note that this same node.js server code (with the mrra code commented out) will run on a Raspberry Pi. The Cordova app would not need modified (however you might want to change the image/logo from the Galileo to a Raspberry).  😎


Update: 12/28/2015 This project is now on GitHub https://github.com/earlt/galileo-node.git

PCDuino Lite – An Arduino with more Power and Flexibility!

For certain Arduino like projects, you might need more CPU power or the flexibility of running Linux ‘on board’. Besides the Arduino Galileo you might consider another device outside the Arduino family, something like the PCDuino from LinkSprite.

I recently experimented with a PCDuino Lite which has 512 MB DRAM, a 1GHz ARM Cortex A8 CPU and a Mali 400 core GPU. It also has HDMI video out, a RJ45 Ethernet connector, two USB ports  and a microSD card slot for loading Linux (Ubuntu 12.04). There are also two microUSB ports (one is OTG and the other is just for power).  It looks like this:

PCDuino Lite Top View

PCDuino Lite Back View

You can access the following interfaces,  UART, ADC, PWM, GPIO, I2C, SPI with programs written in C or Python. Here is a graphic of the pins:

PCDuino Lite Pins

I had several problems once I 1st got Ubuntu (Linux) up and running. Those problems and solutions are well documented here. Additionally I had to use a Class 10 (UH1) microSD card as any lesser class would not boot.  To get access to the GPIO pins, I had to run:

sudo modprobe gpio

to load the GPIO module. This creates the files associated with the pin and the pin mode. Sparkfun.com has a good tutorial on getting started with the PCDuino and one on programming it.

Automated AP-List Scanner for the ESP8266

I recently posted about using the nRF24L01 module to scan for channels in the 2.4GHz range. That will let you know what channels are in use, however, since the nRF24L01 does not have the embedded network stack, we can’t determine other things like what the ESP8266 module can. (Have you checked out the Espressif.com ESP8266 forum? There is a wealth of information there.)

If you are interested in seeing what Access Points are ‘invading’ your space, here is a sketch to list them (runs every 10 seconds):

It is basically a modified version of the MultiserialMega sketch in Examples->Communication. Note: It only works on Arduinos with multiple serial ports (like the Mega or Leonardo). Also, the ESP8266 has to be in AP (Access Point)  mode for this to work (i.e. you may need to uncomment the line which has the “AT+CWMODE=3” command). The wiring for the Arduino <==> ESP8266 is the same as I document in this post.


Using an nRF24L01 Module to Scan the 2.4GHz Frequency Range

There is a lot of electrical ‘noise’ all around us that we can’t see or sense as humans. However, in this day and time we have a great number of electronic devices which can sense what we can’t. Actually, it is these vary same electronic devices in most cases which are the cause of all the ‘noise’.  😯

For example, if you are interested in seeing what frequencies are in the 2.4GHz range (to determine what channel might be best for your WiFi router), you will be interested in the nRF24L01 module from Nordic Semiconductor.  Here is a link to the product specifications.  They look like this:

nRF24L01nRF24L01 Pinout


Here is the Fritzing diagram to wire it up to an Arduino Leonardo:

nRF24L01 Wiring Diagram

If you want to modify the Fritzing diagram, here is the source. This module uses the SPI interface to communicate. Notice that the two ‘radio’ pins in my diagram (CE – Chip Enable  and CSN – Chip Select) are wired to Arduino pins 7 and 8 respectively (this must match what the code is expecting them to be which varies depending upon the library you choose). Also, you may need to place a 10 uf capacitor between +3.3v and ground to stabilize the power supply. These modules use 3.3V not 5V!

You will need an Arduino Library to control the nRF24L01 module, I used the one here. That library has a number of example sketches. The one to use (listed below called scanner.ino) wiil use the nRF24L01 module to scan the 2.4GHz frequency range. Note: I modified the code to use variables for the CE and CSN pins to make it easier to change if needed.


Here is what the output looks like (basically a list of all the available channels/frequencies then a list of what the nRF24L01 found at each frequency):

For your further investigation, there are of course, a number of sites on the internet with information about the nRF24L01 module and I find this one http://arduino-info.wikispaces.com particularly interesting and helpful.

Arduino Galileo

I have been experimenting lately with the Arduino Galileo from Intel. It is not a new Arduino board as it was introduced back in October of 2013. This Arduino has an Intel Quark single-core 32 nm X1000 SoC with a clock rate of up to 400 MHz.  It has several interfaces, including PCIe, UART, I2C, Fast Ethernet, USB 2.0, SDIO, PMC, and GPIO. There is 512K of on-chip embedded SRAM and an integrated DDR3 memory controller. Intel has lots of information about it here. Download the official users guide or the excellent getting started guide from Sparkfun.com.  The Intel Galileo community forum is an excellent source of information too and also a place to get your questions answered.


Arduino Galileo


What makes this Arduino so interesting is that it runs a version of Linux (my favorite OS of choice) called Yocto.  You can get the download image to install on an SD card here.

Once installed you can control this Arduino through Linux (accessing it via SSH)  or via the traditional Arduino IDE. I found Sergey’s log post quite helpful to control the GPIO pins from Linux. You can find a good pin mapping chart here.

This Arduino is more expensive than other Arduinos but has more horsepower under the hood and with the added advantage of Yocto Linux running services such as Node.js and Mosquitto, there are more possibilities for expressing your creativity.

Load more