just to clarify I am attempting to accept sensor data from a temp sensor as well as a compass module through I2C connected on analog in pins 2,3,4,5 at 19200 baud.
it works fine if I am only accepting sensor data.
however trying to serial write and read in order to fire up digital pin 11 is making the program hang... none of my buttons work.
is it possible to accept sensor data, display on the touchshield slide and still be able to fire up a pin (to light an led)
i have the following code snipets to share
arduino code:
#include <LibCompass.h>
#include <Wire.h>
#include <LibTemperature.h>
#include <HardwareSensor.h>
#include <SoftwareSerial.h>
#define rxPin 3
#define txPin 2
int t;
int C;
char myByte;
int eleven = 11;
SoftwareSerial mySerial = SoftwareSerial(rxPin, txPin);
LibTemperature temp = LibTemperature(0);
LibCompass compass = LibCompass(0);
void setup() {
Sensor.begin(19200);
Serial.begin(9600);
pinMode(rxPin, INPUT);
pinMode(txPin, OUTPUT);
pinMode(eleven, OUTPUT);
mySerial.begin(9600);
}
void loop(){
t = (int)temp.GetTemperature();
Sensor.print("temp", t);
C = (int)compass.GetHeading();
sensor.print("compass", C);
myByte = mySerial.read();
if(myByte == 'A') //if the letter "A" comes from the touchshield
{
digitalWrite(eleven, HIGH);
}
if(myByte == 'B') //if the letter "B" comes from the touchshield
{
digitalWrite(eleven, LOW);
}
delay(5);
}
and code for the touch shield slide
#include <BarGraph.h>
#include <HardwareSensor.h>
#include <TButton.h>
TButton tempf = TButton("Temp in F",20,20);
TButton tempc = TButton("Temp in C ",120,20);
TButton compass = TButton(" Compass ",220,20);
TButton back = TButton(" return ",120,80);
TButton doorlock = TButton(" locks ",200 , 80);
TButton doorunlock = TButton(" unlock ",200 , 140);
TButton windowup = TButton("window up", 20 , 80);
TButton windowdown = TButton("window down", 20 , 140);
int state = 0;
int t;
int C;
int newT;
char tempstr[5];
char tempstr2[5];
void setup()
{
Sensor.begin(19200);
Serial.begin(9600);
background(0);
tempf.Paint();
tempc.Paint();
compass.Paint();
doorlock.Paint();
doorunlock.Paint();
windowup.Paint();
windowdown.Paint();
}
void drawNumber(int number, int xPos, int yPos) {
int counter;
int16_t h,t,o;
h = number / 100;
t = (number - (h*100) ) / 10;
o = number - (h*100) - (t*10);
stroke(255);
fill(0);
if (h){
Display7SegmentDigit(xPos,yPos,h,25);
}
if (t) {
Display7SegmentDigit(xPos+32,yPos,t,25);
}
Display7SegmentDigit(xPos+32+32,yPos,o,25);
}
void loop()
{
if (Sensor.available())
{
if (!strcmp(Sensor.getName(), "temp"))
{
t = Sensor.read();
//convert celcius to fahrenheit
newT = (t*1.8 + 32);
}
if(!strcmp(Sensor.getName(), "compass"))
{
C = Sensor.read();
}
}
if (tempf.GetTouch())
{
background(0);
stroke(255);
fill(0);
back.Paint();
text("Temperature in F:", 5, 150,10);
state = 1;
}
if (tempc.GetTouch())
{
background(0);
stroke(255);
fill(0);
back.Paint();
text("Temperature in C:", 5, 150,10);
state = 2;
}
if (compass.GetTouch())
{
background(0);
stroke(255);
fill(0);
back.Paint();
text("Heading:", 5, 150,10);
state = 3;
}
if (Sensor.available() && state == 1)
{
if (!strcmp(Sensor.getName(), "temp"))
drawNumber(newT, 200, 150);
}
if (Sensor.available() && state == 2)
{
if (!strcmp(Sensor.getName(), "temp"))
{
t = Sensor.read();
}
drawNumber(t, 200, 150);
//delay(0);
}
if (Sensor.available() && state == 3)
{
if(!strcmp(Sensor.getName(), "compass"))
{
C = Sensor.read();
if(C >= 0.00 && C < 23.00)
{
//print the compass heading
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("N ", 160, 150, 18);
}
if(C >= 23.00 && C < 68.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("NE", 160, 150, 18);
}
if(C >= 68.00 && C < 113.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("E ", 160, 150, 18);
}
if(C >= 113.00 && C < 158.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("SE", 160, 150, 18);
}
if(C >= 158.00 && C < 203.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("S ", 160, 150, 18);
}
if(C >= 203.00 && C < 248.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("SW", 160, 150, 18);
}
if(C >= 248.00 && C < 293.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("W ", 160, 150, 18);
}
if(C >= 293.00 && C < 338.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("NW", 160, 150, 18);
}
if(C >= 338.00 && C < 360.00)
{
compass.Paint();
back.Paint();
stroke(255);
fill(0,0,255);
rect(150,135,45,30); //draw the rectangle
fill(0);
text("Heading:", 5, 150,10);
state = 3;
fill(0);
text("N", 160, 150, 18);
}
}
}
if (back.GetTouch())
{
background(0);
tempf.Paint();
tempc.Paint();
compass.Paint();
doorlock.Paint();
doorunlock.Paint();
windowup.Paint();
windowdown.Paint();
state = 0;
}
if (doorlock.GetTouch())
{
Serial.print('A');
delay(800);
Serial.print('B');
}
}
I've tried having the sensors at 19200 and the regular serial at 9600 and i've also tried having them both at 19200 for example I tried:
sensor.begin(19200)
serial.begin(19200)
and:
sensor.begin(19200)
serial.begin(9600)
and:
sensor.begin(9600)
serial.begin(9600)
but I can't get both my sensors and my button to turn on the LED to work at the same time.
any help is appreciated.
thank you!