background preloader

Raspberry Pi and Arduino Connected Using I2C

Raspberry Pi and Arduino Connected Using I2C
With Raspberry Pi and I2C communication, we can connect the Pi with single or multiple Arduino boards. The Raspberry Pi has only 8 GPIO’s, so it would be really useful to have additional Inputs and outputs by combining the Raspberry Pi and Arduino. There are many ways of Linking them such as using USB cable and Serial Connection. Why do we choose to use I2C? In this article I will describe how to configure the devices and setup Raspberry Pi as master and Arduino as slave for I2C communication. In the next article I will be doing some Voice Recognition, if you are interested see here Raspberry Pi Voice Recognition Works Like Siri The Raspberry Pi is running at 3.3 Volts while the Arduino is running at 5 Volts. The reason it works is because the Arduino does not have any pull-ups resistors installed, but the P1 header on the Raspberry Pi has 1k8 ohms resistors to the 3.3 volts power rail. These are the images showing where the I2C pins are on the Raspberry Pi and Arduino. i2c-dev Related

arduino uno - How do functions outside of void loop work? - Arduino Stack Exchange The setup() and loop() functions are unusual because they are called automatically for you by the Arduino code. No other functions behave this way. Generally speaking, a function will never run unless you explicitly call it yourself (e.g. from within setup() or loop()), or instruct another part of the program to call it. (There are other ways to execute functions, but that usually involves some very advanced tinkering which is best avoided.) For example, pinMode() is a function just like any other. It only runs when you actually put something like pinMode(3, INPUT) in your code. The example code you've posted is quite interesting. Wire.onReceive(receiveData); Wire.onRequest(sendData); These lines are telling the Wire object to call receiveData() and sendData() in response to I2C events. I'd recommend searching for information about C/C++ function pointers online if you want to learn more about this.

effects-of-varying-i2c-pull-up-resistors Details Created: December 18 2010 Figure 1 I2C is a popular communication protocol in embedded systems. Since the Arduino is a popular micro-controller among hobbyists we'll use it for the following examples. We'll set up our oscilloscope to measure rise time, frequency and peak voltage. Let's take an initial reading using just the Arduino's internal pull-up resistors. Figure 2 As you can see in Figure 2, the signal eventually takes on a square shape which is what we like to see. Next, we'll use the same circuit, but this time let's switch from Standard mode to Fast mode (400kHz). Figure 3 the rise time is very slow with respect to the clock frequency. Figure 4 Arduino Tutorial - Learn electronics and microcontrollers using Arduino! So, I get two or three emails a day, all basically asking the same thing: "Where can I learn about electronics?" In general, most of these people have seen some of my projects and want to be able to build similar things. Unfortunately, I have never been able to point them to a good site that really takes the reader through a solid introduction to microcontrollers and basic electronics. I designed this tutorial course to accompany the Arduino starter pack sold at the Adafruit webshop. The pack contains all the components you need (minus any tools) for the lessons Follow these lessons for happiness and prosperity. Lesson 0 Pre-flight check...Is your Arduino and computer ready? Here are some recommended tools: If you need to get any soldering done, you may also want.... All of the content in the Arduino Tutorial is CC 2.5 Share-Alike Attrib. Love it? To some extent, the structure of the material borrows from: The impressively good "What's a microcontroller?"

Arduino Tutorial - Lesson 5 We've done a lot so far, blinking lights, printing messages...all of that stuff is output: signals coming from the Arduino. The next step is to start playing with input, with the Arduino responding to outside events. In this lesson we will begin with the most basic kind of input, a push-button switch! You're probably familiar with switches, there's tons of them in your house. On the left, the switch is open and no current flows. (thanks wikipedia!) In this photo, you can see the internals of a light switch. Light switches are great but we need something smaller. These little switches are a 1/4" on each side, cost about 25 cents, and can plug directly into a breadboard. Normally, the two wires are disconnected (normally open) but when you press the little button on top, they are mechanically connected. To get the buttons to sit better in the protoshield, you may want to straighten out the legs (just squish them with a pair of pliers) so that they look like the button on the left. Fig 5.2

