An interesting article by some researchers from the University College in London describes the equation they constructed and tested that predicts happiness.
A key part of the equation is that it relates happiness to the difference between people’s expectations of rewards and the actual rewards.
… we show that emotional reactivity in the form of momentary happiness in response to outcomes of a probabilistic reward task is explained not by current task earnings, but by the combined influence of recent reward expectations and prediction errors arising from those expectations.
I wired a temperature sensor to my Arduino as part of the third project in the Arduino Projects Book. The project has the Arduino send the data to the serial port where the Arduino program (IDE) can show it. This data would be most useful to me, however, if it could be logged in a plain text file for data analysis. However, it’s a little annoying that there isn’t an easy way to save the data output by the Arduino.
So, I needed to use the terminal program “cat” to look at what was coming across the serial port. First I had to look up which port the Arduino was connected to in the Tools menu of the Arduino IDE: since I’m on a Mac, running OSX, this turned out to be something like /dev/cu.usbmodem411. (I could have looked this up by listing the contents of the /dev/ directory and then looking for anything connected to the usbmodem). To see the data I used:
> cat /dev/cu.usbmodem411
To actually save the data I directed the output of the cat command to the file data-log.txt:
I’m not sure what’s the deal with the first three lines, but if you ignore them you see the column headers (Time and Temperature) and then the time (in milliseconds) and temperature data) in a nice comma delimited format.
The Arduino program (sketch) that produced this output was:
const int T_sensor_Pin = A0;
const float baselineTemp = 20.0;
const int outPin = 4;
void setup(){
Serial.begin(9600);
pinMode(outPin, OUTPUT);
Serial.println("Time (milliseconds), Temperature (deg. C) ");
}
void loop(){
int T_sensor_Val = analogRead(T_sensor_Pin);
float T_sensor_Voltage = (T_sensor_Val * 5.0)/1024.0;
float T = (T_sensor_Voltage - 0.5) * 100;
float T_F = (T * 1.8) +32.0;
Serial.print(millis());
Serial.print(",");
Serial.println(T);
delay(1500);
}
Alternative Methods of Saving Data
Python
Based on the same Arduino sketch, you can write a Python program to read the data. This method enables you to use the data directly with VPython for visualization.
Ripe, bright-purple sumac berries are quite astringent. Steep a ripe bunch in a quart or two of hot water for a few hours (or cold water for a day) and the result is a tart tea. Add a third of a cup of sugar to make a delicious juice. (Note: Poison sumac is not found in Missouri, but it has been identified in adjacent, eastern states, so be careful.)
One of the key ideas behind the design of the RepRap 3D printer we just built is that you should be able to print as many of the components as possible. So you can use your 3D printer to build other 3D printers. As a consequence, the printer does not come as a nice little box. It looks a bit jury-rigged. Multicolored coils of wire snake everywhere; circuit boards and integrated chips are exposed; nuts, bolts and stainless steel rods are accessible for easy adjustment; and the plastic–printed–components are still rough from the printer. It is all function, no aesthetics. All of which make it a wonderful teaching tool.
The three students who built it got a crash course in robotic assembly. They learnt how to wire a power source, strip and solder wires, and construct the motor-controlled bed and extruder. They also learned how to use constructive solid geometry (using OpenSCAD) to create 3d shapes–I required them to design and print their own models before I would let them download object files from the internet.
On the down side, though they did have to plug a RAMPS motor shield, stepper-driver chips, and connecting wires into the Arduino microcontroller, we did not have much time to go into the detail of what it all was about. Also, we only edited an existing configuration file when we tried to calibrate the machine, so they did not learn how the programming works. Having to use the Arduino did inspire me to get one, and I was quite impressed with their starter kit, so I’m working on a “Microcontrollers for Beginners” type class or elective that I can offer over the next school year.
I’ve been avoiding working with the Arduino microcontrollers because I’d prefer to be able to program in Python with the Raspberry Pi (for example). However, since the 3d printer we just built this summer uses an Arduino for a brain, I broke down and picked up the Arduino Starter Kit (via Adafruit).
What I liked most about the Starter Kit most is the Arduino Projects Book that comes with it. It’s a wonderful introduction to circuits, electronics, circuit diagrams, and microcontrollers at the beginners level. If I offer an Arduino elective, I’ll use it as a textbook. Indeed, I’ll probably use bits of it as a reference when I teach circuits in middle school and Advanced Physics.
As for the programming, the basics, at least, are pretty straightforward. I got a blinking LED controlled by a switch input up an running pretty quickly. The code requires two loops, one to set up the inputs and the output, and a loop for the program to follow. The code below has a blinking light that’s controlled via pin 4, but changes to a solid light when the switch is pressed (the input for the switch is pin 2). The wiring for the circuit is shown in the picture at the top of the page.
Working on algebra over the summer, we tried a little programming. This is O’s first program, which gives the chirp rate of crickets based on the temperature.
t = float(raw_input('enter temperature> '))
n=4*t-160
print "number of chirps=", n
print "t=", t
OpenSCAD bills itself as “The Programmers Solid 3D CAD Modeller”. It does this job pretty well, which is probably why I like it so much. Like POV-RAY, which I’ve used before, you create primitive objects–spheres, boxes, cylinders, etc.–and add or subtract them from one another to create the three-dimensional shapes you want.
Unlike the more graphical 3d modeling programs, like SketchUp (which I’ve played with in the past), in OpenSCAD you have to specify in the script the exact dimensions of your primitives, and how to rotate them and translate them to get them where you want them to be in space. This makes it a great language to use in geometry class, or anywhere else you want students to learn about co-ordinate systems.
The script to create the box with a circle cut out of it (see figure above) is:
Vpython requires students of make similar geometric movements of their objects and renders them nicely in 3d, but given the incentive that they can print up a tangible result of their work, I’d be willing to bet that students, especially younger ones, would be quite motivated to work with OpenSCAD. Vpython does retain the advantage that it is able to do animations, while you can only print static objects. In addition, OpenSCAD is more of a scripting language than a programming language like Python (see some of my Vpython programs here).
The OpenSCAD documentation is quite good. I also found it easy to find instructions on how to create a 3d object from a black and white image, simply by extruding it in the third dimension (by iamwil on the Cubehero Blog and by I Heart Robotics).
One note: I’m using OSX 10.6.8 at the moment, and the current version of OpenSCAD does not work on it. Since I’m loathe to upgrade, I had to use the prior release of OpenSCAD-2013.06.dmg.
I took three students to a workshop were we’re building a 3d printer. It’s run out of the Whitfield School. We spend today putting together the electronics to run the five motors we need to get the thing to work, and starting to put the frame together.
The frame is based on the RepRap Prusa i3 (via DIY Tech Shop), and the plastic parts that hold the rods, electronics and other metal bits together are 3d printed themselves.
The motors is run by an Arduino, which is great because I’ve been thinking about using one to operate the doors to the chicken coops.