Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
LedControl library
11-02-2016, 11:30 PM,
#11
RE: LedControl library
Thanks André

Thr result in the attachment.

I have a board with a max3232, named RS232 TO TTL.

Thanks,
Fernando


Attached Files Thumbnail(s)
   
Reply
12-02-2016, 09:23 AM,
#12
RE: LedControl library
Hello Fernando,
I tried serialprintf.pde with a home-made MAX232N module between pinguino rx-tx and the PC rs232 subd and it works (see my attachment). MAX232N is an older MAX3232 version.
Verify your MAX3232 board and all wires and connectors.
Select 9600 bauds/8bits/ no parity / 1 stop bit/ in your terminal settings.
Hasta pronto
André


Attached Files Thumbnail(s)
   
Reply
13-02-2016, 03:28 PM,
#13
RE: LedControl library
Hello André,

Thanks for your pacience, i've found the mistake.
I assumed the connector on the rs232 to ttl converter where to be switched, rx with tx, and tx with rx, but they where alredy right. Blush if you understand what i mean...

Thanks for the patience again.

Fernando
Reply
13-02-2016, 03:35 PM,
#14
RE: LedControl library
Thanks for the good news ! I am always happy to help.
Have a nice day.
André
Reply
20-03-2016, 07:43 PM,
#15
LedControl library
Hello again,

The code is almost ready, but one thing is anoying me, the micro freezes, and i can find out why.
Another thing is, the clock is amost 2m ahead in one month, is there any way that i can mend that?

Here is the
Code:
/*
rtc_7segment

Real Time Clock with 2x6 Digit 7Segment-Display

Needed Hardware:
   Pinguino 2550 or compatible
   Segment-Display with MAX7219
   DS1307 RTC Board

Created by:
        gtcbreizh (André), Pinguino team www.pinguino.cc
03/01/16 modified by fpeixeiro (Fernando Peixeiro)

working with Pinguino 2550 :
DS 1307 SDA connected to pin0 and SCL to pin1
DS 1307 powered  - by CR2032 lithium battery for backup
                 - by 5V to communicate with Pinguino
with the battery connected, once you have initiated the DS1307 using your Pinguino
In my case i have 2 max7219 connected and 6 digits to each max7219
max 1 shows hour, minuts and seconds
max 2 shows day, month and year
 Button to start adjustment of the clock on pin6
Button to increment the value on pin7
*/

u8 I2C_address=0xD0; // i2c 8 bits address of DS1307
u8 reg=0x00;                    // first addr. reg. to write or to read
u8 i2c_tx_buffer[8];
u8 i2c_rx_buffer[7]={0,0,0,0,0,0,0};
int secondG, minuteG, hourG, dayOfWeekG, dayOfMonthG, monthG, yearG; // variables for time showing

u8 DS1307_send_receive(u8 address, u8 *wbuffer, u8 wlength, u8 *rbuffer, u8 rlength)
{
   u8 i;
   u8 temp;
I2C.start();    // I2C start comunication
if(!I2C.write(address))
{do {I2C.restart;}
while(!I2C.write(address)); }
   for (i=0; i<wlength; i++)
   {
       while(!I2C.write(wbuffer[i]));
   }
if( rlength > 0)
{
   temp = address | 0x01;
do {I2C.restart();}                 // start again
while(!I2C.write(temp));             // read operation (bit 0 set to 1)
for (i=0; i<rlength; i++)           // Sequential read (auto. inc.)
{
rbuffer[i] = I2C_read();
if (i== (rlength-1))            // Last byte is sent ?
I2C.sendNack();             // Yes, send a No Ack to the slave (no more data to read)
else
I2C.sendAck();              // No, send a Ack bit (more data has to be read)
}
}
   I2C_stop();
return(1);
}

u8 decToBcd(u8 val)    //decimal to BCD conversion
{
 return ( (val/10*16) + (val%10) );
}

// Convert binary coded decimal to normal decimal numbers
u8 bcdToDec(u8 val)
{
 return ( (val/16*10) + (val%16) );
}

void setDateDs1307(
                  u8 second,  // Function to do a first time setup of the DS1307
                  u8 minute,
                  u8 hour,
                  u8 dayOfWeek,
                  u8 dayOfMonth,
                  u8 month,
                  u8 year)
{
 u8 j=0;
 u8 nb_reg_towrite = 8;
 i2c_tx_buffer[0]=reg;
 i2c_tx_buffer[1]=decToBcd(second);
 i2c_tx_buffer[2]=decToBcd(minute);
 i2c_tx_buffer[3]=decToBcd(hour);
 i2c_tx_buffer[4]=decToBcd(dayOfWeek);
 i2c_tx_buffer[5]=decToBcd(dayOfMonth);
 i2c_tx_buffer[6]=decToBcd(month);
 i2c_tx_buffer[7]=decToBcd(year);

 j=DS1307_send_receive(I2C_address,i2c_tx_buffer,nb_reg_towrite,i2c_rx_buffer,0);
}  