Arduino Tutorial - Lesson 4 - Serial communication and playing with data Ah, Arduino, I remember when you were just crawling around and blinking LEDs. Now you're ready to learn how to speak! In this lesson we'll learn how to use the Serial Library to communicate from the Arduino board back to the computer over the USB port. Then we'll learn how to manipulate numbers and data. For this lesson we won't be using the shield, so simply remove it (keeping the mood light LEDs on it you'd like). Libraries are great places, and not yet illegal in the United States! Software Libraries are very similar. The library we will be using is the Serial Library, which allows the Arduino to send data back to the computer: Serial may sound like a tasty breakfast food, but its actually quite different. Information is passed back & forth between the computer and Arduino by, essentially, setting a pin high or low. This is as good as Microsoft Visio can do, yay! (Now, people who are all geeked-out will probably get angry at this point because I'm simplifying things. So...click it!

Arduino Tutorial - Lesson 3 - Breadboards and LEDs You've started modifying sketches, and played a bit with the onboard LED (or if you have an NG, an LED you added). The next step is to start adding onto the hardware component of the Arduino. We will do this by adding a solderless breadboard to our setup, connecting up new parts with wire. Solderless breadboards are an important tool in your quest for electronics mastery. Basically, a chunk of plastic with a bunch of holes. In the images above you can see how there are two kinds of metal strips. In this lesson, we will show pictures of both the tiny breadboard on a protoshield and also using a 'standard' breadboard without a shield. Warning! Distressing as it may sound, solderless breadboards can be very flakey, especially as they age. To use the breadboard, you'll need jumper wires. Heres how to do it with just diagonal cutters...Cut the wire first, using wire cutters Nick the insulation, then pull it off. The resistor is the most basic and also most common electronic part. Look again!

Arduino Tutorial - Lesson 2 - Modifying the first sketch OK you've gotten your Arduino set up and also figured out how to use the software to send sketches to the board. Next step is to start writing your own sketches. We'll start off easy by just modifying something that already works. To start we will venture deep into the Blink sketch, looking at each line and trying to understand what its doing. Then we will start hacking the sketch! Start up the Arduino software and open the Blink example sketch, as you did in Lesson 1. The sketch itself is in the text input area of the Arduino software. Sketches themselves are written in C, which is a programming language that is very popular and powerful. int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); } Lets examine this sketch in detail starting with the first section: This is a comment, it is text that is not used by the Arduino, its only there to help humans like us understand whats going on.

Arduino Tutorial - Lesson 1 - Let there be blink! Ah yes, it is finally time to make your Arduino do something! We're going to start with the classic hello world! of electronics, a blinking light. This lesson will basically get you up and running using the Arduino software and uploading a sketch to the Arduino board. Once you've completed this step we can continue to the really exciting stuff, which is when we start writing our own sketches! These instructions mostly show Windows software. Not much is needed for this lesson, just a USB cable and an Arduino. Make sure you've gone through Lesson 0 first! The first thing to do is download the Arduino software. Go to the Arduino Software Download page and grab the right file for your OS. The packages are quite large, 30-50 MB so it may take a while to finish Extract the package onto the Desktop Windows Mac OS X Double click the Arduino software icon To open up the workspace I think I get the red error text shown because I already have Arduino installed. Windows port selection Mac port selection

Arduino Tutorial - Getting ready This lesson won't teach any electronics, really. Its more for making sure that everything is setup and ready for the future lessons. It will verify the Arduino is working as intended and that the computer you are using is compatible. For this lesson you will need some stuff! Take your Arduino out of its protective bag. Diecimila Arduino Or like this: NG Arduino If there's anything missing or really wrong, make sure to contact the store you bought it from. OK, now that you are satisfied that your Arduino looks good, put the rubber bumpers on the bottom of the board. Depending on which Arduino and which OS you have there are different instructions Now we are ready for the moment of truth, it's time to plug your Arduino in and power it up. The jumper-setting step is only for Diecimila and OLDER arduinos! You'll want it set as shown in the picture above. Make sure your cable is a A-B cable. Plug the thin end into your computer Plug the square end into your Arduino If not, double check:

EAS 199A: Fall 2012 :: Using Arduino This page provides links to class notes and on line instructions for the Arduino microcontroller platform. All students in EAS 199A are required to purchase their own Arduino board, which is part of the Sparkfun Inventor's kit. The kit is available from the Textbook Information Desk at the PSU Bookstore. See below for advice on avoiding pin 0 and pin 1 for digital I/O. Arduino Home From the Arduino home page: Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. On the Arduino web site you will find The getting started guide has detailed pages on installing the Arduino IDE: Install the Arduino IDE on Windows 7 ( the Arduino IDE on Mac OS X ( the Arduino IDE on Linux ( Manual for the Sparkfun Inventor's Kit Adafruit Tutorials Adafruit Industries designs and sells electronics kits and components.

Related: