Pages

Tampilkan postingan dengan label sketches. Tampilkan semua postingan
Tampilkan postingan dengan label sketches. Tampilkan semua postingan

Sabtu, 21 Mei 2016

7 Jeremy Blum Video Arduino And Processing Sketches

Today’s blog post takes a look at some of the programming concepts used in the #7 Jeremy Blum ‘Arduino tutorial series’ video.
#7 video exercise Arduino circuitry

The Arduino exercise in the #7 video uses a Microchip Technology TC74A0-5.0VAT temperature sensor to acquire temperature data and display it on the computer to which your Arduino circuitry is connected. To do these two tasks, you’ll need two programs. An Arduino program will be used to grab and transmit the temperature data. Then a Processing program will be used to take that temperature data and display it in the specified font on your computer’s monitor.

The Arduino program Jeremy wrote is called read_temp.pde. He makes the programs for the video tutorial series available online, but you’ll gain a lot more skill with Arduinos if you type the programs yourself rather than downloading them, at least while you’re learning new programming concepts. Arduino.cc explains the .pde files from the Arduino IDE (Integrated Development Environment) this way:
The Arduino environment uses the concept of a sketchbook: a standard place to store your programs (or sketches)...Beginning with version 1.0, files are saved with a .ino file extension. Previous versions use the .pde extension. You may still open .pde named files in version 1.0 and later, the software will automatically rename the extension to .ino.”
So the reason Jeremy’s read_temp Arduino file is has a .pde extension instead of .ino is because the video is a couple years old, and he was using an earlier version of the Arduino IDE. The current IDE version is 1.0.5, with the Beta version being at 1.5.7. The .pde file extension (Processing Development Environment) is the one used by the Processing, Wiring and early-version Arduino IDEs. Processing is often used as an educational tool to teach foundational programming skills in a visual environment and is Java based rather than C.

To have the Arduino get the temperature data from the Microchip sensor, which is done with read_temp.pde, Jeremy starts out by importing the I2C library. For Arduino this is the Wire library. Importing the Wire library is done with the command:

#include <Wire.h>

Next you set the I2C temperature address. For the sensor he used, the I2C address ID was 72, per the #6 video.

int temp_address = 72;

In the setup section for the sketch, you have to start the serial communication and initialize the Arduino listening on I2C communication bus, using:

Serial.begin(9600);
Wire.begin();

The loop section of the sketch has the components shown below. I won’t write out all the code here -- when you go through the exercise, you’ll get a chance to learn what’s needed to accomplish each task shown in the list of loop section comments below.

//Send a request
//Start talking
//Ask for Register zero
//Complete transmission
//Request 1 byte
//Wait for response
//Get the temperature
//Convert from Celsius to Fahrenheit
//Print the results
//Delay, then do it again

Warming temperature sensor; terminal window temperature display
After the above steps are all written for the Arduino sketch, you upload it to your Arduino. Following a successful upload of the Arduino sketch, you’ll see the current temperature of the sensor displayed in a terminal window. Jeremy then puts his finger and thumb over the sensor to confirm that the sensor can measure the difference between the room air and Jeremys skin temperature. To get a temperature display other than just in the terminal window, you need to write a Processing sketch. This will display on your computer monitor the temperature results generated by the temperature sensor circuitry and the Arduino sketch. The Processing file Jeremy wrote to display the temperature on the computer’s monitor is display_temp.pde.

Associated with display_temp.pde is the .vlw file AgencyFB-Bold-200.vlw. The .vlw file type is a font file created by the Processing language. Processing will create the .vlw data file for a font that’s on your computer system when you use the Tools / Create Font command. After you create the data file you can use it in your Arduino / Processing program with the loadFont() function. If you want to dig into the loadFont() function in Processing, two resources are the relevant Processing reference webpage and a tutorial from Purchase College.
Creating a font in Processing

Start out by selecting Tools / Create Font in the Processing sketch window. Select one of the font styles shown in the Create Font window. Next, select the font size you want to use. Jeremy selects 200 for the size so it will create a large font on the computer monitor. When you click OK in the Create Font window, it will create a .vlw file for the specified size font.

Next, write the initial components of the code shown on the video, including things like defining the variables for the program, then do the setup and draw sections of the sketch. After the initial components of the sketch are written, you setup the ‘canvas’ where you’ll display the font, using the command:

