Blink tutorial

In this tutorial we will make perform on of the most basic tasks of an Arduino processor - make an LED blink on and off. We won't be using the radio capabilities of the RFu-328 in this tutorial. That comes later, for now we want to orient ourselves with the RFu-328, the developer board how to uploading sketches (programs). 

You will need:

  • The RFu-328 installed either on a developer board, wireless case kit or your own development environment (refer the building a development environment section)
  • Any LED
  • A suitable resistor (100 OHM and above will usually do the trick, depending on which LED you have). Refer this useful link that will calculate the resistor you need based on which LED you have. Remember your voltage is 3.3V.
  • Some jumper wires and a breadboard. Alternatively you can solder the circuit. 

Construction:

Build the circuit as shown in Figure 1. The resistor shown in the diagram is just a random picture of a resistor. Determine the correct LED as explained above. You do not need to solder the jumper wires to the developer board if you don't want to. Just holding them in place will work good enough for you to see the LED blinking. Make sure you have the LED in the right way around. The longer leg on the LED should go to the positive side (the red line in Figure 1). 

Figure 1 - Circuit diagram for the Blink Sketch

Code:

After starting up the Arduino IDE you need to select the port which you will be using to communicate with the RFu-328. To do this select tools from the menu bar, then port and select the port you will use from the list. If you are using the FTDI cable, make sure it is plugged in otherwise the port won't appear in the list. If you have multiple ports, as shown in Figure 2, then you may need to try them one by one until the upload work. Alternately unplug the FTDI cable and see which port disappears from the list. 

Figure 2 - Selecting the right communications port in the Arduino IDE

If you are using the over the air programming method then select the port of the SRF-stick or ,if you are using a Raspberry Pi, select this port: /dev/ttyS0.

The Blink sketch is one of the examples that come pre-loaded with the Arduino IDE. To open the Blink sketch click File->Examples->Basics->Blink.

The sketch will open as can be seen in the background of Figure 2.

Take a moment to read the code. Don't worry if you have not done any coding before it is quite self explanatory. The fisrt section that has  a "//" at the beginning of each line does not do anything. This area is just for general comments to the programmer telling you about the sketch, who write it and what it does. The real program starts at the line:

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

The setup function is executed when the RFu-328 starts up. The code in this function initializes pin 13 for output. What this means is we will be using pin 13 as an output. We configure this pin for output because we want to send current from the RFu-328 to the LED in order to light it up. Have a look at the technical data for the RFu-328 under the Pin Out section and look down the column labelled Arduino Uno Function for pin 13. You should see "D13/SCK". Now see which RFu pin this maps to. It is pin 8. This is how you map the pins of the Arduino chip to the pins of the RFu-328. The Arduino chip is the diamond shaped chip at the bottom of the RFu-328 which is actually an ATMEGA-328 processor. When you write code in the Arduino IDE is it being sent to and executed by the ATMEGA processor. 

The "D" of D13 stands for digital. A digital pin is either on or off or wavering. When it is on is will be at 3.3V. When it is off it will have 0V and when it is wavering it goes randomly between on and off. 

The next section of code switches the LED on and off:

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}
 
The first line of code tells the processor to loop the code that is between the curly braces over and over, forever. The second line of code tells the processor to switch pin 13 high (3.3V). This will turn the LED on. The third line of code will delay for 1000 milliseconds (1 second), and the fourth line will switch the LED off (0V), and the fifth line delays again for 1 second. Then the loop starts again. The result is a blinking LED.

If you want it to blink faster then change the 1000 to 500 and the delay between blinks will now be half a second. 

Upload the Sketch to the RFu-328

You upload the sketch by clicking the upload button (right arrow within the circle) on the toolbar, or by selecting File->Upload from the menu. The IDE will fist compile the code and you should see "Compiling code" written in the status bar near the bottom of the screen. Once the upload completes then it will say "Uploading complete". If there is an error then you have either changed some of the code and created a compile error, or there is a problem with the connectivity to the RFu-328. Check the cable is attached, if you are using the FTDI cable and you have selected the right communications port. If you are using over the air programming and receive an error that says "programmer not responding" then refer the OTAMP section for troubleshooting.

If all went well you should now see a blinking LED!

That's it, you have completed your first Arduino/RFu-328 project. 

If you have any questions you can post them on the forum of projects.privateeyepi.com 

Comments