December 15, 2008 at 8:15 am · Filed under code
Hey all,
Here is a new updated firmata sketch that fixes the functionality of the servo motor and adds that of the shift register (see previous post ‘multiplying arduino outputs)
servos:
So as i mentioned in class the firmata sketch we used to upload to arduino had a bug in it if you wanted to use a servo motor on pin. The commands were calling
servos[pin-9].attach/detach/write
whereas they should have been servos[pin-9].attach/detach/write. This is because the servos array is an array of 2 servos, and the pins come in as argument = 9 or 10.
shift register
In order to do faster animations on the LEDs with a shift register, we added new sysex functionality. For this, we modified ofArduino.h and ofArduino.cpp and the firmata sketch uploaded in the arduino.
Basically hat we did is define a new constant SYSEX_SHIFT both in ofArduino and on the arduino sketch, and then created functions that send this constant as an indication that this is a shift register command. The ofArduino code sends the arguments (which are the pin configurations of the shift register on the arduino: datain, clockpin and latchpin), and then the arduino takes care of pulsing the appropriate pins and sending the data to the shift register. For instructions on how to connect the shift register, see the previous post ‘multiplying arduino outputs’
what you need to do:
- Backup ofArduino.cpp and ofArduino.h in ‘libs/openframeworks/communication’
- Save and uncompress
ofarduino files in ‘libs/openframeworks/communication
- Save (right click save)
ofstandardfirmataplusservoplusshiftregister in the ‘other/firmata’ folder in OF, and upload it to the the arduino:
Now you can use two servos on pin 9 and 10 of the arduino.
Also, you can just write code that uses the shiftOut function. Here is some code that uses the shift register to animate a 4×4 led matrix.
Remember, the shift registers can be cascaded for an ‘almost’ infinite number of leds!
day9_shiftRegister.zip
December 12, 2008 at 3:02 pm · Filed under documents
I’d started putting this document together to consolidate everything we have seen. Most of the stuff is in the blog posts, but still, there are some good extra links in there.
class11-hardwarethingswehaveseen
Remember, don’t hesistate to email with questions or interests
December 11, 2008 at 8:07 am · Filed under code, tutorial
In last class we saw 3 things sensors solenoids and dc motors here are tutorials and the OF code for them.
Sensors
In class i showed a thermistor (available from sparkfun, but also the NYU computer store) and a photoresistor (available from radioshack ). (the thermistor i showed in class was black)

Basically these two are like potentiometers. Remember that in order to understand how these variable resistors respond with their respective variables (ie temperature and light), we look at their datasheets
How do we connect them?
We attach the thermistor and the photocell as if they were a 2 terminal potentiometer. With one leg going to the power and the other leg going to ground through a resistor of equal value, and that same leg is also going to the input of arduino.

here is the OF code for reading from these two sensors. In this case i connected the thermistor to analog pin 4 and the photoresistor to analog pin 5. We use Xeno smoothing to smooth out the values from the sensors.
day11_sensor_Source
Solenoids
Solenoids are electromagnets with a moving part. Basically when a current is sent to the solenoid it becomes a magnet, and whenthe current is removed, it goes back to being demagnetized.
Here are some. The ones i showed in class were clappers, and looked little like this:

Solenoids require much more current than the arduino can provide. So we need to use them with an external power supply and a transistor. The transistor acts as an electronic switch. The one we saw in class was the 2N2222 and is available from radioshack. Its datasheet is available here

Another very popular one is the TIP120 (available from the NYU computer store). The datasheet for it can be found here.
The transistor has three connections: the base, the collector, and the emitter. The base is connected to the microcontroller’s output. The high-current load (here the solenoid) is attached to its power source (external power supply), and then to the collector of the transistor. The emitter of the transistor is connected to ground.

When there is a high at the base of the transistor, the switch is closed between the collector and so current is allowed to pass from the collector to the emitter.
We also put a diode (which is used to ensure current flows only in one particular way) between emitter and collector in order to protect the transistor if the solenoid sends kickback current in the opposite direction. The diode here is a 1n4004 available from radioshack. Note that the silver line on the diode corresponds to the line in front of the arrow in the schematic.
Remember the arduino and the external power supply should have ground connected to each other.

