cd

Feb 162011
 

This LED traffic light is a straightforward activity you can try with your arduino. It’s based on a slight variation of the dual LED emergency flasher. To build it you’ll need:

  • 3 LEDs (red, yellow, green)
  • 3 Resistors (470 ohm)
  • breadboard
  • jumper wires
  • arduino

How to connect and program the Arduino:

1) Plug your Arduino into the computer using a USB cable. The power light should come on.

2) Place 3 LEDs in the breadboard such that each has a resistor going from the cathode side to a ground rail on the breadboard.

3) A jumper wire goes from the ground rail to the Gnd pin on the digital side of the Arduino. Then connect the other leg (anode ) of each LED to pins 13,12 and 11 using more jumper wires.

4) Open the Arduino IDE and use the following code. It’s almost identical to the dual Led blink (emergency flasher) code except that an extra pin (#11) has been added to the setup and loop sections and is controlling our red LED.

  void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

void loop(){
  digitalWrite(13, HIGH);
  delay(800);
  digitalWrite(13, LOW);
  delay(50);
  digitalWrite(12,HIGH);
  delay(800);
  digitalWrite(12,LOW);
  delay(50);
  digitalWrite(11,HIGH);
  delay(800);
  digitalWrite(11,LOW);
  delay(50);
}

5) Upload the code to the arduino and it should run automatically!

Challenge:

  • Try adjusting the delay times so that it behaves more like a real traffic light!
 Posted by at 12:03 am
Feb 132011
 

This activity is a variation of the single led blink activity. It allows you flash 2 LEDs alternately, like you might see on an emergency vehicle.

You will need:

  • Arduino
  • 2 LEDs
  • 470 ohm resistor
  • jumper wires

Place 3 jumper wires in pin 12, pin13 and Gnd on the digital side of the arduino, shown below.

Set up your breadboard so that the cathode sides of the LEDs are connected to a resistor, and then to a common ground. Doing it this way means we only need a single resistor and ground pin. The other legs (anode) of the LEDs should be in pin 13 for the first LED, and pin 12 for the second LED.

Next connect your arduino to your  computer with a USB cable and open the Arduino IDE. Type in the following code:

void setup(){
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
}

void loop(){
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  delay(500);
  digitalWrite(13,LOW);
  digitalWrite(12,HIGH);
  delay(500);
}

The code above is similar to the single LED blinker except that

  • in the setup section pin 12 is added as a second output
  • in the loop section lines are added so that when pin 12 is on (high),  pin 13 is low (off) and vice-versa.

Questions:

How could you change the code so that both LEDs blink at that same time?

Try it for yourself!

 Posted by at 3:30 am
Feb 122011
 

One of the first and simplest sketches to run on your Arduino is to make an LED blink. If this is your first time using Arduino, read through our “Arduino basics: getting started” article.

Connecting the Arduino and LED

Connect your Arduino to your computer using a USB cable. The power light should come on.

1) Place your LED and a 470 ohm resistor in series (a breadboard will help). Always use resistors with LEDs for safety purposes, and remember that the LED cathode points toward Ground.

2) Connect jumper wires to pins 13 and Gnd on the digital side of the Arduino

3) Open the arduino IDE and type in the following code:

void setup() {
    pinMode(13, OUTPUT);
}
void loop() {
  digitalWrite(13, HIGH);
  delay(1000);
  digitalWrite(13, LOW);
  delay(1000);
}

4) Press the upload button in the IDE to send the code to your Arduino. It should automatically start running it!

Video of the LED blinker in action

(includes code explanation):

.

Modify the LED blink sketch:

  • You can change the blink rate by changing the delay!
  • You may have also noticed a little yellow LED on the board that blinks in time with your LED. That little LED is wired to pin 13 and is used for testing purposes. If you want to avoid it, use a different pin (such as pin 12). But remember to modify the code (see below)
void setup() {
    pinMode(12, OUTPUT);
}
void loop() {
  digitalWrite(12, HIGH);
  delay(500);
  digitalWrite(12, LOW);
  delay(500);
}

The above code is modified to use pin 12 (instead of pin 13) and to only delay for 500 ms. Try your own variations!

Feb 022011
 

Know the parts of the Phidget SBC:

Phidget SBC (single board computer)

Testing and Communicating with the SBC: Brief workflow

  • Download and install phidget control panel, download matching SBC firmware
  • Reset the SBC to factory settings (reset button for 10s)
  • connect SBC to network via ethernet cable
  • open phidget control panel to verify your SBC is attached
  • double click the SBC or enter its IP in a web browser
  • update firmware (under “system” tab)
  • again go to phidget control panel, double click the SBC or enter its IP in a web browser
  • set up an IP (preferably static) for both ethernet and wireless

Testing and Communicating with the SBC: Detailed Guide