void getDateDs1307(void)  // Function to get the time from DS1307
{
 u8 j;
 I2C.master(I2C_100KHZ);
 i2c_tx_buffer[0]=reg;
 
 while(!DS1307_send_receive(I2C_address,i2c_tx_buffer,1,i2c_rx_buffer,7));
 secondG     = bcdToDec(i2c_rx_buffer[0] & 0x7f);
 minuteG     = bcdToDec(i2c_rx_buffer[1] );
 hourG       = bcdToDec(i2c_rx_buffer[2]  & 0x3f);  // Need to change this if 12 hour am/pm
 dayOfWeekG  = bcdToDec(i2c_rx_buffer[3] );
 dayOfMonthG = bcdToDec(i2c_rx_buffer[4] );
 monthG      = bcdToDec(i2c_rx_buffer[5] );
 yearG       = bcdToDec(i2c_rx_buffer[6] );
}

void setup()
   {
   Serial.begin(115200);
   /*
   Connections Pinguino -> MAX7219
   pin 2 is connected to the DataIn
   pin 3 is connected to the CLK
   pin 4 is connected to LOAD
   2 : We have two MAX72XX. */
 LedControl.init(2,3,4,2);
 LedControl.shutdown(0,false);   // Command for wake up
 LedControl.shutdown(1,false);   // Command for wake up
 LedControl.clearDisplay(0);        // Clears the digits
 LedControl.clearDisplay(1);        // Clears the digits
   
/* {
 u8 second, minute, hour, dayOfWeek, dayOfMonth, month, year;
 I2C.master(I2C_100KHZ);
// following values to change according your time and date
 second = 0;
 minute = 38;
 hour = 16;
 dayOfWeek = 2;
 dayOfMonth = 23;
 month = 2;
 year = 16;

   }*/
}

void print7Seg()        // print to 7segments
   {
   int sones, stens;
   int mones, mtens;
   int hones, htens;
   int dones, dtens;
   int mtones, mttens;
   int yones, ytens;
   
   sones=secondG%10;
   secondG=secondG/10;
   stens=secondG%10;
   
   mones=minuteG%10;
   minuteG=minuteG/10;
   mtens=minuteG%10;
   
   hones=hourG%10;
   hourG=hourG/10;
   htens=hourG%10;
   
   dones=dayOfMonthG%10;
   dayOfMonthG=dayOfMonthG/10;
   dtens=dayOfMonthG%10;
   
   mtones=monthG%10;
   monthG=monthG/10;
   mttens=monthG%10;
   
   yones=yearG%10;
   yearG=yearG/10;
   ytens=yearG%10;

   LedControl.setDigit(0,0,(byte)sones,false);    // Seconds
   LedControl.setDigit(0,1,(byte)stens,false);    // Tens seconds
   LedControl.setDigit(0,2,(byte)mones,false);    // Minutes
   LedControl.setDigit(0,3,(byte)mtens,false);    // Tens minutes
   LedControl.setDigit(0,4,(byte)hones,false);    // Hours
   LedControl.setDigit(0,5,(byte)htens,false);    //Tens hours
   
   LedControl.setDigit(1,0,(byte)yones,false);    // Years
   LedControl.setDigit(1,1,(byte)ytens,false);    // Tens years
   LedControl.setDigit(1,2,(byte)mtones,false);    // Months
   LedControl.setDigit(1,3,(byte)mttens,false);    //Tens months
   LedControl.setDigit(1,4,(byte)dones,false);    // Days
   LedControl.setDigit(1,5,(byte)dtens,false);    // Tens days
}

void loop()        // Function to check light intensity and change the brightness of display
   {
   int sensorValue = analogRead(A0);     // routine to get a value from a LDR
       int val = sensorValue/70;              // to adjust the brightness of the segments
       LedControl.setIntensity(0,val);         // Set intensity for the digits (depends on the value of the resistor Iset, from 0 to 15)
       LedControl.setIntensity(1,val);        // on the two max7219
 
   Serial.printf("Valor Sensor=%d\n\r", sensorValue);  // routine to show the value of the LDR
   Serial.printf("Valor=%d\n\r", val);                        // on hyperterminal to check funcionality
   
   // Add buttons to set time and date (still to do)
   /*
       if(pin6==1)     // time and date to init. or update digit by digit
           setDateDS1307();
           
       if(pin7==1)    // increment number
       value = value + 1
   */
   
   delay(1000);

getDateDs1307();
  print7Seg();
}

Any help is apreciated.

Thanks,
Fernando
Reply
21-03-2016, 03:11 PM,
#16
RE: LedControl library
Hello Fernando,
Relating to the 2 min ahead in a month I recognize it is a bit frustrating. On my side it is the same but astern and I stay

yet satisfied with that.

Look at the datasheet. I remember there is a means to adjust delay or advance. Not very simple !

Relating to the controller freezing no idea !

André 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)