Hardware Reference
In-Depth Information
that although once programmed the Arduino will work happily through a hub, at the time of writ-
ing, the Arduino IDE implementation will not work correctly if it is connected through a hub.
Next go to the Tools menu. Choose the Serial Port option and click /dev/ttyACM0 . Your
Arduino is now connected. Check that the Uno board is selected by clicking Tools Board.
Now you need to test that everything is working, so type in Listing 16-1.
Listing 16-1 Arduino Blink
// Blink
void setup(){
pinMode(13, OUTPUT);
}
void loop(){
digitalWrite(13, HIGH);
delay(700);
digitalWrite(13, LOW);
delay(700);
}
Now click the right-pointing arrow to upload the blink program into the Arduino. When it
has inished uploading the orange LED with a letter L next to it will steadily blink. Click the
down-pointing arrow at the top of the IDE window and save your ile under the name blink .
his will automatically generate a sketchbook folder in your home directory. In the Arduino
world the program that runs on an Arduino is known as a sketch.
here are example programs built into the IDE you can look at under File Examples. After you
have the blink sketch in the sketchbook folder you can start the Arduino IDE at any time by
double-clicking any of the .ino iles in this folder. For now you have only one called blink.ino .
I would encourage you to download and study the data sheet of the AS5040 encoder - it
contains a lot more information than you could ever need - but the point is it shows you the
full capability of the chip; you are only using a part of its capabilities here. It talks to the out-
side world using a protocol known as serial protocol interface (SPI), which is a loosely deined
protocol that has a lot of subtle diferences and variations - so much so that this chip is not
quite compatible with the hardware SPI interface of the Arduino, so you will have to write a
program to manipulate the SPI lines speciically. his sort of technique is known as bit bang-
ing. Figure 16-17 shows the way the interface works. Basically a chip select line is brought
low, and then the clock line is made to go up and down - and every time it goes up a new bit
of data is placed on the chip's output. In order for this data to be stable, the Arduino should
read the data bit when it places the clock high. As the data appears one bit at a time on the
chip's output the bit banging code must shift it into a variable one bit at a time to make up all
 
Search WWH ::




Custom Search