Newbie question about TouchShield programming

Hello everyone, I'm new to this forum. Got a few questions about touchShield. I just got mine in over the weekend, problem is, there are so few resources available about the touchShield, so it's kinda frustrating to work with it, especially when it comes to serial communication... Anyway, here is my question:

I'm trying to send an int value (int val = 100) using

mySerial.print((unsigned char)val);

And on the touchShield I'm using

signal = Serial.read();

but when I covert the value to string and display it on touchShield, it displays as 044. I'm using

dtostrf(signal, 10, 0, display);

to convert the value, and use

lcd_puts(display, 10, 10, green, black);

to display.

Can anybody tell me why it's not displaying as 100? Thanks a lot.

:-?

Have you been able to get anything to show up properly? I always start with something very simple like "a" (without quotes). Never had a TouchShield either.

I've already done a little project on the touchShield, displaying graphic and text with no problem. But all I did in that project is to pass constant values like:

mySerial.print((unsigned char)0);

but I never tried to pass variables in until a few mins b4 my initial post.

Hi Terrance, sorry this took so long for me to respond! I literally just saw this thread, and I’ll do my best… hit me up at inthebitz@gmail.com too if email’s easier for you too…

Communicating from the Arduino to the TouchShield is kind of manual right now. It’s easy to pass unsigned chars one at a time, because the serial.read() function grabs one char at a time, which is one byte. The catch is that integers (ints) are 2 bytes long.

So in order to send a full int from the arduino, you have to send one part first, then the second part. Chris figured out how to get this working in the Pin Visualizer project (http://www.liquidware.com/projects/8/Pin+Visualizer), and I’ve adapted it for the Processing graphics library code too (Antipasto Hardware Blog: Processing ported to an Arduino + TouchShield ported from Processing).

On the TouchShield, I use this code:

int getValue = (Serial.read() << 8) + Serial.read();

This first calls Serial.read() to get the high bit. The “<< 8” means bit shift the byte up (to the left) 8 bits. Then, it calls Serial.read() again to get the low byte. And finally it adds both together. It kind of looks like this:

First get byte 1, the high byte:
0000000010101010
Shift it left 8 bits
1010101000000000
Then get byte 2, the low byte:
11111111
Add that to the left-shifted byte:
1010101011111111

And on the Arduino, I’ll use this code:

unsigned char lowByte, highByte;
unsigned int val;
//set val to something
lowByte = (unsigned char)val;
highByte = (unsigned char)(val >> 8);
mySerial.print(highByte);
delay(1);
mySerial.print(lowByte);
delay(1);

That kind of does the inverse behavior. First it take val, and sets lowByte to only the lower or rightmost 8 bits. Then, it sets highByte to the upper or leftmost 8 bits (by bitshifting it down 8 bits first). Then, it prints the high byte, followed by the low byte. I throw a delay(1) in between just to give the Arduino and TouchShield time to separate the two sends from each other.

So if val looks like:
1010101011111111
It sets lowByte to:
11111111
It then shifts val to the right by 8 bits to get:
0000000010101010
Which it then grabs only the lower 8 bits of:
10101010
Which get stored as highByte

Because I send highByte first, and the send lowByte, that means the TouchShield has to know that the first thing it gets will be the highByte. So that’s why the first byte the TouchShield gets is shifted left by 8 bits!

Phew. That was really long… I’m sorry :frowning:

If you send me some code to look at, I can also help debug it too…

I am working on synchronizing the Arduino board with the TouchShield in a similar way (sending int values), using NewSoftSerial on the Arduino side and Serial on the TouchShield side. My question is whether there is a method functionally similar to available() for the HardwareSerial on the TouchShield Stealth, or if I must code it myself. Is there another serial connection you recommend using for this purpose?

The WiNet App is a good example of communication between the Arduino and TouchShield Slide http://www.liquidware.com/apps/show/58