This tutorial shows how to communicate between Embrio programs running on different Arduinos. It does this with custom Arduino nodes that use I2C via the Wire library.

This tutorial uses these pre-built nodes:

View Comments (0)

This simple project will show how to make 2 Arduinos communicate using I2C. In the example just to illustrate the process as simply as possible I’m using one Arduino Nano to records a potentiometer value, and another Nano to control an LED with that value. In a real world situation you might have a sensor that takes up a lot of resources or is really slow, and you can use this technique to isolate it from the rest of your project. For example a temperature and humidity sensor can take several hundred milliseconds to read a value, which would mess up the main Embrio program.

I’ll start the project by plugging 2 Nanos into my bread board. Decide which is the master and which is the slave. Plug the master’s ground and 5 volt output into the power channels, then plug the slaves ground into the ground channel, and the VIN pin to the voltage channel. Next to the slave I plug in a potentiometer, attach one side to ground, the other side to voltage, and the middle pin to an analog in pin, I’ll use A1. Next to the master I plug in an LED, with the small leg stuck in the ground channel and the big leg connected to a resistor, which connects to one of the PWM pins, I’ll use pin D3. The wiring for I2C is very simple, just connect pins A4 and A5 to each other. If you’re using another kind of Arduino you’ll have to look up which are the I2C pins and use those.

This example will have 2 Embrio projects, one for each Nano. I’ll work on the slave project first, so I plug my USB cable into the second Arduino and open up Embrio. I make a new project called I2C Test Slave. To read the potentiometer I add an Analog Input node and select pin A1. To write via I2C I’ll go to the library toolbar and find the premade node in the Outputs folder. Keep in mind that this library is constantly changing, so when you go through this tutorial the node might have moved. I drag the node onto the node screen to make a copy of it. This node is pretty simple, it has an input activation which it sends using Arduino’s Wire library. Note that the input activation is transformed to a byte before being sent. Also notice that the update code block is set to Input Changed, which means it will only fire when the input activation changes. All I have to do now is hook my input node into the Arduino node and upload my program.

Now I’m going to plug my USB cable into the other Arduino. I make another project which I call I2C Test Master. From the Library I find the I2C Read node and drag it onto the node screen. This node simply listens for a message and when it gets one, converts the byte to the output activation value. If I connect to the Arduino, I should be able to see the potentiometer value being sent by the other Arduino. All that’s left to do now is add an analog output node and connect the activations. Now I can use a value recorded by one Arduino in a program running on another Arduino. This technique not only opens up a lot of flexibility when it comes to isolating components of a larger project, but also serves as an example of how to integrate any component that communicates via I2C.

View Comments (0)