Tuesday, April 15, 2008

TouchShield: up and running in 5 minutes

*Update* Matt and I are working on a new installation tutorial for the Stealth and Slide since it now includes a bunch of new SubProcessing and fast graphics functions. See the updated Up and running on the TouchShield Stealth and Slide in 5 minutes where it walks you through the entire installation.


So you just got your TouchShield in the mail...


At this point, if your like many, your probably asking the very valid question which is,

"How the hell do I use this thing?"

Up and Coding Fast
  1. What is the TouchShield
  2. IDE Setup
  3. Programming
  4. The Code
  5. Results

What is the TouchShield?

As it's name suggests, the TouchShield is a shield (add-on board) designed to be used with an Arduino Diecimila (www.arduino.cc). The TouchShield gives the Arduino an OLED and Touchscreen to help design more advanced applications based around the Arduino electronics development platform.

Hardware Description
The Arduino
The TouchShield

The Touchshield shares pins 0,1 only during programming and uses pins 2,3 only if serial comms between the Arduino and TouchShield are desired. Serials communications are useful when you want to do Input/Output with the Arduino.

IDE Setup
  1. Install Arduino (If you haven't already)
  2. Extract the zipped touch core into arduino-xxxx/hardware/cores
  3. Replace the arduino-xxxx/hardware/boards.txt file with this one
Here is a hard to see video of me installing the core



Programing

Remember before writing code, select the TouchShield board option from the Arduino menu to compile and download to the TouchShield.


The Code

COLOR red = {255,0,0};
COLOR blue = {0,0,255};

void setup()

{

lcd_rectangle(20,20,80,80, red, blue);

}
void loop()

{

}



Hit the compile (play) button on the IDE and watch the output window to make sure everything compiled correctly. Then, press the program button on the side of the TouchShield. Now upload your code by pressing the upload button in the Arduino IDE.

Results
The above image was drawn on the TouchShield from the included code in this post.

Thats it!
Stay tuned for another more advanced tutorial using Serial to send data between the Arduino and TouchShield.

18 comments:

Unknown said...

Hi are you able to take photos of this in direct sun light to see how visible the screen is, if you can display some text etc that would be great, i really want to buy one but need to see how good it is in direct sun light.
Thanks

Unknown said...

hello,

touchshield seems to be amazing. is it possible to display small picture (like 128x128 px gif) on the screen ?

Chris said...

Yup, you can display 65K color 24-bit .bmp on the screen.

You just use a little app that downloads the image to the TouchShield.

Then, at any time in your own app, you call it up by calling this command:

bmp_draw("imgName",x,y);

Chris said...

Aliandro23,

Good idea!

If I get a chance, I would like to take a pic of it in direct sunlight comparing it to a popular lcd screen, say a TomTom GPS or an iPod.

Although, everytime I find myself coding, it's at night with a coffee in hand :-)

I'll keep you posted.

Anonymous said...

Which version of the arduino IDE does this require? I'm using Arduino 0011 on a Mac and I get errors like the following when trying to compile any program:

/Users/mattb/Dev/arduino-0010/hardware/cores/touch/dataflash.c: In function 'dataflash_init':

/Users/mattb/Dev/arduino-0010/hardware/cores/touch/dataflash.c:18: error: 'PB3' undeclared (first use in this function)

/Users/mattb/Dev/arduino-0010/hardware/cores/touch/dataflash.c:18: error: (Each undeclared identifier is reported only once

/Users/mattb/Dev/arduino-0010/hardware/cores/touch/dataflash.c:18: error: for each function it appears in.)

/Users/mattb/Dev/arduino-0010/hardware/cores/touch/dataflash.c:19: error: 'PB5' undeclared (first use in this function)

(etc)

This would seem to indicate that the appropriate io header file isn't getting included for this board definition. I did put the boards.txt file in the place as specified.

Chris said...

hackdiary.com,

The touch007 core now supports Mac OS X and has been tested with Arduino 10 and 11

ramirez said...

Hi,

I'm getting a lot of errors when trying to compile for the touchshield using touch-007 and arduino 0011 in Windows Vista. They seems to come while trying to compile the wire library
At the end of my post you can see the output.


LEo


LEo


In file included from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/touchscreen.h:8,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/lcd.h:4,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/wiring.h:31,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/WConstants.h:1,
from EEPROM.cpp:25:
C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/pindefs.h:66:7: warning: no newline at end of file
In file included from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/touchscreen.h:8,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/lcd.h:4,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/wiring.h:31,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/WConstants.h:1,
from Matrix.cpp:34:
C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/pindefs.h:66:7: warning: no newline at end of file
In file included from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/touchscreen.h:8,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/lcd.h:4,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/wiring.h:31,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/WConstants.h:1,
from SoftwareSerial.cpp:24:
C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/pindefs.h:66:7: warning: no newline at end of file
In file included from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/WProgram.h:6,
from Stepper.cpp:48:
c:/users/ramirez/downloads/web/arduino-0011-win/hardware/tools/avr/bin/../avr/include/avr/signal.h:36:2: warning: #warning "This header file is obsolete. Use <avr/interrupt.h>."
In file included from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/touchscreen.h:8,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/lcd.h:4,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/wiring.h:31,
from C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/WProgram.h:10,
from Stepper.cpp:48:
C:\Users\ramirez\Downloads\Web\arduino-0011-win\hardware\cores\touch/pindefs.h:66:7: warning: no newline at end of file
In file included from utility\twi.c:25:
c:/users/ramirez/downloads/web/arduino-0011-win/hardware/tools/avr/bin/../avr/include/avr/signal.h:36:2: warning: #warning "This header file is obsolete. Use <avr/interrupt.h>."
utility\twi.c: In function 'twi_init':
utility\twi.c:79: error: 'TWSR' undeclared (first use in this function)
utility\twi.c:79: error: (Each undeclared identifier is reported only once
utility\twi.c:79: error: for each function it appears in.)
utility\twi.c:79: error: 'TWPS0' undeclared (first use in this function)
utility\twi.c:80: error: 'TWPS1' undeclared (first use in this function)
utility\twi.c:81: error: 'TWBR' undeclared (first use in this function)
utility\twi.c:89: error: 'TWCR' undeclared (first use in this function)
utility\twi.c:89: error: 'TWEN' undeclared (first use in this function)
utility\twi.c:89: error: 'TWIE' undeclared (first use in this function)
utility\twi.c:89: error: 'TWEA' undeclared (first use in this function)


(etc)

Chris said...

There's not an actual touch core compile ERROR in your output listed. ;-)

I used Vista to code the recent iPhone post on antipastohw.blogspot.com

You're not able to compile Arduino Diecimila libraries on the touch core because the TouchShield's pins are different from the Diecimila and are not supported on the TouchShield.

So it makes sense that there's errors. Switching back to the Diecimila in the menu should fix your errors.

You can make your own TouchShield libraries, but like above, they won't be supported on the Diecimila.

This may sound confusing, but it's designed that way.

Hope this helps.

Chris

ramirez said...

Ok. I must confess that I didn't fully understood that explanation. I'm a newbie here, so bear with me. I have been trying to upload code to the touchshield, which is connected to a ArduinoBT, and I got the following error:

Binary sketch size: 15548 bytes (of a 57342 byte maximum)


Connecting to programmer: .
Found programmer: Id = "þø)"; type = þ
Software Version = þ.ø; Hardware Version = þ.ø
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?

What am I doing wrong?

Thanks!

LEo

Chris said...

Mortadelo,

We've only tested the TouchShield on the Diecimila and not the ArduinoBT yet.

That being said, you will see that message if the TouchShield doesn't respond to the PC. Of course, you make sure and pressed the TouchShield's reset button before pressing download.

The TouchShield code is downloaded at 57600 baud serially. It holds the Arduino in reset during this time.

This works fine on the Diecimila but on the ArduinoBT, when it's in reset, you stop driving the BTRES line (see schematic). This could cause the BT chip to reset and mess up communications.

ramirez said...

Ok. I tried that on a Diecimilla and it worked fine. Thanks for your help, AVRMan!

Cheers,

LEo

David Tomlinson said...

The TouchShield looks cool. Has anyone ever done a project which displayed video on it? I'm thinking the Arduino might be too small and slow for true, full-motion video, but has anyone ever tried to create a codec or an app to prove/disprove it?

Chad said...

Hey! Thanks for a great product with the stealth touchshield; I am loving the display...

A BURNING QUESTION: I am able to draw to the touchscreen and display loaded bitmaps, etc. per the examples. But when I try to use a random() variable, I get the following message:


c:/program files/arduino-0010/hardware/tools/avr/bin/../avr/include/stdlib.h: In function 'void loop()':

c:/program files/arduino-0010/hardware/tools/avr/bin/../avr/include/stdlib.h:547: error: too many arguments to function 'long int random()'

error: at this point in file


I thought this was probably related to the above situation of having to switch boards from Touchscreen to NG, but when I tried that (naturally), things like 'COLOR red =' throw errors.

So, if someone could please explain in a really simple way how to, for instance:


i = random(200);
lcd_circle(64,64, i, green, black);


I'd really appreciate it!

Duff said...

Chad,

Make sure your radius is small enough to fit on the screen.

random(200), would get a random radius between 1 and 200.

That's a diameter of 400, but the screen is 128 pixels wide.

Phil Glau said...

Does this tutorial apply to:

Arduino 0012 (IDE)
Duemilanove (board)
TouchScreen Slide (320x240)

I'm having some problems getting everything installed using this tutorial. It seems to be to only one on the site for TouchScreen products though.

Chris said...

Filmo,

Matt and I have been working on an update to this tutorial for both the Slide and Stealth. You can find it here,

http://antipastohw.blogspot.com/2008/12/up-and-running-on-touchshield-stealth.html

CamDAX said...

Hi I'm having problems with this I cant get the Touch Shield to show up in the boards setion of the Arduino IDE. Can some one help me?

Matt said...

@modeltrainsfreak - wow, this is an old blog post, i think i need to update it ... in the meantime, shoot me an email at inthebitz at gmail and i'll try my best