Now, when we send a high to the arduino pin (in the image above its pin 9), the switch is closed, and external power supply going to the emitter (ie ground) passing by the solenoid which becomes magnetized and closes.
As you can see each solenoid requires one transistor attached to it. There is no OF code here but basically we can control the solenoids just by putting a high on the corresponding arduino pin!

DC motors
Unlike Servo motors, DC motors do not know their position, and can rotate 360 degrees. You connect a DC motor to power and ground to rotate in one direction, and flip power and ground to rotate in the opposite direction. DC motors are voltage rated (5V, 7V, etc). And running a DC motor at less than its needed voltage will slow it down. DC motors are widely available, this one is from radioshack
(you can also find them at the NYU computer store, or even car stores, many different voltages and torques are available)

DC motors like solenoids need more current than the arduino can provide, so we need to use them with an external power supply and a transistor. Now because DC motors have two directions of rotation we want to be able to change the direction of rotation so we use an Hbridge instead of a transistor (an hbridge is essentially many transistors in one).
The hbridge we will use here is: L293 and is available at the NYU computer store.

You can assemble the circuit as seen in this tutorial.
http://itp.nyu.edu/physcomp/Labs/DCMotorControl
In the class example, the DC motor i was using was weak and did not require more than 500mA, so i was able to use the power from Vin from the arduino instead of directly from the external power supply. Connect the arduino to a wall wart and move the jumper next to the wall wart connector on the arduino to the ‘EXT’ pins. Then we take the power for the hbridge from the pin labeled Vin on the arduino.

Here is the OF code for controlling the hbridge with a switch. The only difference with the tutorial above is that i added a potentiometer on the arduino analog pin 0 and used that to control the speed of the hbridge.
day11_DCMotorControl_source

December 10, 2008 at 1:13 pm · Filed under code, tutorial
Hi all,
Here is the code needed to smooth out potentiometer and sensor inputs in OF. Basically we are using the Xeno method, and you can experiment with the percentages to get the best response/smoothing effect.
For each potentiometer in testApp.h, declare a variable for the smoothed value:
float potSmoothed;
In testApp.cpp, in setup set potSmoothed to an initial value of the potentiometer
potSmoothed = ard.getAnalog(potPin);
In update, get the value from the pot into potValue, then catch up to it with potSmoothed, and use potSmoothed in all subsequent places instead of potValue
potValue = ard.getAnalog(potPin);
// to smooth out the potentiometer value, you can play wit the coefficients
potSmoothed = 0.75f * potSmoothed + 0.25f * potValue;
now you can go back and smooth out all the potentiometer inputs you have done,
good luck!
ayah
December 7, 2008 at 4:12 pm · Filed under code, tutorial
Homework 7 wa about creating a control panel to control animations on screen. We can do this using potentiometers, switches, push buttons, unconventional switches etc. We can even combine the screen output with some LEDs and have LEDs in the control panel to mimic the screen animation.
in this contrl panel i connected 4 potentiometers, a switch, a pushbutton and 4 LEDs.
- The slide switch controls rectangle versus circle animation
- The potentiometers control various variables of the code
- The pushbutton is a record button as it is pressed down it records the path of the circle

day9_controlpanel
December 7, 2008 at 12:36 pm · Filed under code, tutorial
So as we discussed in class, when we want to address a large number of LEDs (or other outputs), we hit a wall with arduino because of the limited number of pins available to us. There are several techniques to go around this, and these are two of them:
- using an analog multiplexer/demultiplexer chip. This is also called an analog switch. In the case of a 1-8 mux/demux for instance, we connect the I/O line of the Mux/demux to arduino, as well as the 3 control pins. Then, depending on what are the values we put on the control pin, we are closing the switch between the input (or output) and one of the 8 outputs (or input).
Here are some tutorials about the very popular 4051 chip.
Here is some OF code to control the multiplexer, and animate an array of 8 leds with just 4 arduino pins. You can add more multiplexers, and even cascade them for lots more outputs.
day9_multiplexer1
This technique does not allow us to place values on more that one line at a time, so we cannot have more than one led on at a time. But because of how easy and cheap this technique is, it is excellent for applications where this is not necessary or in the case where we want to read from 8 pins as opposed to control them.
Which brings us to the second technique.
- using a shift register. A shift register is serial to parallel converter that allows us to send 8 values serially to the chip, and then when we trigger the clock and latch signal, to have that data come out of the shift register in parallel. This means in the case of the 16 bit shift register, we can control 16 leds at a time, by just using one pin from the arduino for data, as well as one for the clock, and one for the latch signal