size (400, 400);

After setting up the canvas, set up the serial port, using the command:

port = new Serial(this, “COM3”, 9600);

Once the serial port is set up, you tell it to keep looking for information until it gets to the end, which has been defined by a period. You tell it to look for that info with the command:

port.bufferUntil(‘.’);

Next, set up the font, specifying the .vlw file that you created earlier, using the commands:

font = loadFont(“AgencyFB-Bold-200.vlw”);
textFont (font, 200);

I think the 200 is optional in the second line, since the .vlw file specified already defines that it’s a 200 point font. I don’t know if you can use a non-sized font file in the loadFont function, such as AgencyFB-Bold.vlw, then specify the size in the textFont function. Haven’t had time to dig into that Processing function yet; maybe a blog post reader can point out where the Processing.org website explains that, or I might research it in the future. For now, I’ll just type it the way Jeremy did.

Next, write the commands for the draw section of the sketch, which tells the computer what characters to display on the monitor. Do this with the background, fill and text commands. Per the discussions in the recent blog post, “#7 Jeremy Blum Video: I2C And Processing,” you’ll have to use an RGB color chart or list to specify what color you want the background and the text. You also have to specify which variable strings (temperature labels to go with the temperature data) the Processing sketch should ‘draw.’

Now write the serialEvent section of the sketch to grab the temperature data off the serial port, then use a substring command to reformat the information by removing the period at the end, using the commands:

data = port.readStringUntil(‘.’);
data = data.substring(0, data.length() - 1);

Next you write the code for finding the comma in the string, for fetching the Celsius data and Fahrenheit data (as shown in the video).

Once you’re done writing the Processing sketch as described above, click on the Run icon in the Processing sketch window and your computer should display the temperature currently being
measured by the Microchip temperature sensor, as captured and transmitted by your Arduino. If it doesn’t display the temperature, review your code versus what Jeremy shows in the video and make any needed changes in your code so it matches his code. Good luck on not needing any debugging!

Hope to see you at the July 10th meeting for the Humboldt Microcontrollers Group, 6 - 8 PM at 1385 8th Street, Arcata, California. The main topic for the meeting is discussing the I2C and Processing concepts used in the above temperature sensing exercise, as well as any problems people had with the exercise, and maybe some interesting I2C, Processing, or temperature sensing tips and tricks people know of or discovered in the past two weeks.

**********
Read More..

Kamis, 24 Maret 2016

Robotics Takes Flight With Hummingbird Duo Kit

This post was prompted by recent article involving robotics, a microcontroller (MCU) application of high interest, especially to young people.

