They forgot we worked hard

PDFPrintE-mail
15Jun2011
Last Updated on 15 June 2011 | Written by CodeAsm

Like many schools, sometimes teachers forget that when you work in a team and some of the team members speaks and nobody else really say anything, its a wrong assumption that they dint do anything or know nothing.

But before I tell to much before I give skool a change of defence ill tell you that during the project GetConnected I needed to add 2 new IO expanders and theyre adress space apeared diferent. Ofcourse I coald have know that, but when you have 2 hours remaining, its a short time for datasheet searching.
but in the end I did looked at it and spottet that a PCF8574N and PCF8574AN just difrenses in adress 00100xxx and 00111xxx where xxx is the adress you set on the adress lines.

For anyone intrested, ive added the complete Arduino code after the break. Next time ill upload our full java code. To fully explain the code ill later make a document explaining the whole workings.

Ow and its a bit dirty, we did understand it could have been done more "cleaner". sorry for that.

 

 

Full source of GlobaCOM:

#include <Wire.h>
//#include <avr/pgmspace.h> // Not used ?!?

/*  @Author: Nicky en Nico
*   @Date: 6-5-2011
*   @Version: 4.6
*  
*   @input
*   4 chips (PCF857a) tru I2C protocol expanding 8bit I/O by just 2 wires
*   Up to 45 input "buttons" are selected, so not to much "interconnections" can be made by mistake.

*   @output
*   The Arduino setup is selectively checking for updates on the Inputs and at a buttonpress its
*   Sending the correct Country number over serial. with is listened to by a java app.
*/ 

int IC0 = B00100000;                  //PCF8574 ID of chip 1
int IC1 = B00100001;                  //PCF8574 ID of chip 2
int IC2 = B00100010;                 
int IC3 = B00100011; 
int IC4 = B00111000;                  //PCF8574A ID of chip 4
int IC5 = B00111001;   
byte ReadIc0;                         // Read bytes are put in here
byte OldIc0;                          // To check for updates, a ReadIcX is compared to its older version

byte ReadIc1;
byte OldIc1;

byte ReadIc2;
byte OldIc2;

byte ReadIc3;
byte OldIc3;

byte ReadIc4;
byte OldIc4;

byte ReadIc5;
byte OldIc5;

int IC[] = {IC0, IC1, IC2, IC3, IC4, IC5};                      // A array of Chip ID's
int ReadIc[] = {ReadIc0, ReadIc1, ReadIc2, ReadIc3, ReadIc4, ReadIc5};  // Array of storage of the last read
int OldIc[] = {OldIc0, OldIc1, OldIc2, OldIc3, OldIc4, OldIc5};       // Array of bytes to compare to

void setup()  //Arduino setup function, Default
{
Wire.begin();                                         // Start the I2C library, included.
Serial.begin(9600);                                   // Setup an Serial connection with speed at 9600 baud
}

void loop(){  //Arduino Loop fucntion, default (This is run again after finish)
for(int i = 0;i < 6; i++){                            // For each I/O expander chip 0,1,2 and 3
Wire.requestFrom(IC[i],1);                          // Ask for data from chipX
if (Wire.available()){                              // If the chipX response, else go to the next one
OldIc[i] = ReadIc[i];                             // Place old data in OldIcX
ReadIc[i] = Wire.receive();                       // Read the availeble data from ChipX and place in ReadIcX

if (OldIc[i] != ReadIc[i] && ReadIc[i]  != 255) { // If the data compared is new and not 255(no buttons pressed)
Serial.print(i,DEC);
Serial.println(ReadIc[i],HEX);                  // Send the read information over serial.
}
}   
}
delay(125);                                            // Delay a bit so multiple presses are detected like 1.
}

/*Logfile removed for privacy

code made for HvA getConected project 2011

*/