TouchShield and Serial String
hi everyone.
i new @ arduino development , have problem programming touchshield , arduino board communicate together.
always when send string touchshield show first char alone , half second later whole string without first char.
i want show time without flashing of screen.
here code arduino:
and here code touchshield:
thanks or idea.
i new @ arduino development , have problem programming touchshield , arduino board communicate together.
always when send string touchshield show first char alone , half second later whole string without first char.
i want show time without flashing of screen.
here code arduino:
code: [select]
#include "wire.h"
#include <afsoftserial.h>
#define ds1307_i2c_address 0x68
//touch shield slide ports
#define rx_pin 3
#define tx_pin 2
afsoftserial touchserial = afsoftserial(rx_pin, tx_pin);
// convert normal decimal numbers binary coded decimal
byte dectobcd(byte val)
{
return ( (val/10*16) + (val%10) );
}
// convert binary coded decimal normal decimal numbers
byte bcdtodec(byte val)
{
return ( (val/16*10) + (val%16) );
}
// stops ds1307, has side effect of setting seconds 0
// want use testing
/*void stopds1307()
{
wire.begintransmission(ds1307_i2c_address);
wire.send(0);
wire.send(0x80);
wire.endtransmission();
}*/
// 1) sets date , time on ds1307
// 2) starts clock
// 3) sets hour mode 24 hour clock
// assumes you're passing in valid numbers
void setdateds1307(byte second, // 0-59
byte minute, // 0-59
byte hour, // 1-23
byte dayofweek, // 1-7
byte dayofmonth, // 1-28/29/30/31
byte month, // 1-12
byte year) // 0-99
{
wire.begintransmission(ds1307_i2c_address);
wire.send(0);
wire.send(dectobcd(second)); // 0 bit 7 starts clock
wire.send(dectobcd(minute));
wire.send(dectobcd(hour)); // if want 12 hour am/pm need set
// bit 6 (also need change readdateds1307)
wire.send(dectobcd(dayofweek));
wire.send(dectobcd(dayofmonth));
wire.send(dectobcd(month));
wire.send(dectobcd(year));
wire.endtransmission();
}
// gets date , time ds1307
void getdateds1307(byte *second,
byte *minute,
byte *hour,
byte *dayofweek,
byte *dayofmonth,
byte *month,
byte *year)
{
// reset register pointer
wire.begintransmission(ds1307_i2c_address);
wire.send(0);
wire.endtransmission();
wire.requestfrom(ds1307_i2c_address, 7);
// few of these need masks because bits control bits
*second = bcdtodec(wire.receive() & 0x7f);
*minute = bcdtodec(wire.receive());
*hour = bcdtodec(wire.receive() & 0x3f); // need change if 12 hour am/pm
*dayofweek = bcdtodec(wire.receive());
*dayofmonth = bcdtodec(wire.receive());
*month = bcdtodec(wire.receive());
*year = bcdtodec(wire.receive());
}
// touchshield functions
void printclocktoscreen() {
}
void setup()
{
byte second, minute, hour, dayofweek, dayofmonth, month, year;
wire.begin();
//set touch slide communication
pinmode(rx_pin, input);
pinmode(tx_pin, output);
touchserial.begin(9600);
pinmode(9,input);
// change these values want set clock to.
// want set clock once , remove
// setdateds1307 call.
second = 45;
minute = 23;
hour = 23;
dayofweek = 3;
dayofmonth = 28;
month = 4;
year = 10;
//setdateds1307(second, minute, hour, dayofweek, dayofmonth, month, year);
}
void loop()
{
byte second, minute, hour, dayofweek, dayofmonth, month, year;
getdateds1307(&second, &minute, &hour, &dayofweek, &dayofmonth, &month, &year);
//touch slide send
char secondstr[32];
snprintf(secondstr, sizeof(secondstr), "%d:%d:%d", hour, minute, second);
touchserial.print(secondstr);
delay(1000);
}and here code touchshield:
code: [select]
// globals
unsigned int xstore;
unsigned int ystore;
// prepare screen , serial
void setup()
{
background(0,0,0);
stroke(255,255,255);
fill(0,0,0);
serial.begin(9600);
delay(100);
}
void loop()
{
// monitor serial buffer of touchshield slide
char charin = 0;
byte = 0;
char stringin[32] = "";
while( serial.available() ) {
charin = serial.read();
stringin[i] = charin;
i += 1;
}
// clear screen , display serial buffer text
if (stringin[0])
{
background(0,0,0);
text("time:", 50, 50);
text(stringin, 50, 100);
}
}
thanks or idea.
you streaming data touch screen, no indicator end of packet is.
then, on touch screen, reading available data, , assuming that represents full packet, , 1 packet.
that trying make sense of first sentence above if sent this:
youarestreamingdatatothetouchscreen,withnoindicatorastowheretheendofapacketis.
change data being sent include sort of end of packet marker (like space between words). change touch screen software read until encounters end of packet marker, before uses data has read.
then, on touch screen, reading available data, , assuming that represents full packet, , 1 packet.
that trying make sense of first sentence above if sent this:
youarestreamingdatatothetouchscreen,withnoindicatorastowheretheendofapacketis.
change data being sent include sort of end of packet marker (like space between words). change touch screen software read until encounters end of packet marker, before uses data has read.
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > TouchShield and Serial String
arduino
Comments
Post a Comment