NXT - Arduino - homebrew

Thursday, December 31, 2009

linux starter links

http://www.cyberciti.biz/faq/ubuntu-linux-root-password-default-password/
https://help.ubuntu.com/6.06/ubuntu/desktopguide/C/apt-get.html
http://linuxreviews.org/beginner/

working with ubuntu in the terminal window the problem was how to get to the root user to get things installed.

basically:

sudo bash
sudo -s

then to get a file executable:

chmod a+x someFile

to copy files from somewhere to there:

cp somewhere there

somwhere and there being path/someFileName


Tuesday, July 7, 2009

8 x 8 LED Display

Some time ago we bought the LED DISPL. GR 2 3" 8X8 MATRI
Bestnr.: 156380 - 8A at conrad.nl.
Very important you can download the datasheet at conrad service.
First we thought it would be easy to connect the 16 pins, steering 64 LED's. But it proved to be a bit more complicated than we thought. (As usual.)
Looking at the connections you see that you can light one LED, but how to get a pattern running across the matrix of 8 x 8 LED's.

Some tricks are needed!
We have to use a fast timer, from a CPP lib to fool the eye of the beholder, working with the slow response time of the eye. Indeed a camera sees more, which can be seen in the pictures.

here we found the necessary info: http://www.arduino.cc/playground/Main/DirectDriveLEDMatrix
but the FrequencyTimer2.h did not compile right away, we had to modify some lines using advice from here:

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1239820770

then we still had a problem, we dived into the CPP file, we encountered some things we didn't really understand.....we tried several changes....
...
...***
...
then as a final try we changed the HIGH in the LOW everywhere in the ARDUINO script, and it worked, why?

comparing the datasheets we noticed that ...indeed...the LED's were turned, in our device they were in the other way around, compared to the LED matrix used in the script of the link.....