The Design News article, “Hummingbird Makes Coding Easy,” talks about the new Hummingbird robotics kit. Although the title indicates a focus on programming, the article really just briefly mentions the coding aspects of a Hummingbird kit in this paragraph:
The kit is called the Hummingbird Duo and is meant to provide a progressive robotics learning experience. Users start on level one, where they build and program their own homemade robot using the Hummingbird board. At level two, users can program their robots using computer programs Scratch 2.0 or Snap! Makers can also use the very same kit to run Arduino Leondardo (which comes installed on the
Hummingbird Duo robotics kit
backside of the board) to create a standalone robot, capable of doing anything really, since its open source and can run on Mac, Windows, or Linux
.”
The main goal of the Humboldt Microcontrollers Group is to expand and connect the Humboldt community of people using microcontrollers. An important aspect of using microcontrollers is knowing how to program a microcontroller and becoming good at it. Although the above article doesn’t tell us a lot about the programming aspects of working with the Hummingbird robotics kit, the Parents’ Choice review of the kit gives a much better understanding of why Design News might have used a title about ‘making coding easy.’
Parents Choice award
The box contains no manuals as such, but points to the developers website for guides to get started, links to video and print tutorials, and guidance on choosing and using a programming language. No programming skills are needed before beginning; the developers created a baseline CMU CREATE Lab Visual Programmer that is easy for non-programmers to use to get started. This is also a great way for children ages 8 and above to start thinking about the logic and flow of a computer program, and convenient for more experienced programmers to use to test the connectivity of the equipment. A wide range of languages can be used, however. Slightly older children may have fun developing within the Scratch language, which connects to a programming and creativity community online—widely popular with preteens and young teens. Those who are interested in serious design can use Python or Java, among several other choices. In testing, we had success with all of the languages named above. The developers are keen to emphasize the creative side of this...this kit is by no means limited to craft projects; as it uses off-the shelf parts, one could potentially integrate much larger circuitry or even other electronics kits (they have a tutorial with MaKey MaKey) into the system, using the Hummingbird controller as an easy interface. This kit has the possibility to be used in high school and college electronics laboratories.”
An article from the Newport Beach Independent, “ExplorOcean: Robotics for Kids” also addresses the coding involved with Hummingbird robotics kits. This summer, ExplorOcean is offering,
ExplorOcean classroom and parts bins
hands-on “Maker Workshops,” which teach children and teens age 10 and older about technology, programming, and engineering...Classes include how to build robots, rockets, metal detectors and other projects...Grounded in the seventh principle of ocean literacy that the ocean is largely unexplored, the program is designed to provide kids with the tools to discover. The different activities teach the participants to “understand and then innovate.”...On Tuesday, four Huntington Beach siblings worked with Hummingbird robotics kits, programming robotics with a computer to manipulate movements and create noises...“It’s really cool because it can be simplified for someone of a younger age or someone who’s going to go to college,” Aisha Lozada, an Explor Educator said about the equipment she uses to teach kids programming and robotics...Kids learn to control their robots through a computer program. “They had to create a project board that (lists) the materials they used, how the thing works,” she said, “but they also did real world connections, like where might you see this in the real world, but they also had to identify problems and solutions.”...Another one of their programs, EcoTech, teaches kids about ocean threats, and has them create and use underwater robots to film documentaries, thereby mixing ocean ecology, robotics, and film making into one activity. To many kids, robotics may seem more difficult than fun, but most participants enjoy the experience and many comment that they would like to continue learning about robotics in the future. It’s the perfect way to introduce children to programming and engineering...”
Because a large number of Humboldt residents are near Humboldt Bay and the ocean, it would be cool to discuss with local educators, students and parents whether an ocean robotics program similar to the one at ExplorOcean would work well in Humboldt County. As the above article mentions, “It’s the perfect way to introduce children to programming and engineering...”

From a programming standpoint, the Hummingbird’s company website provides lots of coding resources. Some of those resources can be found on the following webpages:
  1. Hummingbird Software -- This page talks about using several programming languages and programming environments with the Hummingbird kit, including Visual Programmer, Scratch, Snap!, Python, Calico, Processing and Java.
  2. Hummingbird Firmware -- The Hummingbird site has a page dedicated to firmware for the Atmel Atmega16u4, the MCU on the Hummingbird ‘controller’ board.
  3. Hummingbird Tutorials -- This page has 13 tutorials to help you get started on different aspects of programming and using the Hummingbird robot you build.
A Kickstarter campaign just finished for the Hummingbird Duo robotics kit. Their campaign goal was $30,000, and they ended up with $42,074. Although they achieved their base funding goal, the campaign wasn’t a runaway success like the Spark Core mentioned in yesterday’s post. The Hummingbird Kickstarter campaign had several stretch goals, with the top one being $250,000. One of the nice things about the campaign showing their stretch goals is that it gives Hummingbird robot builders ideas for expanding the capabilities of their robot.
Bot4Julia, Arduino compatible-based robot

Some interesting or useful MCU projects, like building a plain temperature or light sensing device, aren’t the most effective at getting new people interested in working with MCUs. Other MCU projects, however, have great potential for catching people’s interest or encouraging public interaction. 3D printers are one MCU application that seems to draw a crowd of interested passersby when they are set up in public. Another type of MCU project good for catching people’s interest is robotics.

After the Humboldt Microcontrollers Group finishes the Jeremy Blum Arduino video tutorials, we’ll discuss what the focus should be for future biweekly Thursday meetings. One possibility for meeting topics is various MCU projects. One project near the top of the list should probably be robotics, both to have fun and to get more Humboldt residents interested in MCUs.

Speaking of Humboldt and MCUs, tomorrow, Thursday, July 10, is the next Humboldt Microcontrollers Group meeting from 6 to 8 PM at 1385 8th Street, Arcata, California. Hope to see you there for a discussion about I2C and Processing.

**********
Read More..