Here are some tutorials for the 74hc595 shift register: http://www.arduino.cc/en/Tutorial/ShiftOut.
Since the shift register can work at very high speeds, and the serial comunication is considerably slower we rewrote the firmata sketch and added a shift register command. Now you can send a shift out command from of and the arduino will take care of sending the data to the shift register. See newest post with the ‘new and updates firmata sketch’
Note: if you want to be able to control the LED brightness as well: the above shift register can only do on-off for the LEDs. For brightness nstead you can use a shift register with grayscale control. For instance, one is TLC5940. Here are some tutorials for using this led driver: http://www.arduino.cc/playground/Learning/TLC5940
December 6, 2008 at 7:20 am · Filed under homework
please be SURE to do a print from homework 10 for class -
homework 10
there were several questions about vector output - I tried to answer in class, but I can help anyone that needs it.
+ + + + + +
a) Using one of the three techniques for fast particle particle interaction, please try to make an interesting interaction (not composition) out of them. For example, we’ve seen how particle-particle interaction and vector fields can be used, also, we’ve seen how particle particle interaction can be combined with live or prerecorded video. Make something organic and playful. No particles as circles, please !!!
b) try using the spring system (springs and springs with internal forces, etc) and combine them with something else we’ve covered, like vector fields, force emitters, etc. Can you make something really interesting combing springs and other forces?
c) Take a moment and play with soda constructor.
http://sodaplay.com/
Save a good model and include a screenshot on your homework page. there is info here:
http://sodaplay.dailyforum.net/viewtopic.php?f=1&t=284
http://sodadome.com/tutorials/
ie,
http://sodadome.com/tutorials/sodaconstructor/springs_and_masses/
d) now, with that inspiration (hopefully) use the spring example with muscles (ie, springs that have their rest length changing) to make a creature that does something interesting.
+ advanced +
e) make the fastest particle - particle interaction possible. you might be helped by something like this:
http://www.flipcode.com/archives/Fast_Approximate_Distance_Functions.shtml
also combining approaches can be helpful too -
what is the maximum # of particles you can have interacting with each other above 30fps ?
f) can you make flocking (or interacting) spring based creatures?
December 6, 2008 at 6:44 am · Filed under code
here’s code from class 11, which covers the basics of springs and spring systems:
day11_code
November 27, 2008 at 12:50 pm · Filed under code
hi - here is the code were covered in class this week, about particle particle interaction. Additionally, zach showed an example found here
this zip has three examples - particle particle interaction via binning, particle particle interaction via sorting, and particle / contour interaction using video / live camera. enjoy !
day10_code
November 22, 2008 at 5:30 pm · Filed under homework
a) combine the vector field and particle-particle interaction in an interesting way. think, for example, about your particle particle interaction homeworks (or your vector field homeworks) and is there any one there that you’d like to improve? Make something super interesting. No circles!
b) take a look at the flocking code, especially changing the parameters relating to flocking (see particle.cpp for the definitions of the radius and strength of the different forces). Can you make the flocking more interesting? Find the most interesting parameters (and remember, every particle doesn’t have to have the same values, they can be different) and then work to use this in an interesting composition. For example, can you include other forces in addition to the flock simulation to make it more interesting? Don’t forget about the other things you’ve learned, like the point recorder and sin/cos, etc.
c) use the vector output code to make a poster or print. think about how the forces we have learned can be used to create structure and meaning, and then how capturing that vector wise could be employed in an interesting way. Make something super great. we will take a look after thanksgiving at the prints.
Next entries »