:-(, always the same.....look closer, expect changes everywhere, details details....

but ok, in the end....it worked within a day, and the script is great!

(In this last image the camera sees what the eye cannot see: the LED steered on and off faster than we can see.) Our plan is to built this LED matrix into clothing behind a half transparent outer layer. Use a distance sensor, and change the running text according to distance of others from ourselves...

*** Peter van Vliet explained the (for me) incomprehensible part in the C++ file of the FrequencyTimer2 lib.

What was the problem? We noticed this part at the top of the source file:

{
static uint8_t inHandler = 0; // protect us from recursion if our handler enables interrupts

if ( !inHandler && FrequencyTimer2::onOverflow) {
inHandler = 1;
(*FrequencyTimer2::onOverflow)();
inHandler = 0;
}
}

without a function name....

The explanation is that this part will be flashed in the first part of the program section on top op everything else. It will be called every cycle, which makes sense seeing the purpose of the FrequencyTimer2 lib. So this is special chip (embedded) programming.

Thursday, June 25, 2009

Liquid crystal display WD-C2704M and the ARDUINO

Some time ago we bought a liquid crystal display WD-C2704M. It was a cheap one with 4 lines of possible text.

Of course there are a lot of liquid crystal, some preprogrammed, some with nice connected wires etc, the best (probably the most expensive too :-)

http://www.eink.com/press/releases/pr87.html

But back to our thing the WD-C2704M, of about 5 euro's....at www.pollin.de

It came with a the wires in a special flat plastic setting:

we should have bought the special slot for this, but we soldered, and all wires got mixed up, because they came loose from the ground....we scratched holes in the plastic isolation and succeeded in soldering the wires again. This already made the task daunting: around 20 wires so close together!


It took a while to find the specs. (Because we didn't buy it at pollins, there the datasheets can be found easily, we also paid tooo much at the other place (about 10 euro too much) haha!). Documentations are in German. No problem for the dutch...

WD-C2704M-1HNN.pdf
Text-LCDs.pdf

the pins of the display:

The display is HD44780 compatible, indeed it should be a double separated display. How to program this?
There is a liquid crystal lib for the ARDUINO. But this one is for 4 or 8 bits, so a max of two lines. This display has 4 lines.
We could make a new CPP lib out of the liquidCrystal.h, using the Cpp in the folder hardware\libraries\LiquidCrystal of the ARDUINO files.
This was our first try, following the instructions carefully of the setting up. We tried to set the display up in one go, setting the enable pins the one after the other.
Somehow this file got mixed up, and it refused to function.

The second try was nice and clean, the idea was just to make two different instances of this liquid crystal object:

LiquidCrystal lcd(13, 12, 11, 9,8,7,6,5,4,3,2);//the upper two lines
LiquidCrystal lcd1(13, 12, 10, 9,8,7,6,5,4,3,2);//the lower two lines

the last parameters are the ports, the difference is the enable port, coming from crystal pin: enable one goes to ARDUINO 10 and enable 2 to ARDUINO 11.
This way the two halves, upper and under are seperatly steered. And this solved the problem!

#include

//then setting up is easy: (actually already done)

void setup()
{

lcd.print("hello there");
lcd1.print("goodbye");
}

the two lines are displayed in the two halves.

a test to see what is possible:

lcd.print("hello there and how are you0123456789012hello there and how are you");//first two lines filled.

displays:
hello there and how are you
hello there and how are you

we have 27 characters on the first line of upper, then several spaces not shown, then the next line starts.
The first 27 are mentioned in the specs, but the gap is not what is described....the gap in memory addressing is 13 spaces, making it to 40 (decimal, which is not 64) to start the next line.

so here something is wrong in the data of this image.

The second line the same of course, because it is the same kind of object.

Possible mistakes (the ones we made :-)

As already mentioned: not buying the right slot for the wire connection.

then not connecting the right wires, because of the amount of wires, this is easy....this shows by not producing the right characters, or a lot of spaces.
the next mistake was to connect the pins in the wrong direction, that is , the other way around. Then the setting up wont be done properly and all kinds of problems occur, like not using the 4 lines etc.

Then there seem to be several LiquidCrystal.h files around in different ARDUINO versions.

The ones which worked (also on PC) were the files from the MAC 012 version of the ARDUINO.
Testing on other .h files will be done, now that the wiring is ok.

Also sometimes the ARDUINO + display must be disconnected and connected again to show all lines. This feature is described: resetting the ARDUINO does not reset the display.

ok in the end, when it works, all is fine.

We learnt a lot on the library CPP files of the ARDUINO. So in fact how to write our own classes for the ARDUINO scripts in CPP.

And we learnt where we could buy the cheapest LCD of this kind! www.pollin.de, much other cheap fun around there, the only problem is that they don't accept credit cards or paypal.

Thursday, May 28, 2009

E paper workshop example files


The technical aspect: you ask for images, sounds, using a FLASH movie from keys from the keyboard. But then you decide to make a paper switch, which is just more fun than a dull key. So you need a device/program in between, there are lots of possibilities: hacking a keyboard, using a HID, or using the ARDUINO.

With a hacked keyboard (see other blog) all is easy, just use the FLASH movie.

With the HID, KeyWiz40 interface (we have some at CROSSLAB) use a program between this thing and the FLASH called USB OVERDRIVE (Mac - Windows Joycur for instance)

With the ARDUINO use Serproxy, both MAC and Windows, but different files.

All is included in the download file below, (search USB OVERDRIVE here: http://www.macupdate.com/info.php/id/7115 )

So:

MAC and WINDOWS:

download this folder with the example files in FLASH:

http://www.contrechoc.com/flash/e-paperFiles.zip

all can be tested with the normal keyboard too.

added is also the posibility to stream a video (flv format). Just add the video in the folder and ask for the name of the video (under button “6″)

then for the KeyWiz40 interface:
For “normal” e-paper using the keyboard interfaces from Crosslab we can use this example flash movie, with he folders sounds and images:

keyboard input examples.fla

we need for MAC: USB OVERDRIVE between the Whiz HID and FLASH, configure the buttons after choosing the “joystick” tab on the left.

for WINDOWS: for example JOYCUR (or other freeware), also configure some buttons

——————————————————————————————————–

ARDUINO triggered e-paper, with the same FLASH movie:

WINDOWS:

For e-paper triggered by input from the ARDUINO we start the SERPROXY (windows version) first (after having configured the right port in the serproxy.config, see the com port in arduino tools insert it (three times or so) and the FLASH port must be 5331 please!)

then we need the ARDUINO script: arduinoAsKeyboard.pde in the ARDUINO.

then this flash movie: ARDUINO input examples.fla

MAC:

also use SERPROXY but the mac one found in the folder.

You have to configure the serproxy.config file, using your serial connection, found in the arduino tools, or via the terminal using “ls /dev/cu.usb*” as explained on this page: http://protolab.pbworks.com/TutorialFlashSetup

for the rest all the same, so upload the ARDUINO and run arduino script, and then run the FLASH movie.

/*******************************************************************************

For the real lover of e-paper: in the folder above is added a Processing example of reading the ports of the ARDUINO and triggering sounds, images, and text using Processing.The Arduino script used is the same as the last example: reading inputs from ports 12,11,10,9,8, this can be expanded. This eliminates the use of serproxy, or overdrive. But of course the Processing is not as flashy as FLASH!

Cheapo’s - or an Instable Multi Vibrator (!)

The ARDUINO is sometimes far too big, like a dinosaur in a cupboard. If you want to do a few switches or some simple sensor effects you can use an ATTINY13 for instance, lots of examples to be found on www.instructables.com. You have to program these insects, but the hex files are given too. So in fact it only resolves to loading the program another (clever) person made in assembler.

Another example of a useful IC is the 555 timer (also abundant on instructables), i came across some nice examples:

this is a switchlight, costing about 80 cents! http://www.circuitsonline.net/circuits/view/13

and then the instable multivibrator, or in normal language an ORGAN, :-)

http://www.circuitsonline.net/circuits/view/130

very makeable, so i ordered some 555’s fast at conrad’s

The big advantage of these smaller IC’s is that they can be built/hidden into books, clothing, in toys without a problem, of course on itself they can do not too much, but with the help of the relais (see the blog before this one), they can steer processes as big as you want!

Cool materials, smart whatever, where do i buy it?

You know all kinds of interesting things are everywhere, but even with internet they are pretty difficult to find.

So here the result of a bit of experience, and indeed lots of houres searching.

Since I am on a tight budget, trying to make the most of it, i try to avoid “handling costs” or expensive ways of posting.

These links may change or disappear!

First of course: search in your neighbourhood: Harolds has graphite powder, thin metal wire to sew.

A real cool site is this one:

http://mutr.co.uk/ —postal costs not indicated???

thermo sensitive stuff, conductive stuff, EL, phone flasher, fancy switches, and even expensive things, like conductive cloth in small quantities so it remains affordable….

http://www.sparkfun.com/

for all around Arduino (and the lilypad ), very exciting
(for me as a contrechoc.com and addict to five sided things:) ProtoBoard - Penta-shape, five angled board, don’t buy these, because these are mine :-)!

Sparkfun for conductive thread: yes expensive (everywhere) 20 euros…:-(

for all kinds of electronic equipments, resistors, relays, diodes, also EL sheet:

http://www.conrad.nl/

this comes in handy because the delivery is relatively fast, for us in Holland.

For EL wire, in Rotterdam! So i can go there on bike and save me 6 euros posting

http://www.kitelight.nl/

For thermo-sensitive pigments, used for silkscreen:

http://www.zijdelings.eu/dupont.html

ok here the direct link: http://www.zijdelings.eu/overige-pigmenten.html

For Liquid tape, used with graphite powder from Harolds, to make conductive glue:

http://www.classicinternational.nl/textned/plastidip.htm

(minimum order 25 euro)

Ok, no, not at all: they don’t pay me for making this publicity!

The other way around, also on three legs

A pushbutton for the ARDUINO needs three wires, this is for an input. The output, steering something from the ARDUINO has (no wonder) also three legs, it can be done by a transistor:

The middle wire of a transistor is the boss. When it has the proper signal (depending on type of the transistor , HIGH or LOW) it lets current pass through the outer two legs:

output.jpg

The port can have a 4.7K Ohm resistor, the effect only depends on the HIGH or LOW!

Cees Baarda provided with a transistor type: BC547C, others can be used too.

This way you can switch on or off: LED’s, speakers, etc. For more complex things to switch on, being on higher voltage than the ARDUINO, or if you want to save the power of the ARDUINO (using it stand alone, not on USB) and the thing to switch on has its own power, then you use a relay (relais).

A relay has two circuits, one to switch it (on low voltage) and the other (independant) with the real voltage, which can be much higher. The small voltage switches the high voltage circuit. Here is the picture from the datasheet from a relay:

relay.jpg

You see legs 1 and 10 are the low voltage steering pins, and both sides have a high voltage switch between pins 7 and 8 (3 and 4).

So you can use the transistor to drive the relais, and the relais to switch on heavy duty things! Here the drawing of Cees Baarda, tested!

schema.jpg

relais.jpg

From this relay the High Voltage of EL wire, or EL sheet can be switched of and on, regulated by the ARDUINO. The relais makes a sound (the magnetic jumper like a ticking “cloque de coucou” :-)

PS there is one more: the diode protecting the input port…..but it all very do it yourselfable.

PSS what does this cost? - where to get it?

relatively cheap: transistor BC547c conrad.nl 0,13 euro

resistors (koolfilmweerstand) conrad.nl 0.09 euro

relay (relais) conrad.nl 1.69 euro

diode conrad.nl 0.04 euro

Even a button has three legs

Connecting a button is one of the easiest things to do. A light switch should transmit, or not transmit current, being on of off.

Although some reflection reveals that in reality it is not easy either: a window won’t stay open or shut without a hook, nor a door…

Receiving a signal from a button on an Arduino (Lilypad) is just a bit more complicated than the Boolean (TRUE - FALSE) character found in the laptop

A button on the ARDUINO (or comparable) is read in a digital input port registering either a HIGH or a LOW (being either a connection to 5V or to the Ground GND). So a button has three wires! Two wires to 5V and GND respectively and one to the digital input port.

Also: the button needs a resistor (otherwise there might start running a current and you have a short circuit!). You have to make “the standard” state of a port either a HIGH or LOW, and the non standard, pushed, state where the button connects to the reverse but this last connection through the resistor (10K).

push.jpg

When you make connection only to the HIGH for example through the resistor, then the LOW state might become HIGH too, because it is not kept LOW. This gives erratic (artistic) behaviour! (Ever waked up at night because of an unsecured windowmaking lot’s of noise?)

See all this explained much more technically:

http://www.arduino.cc/en/Tutorial/Button

This is not at all difficult, but just a bit more complicated then you would think, seeing a light switch in a lamp.

Details:

in this link

http://www.lulu.com/items/volume_63/1108000/1108699/4/print/ARDUINO_NOTEBOOKv6.pdf

i came across an important remark, apparently saving the trouble of putting the pullup resistors, because the input port is already protected:

“Arduino digital pins default to inputs, so they don’t need to be explicitly declared as inputs with pinMode(). Pins configured as INPUT are said to be in a high-impedance state.
There are also convenient 20KΩ pullup resistors built into the Atmega chip that can be accessed from software. These built-in pullup resistors are accessed in the following manner:
pinMode(pin, INPUT); // set ‘pin’ to input
digitalWrite(pin, HIGH); // turn on pullup resistors
Pullup resistors would normally be used for connecting inputs like switches. Notice in the above example it does not convert pin to an output, it is merely a method for activating the internal pull-ups.”

more interesting stuff on the pull-up: (apparently the above is partially copied from this source or the other way around:)

http://www.arduino.cc/en/Tutorial/DigitalPins

a very extended bunch of ARDUINO things:

http://www.freeduino.org/

Lilypad

The Lilypad is much more designed than the ARDUINO. The arduino itself is a working horse, a factory. All kinds of hidden extra possibilities, like we have seen in other posts on this blog, even more to come! The ARDUINO board is rectangular, functional. The Lilypad is round, and the pins are shaped like a flower. Also the habit of putting shields on top of the ARDUINO is not possible with the Lilypad. The microcontroller is a bit different, being a ATMAGE168V, smaller, and not replacable(so be careful!). Lilypad can run on a 3V coin battery.

The Lilypad was designed and developed by Leah Buechley and SparkFun Electronics. It can be used as a wearable much more comfortable than the ARDUINO, although, when using small scripts, either a “naked” ATMEGA168 can be used, or even a Tiny13. These IC’s without the boards can be hidden quite easily too.

But no using the Lilipad, you have to SHOW it!

Starting it up is different too. You can use the ARDUINO (without the ATMEGA168) to transfer scripts. See the http://web.media.mit.edu/~leah/LilyPad/01_computer_attach.html The resetting of the Lilypad and the starting the transfer of the script is rather tricky! I saw my Lilypad flickering so I knew it was alive, otherwise… In XP it didnt work at all, On my OS side (of my MACBOOK) with apparently a different setup of the ARDUINO software (version 012) it works after a few tries. So first you get an error “out of sync” or “programmer not connected” the suddenly, the normal announcement of the script size (in the editor window of the ARDUINO software). So keep trying, resetting the Lilypad after hitting the transfer button varying a bit in seconds between these two actions.

My first real test was sewing the Lilypad on a cap, with a light resistor, when the light goes, (or somebody tries to steal my cap) a LED is fired up. Not very spectacular, but good as a starter. I didn’t try to hide the wiring!

Having to transfer these scripts (after testing the script on a normal ARDUINO), having to sew the Lilypad on the clothing, and thinking about how to hide, or show the wiring…this becomes a complex job!

And be careful not to walk around showing the Lilypad in Airport areas, because people might think that you want to blast the place away and call the police (this has actually happenend, see the last MAKE magazine, and the consequences for the “really innocent”wearer were not pleasant!).

cap1.jpg

A few links:Very much the Lilypad home: http://www.cs.colorado.edu/~buechley/LilyPad/index.html

This link to get arduino (in general) running in 15 minutes and…the help!:http://www.ladyada.net/learn/arduino/help.html

lilypad doc:http://arduino.cc/en/Guide/ArduinoLilyPad

a report of a workshop:link:http://web.media.mit.edu/~leah/publications/buechley_CHI_08.pdf

Saving an ATMEGA 168

Why did I write this mail to Jeff?: (it is a long story…)

http://mightyohm.com/blog/2008/09/arduino-based-avr-high-voltage-programmer/

He Jeff, thx, for the artschool in Rotterdam Holland (WDKA) I thought I could save a bit of money buying ATMega’s instead of Lilypads and Arduino’s. I ran in the same fuses trouble I found in your blog (having more experience in Iphone programming :-). Just in this holiday week I decided I could try building your shield. I had to be careful (so being not at all artistic) and indeed I succeeded in…yes! making a tiny shortcut in between two near pins, of course the 5.5V and the GND of the ARDUINO. Invisible to the naked eye, there was a microscopic soldering error on my board between the not even “used” pins!
USB protection saved me twice, but then amazingly my shield (a master copy of your shield) worked! I could recuperate the ATMEGA 168. (And the 9 others I had apparently meshed up!)

(See Bootloading the Arduino a blog of 27 januari.)

shield1.jpgyou see the Arduino is so rectangular, the lilypad is already nicer, but the single ATMEGA is even more small and “hideable”. Only, get this thing programmed! (Don’t forget to set the internal timer….)

shield2.jpgWhat happened? I wanted to try “the naked ATMega168″. But I ran into trouble: the hex file to bootload the ATMEGA was nt the right one. First i started altering settings, I didn’t know about fuses, lockbits, so….in the end I foudn the right HEXfile, see former blog about this. But then apparemtly I already had bad settings for quite a few of the 10 ATMEGA’s.

So I started digging the internet and found the blog of Jeff. But well, it took me a few weeks to decide to build this shield (picture above). And after some trouble it did save 7 out of 10 ATMEGA’s. For the last three i am writing in the file of Jeff on the ARDUINO the eraseChip function, but that does not save me at the moment. Anyway, you don’t save time buying naked ATMEGA’s :-) But i have learnt a lot! Being able t make a shield is perfect and from the script of Jeff i learnt the possibility of setting ports 0-7 at once using the DATA.

And in the end the best reward is when it actually works!

I lost this link several times: the datasheet, the page to program HIGH VOLTAGE stuff is around 297:

http://www.atmel.com/dyn/resources/prod_documents/doc2545.pdf