*arg max *arg min
CSCE 236 Embedded Systems, Spring 2015
Lab 6


Thursday, April 16, 2015
Names of Group Members:


1  Instructions

This is a group assignment to work on during class. You only need to hand in one copy of this, but make sure that the names of all of your group members are on this sheet to receive credit. Complete all of the sections below and make sure to get the instructor or TA to sign off where required. You should keep your own notes on what you complete since parts of future homework will build on this lab.

2  I2C Inter-Robot Communication

In this section we will modify the sample I2C code from the Arduino library to enable bi-directional communication between two Arduinos connected together. The Arduino calls their I2C library Wire1. Look at the Arduino example code for the Wire library, in particular the master_writer and slave_receiver.
Now, connect your Arduinos' I2C buses together. First, you must connect the grounds of the two boards together (to give them the same voltage reference). Then connect the SCL and SDA pins together. SCL is on pin A5 and SDA is pin A4 (they are also available above the AREF pin if you prefer). Test the master_writer and slave_receiver to verify that they function together correctly.
Checkoff: Show the sample Arduino code working on your Arduinos.
It turns out that with I2C a device can be both a master and a slave. Now, write code so that when one of the buttons is pressed, the light on the other Arduino will turn on. To do this, you simply need take the slave_receiver code and in the main loop add a transmission (same as from master_writer) whenever the button is pressed or released. You can use identical code on each Arduino, just make sure you switch the addresses. In addition to turning on the other's LED, print over the serial port "my button pressed" and "other button pressed." Note, you should not send this whole string over I2C, you should just send a single character (e.g. 'p' for pressed). In addition, due to the way the library works you may have problems if you try to print too much within these functions as both I2C and the serial library require interrupts.
Checkoff: Show the code turning on and off the other Arduino's LED and the serial printing. Note that it should work from board A to B and from B to A.

Footnotes:

1 I 2 C i s g e n e r i c a l l y k n o w n a s a ` ` t w o -w i r e i n t e r f a c e ' ' ( T W I ) b e c a u s e u s i n g t h e I 2 C n a m e u s e d t o r e q u i r e p a y i n g a l i c e n s i n g f e e . S M B u s i s a s t r i c t e r s u b s e t o f t h e I 2 C p r o t o c o l a n d i s o f t e n u s e d o n c o m p u t e r m o t h e r b o a r d s t o c o m m u n i c a t e w i t h l o w - s p e e d p e r i p h e r a l s ( e . g .   a t e m p e r a t u r e s e n s o r o n t h e m o t h e r b o a r d ) . I n o t h e r w o r d s , t h e r e a r e t h r e e n a m e s ( I 2 C , T W I , S M B u s ) t h a t a l l r e f e r t o b a s i c a l l y t h e s a m e i n t e r f a c e a n d p r o t o c o l .


File translated from TEX by TTH, version 4.03.
On 15 Apr 2015, 11:40.