Connect the Following:

  • 12 V power adapter
  • Ethernet cable
  • Analog sensor (we used phidget mini joystick)
  • LED to Gnd & 7 on digital outputs (remember polarity!)
  • Switch on Gnd & 0 on digital inputs

phidget sbc test hookups

Install the software:

Download and install the latest Phidget control panel for your system from http://www.phidgets.com/drivers.php. While you’re there you should get the latest SBC firmware as well. You’ll need it later.

If it installed properly you will see a icon in your taskbar

You’ll also need a program called “bonjour” which helps your PC “talk” to the SBC. If the phidget panel doesn’t ask you to install it, go here , get it and install it.

Run the Phidget Control Panel:

Make sure your phidget SBC is powered and connected by ethernet cable to your network.

Double click on the Phidget icon and the phidget control panel will show up.

Go to the PhidgetSBC tab as in the picture above. Two VERY important pieces of information are here:

  • The mac address of the SBC (uniquely identifies the phidget on a network)
  • The IP Address (knowing this is ESSENTIAL for communicating with your SBC)

It may take a moment for your phidgetSBC to show and a few moments more for an IP address to show at the bottom.

Now open that PhidgetSBC with a web browser:

In a perfect world you’ll click on that PhidgetSBC, and a web browser will open with login and settings pages.

If it doesn’t work:

The first thing to try is to type the PhidgetSBC’s IP address into the address bar of your web browser. From the picture above I wrote down the ip address at the bottom and typed it (http://192.168.2.231) into the browser. If that doesn’t work, it’s reset time!

Reset the PhidgetSBC to factory specs: A factory reset on the phidgetSBC (hold in reset button for 10 seconds until red LED starts flashing) causes it to lose all settings and receive a new IP address when connected to a new network. My problem arose because I tried to connect a PhidgetSBC which had a previously configured static IP to a network with a totally different IP scheme.

Once you’ve got the settings webpage open you can set the phidget ethernet and wireless ip addresses to match your network configuration (more on this below)

Create a password:

It will ask you to set one if  none exists (the user name is root)

Upgrade the firmware::

I had the full firmware already downloaded (http://www.phidgets.com/drivers.php). Then I just clicked on System, Upgrade and chose the file. The process takes several minutes.

When it’s done the PhidgetSBC will reboot. Do this only using ethernet cable (we don’t want a wireless signal dropping in the middle of a firmware upgrade!) Also bear in mind that after the firmware upgrade, you may have to reconnect to the PhidgetSBC settings page. This is a given if you changed the PhidgetSBC IP address.

Wireless on a school or other existing network:

Once you’ve got the boards working over ethernet cable the wireless bit is fairly simple.( But you should have a plan!) My school network runs locked down windows workstations. The goal is for students to use the workstation to communicate with a PhidgetSBC and control a robot wirelessly.

We set up a dedicated router (WRT54GL)  as a wireless switch/access point.

How I set  set myWRT54GL router (robo-router) up as a wireless access point:

  • turned off DHCP on robo-router
  • set robo-router IP to be within school network subnet (but outside DHCP range of school network).
  • connected robo-router to school network via lan port (instead of WAN port).

When I need wireless access, I plug it in (you can also use wireless security with the phidget SBC!)

I then configured each phidget to have a static ethernet IP address AND static wireless IP address to prevent conflicts. The options for each are under the network tab on the phidgetSBC configuration page (the one we accessed with our web browser).

So, here’s how the network setup looks:

  • School network: Gateway is 192.168.2.1, DHCP runs from 192.168.2.2 through 192.168.2.150 (so I need to set robo-router above 150)
  • Robo-router: IP is 192.168.2.230 with DHCP turned OFF (don’t want two routers on a network running dhcp)
  • PhidgetSBC:  Ethernet: 192.168.2.231 Wireless:192.168.2.241
  • Subsequent  SBCs: Ethernet 192.168.2.232 Wireless 192.168.2.242 (just increment for each additional SBC!) I’ll never use more than 10 SBCs in one class, but you can adjust your numbering scheme accordingly

Testing the inputs and outputs:

Open the Phidget control panel and go to the WebService tab.

Click the PhidgetSBC to bring up a testing screen called “interfacekit – full”.

  • Attached should say “true”
  • Digital-in should check when you press the switch you connected to the input side
  • Analog-in should show value change when you move the joystick
  • Digital-out should light the LED when you check the box

Connecting a webcam

This is as simple as connecting a webcam to the device and selecting your resolution, framerate, and port. Bear in mind that a heavy video stream may slow down other processes, so use what you need.

Resetting / Rebooting the PhidgetSBC

The phidget boot process happens when you power the device or press the reset button. It’s indicated by the red and green lights both lighting, then the green light goes off for several seconds, then it comes back on again.

  • Pressing the reset button once will reboot the device.
  • Holding the reset button for 10 seconds sets it back to factory defaults and firmware (the red light will also start flashing)
 Posted by at 1:15 am