BLOG > Tutorial 7 for Arduino: I2C and Processing

This tutorial was featured on the official Arduino blog on 3/9/2011

As promised, this week brings another communications tutorial! In this video, we’ll use both the serial and processing knowledge that we gained last week, plus an I2C enabled temperature-sensing IC. We’ll use processing to generate a pretty room temperature display on your computer screen.  If you are new to processing, they have an excellent set of tutorials to help you get started.


You can download the files associated with this episode here:

GNU GPL License Distributed under the GNU General Public (Open-Source) License.
Please Attribute and Share-Alike.


115 comments

  1. P.S. I downloaded an older version of Processing: 1.5.1. and that version works just fine. Still, I’d like to know what’s changed in V 2 that makes such a difference.

  2. Jeremy ~ thanks for all your excellent tutorials. It’s been a tremendous help.

    Can you tell me what the distance limitations are for I2C or SPI communications? What is the best way to achieve long distances between the master and slave devices? I would like to have a string of temperature and humidity sensors as well as be able to control relays connected to ATTiny processors. Any suggestions would be appreciated.

    Mike

    1. I2C and SPI protocols are designed for on-board communication, or ocassionally between boards via board-to-board connectors. If you are looking to go long distance consider CAN bus, RS-485, UART, or USB.

  3. Yes, I had thought that might be the problem too Jeremy. But now Processing version 2.1.1 has been released and while it does seem to accept the “readStringUntil(‘.’)” command it still hitches up on the “substring()” functions and shuts down the serial port without finishing parsing the data. I used some print() commands to see what is happening on the serial monitor. I can see that the readStringUntil(‘.’) is doing what it should do, but there are spurious ‘null’ signals coming through every once in a while between the expected data and processing is telling me it can’t deal with the ‘null’ data so it shuts the serial port down. I checked the Arduino side and the serial monitor shows consistently clean data coming from the Arduino. There are no spurious ‘null’ signals coming from the Arduino. So, I’m guessing that there must be some larger incompatibility issue with Processing and the newest version Mac OS 10.9.1. Maybe some sort of Java incompatibility? Even the older 1.5.1 version of Processing is fragile. It works most of the time but it too has a tendency to freeze up and there are Java mismatch error messages showing that I don’t understand. I wonder if anyone else is having trouble using Processing on their Macs?

  4. Hi Jeremy,
    Videos are brilliant but is the Arduino able to ‘point’ to an Address in the chip and then just read from that address alone and not then entire data on the chip. e.g 0x1C would be the chip address point to 0x0A then write whatever was needed. so can i just read back from this address and not have the pointer start at 0x00??? This could be the simplest thing but my head is melted!!!! Thanks.

  5. Dear Mr. Blum,

    I have read so many tutorial that my head is spinning now, no matter which program I use or code I use it still will not display my data.

    I just used your code with miner alteration and still nothing is displayed, on the version 2.1.1.

    PS. it will not even compile on the 1.5 version.

    please any help?

  6. I am trying to solve a problem

    I am using Arduino DUE to connect MMA7455 Accelerometer of parallax

    http://www.parallax.com/sites/default/files/downloads/28526-MMA7455-3-Axis-Accelerometer-Documentation-v1.1.pdf

    but it seems that I2C doesn’t recognize the entire wiring diagram, please help me because I am in troubles. I tried to copy a lots of codes from arduino.cc but nobody seems to be able to give the right answer. More over in internet many people have the same problem, Now I don’t know if I have to swithc to Arduino UNO.

    Please help me

  7. i have tried a project on arduino in which as i rotate potentiometer the data is to be sended to processing monitor but as i don’t rotating potentiometer then also i’m getting some fixed range random values and while turning potentiometer as well.

    1. hey, you might be having noise problems, connect your potentiometer to the the breadboard and then connect the other end of the potentiometer to a external small value resistor and then the resistor to the ground.

  8. I come across your website with a great Arduino tutorial. Now, I am working on the project that I have to detect the existing of people in the room. I try with motion sensor but it is not working the way I want it to. It sending signal only when people moving. I want to know the existing of the people in that room. Therefore, I found one great sensor that might work, MEMS IR Thermal Sensor – D6T-44-L06. However, it is lacking the tutorial on how to make it work with Arduino. I hope you can share some of your experience with me if you had happened to use that sensor. Thank :D

  9. Hi Mr.

    I need you to help me … How can I connect 2 arduino together??

    one arduino attach to GSM and other attach to some sensors…

    thank you

  10. Jeremy,

    My 13 year old son and I are working on the processing portion of the tutorial on a Mac. We figured out how to reference the mac serial port, but I am still getting the black window with no temps. But when I put in string values for temp_c & temp_f in void draw(), those string values show up in the window so I can see the void draw () is working.

    I don’t quite see in the processing code how the values for the temp get retrieved from from the temp sensor, continually updated, and converted to farenheit like in the arduino code of the first example of the same tutorial. My understanding was that in both arduino & processing void setup runs once and void loop/void draw runs over & over. When does void serialEvent() occur? Does the arduino code need to run simultaneously with the processing code?

    Thanks have enjoyed the series.

    Martin

  11. Hi
    could you please make a tutorial on interfacing D6T-44L Thermal(MEMS) sensor with arduino. It would help us a lot . I don’t see any understandable code in none of the websites. please help me out.

    1. Have you been able to complete it? I am using the same sensor and I am stuck on how to interface it. Would be great if you could help me out with it if you have used it in your project?

  12. Hi Jeremy,

    I don’t know much about Arduino, but I watch your Tutorial and it looks easy so I’m trying to comunicate an air flow sensor and the Arduino by the I2C Protocol and it works great, however, the datasheet of the sensor say that it has a resolution of 10^-3 but I can’t see it in the Serial Monitor I try using float but it only send me values with .000 at the end. I would greatly appreciate it if you could help me.

    Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Advertisement