Show Posts
Pages: 1 ... 202 203 [204] 205 206
3046  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: December 06, 2009, 05:43:59 pm
This is my code, it's working but perhaps not perfect smiley Keep in mind that is my code there is also the part of code that is needed by my rtc.

Code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <WProgram.h>
#include <DS1307.h>

int rtc[7];
byte data[56];
char orario[16]; //non cambiare 16 perchè per qualche motivo non va piu' niente dopo
char dataOdierna[16];
int anno;
int changeScreen = 0;
int k = 0;
int primaAccensione = 0;

#define expander 0x20  // Address with three address pins grounded (B0100000).
                     // Note that the R/W bit is not part of this address.
volatile byte count = 0;


uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = {      0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
  
LiquidCrystal_I2C lcd(expander,8,2);  // set the LCD address to 0x20 for a 16 chars and 2 line display


void setup()
{
  Wire.begin();
  attachInterrupt(0, expanderInterrupt, CHANGE);
 
  Serial.begin(9600);
  lcd.init();        // initialize the lcd
  lcd.noBacklight(); // accende e spegne l'uscita sul pin 12.
                     // lcd.backlight();
                     // sink current +5V------+LED-------330Rresistor------P8574pin
  
  lcd.createChar(0, bell);
  lcd.createChar(1, note);
  lcd.createChar(2, clock);
  lcd.createChar(3, heart);
  lcd.createChar(4, duck);
  lcd.createChar(5, check);
  lcd.createChar(6, cross);
  lcd.createChar(7, retarrow);
  lcd.home();
  
  lcd.print(" System");
  lcd.setCursor(0, 1);
  lcd.print(" Ready.");
  delay(1000);
  for(int i=0; i<9; i++)  {
    lcd.scrollDisplayLeft();
    delay(100);
  }
  lcd.clear();
  lcd.home();
  
  //RTC SETUP
  /*RTC.stop();
  RTC.set(DS1307_SEC,1);
  RTC.set(DS1307_MIN,26);
  RTC.set(DS1307_HR,1);
  RTC.set(DS1307_DOW,4);
  RTC.set(DS1307_DATE,30);
  RTC.set(DS1307_MTH,10);
  RTC.set(DS1307_YR,9);
  RTC.start();*/
  
  for(int i=0; i<56; i++)  {
    RTC.set_sram_byte(65,i);
  }

}

void loop()
{
  RTC.get(rtc,true);

  /*for(int i=0; i<7; i++)
   {
   Serial.println(rtc[i]);
   Serial.print(" ");
   }
   Serial.println();*/

  //rtc[0] --> secondi
  //Tramite questo IF faccio lampeggiare il : per i secondi
  if (rtc[0]%2) {
    sprintf(orario,"%02d:%02d",rtc[2],rtc[1]); //%02d converte 9 in 09 e 32 in 32
  }
  else {
    sprintf(orario,"%02d %02d",rtc[2],rtc[1]);
  }
  Serial.println(orario);
  
  anno=rtc[6]-2000;
  sprintf(dataOdierna,"%02d/%02d/%02d",rtc[4],rtc[5],anno);
  
  
  if (changeScreen==0) {
    lcd.setCursor(1,0);
    lcd.print(orario);
    lcd.setCursor(7,0);
    lcd.print(2, BYTE);
    lcd.setCursor(0,1);
    lcd.print(dataOdierna);
  }
  else if (changeScreen==1) {
    lcd.setCursor(0,0);
    lcd.print(1, BYTE);
    lcd.setCursor(1,0);
    lcd.print("XX");
    lcd.setCursor(4,0);
    lcd.print(4, BYTE);
    lcd.setCursor(5,0);
    lcd.print("XX");
    lcd.setCursor(0,1);
    lcd.print("hcca XX");
  }
  
  if (count == 1) {
    //Serial.println(expanderRead(),BIN);
    count = 0;
    attachInterrupt(0, expanderInterrupt, LOW);
    
    k++;
    if (primaAccensione==0) {changeScreen=0; primaAccensione++;}
    else if (k==1) { changeScreen=!changeScreen; lcd.clear(); }
    else if (k>1) { k=0; }
    //Serial.println(k);
  }
    
}

// display all keycodes
void displayKeyCodes(void) {
  uint8_t i = 0;
  while (1) {
    lcd.clear();
    lcd.print("Codes 0x"); lcd.print(i, HEX);
    lcd.print("-0x"); lcd.print(i+8, HEX);
    lcd.setCursor(0, 1);
    for (int j=0; j<8; j++) {
      lcd.print(i+j, BYTE);
    }
    i+=8;  
    delay(4000);
  }
}

// Funzioni per interrupt da arduino
void expanderInterrupt() {    
  detachInterrupt(0);
  count = 1;
}

void expanderWrite(byte _data ) {
  Wire.beginTransmission(expander);
  Wire.send(_data);
  Wire.endTransmission();
}

byte expanderRead() {
  byte _data;
  Wire.requestFrom(expander, 1);
  if(Wire.available()) {
    _data = Wire.receive();
  }
  return _data;
}
3047  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: November 03, 2009, 06:44:54 pm
Yei! I have double checked every connection again and I have ended up with a pair of codes in output what I press my button. I was able to idendify this to change the data on my lcd screen. I have still to semplify my code but more or less is working now. I will post it as soon as possible. The code of Yot was my key in this work, thanks again! Thanks to everyone smiley

I am programming this system to sobstitute the lcd clock of my car, to have an enhanced clock and the possibility to switch visual to see the temperature of many electronics I have installed (via i2c) into.

3048  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: November 03, 2009, 09:49:58 am
I have correct the "==" typo, but my pullup resistor (10k) is from the +5v line to the INT on che PCF, I thought it was to set like this reading your post... I will change if connecting the pullup to the pin "2" on my arduino diecimila and test again tonight. I have changed the external interrupt from 5 to 0 if I can remeber exactly. I will check as soon as I came back home! Fede
3049  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: November 02, 2009, 05:05:47 pm
Thank you for discussing about this topic, I am learning many things.
By the way, still I can't undestanding I am doing it right. Following the code of Yot, in my serial debug I have
Code:
11001001
11001001
11001001
11001001
11001001
no stop (well, I have some wire attached to the expander)
When I press the button for less than one sec i have
Code:
1001001
1001001
1001001
1001001
1001001
1001001
So I can see that something change, and when I release my button I have again, over and over smiley the code inserted at the top (11001001).
Is this supposed to be correct? It will be a little tricky to hook...

Federico
3050  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: November 01, 2009, 07:16:56 pm
With the help of your code as test I have read a bit of documentation from the arduino site and now I am doing some test.
If I understand it right when I press the button, connected to ground, I receve a different binary number, so I can hook this to actions. Am I right?

Still have to test it, but can you tell me if the pin used from the arduino to the external interrupt is still usable?

Federico
3051  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: November 01, 2009, 03:26:46 pm
Hi Mario,
I have already planned not to use the backlight with your library because I will always need the backlight on. I could use the pin 12, but still I have to understand how. I am working on it...
Thanks, Fede
3052  Forum 2005-2010 (read only) / Interfacing / Re: i2c port expander PCF8574 as input on: October 30, 2009, 11:39:15 am
I will be absolutly fine with a normal digital button smiley
I need this button to change the state of the visualization on the lcd, but looks like every example on the forum is about using the expander as output, and not as input (on a single pin)
3053  Forum 2005-2010 (read only) / Interfacing / i2c port expander PCF8574 as input on: October 30, 2009, 10:17:48 am
Hi, I have a PCF8574p and I am using it with an lcd. This works fine.
The library that I use let a pin of the PCF, the 13, free.
I wish to use this pin of the port expander as an input pin, to read the pressure of a button, but I can't understand how, through the wire library (i think that i need this).
Is it possible to do this? Does anyone knows where I can look for understanding how to do this? Thanks, Fede
3054  Forum 2005-2010 (read only) / Interfacing / Re: DS1307 rtc hang-up on: June 02, 2009, 06:50:14 pm
Thank you, I will try also a smaller cap, to see what happens!
Federico
3055  Forum 2005-2010 (read only) / Interfacing / Re: DS1307 rtc hang-up on: June 02, 2009, 02:59:22 pm
Hi!
Basically my scheme looks like this
http://img89.imageshack.us/img89/6505/ds13070sm4.gif
with the pullup resistors.

During the last hour, things started to work. Looks like...
I have the system in test because is running by one hour, and I am continuosly detaching the current and keep working.

I have added an electrolitic capacitor, 10uF 25v beetween the vcc and gnd of the ds1307 and now looks like working. Don't know exactly WHY, by the way. I tested just because I was without any other idea, and looks like a solution. (Well, if this keep working)

Can't understand why...
3056  Forum 2005-2010 (read only) / Interfacing / DS1307 rtc hang-up on: June 02, 2009, 12:16:00 pm
I have tried everything and I can't understand this. I have a ds1307 rtc, the right crystal and a battery. Everything apparently works fine.

When I try the battery, to see if everything works,  I detach the VCC cable from the pin8 on the ds1307 and when I attach it again I see that the battery works, because the time is exact.

Looks like ok BUT.. When I detach the +5 cable from the arduino (meaning that breaks the connection with pin 8 VCC, 5 SDA,6 SCL) and I attach it again, most of the times (but not every time) the RTC hangs and show always the time when i gave again the +5. (Looks like hanging in the exact moment that I put the +5)

I am working on this from many hours, without understanding why it stop working...

Thank you for help!
3057  Forum 2005-2010 (read only) / Interfacing / Re: rgb led from seeedstudio - red is dominating?! on: June 02, 2009, 03:14:47 pm
I haven't tried the leds from seed studio, but I had this problem with RGB leds when there was not enaugh power. Try to give more power to the led!
3058  Forum 2005-2010 (read only) / Exhibition / Re: robots band on: January 20, 2011, 09:19:15 am
FANTASTIC!!!
I like it a lot!
Do you have extra pics of the work in progress??
Fede
3059  Forum 2005-2010 (read only) / Exhibition / Re: Saying "Hi!" with my current project on: January 04, 2011, 09:29:22 am
Can I ask you a thing about the futaba s3003? With a bit of try and error I ended that they go, in microseconds, from 500 to 2400. Have you ever tried?
3060  Forum 2005-2010 (read only) / Exhibition / Re: ArduSpider Sara : a robot project for my daughter on: January 10, 2011, 04:45:07 pm
Super super super cool. You are great!
Pages: 1 ... 202 203 [204] 205 206