tag:blogger.com,1999:blog-90593853548129821392024-03-13T10:23:06.426-07:00codergirljpcodergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.comBlogger21125tag:blogger.com,1999:blog-9059385354812982139.post-24348450364714595552015-02-15T17:48:00.002-08:002015-02-15T17:48:51.057-08:00Micro Servo Motor - calibrating position anglesI want to use a rather typical micro servo motor to move the eyes of my rover to "look" side to side and determine if there is an object present. I received the 3D prints this week for the servo mounting and the ultrasonic distance sensor so it's time to make sure my micro servo control works as planned. I'm going to use a Arduino Micro and some simple code with a basic bread board to bring the servo to life and tweak the positioning.<div>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPfF1n59L-hrRo3rnMHER65vp5ibRvqg7fnLNEHc-0oLOdt0_M1Z-KTDn0hjvcBXKWoz5Nurh8uQpNyRXgCphj_TSjHjEp03u5r_JHwwpIOEb_rMJYmEXzc95IGLN65RMM6tlDS-9hWs4j/s1600/microservocalibration.jpg.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhPfF1n59L-hrRo3rnMHER65vp5ibRvqg7fnLNEHc-0oLOdt0_M1Z-KTDn0hjvcBXKWoz5Nurh8uQpNyRXgCphj_TSjHjEp03u5r_JHwwpIOEb_rMJYmEXzc95IGLN65RMM6tlDS-9hWs4j/s1600/microservocalibration.jpg.jpg" height="320" width="162" /></a></div>
<div>
Parts Needed: </div>
<div>
1 Breadboard</div>
<div>
1 <a href="http://www.adafruit.com/products/1086">Arduino Micro</a> (or other Arduino board) ($24.95)</div>
<div>
3 wires (female to female)</div>
<div>
1 <a href="http://www.radioshack.com/radioshack-micro-servo/2730765.html#.VOEw6PnF_yg">Micro Servo Motor</a> ($12.99)</div>
<div>
1 <a href="http://www.radioshack.com/6-ft-usb-to-micro-usb-cable-black/2602738.html#.VOEx3fnF_yg">USB to Micro USB cable</a> ($9.99) you might already have one from your smart phone</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
There are only three wires to connect so the hook up is easy... </div>
<div>
Here is the pin mapping:</div>
<div>
<br /></div>
<div>
Micro Pin Servo Connection</div>
<div>
Grd --> Brown Wire</div>
<div>
5V --> Red Wire</div>
<div>
9 --> Yellow Wire</div>
<div>
<br /></div>
<div>
Insert the Arduino Micro into the breadboard and connect the ground, 5 volt and pin 9 to the servo motor as shown above. </div>
<div>
<br /></div>
<div>
Upload the code to and and tweak the servo position values until they match your setup.. Get the code here.. <a href="https://github.com/codergirljp/MicroServoCalibration">MicroServoCalibration Code</a></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-79520627244983488042015-01-04T13:58:00.000-08:002015-01-04T13:58:04.126-08:00SainSmart Mega 2560 R3 4WD Mobile Car Robot Kit Build<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_KF648ZLzIkdwqz73oXzx2YrrLtIz5JCR1Gbe8XBx0hC6NgRpb8hvV5FSOiww5F4baz1m6u71_U5GBe2IO1emG26A9GcW-YXgnvBnT0Ue7GL6AkJ-ta8rSJ7dMVxo_ZnZfNEmQNW4Y4TK/s1600/RoverBuilt-sm.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj_KF648ZLzIkdwqz73oXzx2YrrLtIz5JCR1Gbe8XBx0hC6NgRpb8hvV5FSOiww5F4baz1m6u71_U5GBe2IO1emG26A9GcW-YXgnvBnT0Ue7GL6AkJ-ta8rSJ7dMVxo_ZnZfNEmQNW4Y4TK/s1600/RoverBuilt-sm.jpg" height="275" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Assembled Rover</td></tr>
</tbody></table>
I got <span style="color: blue;"><a href="http://www.sainsmart.com/sainsmart-mega-2560-r3-sensor-shield-v5-4wd-mobile-car-l298n-hc-sr04-for-arduino-robot.html">a SainSmart Mobile Car Robot Kit</a> </span>for Christmas so I thought I'd share the build experience. The kit costs about $95 and it doesn't come with any instructions. However, thanks to some other makers out there, I found some <a href="http://www.instructables.com/id/SainSmart-C98-Kit-Instructions/">helpful instructions posted on Instructables</a> and also a <span style="color: blue;"><a href="http://www.thingiverse.com/thing:183896">useful post about it on Thingiverse</a>.</span><br />
<br />
There were a few problems with this kit. I wouldn't recommend getting this kit unless you have some experience. Some of the screw holes in the metal frame don't line up very well, but that was pretty minor. The biggest problems are that it doesn't come with enough wire and several of the parts in the kit were bad. In my kit, the Mega 2560 wouldn't accept code uploads and the reset button on it didn't work at all. Also, the battery pack had a short so when I hooked it up it started smoking.<br />
<br />
Fortunately, I was able to use an Arduino Mega, some 9 volt battery connectors, and extra wire I already had. Hopefully SainSmart will send me a functional Mega to replace the non-working board in my kit. There is also nothing to mount the distance sensor and no hook up wires for it, so you'll have to get creative if you want to use it.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv_He508__DgnA4h47mWAZLuVfAa9Xl54yNoSIEaUrrkn4gSkmpaPl6bHGfJ7q9BDJ_sL8utGkZbSkUh1IdLTMBDuxxMk7YGvJqjPLvgGHcWvUwGMLtHjlIyXuBfEQcpsB8tqwgYuv4Hhx/s1600/KitParts2.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv_He508__DgnA4h47mWAZLuVfAa9Xl54yNoSIEaUrrkn4gSkmpaPl6bHGfJ7q9BDJ_sL8utGkZbSkUh1IdLTMBDuxxMk7YGvJqjPLvgGHcWvUwGMLtHjlIyXuBfEQcpsB8tqwgYuv4Hhx/s1600/KitParts2.jpg" height="165" width="200" /></a></div>
<h4>
Parts List from the Kit: </h4>
4 wheels<br />
4 motors<br />
2 rounded metal plates fro the front and back<br />
2 side plates<br />
2 flat plates for the top and bottom of the case<br />
A bunch of screws<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3B1maLFvU0RjW4Y30mC6jZPymHrMUSpfU1nHi0BHL-17uA3HfHDRJfxgvDkdgE02_XTpmFpG024JQ0JC6RyX7UordAsCspvMo2BJoj9FdINi5jIpfsXcl5rrjdoqxMjk4SotzLeCFI-9m/s1600/KitParts1.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3B1maLFvU0RjW4Y30mC6jZPymHrMUSpfU1nHi0BHL-17uA3HfHDRJfxgvDkdgE02_XTpmFpG024JQ0JC6RyX7UordAsCspvMo2BJoj9FdINi5jIpfsXcl5rrjdoqxMjk4SotzLeCFI-9m/s1600/KitParts1.jpg" height="135" width="200" /></a>2 wires (1 red, 1 black)<br />
1 4-wire female to female connection harness<br />
1 battery pack<br />
1 toggle switch<br />
1 re-charge connector<br />
1 USB cable<br />
1 SainSmart MEGA 2560 R3<br />
1 SainSmart Sensor Sheild V5<br />
1 SainSmart L298N Dual H Bridge DC motor driver<br />
1 HC-SR04 Distance Sensor<br />
<br />
<br />
<br />
<br />
<h4>
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLHHAy2g3L4_WfMyENcMYz-u7CWSvCweg4UsdVsBG5ivn6hBv3-oJAHFiGvlz1ZQ2_V4hJh8vLyMDOrneAsIXfw7TECMUQUYdFsS4qB_Oth-Op8ewO4Kwmn_JXGXzHGvq7n_YUhgwH9zvX/s1600/OtherTools.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjLHHAy2g3L4_WfMyENcMYz-u7CWSvCweg4UsdVsBG5ivn6hBv3-oJAHFiGvlz1ZQ2_V4hJh8vLyMDOrneAsIXfw7TECMUQUYdFsS4qB_Oth-Op8ewO4Kwmn_JXGXzHGvq7n_YUhgwH9zvX/s1600/OtherTools.jpg" height="148" width="200" /></a>Other Items you'll need: </h4>
2 9 volt batteries<br />
2 9 volt battery connectors<br />
extra wire<br />
solder and a soldering iron<br />
electrical tape<br />
wire strippers<br />
A volt meter<br />
<br />
<span style="font-family: Arial, Helvetica, sans-serif; font-size: x-large;"><b>Build it ..</b></span><br />
<h3>
STEP 1: Hook up the Toggle Switch and connect the battery leads to the L298N Motor Driver</h3>
<ol><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOLWyJIM9UD_thoj8P2KpEvo41CdApuBbf2pRtvDJV2ueKAw6TLVj72jDIkZA_Yd3AB3MKtxo18rQS9UIIEXQDgqphDk3IvRZ8_cF01sC8LUHwpwgF-71tfhOVzc7dc5kdJDoSKue9Miwp/s1600/ToggleSwitch.jpg" imageanchor="1" style="clear: right; float: right; margin-bottom: 1em; margin-left: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgOLWyJIM9UD_thoj8P2KpEvo41CdApuBbf2pRtvDJV2ueKAw6TLVj72jDIkZA_Yd3AB3MKtxo18rQS9UIIEXQDgqphDk3IvRZ8_cF01sC8LUHwpwgF-71tfhOVzc7dc5kdJDoSKue9Miwp/s1600/ToggleSwitch.jpg" /></a>
<li>Place the toggle switch in one of the holes on the top plate and use the washer and nut (only one fits) to secure it in place. </li>
<li>Secure the L298N Motor Driver to the bottom plate using the screws provided. (The wholes in the plate should line up pretty will with the mounting wholes on the board.)</li>
<li>Connect the battery connectors together in series by soldering the ends of the black lead on one connector to the red lead on the second connector. Use electrical tape to cover the connection.</li>
<li>Connect/solder the remaining red lead on the first battery connector to the center lead on the toggle switch.</li>
<li>Connect the remaining black lead on the other battery connector to the screw connector on the Motor Driver labeled Gnd (The ground pin). </li>
<li>Cut a 4 inch piece of the red wire that came in the kit and strip away the sheath on the end to expose the wire on the cut side. Connect one side of this wire to one of the side leads on the toggle switch. Connect the other end to the to the screw connector labeled Vcc on the Motor Driver board. </li>
<li>Test the toggle switch connections and make sure it works. <br />With the switch in the off position, connect the batteries. Then flip the switch to the on position. If your connections are good, the red led on the Motor Driver board should light up. if it doesn't, check the connections and try again. </li>
<li>Turn the switch off and disconnect the batteries. </li>
</ol>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<h3>
STEP 2: Connect the Motors to the Motor Driver</h3>
<br />
<ol>
<li>Cut 2 4 inch wires from the red wire, and 2 4 inch wires from the black wire. </li>
<li>Cut 2 6 inch wires from the red wire and 2 6 inch wires from the black wire. </li>
<li>Strip the ends of each of the wires. </li>
<li>Solder the 4 inch black wire to one of the leads on the first motor, and the 4 inch red wire to the other lead on the first motor. </li>
<li>Solder the the 6 inch wires (one red and one black) to the second motor for the same side as shown in the picture. Caution: Take care to make sure that the wire colors match the orientation in the picture so that the wheels will both spin in the same direction. </li>
<li>Secure The motors to the side plate and secure the side plate to the bottom plate using the screws provided. </li>
<li>Connect the red leads for the two motors to one of the screw connection ports on the Motor Driver board labeled out. </li>
<li>Connect the black leads for the two motors to the other out port on the same side of the Motor Driver board. </li>
</ol>
<br />
Repeat this process for the remaining two motors on the other side.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKo5TpjCEC5X8a6F3sdtxoWtJTvdB8byrmNYhMUPTSF9oGrTs4ww0sltFYOQmivsMRg8hBAvbZgGcyt3AgguIloiH6cO7sn8fcLqhKuMK37rfAox0QqKEv-8FAFrmBiD5h61ypf2hzU85C/s1600/MotorConnections.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiKo5TpjCEC5X8a6F3sdtxoWtJTvdB8byrmNYhMUPTSF9oGrTs4ww0sltFYOQmivsMRg8hBAvbZgGcyt3AgguIloiH6cO7sn8fcLqhKuMK37rfAox0QqKEv-8FAFrmBiD5h61ypf2hzU85C/s1600/MotorConnections.jpg" height="239" width="320" /></a></div>
<br />
<br />
<h3>
STEP 3: Connect the remaining wires to the Motor Driver board</h3>
<br />
<ol>
<li>Cut and strip two wires (black and red preferred) to be used as ground and voltage supply wires for the Arduino. These wires will need to be about 6-7 inches long. </li>
<li>Connect the black wire to the ground on the Motor Driver board using the screw connector. </li>
<li>Connect the red wire to the 5V screw connector on the Motor Driver board.</li>
<li>Using the 4 wire harness, connect the wires to the INT pins on the Motor Driver board as follows:<br /><div style="text-align: left;">
<span style="font-size: x-small;">INT1 -> Red </span></div>
<table cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: right; margin-left: 1em; text-align: right;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4VdrAJdnGeHj6ei4iSo99W0uz3Euho7Z0JKtX0PQbgjP3pyjjDYyK0QkqpYAzNDcdNBySKBsIcTUyQG63cre12kMEX0SQ7Is1tXq_Vdp1YEgusnswUZAw3APYprzTlSzGSHRnYEh7nzTt/s1600/ToggleAndINTPinConnections.jpg" imageanchor="1" style="clear: right; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj4VdrAJdnGeHj6ei4iSo99W0uz3Euho7Z0JKtX0PQbgjP3pyjjDYyK0QkqpYAzNDcdNBySKBsIcTUyQG63cre12kMEX0SQ7Is1tXq_Vdp1YEgusnswUZAw3APYprzTlSzGSHRnYEh7nzTt/s1600/ToggleAndINTPinConnections.jpg" height="200" width="178" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Switch and INT pin Connections</td></tr>
</tbody></table>
<div style="text-align: left;">
<span style="font-size: x-small;">INT2 -> Brown</span></div>
<div style="text-align: left;">
<span style="font-size: x-small;">INT3 -> Black</span></div>
<div style="text-align: left;">
<span style="font-size: x-small;">INT4 -> White<br /><br /></span></div>
</li>
</ol>
<br />
<ol>
<li>Re-connect the batteries, but leave the switch off for now. </li>
<li>Fish the power, ground and 4 wire harness wires through the top plate from the bottom side.</li>
<li>Place the top plate on top of the two sides where it will eventually be screwed on.</li>
</ol>
<br />
<h3>
STEP 4: Program the Mega Using the Arduino IDE</h3>
<div>
The great thing about the Motor Driver board, is that for on and off control of the motor, you don't need any external libraries, just set the pins HIGH and LOW to control the direction of the motors. </div>
<div>
<br /></div>
<div>
Copy the following code upload it to the Mega board using the Arduino IDE. </div>
<div>
<br /></div>
<span style="font-size: x-small;">//declaring the pins for the IN pins on the L298N</span><br />
<span style="font-size: x-small;">const int rightForwardPin = 4;</span><br />
<span style="font-size: x-small;">const int rightBackwardPin = 2;</span><br />
<span style="font-size: x-small;">const int leftBackwardPin = 7;</span><br />
<span style="font-size: x-small;">const int leftForwardPin = 5;</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">int runTime = 1000;</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">void setup() {</span><br />
<span style="font-size: x-small;"> //Stating that the pins are OUTPUT</span><br />
<span style="font-size: x-small;"> pinMode(rightForwardPin, OUTPUT);</span><br />
<span style="font-size: x-small;"> pinMode(rightBackwardPin, OUTPUT);</span><br />
<span style="font-size: x-small;"> pinMode(leftForwardPin, OUTPUT);</span><br />
<span style="font-size: x-small;"> pinMode(leftBackwardPin, OUTPUT);</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">//Looping to test the wheels of the car</span><br />
<span style="font-size: x-small;">void loop() {</span><br />
<span style="font-size: x-small;"> forward();</span><br />
<span style="font-size: x-small;"> stopCar();</span><br />
<span style="font-size: x-small;"> backward();</span><br />
<span style="font-size: x-small;"> stopCar();</span><br />
<span style="font-size: x-small;"> left();</span><br />
<span style="font-size: x-small;"> stopCar();</span><br />
<span style="font-size: x-small;"> right();</span><br />
<span style="font-size: x-small;"> stopCar();</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">//Setting the wheels to go forward by setting the forward pins to HIGH</span><br />
<span style="font-size: x-small;">void forward(){</span><br />
<span style="font-size: x-small;"> digitalWrite(rightForwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> digitalWrite(rightBackwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftForwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftBackwardPin, LOW);</span><br />
<span style="font-size: x-small;"> delay(runTime);</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">//Setting the wheels to go backward by setting the backward pins to HIGH</span><br />
<span style="font-size: x-small;">void backward(){</span><br />
<span style="font-size: x-small;"> digitalWrite(rightForwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(rightBackwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftForwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftBackwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> delay(runTime);</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">//Setting the wheels to go right by setting the rightBackwardPin and leftForwardPin to HIGH</span><br />
<span style="font-size: x-small;">void right(){</span><br />
<span style="font-size: x-small;"> digitalWrite(rightForwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(rightBackwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftForwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftBackwardPin, LOW);</span><br />
<span style="font-size: x-small;"> delay(runTime);</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">//Setting the wheels to go left by setting the rightForwardPin and leftBackwardPin to HIGH</span><br />
<span style="font-size: x-small;">void left(){</span><br />
<span style="font-size: x-small;"> digitalWrite(rightForwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> digitalWrite(rightBackwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftForwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftBackwardPin, HIGH);</span><br />
<span style="font-size: x-small;"> delay(runTime);</span><br />
<span style="font-size: x-small;">}</span><br />
<span style="font-size: x-small;"><br /></span>
<span style="font-size: x-small;">//Setting the wheels to go stop by setting all the pins to LOW</span><br />
<span style="font-size: x-small;">void stopCar(){</span><br />
<span style="font-size: x-small;"> digitalWrite(rightForwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(rightBackwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftForwardPin, LOW);</span><br />
<span style="font-size: x-small;"> digitalWrite(leftBackwardPin, LOW);</span><br />
<span style="font-size: x-small;"> delay(1000);</span><br />
<span style="font-size: x-small;">}</span><br />
<div>
<br /></div>
<h3>
STEP 5: Connect the Sensor Shield and Mega to the Circuit </h3>
<div>
<ol>
<li>Place the sensor shield on the Mega making sure the connection pins are placed in the correct slots. </li>
<li>Connect the 5V power line to the Vcc screw connection terminal on the Sensor Shield. </li>
<li>Connect the Ground line to the GND ground screw connection terminal on the Sensor Shield. </li>
<li>Connect the 4 wire harness to the following pins on the Sensor Shield:<br /><span style="font-size: x-small;">Red - > pin 7<br />Brown -> pin 5<br />Black -> pin 4<br />White -> pin 2</span></li>
</ol>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhete6UxgXu9SdOjwBquTYAZ60ofrjs1dU26L0FLyrYYiTySqLw2HXQVnopVb4yG1xFoUcRsVhDLlXNRO6lCE70nMmurh_tkOTCA4aIBY33MnSGIhsPOwhuzUGNhzHN0ZlPAw5kKgonWKqX/s1600/SensorShieldConnect.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhete6UxgXu9SdOjwBquTYAZ60ofrjs1dU26L0FLyrYYiTySqLw2HXQVnopVb4yG1xFoUcRsVhDLlXNRO6lCE70nMmurh_tkOTCA4aIBY33MnSGIhsPOwhuzUGNhzHN0ZlPAw5kKgonWKqX/s1600/SensorShieldConnect.jpg" height="300" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Sensor Shield Connections</td></tr>
</tbody></table>
<div>
<span style="font-size: x-small;"><br /></span></div>
</div>
<h3>
STEP 6: Test It </h3>
<div>
Now with all the connections made, it's time to see if works.</div>
<div>
<ol>
<li>Secure the top plate and secure the Mega board to the top plate (using the small screws). </li>
<li>Turn the switch to the ON position. </li>
<li>The motors should start to turn soon after it is turned on.</li>
<li>The green LED on the Mega board should come on and a red LED may be lite or flashing on the Sensor Shield, indicating that is has power. If there is no power, try pushing the button on the Motor Driver board to turn on the external power.</li>
<li>Verify the direction that the motors are turning in. Both motors on any given side should always turn in the same direction. </li>
</ol>
</div>
<div>
<br /></div>
<div>
If everything is working, Attach the wheels and finish securing the front and back metal plates. </div>
<div>
<br /></div>
<div>
<br /></div>
<!-- Blogger automated replacement: "https://images-blogger-opensocial.googleusercontent.com/gadgets/proxy?url=http%3A%2F%2F1.bp.blogspot.com%2F-j6qMp9EPgQk%2FVKlzkOJBMyI%2FAAAAAAAAAcA%2FNbC77xoPMHo%2Fs1600%2FKitParts2.jpg&container=blogger&gadget=a&rewriteMime=image%2F*" with "https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiv_He508__DgnA4h47mWAZLuVfAa9Xl54yNoSIEaUrrkn4gSkmpaPl6bHGfJ7q9BDJ_sL8utGkZbSkUh1IdLTMBDuxxMk7YGvJqjPLvgGHcWvUwGMLtHjlIyXuBfEQcpsB8tqwgYuv4Hhx/s1600/KitParts2.jpg" -->codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-30958751884510249012014-09-13T14:33:00.000-07:002014-09-13T14:33:38.012-07:00Building a Color Sensor using the Adafruit TCS34725 and an ATMega32A MicroprocressorThis project uses the Adafruit TCS34725 RGB Color Sensor and an ATMega32A microprocessor to collect and display color data in a WPF application.<br />
<br />
The TCS34725 RGB color sensor is a neat little sensor. The sensor itself uses a photo-diode array with red, green and blue filters to measure color temperatures in Kelvin. The Adafruit library takes care of communications with the sensor, and converts the color temperatures to familiar RGB values. The Adafruit breakout for the sensor also includes a white led to illuminate objects so you can use the sensor for reflected light from colored objects when the light is on, or turn the light off and use the sensor to detect the color of light emitted from an external source (such as an RGB led). I use a push button to make it easy to toggle the led on or off.<br />
<br />
<br />
<h4>
Parts List</h4>
<br />
<a href="http://www.mouser.com/ProductDetail/Atmel/ATMEGA32A-PU/?qs=6WoM/Y8vMbadJ8khIfKCsQ=="><span style="color: blue;">ATMega32A-PU </span></a> ($3.15)<br />
<a href="https://www.adafruit.com/products/954"><span style="color: blue;">USB to TTL Serial cable</span></a> ($9.95)<br />
<a href="https://www.adafruit.com/products/1334"><span style="color: blue;">TCS34725 RGB Color Sensor</span></a> ($7.95)<br />
<a href="https://www.adafruit.com/products/1490"><span style="color: blue;">A tactile switch button</span></a> ($2.50 for 10 pack)<br />
<a href="https://www.sparkfun.com/products/8374"><span style="color: blue;">A 10k Resistor</span></a> ($0.25)<br />
<a href="https://www.adafruit.com/products/1609"><span style="color: blue;">Perma-Proto half-sized breadboard PCB</span></a> ($4.50) (optional)<br />
<br />
<b>Estimated Cost ~$26</b><br />
<br />
<h4>
Additional Hardware Tools Need</h4>
<br />
An ISP Programmer or an Arduino Board to use as an ISP Programmer<br />
A breadboard and some wires<br />
A soldering iron (optional)<br />
A 10pF capacitor if using the Arduino as an ISP Programmer<br />
<br />
Downloads<br />
<br />
<a href="http://arduino.cc/en/main/software"><span style="color: blue;">Arduino IDE</span> </a><br />
<a href="http://www.visualstudio.com/en-us/downloads#d-2010-express"><span style="color: blue;">Visual Studio Express 2010 (with C#)</span></a><br />
<a href="https://github.com/eaconner/ATmega32-Arduino/archive/master.zip">ATMega32 board and pin files</a><br />
<a href="https://github.com/adafruit/Adafruit_TCS34725"><span style="color: blue;">Adafruit_TCS34725 library</span></a><br />
<a href="https://github.com/codergirljp/ATMega32ColorSensor"><span style="color: blue;">Color Sensor sketch for ATMega32</span></a><br />
<a href="https://github.com/codergirljp/ColorSensor-WPF"><span style="color: blue;">Color Sensor WPF Application</span></a><br />
<br />
<br />
<div>
<h3>
Step 1: Environment Setup</h3>
<br />
<br />
<ol>
<li>Download the <a href="http://arduino.cc/en/main/software"><span style="color: blue;">Arduino IDE</span></a> and install it (if you don't have it already)</li>
<li>Install the boards and pins files for the ATMega32 to the Arduino IDE</li>
</ol>
<ul>
<li>Download the <a href="https://github.com/eaconner/ATmega32-Arduino/archive/master.zip">ATMega32 board and pin files</a></li>
<li>Create a folder named mega32 in the directory:<br /> C:\Program Files (x86)\Arduino\hardware\arduino\variants</li>
<li>Copy the arduino_pins.h file to the folder you created:<br /> C:\Program Files (x86)\Arduino\hardware\arduino\variants\mega32</li>
<li>Copy the text from the boards.txt file and past it into the boards.txt located at:<br /> C:\Program Files (x86)\Arduino\hardware\arduino\boards.txt</li>
<li>Open the Arduino IDE. You should now see the ATMega32 boards under the<br />Tools -> Board menu. Select ATMega32 - 1mhz</li>
</ul>
<br />
<h3>
Step 2: Program the ATMega32 with the color sensor sketch</h3>
<br />
If using an arduino as an ISP:<br />
<br />
<br />
<ul>
<li>Upload the ArduinoISP sketch from File->Examples -> ArduinoISP in the Arduino IDE.</li>
<li>Set up the circuit for to use the Arduino as an ISP programmer by making the following connections:</li>
</ul>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="-webkit-box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 5px; background: rgb(255, 255, 255); border: 1px solid rgb(238, 238, 238); box-shadow: rgba(0, 0, 0, 0.0980392) 1px 1px 5px; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.4799995422363px; margin-left: auto; margin-right: auto; padding: 5px; position: relative; text-align: center;"><tbody>
<tr><td><b>Arduino Mega/ Uno Pins</b></td><td><b> to</b></td><td><b> ATMEGA32A Pins</b></td></tr>
<tr><td>MISO pin 50/ pin 12</td><td>-></td><td>pin 7 MISO</td></tr>
<tr><td>MOSI pin 51/ pin 11</td><td>-></td><td>pin 6 MOSI</td></tr>
<tr><td>CLK pin 52/ pin 13</td><td>-></td><td>pin 8 SCK</td></tr>
<tr><td>SS pin 53/ pin 10</td><td>-></td><td>pin 9 RESET</td></tr>
<tr><td>5V</td><td>-></td><td>pin 10 VCC</td></tr>
<tr><td>GND</td><td>-></td><td>pin 11 GND</td></tr>
<tr><td>RESET to Capacitor to</td><td>-></td><td>GND</td></tr>
</tbody></table>
</div>
<div>
<br />
<ul>
<li>Under Tools->Programmer select the "Arduino as ISP" option. </li>
</ul>
<div>
If you are using another flash programmer, select the appropriate option for your device.</div>
</div>
<div>
<br /></div>
<div>
Next, upload the Color Sensor stetch to the ATMega32:</div>
<div>
<ol>
<li>Download and Install the <a href="https://github.com/adafruit/Adafruit_TCS34725"><span style="color: blue;">Adafruit_TCS34725 library</span></a> to your Arduino IDE.</li>
<li>Download the <a href="https://github.com/codergirljp/ATMega32ColorSensor"><span style="color: blue;">Color Sensor Sketch</span></a> and open it in the Arduino IDE. </li>
<li>Select "ATMega32 - 1mhz" as your board under Tools -> Board. </li>
<li>Make sure the Serial Port is selected under the Tools menu.</li>
<li>Press Ctrl + Shift + U to upload the code using a programmer. </li>
</ol>
</div>
<div>
<br /></div>
<div>
If everything worked you should see the message "avrdude done. Thank you.".</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<h3>
Step 3: Setup the Color Sensor Circuit</h3>
<br />
Now that the ATMega32 is programmed for the Color Sensor, lets set up the circuit and test it out. The diagram below shows the circuit connects for the sensor. The power is supplied by the USB to TTL cable through the USB port. The circuit connections needed are shown in the diagram below.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifUtPxBakjDYZW3ZNtcnXNV_mh50yoRmacl3hkB_tZ-9jQtzpJmwTnCadFrCSoJc1NU_AKLB8yf7j1EjoH_7p7p0jnOI7hZs56vMLyPlhuKtD31m-0z2li3HtyLKoFay6DiZPwEFE4Ee_3/s1600/ATMega32ColorSensorConnections.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEifUtPxBakjDYZW3ZNtcnXNV_mh50yoRmacl3hkB_tZ-9jQtzpJmwTnCadFrCSoJc1NU_AKLB8yf7j1EjoH_7p7p0jnOI7hZs56vMLyPlhuKtD31m-0z2li3HtyLKoFay6DiZPwEFE4Ee_3/s1600/ATMega32ColorSensorConnections.png" height="248" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Color Sensor Circuit Connections</td></tr>
</tbody></table>
<h3>
Step 4: Test the Circuit with the Color Sensor WPF application</h3>
<br />
Download the <a href="https://github.com/codergirljp/ColorSensor-WPF"><span style="color: blue;">Color Sensor WPF Application</span></a>.<br />
Open the solution file in Visual Studio 2010 Express and compile it. Here is the link to download and install <a href="http://www.visualstudio.com/en-us/downloads#d-2010-express"><span style="color: blue;">Visual Studio Express 2010 (with C#)</span></a> if you do not have it.<br />
Plug in the USB to TTL Serial cable to your computer.<br />
The led light on the color sensor will come on at this time. If your circuit is correct, you should be able to turn it off by pressing the button.<br />
Windows should automatically recognize the serial connection and assign it to a COM port. You can see which COM port it is on either by looking in the Device Manager under Ports (COM and LPT) or in the Arduino IDE the COM port will show up as a selection under Tools->Serial Port.<br />
<br />
If everything worked so far, it's time to run the Color Sensor application. You can run the application in debug mode by pressing F5 in Visual Studio if you still have the solution open. It should look something like picture below:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Av1fTVF1OiTs1SYxAVFKzZgPmD1O9dl_R4g7VuL6zCfRM4cfJYgfDtv4mR2m5JQjwZ8Xcv-fIA_2-gaTsFxyptpjwzwm_wrnH_G64YCFIsc81n-hRBiJKgBvzhUYH238azc0677-NM24/s1600/ColorSensorWPFAppDebugStartUp.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh4Av1fTVF1OiTs1SYxAVFKzZgPmD1O9dl_R4g7VuL6zCfRM4cfJYgfDtv4mR2m5JQjwZ8Xcv-fIA_2-gaTsFxyptpjwzwm_wrnH_G64YCFIsc81n-hRBiJKgBvzhUYH238azc0677-NM24/s1600/ColorSensorWPFAppDebugStartUp.PNG" height="371" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">ColorSensor-WPF application running in Debug Mode</td></tr>
</tbody></table>
<br />
Select the correct COM port for your USB to Serial TTL cable and press the Start button to begin receiving color data from the color sensor.<br />
After you press the Start button, you will see the Current Color and Gamma Color change based on the colors detected by the sensor!<br />
<br />
<h3>
Step 5; Experiment with the the Color Sensor using different colored objects</h3>
<br />
If you want to see the color of an object that does not emit light such as a notebook then press the button on the sensor a few times until the led light ON.<br />
With the light on, try holding different colored objects up to the sensor so that the led light is reflected back onto the adjacent sensor array.<br />
Notice the color show in Current Color compared to the actual object color? The color sensor is better at detecting some colors than others..<br />
<br />
It is pretty good at detecting that a color is blue.. Here is the result when I held a blue Nivea lotion bottle directly up to the sensor. I set the Compare to Color Value to pure blue for an reference color. The Gamma Color Value doesn't seem to be closer for these purposes. It seems much darker.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxGKgp7z2P_x787brHsGahmoUdG0S_qSzF_qILxyYkNag6QXErstkAPceTM8trCtuQm94qoQWrG_Tb0UiyENlXyL_cpc2Mh9bAmsw5O7RHCbnByv9oitBwLt15zaW24QsBRbE8Fu3kTfNf/s1600/BlueObject.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgxGKgp7z2P_x787brHsGahmoUdG0S_qSzF_qILxyYkNag6QXErstkAPceTM8trCtuQm94qoQWrG_Tb0UiyENlXyL_cpc2Mh9bAmsw5O7RHCbnByv9oitBwLt15zaW24QsBRbE8Fu3kTfNf/s1600/BlueObject.PNG" height="224" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Current Color is the color detected when a blue object was held up to the sensor.</td></tr>
</tbody></table>
<br />
Now I'd like to try a few other object colors. here is the screen shot from the output from a red ball.<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDGOBJDdQ7dMs0aP8MAmtye2e3-35WyFC5uQ6-T87k4HGF7PPT5naiu3JMKnaDaWhm7AIKkTEYZA3lvXhwSE5AUcW2Uf4epabs73_wp4htJtwajnsdCR7Qq-nDqMQ1jDoXz8mmsJWTRcOb/s1600/RedObject.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDGOBJDdQ7dMs0aP8MAmtye2e3-35WyFC5uQ6-T87k4HGF7PPT5naiu3JMKnaDaWhm7AIKkTEYZA3lvXhwSE5AUcW2Uf4epabs73_wp4htJtwajnsdCR7Qq-nDqMQ1jDoXz8mmsJWTRcOb/s1600/RedObject.PNG" height="99" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">The Current Color is from a Red Ball held up to the Sensor.</td></tr>
</tbody></table>
Red and Blue are not perfect, but they are at least in the right range, lets try green.Green is not too bad but not perfect either. </div>
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8UqRYly3vp1YPdMGjRKsGI1ZeIqwNkrBmz7VS9UbjM35VrT-pzLxhZBE00Y_misy71xa5H7eu1Pyic_5-fJKjOFShyphenhyphenHMf53A4O6GmIcNkPtEi8qtAXXx5hWgRPGVM3m-JSicq1E8QkIM/s1600/GreenObject.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEig8UqRYly3vp1YPdMGjRKsGI1ZeIqwNkrBmz7VS9UbjM35VrT-pzLxhZBE00Y_misy71xa5H7eu1Pyic_5-fJKjOFShyphenhyphenHMf53A4O6GmIcNkPtEi8qtAXXx5hWgRPGVM3m-JSicq1E8QkIM/s1600/GreenObject.PNG" height="105" width="320" /></a></div>
<div>
<br /></div>
<div>
<br />
So what about mixed colors like yellow? Here is what it looks like when I hold a yellow object next to the sensor:<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc97Su_wrezcrFgfeLIrwrGejN1Pw4G3veoi92b0wEL-kb1TIZxmPqbc47buhVFMgX64tdr1jvhfzPO2kvpUsvFz5D5n1AiMS-5X68skDVvBayjFMw7pOioP6-nbiWTkwuqpcWQB-X_rZU/s1600/YellowObject.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjc97Su_wrezcrFgfeLIrwrGejN1Pw4G3veoi92b0wEL-kb1TIZxmPqbc47buhVFMgX64tdr1jvhfzPO2kvpUsvFz5D5n1AiMS-5X68skDVvBayjFMw7pOioP6-nbiWTkwuqpcWQB-X_rZU/s1600/YellowObject.PNG" height="108" width="320" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
The yellow object appears more olive green than yellow. It seems to detect more green from the yellow, but not enough red to show the yellow. Hopefully I can find a way to adjust the colors so they are closer to those of the actual object. The gamma corrected color doesn't seem like it's going to help here either, it still appears too dark.<br />
<br /></div>
<div>
<br />
<h4>
Other References</h4>
<br />
<a href="http://www.ams.com/eng/Products/Light-Sensors/Color-Sensor/TCS34725"><span style="color: blue;">The AMS Light Sensors product Website</span></a> - Look under Technical Documentation. There are several documents that explain the science in measuring and converting color temperature to RGB values. If you dig into the Adafruit library, you will see the formula's there come from this documentation.<br />
<br />
<a href="http://www.ams.com/eng/content/download/319364/1117183/file/TCS3472_Datasheet_EN_v1.pdf"><span style="color: blue;">TCS34725 color sensor data sheet</span></a><br />
<a href="http://www.taosinc.com/"><span style="color: blue;">TAOS Inc (now AMS)</span></a></div>
<div>
<br /></div>
<div>
<br /></div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-22718598490994744802014-08-24T13:50:00.003-07:002014-08-24T13:50:44.849-07:00Setting up the Toolchain for Atmel AVR programming in WindowsThe basic setup for an open source toolchain will get you pretty far in programming Atmel AVR's that are supported by avr-gcc. If you want to program these AVR's directly using standard c code, you'll need a toolchain, plus some hardware. Here are my notes for setting this up on a Windows 8 machine.<br />
<br />
<h3>
Hardware Needed:</h3>
<ol>
<li><b>ATMega32A - PU</b> (the PU package is breadboard friendly)</li>
<li><b>An ISP / USB Flash Programmer</b> - <br />This is a USB device that allows you to send compiled hex files down from your computer to the chip. The device uses the SPI interface and reset on the chip to load code onto the chip. I've been using my Arduino Mega for this.</li>
<li><b>Some basic hardware</b>: A Breadboard, an LED, and some wires for testing.</li>
</ol>
<h3>
Software Needed:</h3>
<ol>
<li><b>Notepad++</b> (You could also use Programmers Notepad that is included with the WinAVR suite or another IDE to edit and write your code).</li>
<li><b>WinAVR </b>- This is an open source suite of compiler tools that includes the compiler and AVRDUDE uploader software in one great package</li>
<ul>
<li> <b>avr-gcc</b> - this a compiler you can use to compile c and c++ code and turn it into a hex file that can be run on an ATmel AVR </li>
<li><b>AVRDUDE </b>- This is the software tool that understands how to make your flash programmer upload your hex compiled code to your AVR chip.</li>
</ul>
<li><b>make file</b> - these are text files that allow you to run all the tools in one easy step from from compiling your c code with avr-gcc to uploading it with AVRDUDE</li>
<li><b>Code</b> to upload and test with.</li>
</ol>
<br />
<br />
<h3>
Step 1: Install WinAVR</h3>
<ol>
<li>Download WinAVR and install it on your computer.<br />You can <a href="http://sourceforge.net/projects/winavr/files/WinAVR/20100110/"><span style="color: blue;">download WinAVR from sourceforge by clicking here</span></a>.</li>
<li>Download Notepad++ and install it on your computer (or use another editor).<br />You can <a href="http://notepad-plus-plus.org/download/v6.6.8.html"><span style="color: blue;">download Notepad++ here</span></a></li>
</ol>
<br />
<br />
<h3>
Step 2: The Makefile</h3>
A make file is sort of like a script (or batch file) that can help you compile your code and then do other stuff too. In this case, it's going to compile your code and if your circuit connections are good, it's going to upload your code to the AVR chip! Sweet right!?! The easiest way to get started with make files is to start with one that already does most of what you want it and customize it for your needs.<br />
<a href="https://github.com/codergirljp/ATMega32-AVR-Programming">Click here to download a Makefile and blink.c code to test with</a>.<br />
<br />
The make file contains only a few items that need to be changed. These are items specific to the type of programmer being used, the target avr chip, and the source code being compiled and uploaded.<br />
<br />
<h4>
Target AVR Flags:</h4>
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">MCU</span> = atmega32 </span><span style="font-family: 'Courier New', Courier, monospace;"> </span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">F_CPU</span> = 1000000</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">BAUD</span> = 9600</span><br />
<br />
MCU : This tells avr-gcc what target to compile the code for. In this case the target is an atmega32. To find out what other targets are supported just go to the command prompt and type:<br />
<div style="text-align: center;">
<span style="font-family: Courier New, Courier, monospace;">avr-gcc --target-help</span></div>
F_CPU : This tells avr-gcc the clock frequency in Hertz for the target AVR. This needs to be correct for anything timing related to work properly. Note: this does not set the clock frequency! It just tells avr-gcc what the frequency is. The specifics of the clock operations can be found by searching for "System Clock and Clock Options" in the <a href="http://www.atmel.com/images/atmel-8155-8-bit-microcontroller-avr-atmega32a_datasheet.pdf"><span style="color: blue;">ATMega32 Datasheet</span></a>. It may be a bit daunting, but basically it tells you that the default clock source is set to 1 MHz.<br />
BAUD : This is the baud rate used for serial communications between the avr and your computer. This just tells the avr what speed you want to talk at. The avr may support higher baud rates that are documented in the datasheet. 9600 is a safe default.<br />
<br />
<h4>
Source Code specifiers:</h4>
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">MAIN </span>= blink.c</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">LOCAL_SOURCE </span>= blink.h</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">EXTRA_SOURCE_DIR </span>= ..\..\lib</span><br />
<span style="color: blue; font-family: 'Courier New', Courier, monospace;">EXTRA_SOURCE_FILES </span><span style="font-family: 'Courier New', Courier, monospace;">= myotherfile.c</span><br />
<br />
MAIN: The source file that contains your main function.<br />
LOCAL_SOURCE: Additional code files in the same directory as your main file.<br />
EXTRA_SOURCE_DIR : Specify another directory to look for source files.<br />
EXTRA_SOURCE_FILES: Specify additional source files to include.<br />
<br />
Every Make file usually has some way of specifying these, although it often has different variables than the ones above. Check out the one make file template included with WinAVR to see one that is very different.<br />
<br />
<h4>
Programmer Flags:</h4>
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">PROGRAMMER_TYPE </span>= avrisp</span><br />
<span style="font-family: Courier New, Courier, monospace;"><span style="color: blue;">PROGRAMMER_ARGS </span>= -v -v -cstk500v1 -P\\.\COM4 -b19200</span><br />
<br />
PROGRAMMER_TYPE : This is the name that tells avrdude what programmer you are using. To find out what programmer options are supported in avrdude go to the command prompt and type:<br />
<div style="text-align: center;">
<span style="font-family: Courier New, Courier, monospace;">avrdude -c ?</span></div>
PROGRAMMER_ARGS : These are all the other arguments that will be passed to avrdude. Depending on the type of programmer you use. To use the arduino as an ISP, I need to specify that the Arduino is on COM4, and that the ISP programmer code uses a baud rate of 19200. Also stk500v1 tells it to use the Atmel STK 500 version 1 and -v -v tells it to give verbose output. <br />
<br />
<h3>
STEP 3: Circuit Setup - Arduino as an ISP programmer</h3>
The circuit setup is the same as it was to program the ATTIN84A except that the pins are different on the ATMega32A.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td><b>Arduino Mega/ Uno Pins</b></td><td><b> to</b></td><td><b> ATMEGA32A Pins</b></td></tr>
<tr><td>MISO pin 50/ pin 12</td><td>-></td><td>pin 7 MISO</td></tr>
<tr><td>MOSI pin 51/ pin 11</td><td>-></td><td>pin 6 MOSI</td></tr>
<tr><td>CLK pin 52/ pin 13</td><td>-></td><td>pin 8 SCK</td></tr>
<tr><td>SS pin 53/ pin 10</td><td>-></td><td>pin 9 RESET</td></tr>
<tr><td>5V</td><td>-></td><td>pin 10 VCC</td></tr>
<tr><td>GND</td><td>-></td><td>pin 11 GND</td></tr>
<tr><td>RESET to Capacitor to</td><td>-></td><td>GND</td></tr>
</tbody></table>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<div style="text-align: left;">
<span style="font-family: inherit;">The <a href="http://codergirljp.blogspot.com/2014/08/pinout-for-various-boards-and.html">pinout for the ATMega32 can be found here</a></span></div>
<div style="text-align: left;">
<span style="font-family: Courier New, Courier, monospace;"><br /></span></div>
<h3 style="text-align: left;">
<span style="font-family: inherit;">STEP 4: Program the Arduino as an ISP programmer</span></h3>
To turn the Arduino Mega into an AVR ISP you need to upload the ArduinoISP sketch to your Arduino board.<br />
<ol>
<li>Using the USB cable, connect your Arduino Mega 2560 or Arduino Uno to your computer.</li>
<li>Open the the Arduino IDE. </li>
<li>Under Tools -> Boards select the "Arduino Mega 2560" (or select "Arduino Uno" if you are using that instead) as the board.</li>
<li>Under Tools -> Programmer select "<b>AVR ISP</b>"</li>
<li>Select File -> Examples -> ArduinoISP to open the Arduino ISP sketch. </li>
<li>Compile the sketch and upload it to your Arduino Board. </li>
</ol>
<div style="text-align: left;">
Your Arduino is now ready to use as an in system programmer!</div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
STEP 5: Run the Makefile </h3>
<div style="text-align: left;">
Now we are ready to test it out. </div>
<div style="text-align: left;">
<ol>
<li>Make sure the COM port in the make file PROGRAMMER_ARGS matches the one the Arduino is connected to. (It is currently set to COM4 in the make file).</li>
<li>Once the COM port is correct, go to the command line in the directory where the Makefile and blink.c are extracted. On the command line type:<br /><div style="text-align: center;">
<span style="font-family: 'Courier New', Courier, monospace;">make flash</span></div>
</li>
</ol>
<div>
If it works you should see a lot of output with no errors. At the end it should say:<br /><div style="text-align: center;">
<span style="font-family: Courier New, Courier, monospace;">avrdude done. Thank you.</span></div>
</div>
</div>
<div style="text-align: left;">
<br />If you get an error, check your circuit and make sure the connections are correct. Also verify the COM port is correct, and verify the baud rate matches the ArduinoISP sketch.</div>
<div style="text-align: left;">
<br /></div>
<h3 style="text-align: left;">
STEP 6: Test the blink code on the ATMega32 with an LED</h3>
<div style="text-align: left;">
If everything else worked above, connect an LED from Pin 1 (PB0) to ground. And it blinks!</div>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDi34ha8rjEAJ3n-x97WwtjJ2ExOAkcRIdDs9nJ-jCXaR0zWTiH-pkdPEJQOysDOeIpfTphGfxkh9FogivgiyoaP8tVcoR0ZNg0Pr4xzk-h7qx2poDP8k2qQBJSuz0C43SsvqiUuk-iLzR/s1600/Atmega32Blink.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhDi34ha8rjEAJ3n-x97WwtjJ2ExOAkcRIdDs9nJ-jCXaR0zWTiH-pkdPEJQOysDOeIpfTphGfxkh9FogivgiyoaP8tVcoR0ZNg0Pr4xzk-h7qx2poDP8k2qQBJSuz0C43SsvqiUuk-iLzR/s1600/Atmega32Blink.jpg" height="320" width="263" /></a></div>
<div style="text-align: left;">
</div>
<div style="text-align: left;">
<br /></div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-77742948093141529952014-08-23T15:29:00.000-07:002014-08-23T15:29:43.271-07:00Bit Twiddling Reference for AVR programmersIf you do any AVR programming in c or c++, you'll very likely need these operations. As often as I've seen them, I still sometimes need to look these up if I haven't used them in a while. So here they are...<br />
<div>
<br /></div>
<div>
Assume that the variable <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">myByte </span>is a 8 bit variable defined as the following in c code:</div>
<div>
<span style="font-size: x-small;"> <span style="font-family: Courier New, Courier, monospace;">byte myByte = 0x00;</span></span></div>
<div>
<br /></div>
<div>
The above line of code sets all 8 bits (0-7) to 0, turning them all OFF using the hex notation.</div>
<div>
<br /></div>
<h3>
<b>Set bit <i>i </i>(ON/1):</b> <span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">myByte |= (1 << </span><b style="font-family: 'Courier New', Courier, monospace; font-size: small; font-style: italic;">i </b><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">);</span></h3>
<h3>
<b>Clear bit <i>i </i>(OFF/0): </b> <span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">myByte &= ~(1 << </span><b style="font-family: 'Courier New', Courier, monospace; font-size: small; font-style: italic;">i </b><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">);</span></h3>
<div>
<h3>
<b>Toggle bit <i>i </i>: </b> <span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">myByte ^= (1 << </span><b style="font-family: 'Courier New', Courier, monospace; font-size: small; font-style: italic;">i </b><span style="font-family: 'Courier New', Courier, monospace; font-size: x-small;">);</span></h3>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
</div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-68421449023103781392014-08-16T14:46:00.000-07:002014-08-30T12:06:45.289-07:00Pinout for various boards and microcontrollers<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHiITgan5ZPJKAiUrHegmROZTDN7ZxUhPHyp0PvQDiKlmAy4y0pq2EvkPyfsY5CgZulQ5B8qRLTVAMQ1tRkAaVs6OhmDtuorOWtZ11sSj7QQBUTSljqoS1OSvcNYaQVxGPpQlhcQmXOkyz/s1600/ArduinoMicroPins.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjHiITgan5ZPJKAiUrHegmROZTDN7ZxUhPHyp0PvQDiKlmAy4y0pq2EvkPyfsY5CgZulQ5B8qRLTVAMQ1tRkAaVs6OhmDtuorOWtZ11sSj7QQBUTSljqoS1OSvcNYaQVxGPpQlhcQmXOkyz/s1600/ArduinoMicroPins.PNG" height="200" width="171" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><h2>
<b>Arduino Micro Pins </b><span style="font-weight: normal;"><span style="font-size: x-small;">(based on ATMega32 chip series)</span></span></h2>
</td></tr>
</tbody></table>
<div style="text-align: center;">
<a href="http://arduino.cc/en/Hacking/PinMapping32u4">Arduino to Micro ATMega32 Pin Mapping </a></div>
<div style="text-align: center;">
<br /></div>
<div style="text-align: center;">
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3vTxPfmZV1pKz51dP0wH-JgbW2uuIMI8HXNPcOmwpuQmGY14oLSaQ5Uoy6vEy9ueHQRLWaaS4JpKimzS70gIlnnc5rWMpWv1doe6ZCETq_RcKHL-GvGBqnjQhrzDhzPO8wR7Dm288FeyB/s1600/ATMega32Pins.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj3vTxPfmZV1pKz51dP0wH-JgbW2uuIMI8HXNPcOmwpuQmGY14oLSaQ5Uoy6vEy9ueHQRLWaaS4JpKimzS70gIlnnc5rWMpWv1doe6ZCETq_RcKHL-GvGBqnjQhrzDhzPO8wR7Dm288FeyB/s1600/ATMega32Pins.PNG" height="304" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><h2>
<b>ATMega32 Pins </b><a href="http://www.atmel.com/images/atmel-8155-8-bit-microcontroller-avr-atmega32a_datasheet.pdf">ATMega32 Datasheet</a></h2>
</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4E8gt5QrohdclXSUrDxw1QEXAA9Ffw7LC7pQjaXiHiFavkyD6vw7jU7ATfdKIM8GMPZ53pHnRDz45bFXJkN2kUsMIYoSy1kCJJtd3AAE7ekUCk1qMIEtMtGUlnhfy32c3b1FD28_WSm0T/s1600/ATMega168Pins.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4E8gt5QrohdclXSUrDxw1QEXAA9Ffw7LC7pQjaXiHiFavkyD6vw7jU7ATfdKIM8GMPZ53pHnRDz45bFXJkN2kUsMIYoSy1kCJJtd3AAE7ekUCk1qMIEtMtGUlnhfy32c3b1FD28_WSm0T/s1600/ATMega168Pins.PNG" height="211" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><h2>
<b>ATMega168 Pins </b><a href="http://www.atmel.com/images/doc2545.pdf">ATMega168 Datasheet</a></h2>
</td></tr>
</tbody></table>
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhejeiHdYKBSaBVqyxwB9qwinrQEed6T2fkaxY2eahaQGT5pXpjaRWiD2nNn63475iBWRC1CQtCV6rcdumLORgItEIaP8u8MPPVy1sLQW7UA76LiJ-h0waVv3GItkqT5wHTS3lJe0CI3LCu/s1600/ATTiny84APins.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhejeiHdYKBSaBVqyxwB9qwinrQEed6T2fkaxY2eahaQGT5pXpjaRWiD2nNn63475iBWRC1CQtCV6rcdumLORgItEIaP8u8MPPVy1sLQW7UA76LiJ-h0waVv3GItkqT5wHTS3lJe0CI3LCu/s1600/ATTiny84APins.PNG" height="101" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><h2>
<b>ATTiny84A Pins <br /><a href="http://www.atmel.com/images/doc8183.pdf">ATtiny84 Datasheet</a></b></h2>
</td></tr>
</tbody></table>
<br />codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-59528836345864573692014-07-26T20:15:00.000-07:002014-07-26T20:15:06.852-07:00Use an Arduino Mega 2560 to program an ATTINY84A<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; margin: 0px; padding: 0px;">
This is a hello world AVR programming project. A simple way to get started programming an inexpensive AVR chip for anyone who has an Arduino board. I am going to use an <a href="https://www.adafruit.com/products/191">Arduino Mega 2560</a> as an ISP AVR programmer but you can also do this with an Arduino UNO or any board with a SPI interface if you know how. </h1>
<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; margin: 0px; padding: 0px;">
</h1>
<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; margin: 0px; padding: 0px;">
If you have been working with some developer boards like the Arduino UNO or the Arduino Mega 2560, and you are comfortable soldering your own projects, then you might have realized that the chips alone usually cost from $1-$3 and take up a lot less space than the breakout boards do. The good news is, you can easily get started programming these chips using the developer board that you have on hand! </h1>
<div>
<br /></div>
<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; margin: 0px; padding: 0px;">
</h1>
<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; margin: 0px; padding: 0px;">
For this example, I am going to use my <a href="https://www.adafruit.com/products/191">Arduino Mega 2560</a> as an ISP AVR programmer to program an <a href="http://www.mouser.com/ProductDetail/Atmel/ATTINY84A-PU/?qs=JVB2vxgwrww2b/em/NzH9Q==">ATTINY84A-PU</a> chip to do a simple LED blink. There are other ways to program this chip, but if you happen to already have an Arduino board on hand and don't want to spend the extra money to buy a programmer, this is a quick and easy way to get started. </h1>
<div>
<br /></div>
<h1 style="background-color: white; font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; margin: 0px; padding: 0px;">
</h1>
<h3 style="background-color: white; font-family: Arial, Helvetica, sans-serif; margin: 0px; padding: 0px;">
<span style="font-size: small;">
Parts List: </span></h3>
<div>
<ol>
<li><a href="http://www.radioshack.com/product/index.jsp?productId=3111495">10mm Ultra-High Brightness Blue LED</a> - <i><span style="font-style: normal;">any LED will work</span></i></li>
<li>An Arduino Mega 2560 or UNO </li>
<li>A <a href="http://www.radioshack.com/product/index.jsp?productId=2062393&cid=ip%3Asem%3Arso%3Agoogle%3Aradioshack_capacitor&stop_mobi=yes&utm_campaign=RSO_SRC_EN_NCA_TM_B_Hobby_Do_It_Yourself&utm_source=google&gclid=CjwKEAjw0a2eBRDVrabv9vWJ90USJACsKRDH6ke10SQmqTW2Ib4z8wjEs2hEAPD_N_0IwTLgX8s2DxoC7kzw_wcB&utm_medium=ppc&gclsrc=aw.ds">10uF capacitor</a></li>
<li>An <a href="http://www.mouser.com/ProductDetail/Atmel/ATTINY84A-PU/?qs=JVB2vxgwrww2b/em/NzH9Q==">ATTINY84A-PU </a> <i>($1.41)</i></li>
<li>Small Breadboard</li>
<li>Connection Wires</li>
</ol>
<div>
<a href="http://www.atmel.com/Images/doc8183.pdf">ATtiny84A Datasheet</a></div>
<div>
<br /></div>
<div>
The first thing you need to do is be able to program your chip using the Arduino Mega. To do that with the Arduino IDE you will need to install the Tiny bootloader and supporting libraries into the Arduino IDE. Then you will need to set up the circuit for the programmer, upload a blink sketch to the chip, and finally, setup the chip circuit to work with the blink circuit.<br />
<br /></div>
<h3>
<b>Using the Arduino Mega as an AVR programmer</b></h3>
<div>
<b><br /></b></div>
<h3>
<b>Step 1: Prepare the Arduino IDE environment to program the ATTINY84A</b> </h3>
You need to be able to compile code into a hex file to load onto the ATTINY84A and upload that code from the Arduino IDE but the functionality to do that requires some additional software components that are not included by default.<br />
<br />
<br />
<ol>
<li><a href="https://arduino-tiny.googlecode.com/files/arduino-tiny-0150-0020.zip">Click here to download the "Tiny" archive</a> </li>
<li>Create a new directory named tiny under your ..\Arduino\hardware directory.<br />For newer versions of the Arduino IDE, this may be located in:<br /> "C:\Program Files (x86)\Arduino\hardware"</li>
<li>Copy and paste the contents of the tiny/avr directory of the archive to the ..\Arduino\hardware\tiny directory you created.</li>
<li>In the ..\Arduino\hardware\tiny directory, rename the <i>Prospective Boards.txt</i> file to <i>boards.txt</i>. </li>
<li>Open the Arduino IDE. You should see the ATTINY84 under the Tools->Boards menu.</li>
</ol>
<div>
<br /></div>
<br />
<h3>
<b>Step 2: Program the Arduino Mega 2560 to be an AVR ISP</b></h3>
To turn the Arduino Mega into an AVR ISP you need to upload the ArduinoISP sketch to your Arduino board.<br />
<ol>
<li>Using the USB cable, connect your Arduino Mega 2560 or Arduino Uno to your computer.</li>
<li>Open the the Arduino IDE. </li>
<li>Under Tools -> Boards select the "Arduino Mega 2560" (or select "Arduino Uno" if you are using that instead) as the board.</li>
<li>Under Tools -> Programmer select "<b>AVR ISP</b>"</li>
<li>Select File -> Examples -> ArduinoISP to open the Arduino ISP sketch. </li>
<li>Compile the sketch and upload it to your Arduino Board. </li>
</ol>
<div>
Your Arduino is now ready to use as an in system programmer!</div>
<br />
<br />
<h3>
<b>Step 3: Hardware Setup to use the Arduino ISP (for the ATtiny84)</b></h3>
<div>
<br /></div>
<div>
Next we need to make the connections between the Arduino Mega (or Uno) and your ATTINY84A chip.</div>
<div>
The Arduino Mega has a hardware SPI interface on pins 50 - 53 that can be used to program other chips like the ATTINY84A as shown in the picture below. (If you are using the Uno, pins 50, 51, 52, and 53 on the Mega should be mapped to pins 12, 11, 13, and 10 on the Uno). </div>
<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaAC8owIsfMZ6GwuuNwD_3eH8fMt0j3s0kqwoECgbxAIw6rFcyTl32_pHXTfIYN9Ornon1wFolCsi5RqNqUGkZ6ck0ok8yzwoPacJ2zNw8AbvPGwgZ6Fq6BHAn4OnbzynLwCXcrOwJu3h4/s1600/ArduinoMegaHWSPI.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiaAC8owIsfMZ6GwuuNwD_3eH8fMt0j3s0kqwoECgbxAIw6rFcyTl32_pHXTfIYN9Ornon1wFolCsi5RqNqUGkZ6ck0ok8yzwoPacJ2zNw8AbvPGwgZ6Fq6BHAn4OnbzynLwCXcrOwJu3h4/s1600/ArduinoMegaHWSPI.PNG" height="118" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Arduino Mega 2560 Hardware SPI Pins<br />
(note: we also use pin 53 - the SS pin to reset to ATtiny84)</td></tr>
</tbody></table>
<h3>
</h3>
<div>
We need to connect the SPI pins from our Arduino to the SPI pins on the ATTINY84A. I am using the ATTINY84A-PU because the PU extension chips are breadboard friendly. The pins needed for this on the ATTINY84A are shown below.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG1VvBEd3O9RHXOl9c-8gyGzC9CyP76HL8pHAKaa2WM5eeuUeyRls-BIpk8JXze7zsn3HqNXceHwxtrDXWYBYUJs-t_Iy5mGv7_W17RVaEjHtm-RexA7hiKttOWGwZeAcb0CxUb4GsHUWY/s1600/ATTINY84A-programming.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgG1VvBEd3O9RHXOl9c-8gyGzC9CyP76HL8pHAKaa2WM5eeuUeyRls-BIpk8JXze7zsn3HqNXceHwxtrDXWYBYUJs-t_Iy5mGv7_W17RVaEjHtm-RexA7hiKttOWGwZeAcb0CxUb4GsHUWY/s1600/ATTINY84A-programming.PNG" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">ATTINY84A SPI / ISP Pins<br />
(note: the RESET Pin 4 will also be needed)</td></tr>
</tbody></table>
<br />
<br />
<h4>
Curcuit setup for the ISP AVR programmer</h4>
<div>
<br /></div>
Unplug the Arduino Board and make the following connections:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;">
<tbody>
<tr><td><b>Arduino Mega/ Uno Pins</b></td><td><b> to </b></td><td><b> ATTINY84A Pins</b></td></tr>
<tr><td>MISO pin 50/ pin 12</td> <td>-></td><td>pin 8</td></tr>
<tr><td>MOSI pin 51/ pin 11</td> <td>-></td><td>pin 7</td></tr>
<tr><td>CLK pin 52/ pin 13</td> <td>-></td><td>pin 9</td></tr>
<tr><td>SS pin 53/ pin 10</td> <td>-></td><td>pin 4</td></tr>
<tr><td>5V </td> <td>-></td><td>pin 1 VCC</td></tr>
<tr><td>GND </td> <td>-></td><td>pin 14 GND</td></tr>
<tr><td>RESET to Capacitor to </td> <td>-></td><td>GND</td></tr>
</tbody></table>
</div>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtYZpjJkOwBwPiFFFYYcc07bTGt1qj12c2To0RYtXM_tcv6XZI7P-xUI4DESnBrpfOVyLp74HGbgg-HibSXFT9nIa0N8DcMY9w14W5I14hbynruRPy2jJnN0WL4u_Kv5feDvaRbE0ZEEI_/s1600/arduinoMegaISP.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtYZpjJkOwBwPiFFFYYcc07bTGt1qj12c2To0RYtXM_tcv6XZI7P-xUI4DESnBrpfOVyLp74HGbgg-HibSXFT9nIa0N8DcMY9w14W5I14hbynruRPy2jJnN0WL4u_Kv5feDvaRbE0ZEEI_/s1600/arduinoMegaISP.jpg" height="253" width="320" /></a></div>
<h3>
</h3>
<h3>
<br /></h3>
<h3>
Step 4: Use the AruinoAVR ISP to program the ATTINY84A</h3>
</div>
<div>
<br />
<ol>
<li>Plug in the USB connection for Arduino board to your computer.</li>
<li>Open the Arduino IDE.</li>
<li>Open the Arduino Blink sketch by selecting <br /> File -> Examples -> Basics -> Blink.</li>
<li>Change the led pin in the blink sketch by changing <br /> "<b>int led = 13;" to "int led = 1;</b>" </li>
<li>Select the ATtiny84 @ 8 MHz Internal Oscillator by selecting <br /> Tools -> Boards -> <b>ATtiny84 @ 8 MHz Internal Oscillator</b><br /><br />(Caution: Do not select the External oscillator unless you have added an external oscillator; this can cause issues if selected by mistake).</li>
<li>Choose the Arduino as an ISP programmer by selecting <br /> Tools-> Programmer-> "<b>Arduino as ISP</b>"</li>
<li>Upload the sketch to the chip by selecting<br /> File-> "Upload Using Programmer" or pressing <b>Ctrl +Shift + U</b>.</li>
</ol>
</div>
<div>
<br /></div>
<div>
<h3>
<b>Step 5: ATTINY84A-PU LED Blink Hardware Setup</b></h3>
</div>
This is the easiest part.. connect the LED o Pin 3 of the ATtiny84, connect the power and ground pins and you will see the LED blink on and off slowly.<br />
<br />
Make the connections:<br />
<br />
ATtiny84 Vcc Pin 1 -> 3.5V to 5V source voltage<br />
ATtiny84 GND Pin 14 -> Ground<br />
ATtiny84 Pin 3 /PB1 -> LED +<br />
LED- -> Ground<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXqxU6IKzGtm7T5ZMKMyTS5r9VTo2-VtudX1-cTB6wcE0x3tW8GsuK4zd7GWdPzxakjRkBVBJHp2ofO2BMJxRPMVJl3zd-LwMlOSHh0YcpKbWBKaguCofkCOJrX7_aqfITSOQZ37m9xSFn/s1600/ATtiny84LedBlink.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjXqxU6IKzGtm7T5ZMKMyTS5r9VTo2-VtudX1-cTB6wcE0x3tW8GsuK4zd7GWdPzxakjRkBVBJHp2ofO2BMJxRPMVJl3zd-LwMlOSHh0YcpKbWBKaguCofkCOJrX7_aqfITSOQZ37m9xSFn/s1600/ATtiny84LedBlink.jpg" height="227" width="320" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
I used a Lipo battery I had to power it but you could also power it from the Arduino 5V, or another power source you might have.<br />
<br />
<br />
Here is another useful link with more details for doing this with the UNO.<br />
<a href="http://www.instructables.com/id/Using-the-Arduino-Uno-to-program-ATTINY84-20PU">Using the Arduino Uno to program ATTINY84-20PU</a><br />
<br /></div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-12377783352599340542014-06-29T14:30:00.002-07:002014-06-29T16:40:38.467-07:00LPD8806 RGB Light Strips - Using an Arduino Mega to count the pixelsThe goal of this project is to count the number of LED pixels on a LPD8806 light strip using SPI MISO and the DO (Data Out) pin at the end of the strip. I used the hardware SPI pins on the Arduino Mega 2560 because it is faster and more reliable than a bit banged software SPI. The code will send data to the light strip increasing the number of pixels on the strip each time until it reaches a maximum number of pixels specified in the code, or until data is found in the Arduino's SPI MISO buffer. I used 100 as the maximum but this could be changed to any number.<br />
<br />
This technique can be used to connect a strip of any length and dynamically determine the number of LED pixels on the strip at start up. This allows for trading out light strips of different lengths without changing the code, as long as the maximum number of LED pixels set in the code is greater than the number of the longest light strip that might be used.<br />
<br />
The disadvantage of this technique is that you need a physical connection to the end of the light strip. It would be really cool if they added a 5th connection to the strip that was pass through. Then the DO at the end of the strip could be connected to the pass through line and all the connections here could be at the beginning of the strip.<br />
<br />
<a href="https://github.com/codergirljp/LPD8806PixelCount">Click Here to get the Code</a><br />
<h4>
LPD8806 RGB Light Strips and SPI </h4>
The LDP8806 light strips are used as a slave device on a SPI bus to transfer data to each pixel in the strip.The hardware SPI (Serial Peripheral Interface) available on the Arduino Mega 2560 is on Pins 50, 51, and 52. The Arduino is the master device, and the light strip is the slave device.<br />
<br />
As shown in the image below, pin 52 is the CLK (Clock), pin 51 is the MOSI (Master Out Slave In), and pin 50 is the MISO (Master In Slave Out). The MOSI and CLK pins are used to send data to the light strip. The MISO pin will be used to receive data from the light strip.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd8f4NBbfCJqZXeJvchiyv5Z__mFDbFRKW_TGoQp6EhjXmDobXmJXdyGIY7_tsi0yZ6DQhk2SzD3Y_6eGDIaWzDE3_6GFdV-4DfmNQWwjKjwn4vC1uNFLJx1K5Oi_wIJZDh1YSwFan2WAn/s1600/ArduinoMegaHWSPI.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgd8f4NBbfCJqZXeJvchiyv5Z__mFDbFRKW_TGoQp6EhjXmDobXmJXdyGIY7_tsi0yZ6DQhk2SzD3Y_6eGDIaWzDE3_6GFdV-4DfmNQWwjKjwn4vC1uNFLJx1K5Oi_wIJZDh1YSwFan2WAn/s1600/ArduinoMegaHWSPI.PNG" height="118" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Arduino Mega 2560 Hardware SPI Pins</td></tr>
</tbody></table>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
The light strip has 4 connections at the beginning of the strip labeled GND, DI, CI, and +5V and 4 connections at the end of the strip labeled GND, DO, CO and +5V. The connections at the beginning of the strip are used to send data to the light strip and power the light strip. The DO pin at the end of the strip is used to receive data back from the strip.<br />
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK0yCk0ZJ_NDRAb1ByhKWlKVwLs8TlNt_HchmiAbUBr8cfDSPTtd-B4_yaAMlD4OwAjBaQxxj7mmuJGFQ-oGRfsOpkXZJuumT1BAVgj1Jmxet0-D58heKTq1AEqNXeUXucthEFOhxsSKXS/s1600/LPD8806Pins.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiK0yCk0ZJ_NDRAb1ByhKWlKVwLs8TlNt_HchmiAbUBr8cfDSPTtd-B4_yaAMlD4OwAjBaQxxj7mmuJGFQ-oGRfsOpkXZJuumT1BAVgj1Jmxet0-D58heKTq1AEqNXeUXucthEFOhxsSKXS/s1600/LPD8806Pins.PNG" height="104" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">LPD8806 RGB Light Strip Pins</td></tr>
</tbody></table>
<b>Light Strip Data</b><br />
At the beginning of the light strip, the DI and CI pins are the Data In and Clock In pins. The DI pin is connected to the Arduino MOSI (pin 51) and the CI pin is connected to the Arduino CLK (pin 52).<br />
The DO pin at the end of the strip is connected to the MISO (pin 50) on the Arduino. If this pin is not connected, you will never receive data back from the strip!<br />
<br />
<b>Powering the Light Strips</b><br />
The light strip requires an external 5 volt power supply. The Arduino cannot supply enough power to run these strips.<br />
<br />
<br />
<h3>
Step 1: Making the Hardware Connections</h3>
<h4>
Parts Needed:</h4>
<div>
<br />
<ol>
<li><a href="http://www.gearbest.com/development-boards/pp_18651.html">Arduino Mega 2560</a> <i>($16)</i></li>
<li><a href="http://www.adafruit.com/products/306">LPD8806 RGB LED Light Strip</a> <i>($30)</i></li>
<li>Power Supply to supply 5 Volts to light strip - I used an old PC power supply but this one will also work, <a href="http://www.adafruit.com/product/276">Power Supply + 5 volts</a><i> ($8) </i></li>
<li>You may also need connectors to connect the power supply to your bread board depending on your setup</li>
<li>A bread board </li>
<li>Some connection wires</li>
<li>A Soldering Iron (to make connections to the light strip)</li>
<li>A voltage meter to measure supply voltages and ensure they are at or around 5 volts. </li>
</ol>
<br />
<br />
Here is the diagram of the circuit I used: </div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs0Y9LqJQoXtaqwe3TEE8WKKAUCYaAr_wOWcqjfITiJqKpB2BEoHw9lVZqQaF8ixonNfYkvL-3tAMJIXyFoSwpIbvvR9h0wbvXmAHydYAhV4JnGwOfXqIPsw77hhF15lX-L1aavWTf6Ztr/s1600/CircuitDiagramLPD8806Count.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhs0Y9LqJQoXtaqwe3TEE8WKKAUCYaAr_wOWcqjfITiJqKpB2BEoHw9lVZqQaF8ixonNfYkvL-3tAMJIXyFoSwpIbvvR9h0wbvXmAHydYAhV4JnGwOfXqIPsw77hhF15lX-L1aavWTf6Ztr/s1600/CircuitDiagramLPD8806Count.jpg" height="230" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Circuit Diagram: LPD8806 RGB LED Light Strip and Arduino Mega</td></tr>
</tbody></table>
<h4>
Connections:</h4>
<div>
<b>Connections at the START side of the Light Strip</b></div>
<div>
<ol>
<li>Identify the START side of the light strip, this is the side with the labels DI, and CI on the two center connection pads. Connect the GND on START side of the light strip to the power source GND on the bread board. </li>
<li>Connect the +5V pad on the START side of light strip to the power source +5V on the bread board.</li>
<li>Connect the DI pad on the START side of the light strip to the Arduino Mega's MOSI (pin 51). </li>
<li>Connect the CI pad on the START side of the light strip to the Arduino Mega's CLK (pin 52). </li>
</ol>
</div>
<div>
<br /></div>
<div>
<b>Connections at the END side of the Light Strip</b></div>
<div>
<ol>
<li>Connect the DO pad on the END side of the light strip to the Arduino Mega's MISO (pin 50).</li>
<li>Optionally, you can also connect the GND and +5V on the END side of the light strip to the power source GND and +5V.</li>
</ol>
</div>
<div>
<br /></div>
<div>
<b>Additional Arduino Connections</b></div>
<div>
<ol>
<li>Connect the Arduino Mega GND pin to the GND from the power source. </li>
<li>Plug in the USB connection from the Arduino to your Computer.</li>
</ol>
<div>
Make sure the power to your power source is turned on. </div>
</div>
<div>
<br /></div>
<div>
<h3>
Step 2: Loading and Running the code</h3>
</div>
<div>
<ol>
<li><a href="https://github.com/codergirljp/LPD8806PixelCount">Click here to download the sketch for the Arduino</a>. </li>
<li>Open the Sketch in the Arduino IDE. </li>
<li>Select the Arduino Mega 2560 under Tools->Boards in the Arduino IDE</li>
<li>Make sure the Port for the Arduino is selected under Serial Ports</li>
<li>Change the maxLEDs value in the code to your preferred maximum. This should be a number larger than the largest number of LED pixels any of your LED strips might have.</li>
<li>Compile and Upload the sketch. The code will start running immediately and the LED's on the light strip should turn blue one by one. </li>
<li>Open the the Serial Monitor from the Arduino IDE to see the output from the code. If everything is wired correctly, you should see the following line at the end of the output with the correct number of pixels for your light strip:<br /> "Found 64 LED pixels in the strip.</li>
<li>If the MISO/DO connection is not connected, then the following line will be seen at the end of the output: <br />"No Data received after testing the maximum number of LEDs 100 Is the DO on the light strip connected to the MISO pin?"</li>
</ol>
</div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<div>
<br /></div>
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />
<br />codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com2tag:blogger.com,1999:blog-9059385354812982139.post-65887722367666269352014-05-18T14:20:00.000-07:002014-05-18T14:20:08.546-07:00Teensy 3.1 Accelerometer - Control a Game Object in Unity<span style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px;">Getting the accelerometer data from the Teensy is nice, but the WPF application with some lines on the screen was sort of boring. I wanted to do something more fun with the <a href="http://codergirljp.blogspot.com/2014/05/adxl335-accelerometer-on-teensy-31.html">Teensy 3.1 Accelerometer</a> - use it as a game controller! </span><span style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px;">So this project is all about using the Teensy 3.1 Accelerometer to control an airplane on the screen using the </span><a href="http://unity3d.com/unity" style="background-color: white; font-family: 'Trebuchet MS', sans-serif; font-size: 13px;">Unity game development suite</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfu-TEilaxb5RU1Pc547XOAOGL85vQ_aRhntxyefPI7tb_Evk7fs3YKF63tfH44V8eJLmTMdJ-AwVO2td87FIibNMkMxHeUGqmngj0NaIFMm_sl4ioOWAEGdHk6FG7HdR68__5rT04cj1r/s1600/UnityPlaneGameScreen.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhfu-TEilaxb5RU1Pc547XOAOGL85vQ_aRhntxyefPI7tb_Evk7fs3YKF63tfH44V8eJLmTMdJ-AwVO2td87FIibNMkMxHeUGqmngj0NaIFMm_sl4ioOWAEGdHk6FG7HdR68__5rT04cj1r/s1600/UnityPlaneGameScreen.PNG" height="250" width="320" /></a></div>
<br />
<br />
<h2>
<span style="font-family: Trebuchet MS, sans-serif;">Hardware Setup</span></h2>
<ol>
<li><span style="font-family: Trebuchet MS, sans-serif;">Follow the instructions to build the <a href="http://codergirljp.blogspot.com/2014/05/adxl335-accelerometer-on-teensy-31.html">Teensy 3.1 Accelerometer</a>. This will be used as the game controller through a USB serial connection.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">Note: the Unity game expects the Accelerometer's x, y, and z axis' to be oriented with the Y-axis arrow pointing to the right of the user and the X-axis arrow pointing toward the user when the circuit is in use. </span></li>
</ol>
<br />
<br />
<h2>
<span style="font-family: Trebuchet MS, sans-serif;">Software Setup</span></h2>
<div>
<ol>
<li><span style="font-family: Trebuchet MS, sans-serif;">Download and install the<span style="background-color: white;"> </span><a href="http://unity3d.com/unity" style="background-color: white;">Unity game development suite</a>. (this takes a while, it's a big download)</span></li>
</ol>
</div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
<div>
<span style="font-family: Trebuchet MS, sans-serif;">Now lets take a get the Unity project working.</span><br />
<span style="font-family: 'Trebuchet MS', sans-serif;"><br /></span>
<h3>
<span style="font-family: 'Trebuchet MS', sans-serif;">Step 1 - Download the Unity Plane Game project.</span></h3>
</div>
<div>
<ol>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Download the <a href="https://github.com/codergirljp/ADXL335-Accelerometer-Unity/blob/master/UnityPlaneGame.zip">UnityPlaneGame.zip</a> file and extract it to a UnityPlaneGame directory. </span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Create an Assets directory under the UnityPlaneGame directory that was just created on your local drive.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Download everything in the <a href="https://github.com/codergirljp/ADXL335-Accelerometer-Unity/tree/master/UnityPlaneGame/Assets">UnityPlaneGame/Assets</a> directory of the repository and to your Assets directory. </span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Extract the .7z compressed files to sub directories of the Assets directory that match the compressed file names. You will need 7-zip to extract the files. You can download 7-zip <a href="http://www.7-zip.org/">here</a>.</span></li>
<li><span style="font-family: 'Trebuchet MS', sans-serif;">Copy the scripts directory and other files directly to the root of your Assets directory. Your Assets directory file structure should look as shown below. </span></li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG6LiTyjLN1D2lmGvCeVyhQAPCPpz3o584kSsd1XA0Q-_5-MqeQKWuUF-IRiL1Goqs9RcsJyLLUeRcT7rx_iteGrG7O-e-Q1dh5neGm1pwfXdXwK34Fmf-h2B1B52SMD8A_26eVwIhYq0Z/s1600/UnityPlaneGameAssetsDir.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhG6LiTyjLN1D2lmGvCeVyhQAPCPpz3o584kSsd1XA0Q-_5-MqeQKWuUF-IRiL1Goqs9RcsJyLLUeRcT7rx_iteGrG7O-e-Q1dh5neGm1pwfXdXwK34Fmf-h2B1B52SMD8A_26eVwIhYq0Z/s1600/UnityPlaneGameAssetsDir.PNG" height="305" width="640" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
</div>
<div>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Step 2 - Open the Unity Project.</span></h3>
<br />
<ol>
<li><span style="font-family: Trebuchet MS, sans-serif;">Open the Unity Game development suite. </span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">From the "File" menu, select "Open Project", then choose "Open Other" at the bottom left corner and browse to the UnityPlaneGame directory. Then click the "Open" button.</span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">The project should open and look something like the image below.<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjZ-CDILb06gYyErc4P77huoruE97dQiykZXP7a6AD8cT7i72uIMBLGfEnsOt61L3NTzGkWaIKo-L7IuxBdabyYiMX7HNOV5NGgbLhsIp_Hk1z8eFEeO9mIKVCYhbwSijRWYENPfjFPZv/s1600/UnityPlaneGameProjectScreenShot.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnjZ-CDILb06gYyErc4P77huoruE97dQiykZXP7a6AD8cT7i72uIMBLGfEnsOt61L3NTzGkWaIKo-L7IuxBdabyYiMX7HNOV5NGgbLhsIp_Hk1z8eFEeO9mIKVCYhbwSijRWYENPfjFPZv/s1600/UnityPlaneGameProjectScreenShot.PNG" height="168" width="320" /></a><br /></div>
</span></li>
<li><div class="separator" style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Now Choose "Build and Run" from the "File" Menu to make sure the project will build. If not, verify the above steps.</span></div>
</li>
</ol>
<h3>
<span style="font-family: Trebuchet MS, sans-serif;">Step 3 - Change the COM port to match your Teensy 3.1 Accelerometer</span></h3>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnJjUgGOQnTTTRwrFH3z1-KSPALPZKMJ_4F1aLSpztb8etwwgFxNFOyqNYHecMXSZE7Mnra6ItAQRsmacUHhrTqyZ_D0oJCzgWTD-4MHZfdnrpJnLc1CLPqoivGeSMU0gVV4WuLWuYag_A/s1600/ProjectTabScriptsDir.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhnJjUgGOQnTTTRwrFH3z1-KSPALPZKMJ_4F1aLSpztb8etwwgFxNFOyqNYHecMXSZE7Mnra6ItAQRsmacUHhrTqyZ_D0oJCzgWTD-4MHZfdnrpJnLc1CLPqoivGeSMU0gVV4WuLWuYag_A/s1600/ProjectTabScriptsDir.PNG" height="175" width="200" /></a></div>
<ol>
<li><span style="font-family: Trebuchet MS, sans-serif;">From the Project window in Unity, navigate to the scripts directory and open the PlaneAnimator.cs script by double clicking on the file. The file will open with MonoDevelop. </span></li>
<li><span style="font-family: Trebuchet MS, sans-serif;">In the script, change the COMPORT string from "COM6" to the COM port that your Teensy 3.1 Accelerometer is on and Save your changes.</span></li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiI4aHoGNR6aNKaSMQ1Cnh70e3rOC7H2KeEAiGYxQfIiJH3oCVuKRY_WvRJfA9C258shbTFXjBtsFJLmnBr5JUtEU7glCE_FpBo0YILyIF2kZAywMlyTPV0u_SnP5L__HHUYsJd9GaHfEYf/s1600/PlaneAnimatorScriptComport.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiI4aHoGNR6aNKaSMQ1Cnh70e3rOC7H2KeEAiGYxQfIiJH3oCVuKRY_WvRJfA9C258shbTFXjBtsFJLmnBr5JUtEU7glCE_FpBo0YILyIF2kZAywMlyTPV0u_SnP5L__HHUYsJd9GaHfEYf/s1600/PlaneAnimatorScriptComport.PNG" height="202" width="400" /></a></div>
<div class="separator" style="clear: both; text-align: center;">
<br /></div>
<div class="separator" style="clear: both; text-align: left;">
<br /></div>
<h3 style="clear: both; text-align: left;">
<span style="font-family: Trebuchet MS, sans-serif;">Step 4 - Run the Game</span></h3>
<div class="separator" style="clear: both; text-align: left;">
</div>
<ol>
<li>At this point, make sure your Teensy Accelerometer is plugged in. (The USB cable). The game is programmed to open the serial port only once on start up, so it will not work if you plug it in after the game is already running.</li>
<li>Return the the Unity project window. </li>
<li>From the File menu, select Build and Run. A window will open with the Unity logo in it, and then the game scene will appear with the plane visible on the screen. Try using the Teensy accelerometer to control the plane. Tilting the accelerometer left and right should make the plane move left and right. Also try tilting it back with the front side higher than the backside. That should make the plane climb on the screen. Tilt it in the opposite direction to make the plane dive. See if you can find the buildings and fly through them! There are no collisions in the game so you can fly through anything! </li>
</ol>
<div>
<br /></div>
<br />
<div>
<span style="font-family: Trebuchet MS, sans-serif;"><br /></span></div>
</div>
</div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-53675786635175063522014-05-11T09:30:00.003-07:002014-05-11T10:02:52.356-07:00Teensy 3.1 Accelerometer - Controlling WPF UI Objects<div style="background-color: white;">
<div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
Now that I can get the data from the Accelerometer, it would be nice to do something with the data. This project demonstrates how to use the serial data from the
<a href="http://codergirljp.blogspot.com/2014/05/adxl335-accelerometer-on-teensy-31.html">Teensy 3.1 Accelerometer</a> project to update objects on a screen in a simple C# WPF (Windows Presentation Foundation) application.
<span style="font-size: 13px;">The data received from the accelerometer is used to change the size of lines mapped to the X, Y, and Z axis values of the accelerometer.</span>
</div>
<div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<br /></div>
</div>
<div style="background-color: white;">
<div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<span style="font-size: 13px;">1. Complete the steps described to hook and program the
<a href="http://codergirljp.blogspot.com/2014/05/adxl335-accelerometer-on-teensy-31.html">Teensy 3.1 Accelerometer</a>
</span>
</div>
<div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<br />
</div>
<h2 style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
Software Setup</h2>
<div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<span style="font-size: 13px;">2. <a href="http://www.visualstudio.com/en-us/downloads#d-2010-express">Download and install Visual Studio 2010 Express</a> </span>
</div>
<div style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<span style="font-size: 13px;">3.
<a href="https://github.com/codergirljp/ADXL335-Accelerometer-WPF">Get the WPF application code</a>.
Download the repository as a zip file and extract it.
</span>
</div>
<br />
<h2 style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
Set the COM Port and Build</h2>
<span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">4. Navigate to the
</span>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">ADXL335SerialApp directory and open the ADXL335SerialApp.sln solution file with Visual Studio.
</span>
</span>
<br />
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">5. Open the Window1.xaml.cs file and change the COMPORT to the one used by the Teensy accelerometer.
</span>
</span>
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzNRqpWyzhotDbZKH2zKuXJu69IhZ26sVm5_fK1IgyaZZeSuU4CSbvJ4SEgcsG4ChC3f3flQ2K7UPw7dHqqr7iTCRKplZatHa0ZXMvtqE6Bq372PqGV3011ABJR6b0Oig6aunzdpfQKprd/s1600/comportChange.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjzNRqpWyzhotDbZKH2zKuXJu69IhZ26sVm5_fK1IgyaZZeSuU4CSbvJ4SEgcsG4ChC3f3flQ2K7UPw7dHqqr7iTCRKplZatHa0ZXMvtqE6Bq372PqGV3011ABJR6b0Oig6aunzdpfQKprd/s1600/comportChange.PNG" height="312" width="400" /></a>
</div>
<br />
<br />
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">6. Save the file and build the solution.
</span>
</span>
<span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"> </span>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">Make sure there are no compile errors in the build Output window. If the build succeeded, an executable file named "ADXL335SerialTest.exe"
</span>
</span>
<span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">will be created in sub directory (usually
</span>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">ADXL335SerialApp/</span></span>
<span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">bin/Release or bin/Debug). The exact file location of the executable can be found in the build "Output" window.</span>
<br /><br /><br />
<h2>
<span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">Run the Application</span>
</h2>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">8. Double click on the executable file to run the application. A window with the following screen should appear. The white text box area is where exception messages will appear if they occur. </span></span>
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhHE76kJ51qMNSWlZ-D9kgUn8VCc6bdeC56c6wHdpcMpnBX14uqrpSfLlg0TtVTBtyXPKTg-XUX8KP0yo0BmmtvlkWl_RiU9IL-1wg3IZOeFhLvrPmb9Wa2DcWO9o3j0ys5tUga1yFV8wO/s1600/WPFAppScreen.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhhHE76kJ51qMNSWlZ-D9kgUn8VCc6bdeC56c6wHdpcMpnBX14uqrpSfLlg0TtVTBtyXPKTg-XUX8KP0yo0BmmtvlkWl_RiU9IL-1wg3IZOeFhLvrPmb9Wa2DcWO9o3j0ys5tUga1yFV8wO/s1600/WPFAppScreen.PNG" height="224" width="320" /></a>
</div>
<br />
<br />
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">9. Now make sure the Teensy accelerometer USB is plugged in. </span>
</span>
<br />
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">10. Press the "Start" button on the screen to start controlling the X, Y, Z axis lines with the Teensy Accelerometer.</span>
</span>
<br />
<br />
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">If the accelerometer is sitting on a flat surface, only the blue line representing the Z axis will be visible as shown below.</span></span>
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7vQLNgEoG9fY0TsJelH75pIR9OI9RQLHDbN9mTi40D6KCj0SQHj6GOZpDtpbtcuNNo1OGX5oACSokkDFMfiuocySDIgif7TlmshPJNzyPo1d7iqPOpLred3SOa3JEded0tn90PAJ465Av/s1600/WPFAppScreenAfterStart.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj7vQLNgEoG9fY0TsJelH75pIR9OI9RQLHDbN9mTi40D6KCj0SQHj6GOZpDtpbtcuNNo1OGX5oACSokkDFMfiuocySDIgif7TlmshPJNzyPo1d7iqPOpLred3SOa3JEded0tn90PAJ465Av/s1600/WPFAppScreenAfterStart.PNG" height="223" width="320" /></a>
</div>
<div class="separator" style="clear: both; text-align: center;">
<br />
</div>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">11. Try rotating the Teensy Accelerometer so that the X or Y axis is pointing upward. The lines on the screen will change in real time as you rotate the accelerometer. </span></span>
<br />
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<br /></span>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: 13px;">
<span style="line-height: 18.479999542236328px;">12. Press the Stop button to stop listening to the serial port when your done.</span></span>
<br />
<br />
</div>codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-61662976261434912272014-05-10T08:22:00.002-07:002014-05-15T17:39:56.206-07:00ADXL335 Accelerometer on the Teensy 3.1 - Getting Started<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; font-weight: normal;">
This is a little project to get started with the Teensy 3.1 and a triple-axis accelerometer. I want to get data from the accelerometer in a form that can be used by an application so the code in the end normalizes the values to the G forces measured and outputs the values o the USB serial port.</div>
<br />
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguGDSyjY_hXSUU5hAPY4mkLjAWKUKQWy90qpTGt8kpaWtino7jGx0MHFqBrAtFJ5UD4skkvzCO-CuQ0kFbqoPwC9Z0nN5_ia6q6DoS1xn-N6yWcyQ5D6NmoLuL2e5Gu0oStMVP4Ibl2xGm/s1600/teensyadxl335bb.jpg" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEguGDSyjY_hXSUU5hAPY4mkLjAWKUKQWy90qpTGt8kpaWtino7jGx0MHFqBrAtFJ5UD4skkvzCO-CuQ0kFbqoPwC9Z0nN5_ia6q6DoS1xn-N6yWcyQ5D6NmoLuL2e5Gu0oStMVP4Ibl2xGm/s1600/teensyadxl335bb.jpg" height="200" width="137" /></a>
<br />
<span style="font-family: Trebuchet MS, Verdana, sans-serif; font-size: 13px; font-weight: normal;">This project only requires a couple parts. You will also need some wire, a small breadboard and a micro USB cable. You will also want the pin out for the <a href="https://www.pjrc.com/teensy/teensy31.html">Teensy 3.1</a>.</span><br />
<br />
<h3>
Parts List</h3>
<div style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<a href="https://www.adafruit.com/products/163" style="color: #888888; text-decoration: none;">ADXL335 - Triple Axis Accelerometer</a><i> ($14.95)</i></div>
<div>
<div style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<a href="https://www.pjrc.com/store/teensy31.html" style="color: #888888; text-decoration: none;">Teensy 3.1 Development Board</a> <i>( $19.80)</i></div>
<i style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;"><br /></i><b style="background-color: white; color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">Total Cost $35</b></div>
<br />
<br />
<br />
<br />
<h3>
Step 1 - Circuit Setup</h3>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
I used analog input pins A0, A1, and A2 for the x,y,z outputs from the accelerometer and powered the accelerometer directly from the 3.3V output of the Teensy. I soldered headers onto the the Teensy's side pins to make it breadboard friendly.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9mt5lBO0XuNDVHVbj1rB-l82_i2MllF-a2FKvvXwRyb7_WLD8xTaY6-g0BDS2u2KWwvGCUxS05RikEiwHkmRwuVJiOttdPFvxYD499fXqwauWeg1n2P71MlhHexHyOx8f4UEB_KZMZnWD/s1600/teensy31adxl335circuit.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg9mt5lBO0XuNDVHVbj1rB-l82_i2MllF-a2FKvvXwRyb7_WLD8xTaY6-g0BDS2u2KWwvGCUxS05RikEiwHkmRwuVJiOttdPFvxYD499fXqwauWeg1n2P71MlhHexHyOx8f4UEB_KZMZnWD/s1600/teensy31adxl335circuit.jpg" height="246" width="320" /></a></div>
<br /></div>
<h3>
Step 2 - Programming Environment Setup</h3>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
The Teensy can be programmed through the Arduino IDE with the Teensyduino add on and a micro USB cable. Many of the Arduino libraries are also compatible with the Teensy. </div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<ol>
<li>Download and install the <a href="http://arduino.cc/en/main/software">Arduino IDE</a> if you do not already have it.</li>
<li><a href="https://www.pjrc.com/teensy/td_download.html">Download and install the Teensyduino add on</a> for the Arduino IDE.</li>
<li>Download the <a href="https://www.pjrc.com/teensy/loader.html">Teensy loader program</a> for your OS .</li>
</ol>
</div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
Next we need to calibrate the Accelerometer.<br />
<br /></div>
<div style="background-color: white; line-height: 18.479999542236328px;">
<h3 style="line-height: normal;">
Step 3 - Accelerometer Calibration </h3>
</div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
We need to determine the max and min values for each axis of the accelerometer. To do this, you need get multiple readings with the accelerometer oriented in the min and max positions along each of the axis. The values will be used as constants in the code that will run on the Teensy to get scaled readings.</div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<br /></div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; line-height: 18.479999542236328px;">
<div style="font-size: 13px;">
I used a modified procedure based on the <a href="https://learn.adafruit.com/adafruit-analog-accelerometer-breakouts/programming">calibration instructions on the Adafruit learning site</a> to calibrate my accelerometer because I didn't want to do any additional hardware setup. </div>
<div style="font-size: 13px;">
<br /></div>
<h4>
Compile and Load the Calibration code</h4>
<ol style="font-size: 13px;">
<li>Download the <a href="https://github.com/codergirljp/ADXL335-Accelerometer-Teensy31/blob/master/ADXL335Calibration.ino">ADXL335 Calibration</a> sketch and open it in the Arduino IDE.</li>
<li>Open the calibration sketch in your Arduino IDE. </li>
<li>Plug in the Teensy micro USB cable.</li>
<li>Select Teensy 3.1 as the board under Tools -> Board -> Teensy 3.1</li>
<li>Verify that the correct COM port is selected for the Teensy under Tools->Serial Port. (It will probably be the only one shown unless there are other COM devices connected to your computer.)</li>
<li>Compile/Verify the sketch by typing Ctrl+R or clicking on the check mark icon near the top left corner.</li>
<li>When the sketch is done compiling, the Teensy Loader will open automatically. </li>
<li>With the Teensy Loader in Auto mode (the Auto button is green as shown below), press the button on the Teensy board to upload the calibration code.</li>
</ol>
<div style="font-size: 13px;">
</div>
</div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh66EZ1vGc3AW2lWsMBuNTl9AMBCqinihEu7DIdg4B4sXfpl9pkgRXF1bH2kt42reKXSHtLMhix_y_9mrqNegp4Y9LBwgr_3MC6uksfT_5cDYwUHi7t7YadRnOcWQi5SJtbqIWjgwp9knGk/s1600/uploadingToTeensy.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh66EZ1vGc3AW2lWsMBuNTl9AMBCqinihEu7DIdg4B4sXfpl9pkgRXF1bH2kt42reKXSHtLMhix_y_9mrqNegp4Y9LBwgr_3MC6uksfT_5cDYwUHi7t7YadRnOcWQi5SJtbqIWjgwp9knGk/s1600/uploadingToTeensy.PNG" height="400" width="365" /></a></div>
<br /></div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; line-height: 18.479999542236328px;">
<div style="font-size: 13px;">
<span style="font-size: x-small;"><br /></span></div>
<h4>
Perform the Calibration</h4>
</div>
<div style="background-color: white;">
<ol style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<li>Open the Serial Monitor under Tools-> Serial Monitor in the Arduino IDE.</li>
<li>Set the baud rate. The baud rate can be set to 38400 using the drop down at the bottom right corner of the Serial Monitor window. </li>
</ol>
<span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; line-height: 18.479999542236328px;">Measure Z-Max</span><span style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; line-height: 18.479999542236328px;"> </span><br />
<div>
<ol style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<li>Place the Accelerometer circuit on a flat surface to get the Z-max value.</li>
<li>Send a "1" to the Teensy using the Serial Monitor Send feature to run the calibration code. You should see output in the Serial Monitor as shown below. Notice that the upper range for Z is now 612, this is the max value for Z when the board is at rest. The X and Y Min values have changed too, but we are not done with those yet.</li>
</ol>
</div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4eS5Goc24eZq7Y-m4K28RMjEUbrsPNEKd8ar37cIIVrRnf4hIYlB4IDeZYqW9cUsHn1eRP83RvlYEewrNXAAvc4KQb5I-fQuCAMwg0bsXPtMT0DAm151MPjduUam7MsykrN4FGyNpUDou/s1600/CalibrationOutput1.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi4eS5Goc24eZq7Y-m4K28RMjEUbrsPNEKd8ar37cIIVrRnf4hIYlB4IDeZYqW9cUsHn1eRP83RvlYEewrNXAAvc4KQb5I-fQuCAMwg0bsXPtMT0DAm151MPjduUam7MsykrN4FGyNpUDou/s1600/CalibrationOutput1.PNG" height="68" width="320" /></a></div>
<div>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: x-small;"><span style="line-height: 18.479999542236328px;"><br /></span></span></div>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif;"><span style="line-height: 18.479999542236328px;">Measure Z-Min</span></span><br />
<ol style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<li>Hold the Accelerometer circuit upside down against a flat surface(such as the underside of a table) to get the Z-min value. (Hold it still during the measurement). </li>
<li>Again, send a "1" to the Teensy using the Serial Monitor Send feature to run the calibration code. A second calibration output will appear in the Serial Monitor as shown below. Now the lower range for Z will have changed, in my measurement, it was measured at 413 as shown below. </li>
</ol>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSDz-n8NW50xu_ohPyd59XVEVj6vYYyvQge9gYaoulO_eSPC_jWFY1VqUeMeYQi5rKeJFfS2pJJveinUFoFMtVmzFzcn43MqU5kCTIZraToCK0qh8IW8PuPLhUZEFPiyXIrcvGThoxuYUt/s1600/CalibrationOutputZMin.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgSDz-n8NW50xu_ohPyd59XVEVj6vYYyvQge9gYaoulO_eSPC_jWFY1VqUeMeYQi5rKeJFfS2pJJveinUFoFMtVmzFzcn43MqU5kCTIZraToCK0qh8IW8PuPLhUZEFPiyXIrcvGThoxuYUt/s1600/CalibrationOutputZMin.PNG" height="178" width="320" /></a></div>
<div>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: x-small;"><span style="line-height: 18.479999542236328px;"><br /></span></span></div>
</div>
<div style="background-color: white; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; line-height: 18.479999542236328px;">
Measure the Y-Max, Y-Min, X-Max, and X-Min Values<br />
<br />
<div style="font-size: 13px;">
Repeat the procedure above with the circuit oriented in the Max and Min positions for the X and Y axis's using the following orientations:</div>
<div style="font-size: 13px;">
<br /></div>
<div style="font-size: 13px;">
Y-Max: Y arrow on the accelerometer should be pointing straight up. </div>
<div style="font-size: 13px;">
Y-Min: Y arrow on the accelerometer should be pointing straight down.</div>
<div style="font-size: 13px;">
X-Max: X arrow on the accelerometer should be pointing straight up.</div>
<div style="font-size: 13px;">
X-Min: X arrow on the accelerometer should be pointing straight down.</div>
<div style="font-size: 13px;">
<br /></div>
<div style="font-size: 13px;">
The min max values for each axis are retained through calibration runs so the final output will have the min and max ranges for the raw values for each axis. These values will be used as constants in my code to normalize the output values.<br />
<br />
<br />
<span style="font-family: 'Times New Roman'; font-size: 19px; font-weight: bold; line-height: normal;">Step 4 - Program the Teensy</span><br />
<span style="font-family: 'Times New Roman'; font-size: 19px; font-weight: bold; line-height: normal;"><br /></span></div>
</div>
<div style="background-color: white;">
<div style="color: #666666; font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<span style="color: black;">Now that we have the min max values to use, we use the values in code to send normalized values between 1 and -1 for the x, y, and z orientations detected by the accelerometer.</span></div>
<ol style="font-family: 'Trebuchet MS', Trebuchet, Verdana, sans-serif; font-size: 13px; line-height: 18.479999542236328px;">
<li>Download the <a href="https://github.com/codergirljp/ADXL335-Accelerometer-Teensy31/blob/master/TeensyAdxl335.ino">Teensy Accelerometer Code</a>. </li>
<li>Open the TeensyAdxl335.ino sketch and change the min/max values for each axis to the values measured in the calibration above. </li>
<li>Save and Verify/Compile, and upload the code to the Teensy using the same procedure described above to upload the calibration code.</li>
<li>Use the Serial Monitor to verify the output from the Accelerometer. You should see the out values scrolling. The output should look like the view below.</li>
</ol>
<div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYZnGGDg_WBO1uLv1ca4LzKdUZd9uMCuTIme5ryd6ri6I0LGTD_J4zavLr5A1R1Im39Kf2EPwIqyqc6mDQEj0vJgoqzA5L0ImulNeQKKSeFhEQrk5lEx0htzIiAIJdGCMPc-nZvoviG41Q/s1600/teensyAdxl335Output.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYZnGGDg_WBO1uLv1ca4LzKdUZd9uMCuTIme5ryd6ri6I0LGTD_J4zavLr5A1R1Im39Kf2EPwIqyqc6mDQEj0vJgoqzA5L0ImulNeQKKSeFhEQrk5lEx0htzIiAIJdGCMPc-nZvoviG41Q/s1600/teensyAdxl335Output.PNG" height="127" width="320" /></a></div>
<span style="font-family: Trebuchet MS, Trebuchet, Verdana, sans-serif; font-size: x-small;"><span style="line-height: 18.479999542236328px;"><br /></span></span></div>
</div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-27036436016978031342014-02-21T04:06:00.001-08:002014-02-21T04:06:15.018-08:00Netduino 2 Getting StartedWhile I'm waiting for my other parts to come in, I got one of these Netduino's a while back to try out. After all, most of my programming experience is in .Net, not C! So for $35 I figured this board is worth a try. The board touts an ARM 7 processor with multi-processing capability and a form factor that almost exactly matches the Arduino Uno. So all the Uno proto shields can be used with this board. You can write code for it using Visual Studio and C# which is pretty sweet.<br />
<br />
Getting started is pretty simple, especially if you already use C#.Net for other programming projects.<br />
You'll need to install 3 things to get going:<br />
<br />
<a href="http://www.netduino.com/downloads/">http://www.netduino.com/</a><br />
<br />
<ol>
<li><a href="http://www.visualstudio.com/downloads/download-visual-studio-vs#d-csharp-2010-express">MS Visual Studio C# Express 2010</a></li>
<li><a href="http://www.netduino.com/downloads/MicroFrameworkSDK_NETMF42_QFE2.msi">Net MicroFramework 4.2 SDK</a></li>
<li><a href="http://www.netduino.com/downloads/netduinosdk_32bit_NETMF42.exe">Netduino SDK v4.2.2.0 (32-bit)</a> or <a href="http://www.netduino.com/downloads/netduinosdk_64bit_NETMF42.exe">Netduino SDK v4.2.2.0 (64-bit)</a></li>
</ol>
<br />
And of course.. you need a <a href="http://www.adafruit.com/products/1228">Netduino 2</a><i> ($34.95)</i><br />
<br />
To create a new Application for the Arduino 2, open Visual Studio and create a new project.<br />
When the dialog comes up select Micro Framework and Netduino 2 Application.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi69TtR0vwsDXCxhf6s75IwFfkuyAghVfvEI5Qc-LSLdD_tlCKQ6ZLypJOY5UgTrlkOalLO8UV2YhWSAHe4-F07v1Pt2COyHXN0Lv2oFZt-fOGE1481siXn4_9wU5CRfzIg5hiMtmiXM3VK/s1600/NetduinoNewProject.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi69TtR0vwsDXCxhf6s75IwFfkuyAghVfvEI5Qc-LSLdD_tlCKQ6ZLypJOY5UgTrlkOalLO8UV2YhWSAHe4-F07v1Pt2COyHXN0Lv2oFZt-fOGE1481siXn4_9wU5CRfzIg5hiMtmiXM3VK/s1600/NetduinoNewProject.PNG" height="388" width="640" /></a></div>
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />
I want to debug on the real hardware, not using the Emulator. To do this I'm going to set the Project properties for the .Net Micro Framework:<br />
<br />
<ol>
<li>Make sure the Netduino is plugged into the computers USB port so it will show up in the device list.</li>
<li>Change the Transport to <b>USB </b>and select <b>Netduino2_Netduino </b>as the device.</li>
</ol>
<br />
That's all it takes to be able to debug your code on the hardware. I can now run my code in debug mode, directly on the Netduino 2!<br />
<br />
Now just write a little code to blink the blue on board LED (to the right of the board) in program.cs. Here is some code:<br />
<br />
namespace NetduinoApplication1<br />
{<br />
public class Program<br />
{<br />
public static void Main()<br />
{<br />
// Create an Output port for the Onboard led pin and set it to false.<br />
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);<br />
<br />
// Blink the LED<br />
Blink(led);<br />
}<br />
<br />
// Blink the LED at 250ms on/off intervals<br />
public static void Blink(OutputPort led)<br />
{<br />
while (true)<br />
{<br />
led.Write(true); // turn on the LED<br />
Thread.Sleep(250); // sleep for 250ms<br />
led.Write(false); // turn off the LED<br />
Thread.Sleep(250); // sleep for 250ms<br />
}<br />
}<br />
<br />
}<br />
}<br />
<br />
Press the run button to start debugging, the blue LED will blink.. Hello World Netduino!<br />
<br />
More information about the Netduino can be found at <a href="http://www.netduino.com/">Netduino.com</a>.codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-34525501667634244562014-02-02T18:37:00.001-08:002014-02-02T18:37:41.560-08:00Trinket-izing the 434Mhz RF Transmitter<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="float: left; margin-right: 1em; text-align: left;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijUVo1KMB6DA_dl7sGgSyIRwRASA9snCb_24cHuBhsqjvL1EWwpdgu9BPl_GndgNSixH_O37Rsthg4RNxobdirM7q0-XHJMndieglJ_9tkHV-mm5Qb0WUI929iiLNJcr3He9tb75tCXk3M/s1600/TrinketRFTransTempSensorCircuit.jpeg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEijUVo1KMB6DA_dl7sGgSyIRwRASA9snCb_24cHuBhsqjvL1EWwpdgu9BPl_GndgNSixH_O37Rsthg4RNxobdirM7q0-XHJMndieglJ_9tkHV-mm5Qb0WUI929iiLNJcr3He9tb75tCXk3M/s1600/TrinketRFTransTempSensorCircuit.jpeg" height="320" width="180" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">434MHz RF Transmitter with the Trinket</td></tr>
</tbody></table>
The transmitter side of the <a href="http://codergirljp.blogspot.com/2014/01/434mhz-rf-transmitterreceiver-with.html">434mhz RF Transmitter/Receiver with the Arduino Micro</a> doesn't really do much processing. It doesn't really need all of the functionally of the Arduino Micro just to collect a little temperature reading and send it the RF Transmitter! The Adafruit Trinket has plenty of power and space for the processing needed, with the added benefit that it shrinks the size and the cost of the project!<br />
<br />
<h3>
Parts List</h3>
<br />
<div>
<b>Temperature Sensor and RF Transmitter:</b></div>
<div>
<a href="http://www.adafruit.com/products/165">TMP36 - Analog Temperature sensor</a><i> ($2.00)</i></div>
<div>
<a href="https://www.sparkfun.com/products/10534">RF Link Transmitter - 434MHz</a> <i>($3.95)</i><br />
<a href="http://www.adafruit.com/products/1500">Adafruit Trinket 3V Logic</a> <i>( $7.95)</i><br />
<i><br /></i>
<b>Total Cost $14</b></div>
<br />
<a href="https://github.com/codergirljp/434MHz-RF-Link-Temperature-Sensor-Data">Click here to get the code for this project ...</a><br />
<br />
<span style="font-size: large;"><b>
Serial Communications on the Trinket</b></span><br />
The Trinket doesn't have is a serial interface like most Arduino boards have. Fortunately there are ways around it! With a little research, I found there are three main methods being used to get serial communications with the Trinket:<br />
<br />
<ol>
<li>Use Virtual Wire to simulate it. I tried a couple of versions of this but I could not get this to compile. Some people also seem to write their own implementation of this.</li>
<li>Use Software Serial to turn a couple of pins into an RX/TX. The plus side of this is that it works! The downside is that it takes a lot of memory so you may not have much room left for other stuff if you use this. Pulling in the Software Serial put the size of the Transmitter/Temperature reading sketch up to 5,058 bytes, which still fits on the Trinket!</li>
<li>Another option - use the <a href="https://github.com/frank26080115/Arduino-UsiSerial-Library">UsiSerial library posted by Frank Zhao</a> to implement a hardware serial port. The upside of this is a much smaller foot print! Using the UsiSerial, my compiled sketch is only 3,666 bytes! Plenty of room left! Unfortunately, while this compiled and loaded, it didn't work. Maybe because I am using the 3 Volt Trinket? The notes say it was tested on the 16MHz trinket which I believe is the one with 5 Volt Logic.</li>
</ol>
<br />
<span style="font-size: large;"><b>
Circuit Setup</b></span><br />
<br />
<br />
<div>
<b>434MHz RF Transmitter Connections</b>:<br />
GND -> Ground on Trinket<br />
DataIn -> Software Serial TX pin 1 on Trinket<br />
Vcc -> 3V from Trinket<br />
ANT -> 13 cm wire used as an antenna</div>
<div style="text-align: left;">
</div>
<br /><b>TMP36 Connections:</b><br />Vcc -> 3.3V on Trinket (TMP36 Pin 1 on left when looking at flat side of sensor)<br />Vout -> Pin 2/AnalogRead(1) on Trinket (TMP36 Center Pin)<br />Gnd -> Ground on Trinket (TMP36 Pin 3 on right when looking at flat side of sensor)<div>
<br /><div>
<br /><table cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGAK17VqPtWsc11GAEzxNU5yhx2QgYC5UHg_3-Uvy6510rXQO0d9Hgcz-nOl2n4QGyiY6PDSoCU-RoXss2ajHauLGGWYMjbeHiIuCdt8HrK4WI903bJg406Bcp1K5VVXlBOYsogXzD8qy/s1600/Circuit.jpg" imageanchor="1" style="clear: left; margin-bottom: 1em; margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYGAK17VqPtWsc11GAEzxNU5yhx2QgYC5UHg_3-Uvy6510rXQO0d9Hgcz-nOl2n4QGyiY6PDSoCU-RoXss2ajHauLGGWYMjbeHiIuCdt8HrK4WI903bJg406Bcp1K5VVXlBOYsogXzD8qy/s1600/Circuit.jpg" height="297" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Trinket Transmitter Temperature Sensor Circuit</td></tr>
</tbody></table>
<div>
<b><br /></b></div>
<div>
<a href="https://github.com/codergirljp/434MHz-RF-Link-Temperature-Sensor-Data">Click here to get the code for this project ...</a></div>
</div>
</div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-30890183544847530292014-01-26T17:29:00.002-08:002014-01-27T17:52:13.544-08:00434Mhz RF Transmitter/Receiver with the Arduino MicroI wanted to experiment with the RF Link transmitter/receiver for my wireless projects. With the temperature around here going from below 0 to 60 degrees, a wireless temperature sensor would be nice! The project is to get data from an analog temperature sensor and use an RF link to transmit the data to a receiving device.<br />
<div>
<br />
<h4>
The Parts List:</h4>
</div>
<div>
<b>Temperature Sensor and RF Transmitter:</b></div>
<div>
<a href="http://www.adafruit.com/products/165">TMP36 - Analog Temperature sensor</a><i> ($2.00)</i></div>
<div>
<a href="https://www.sparkfun.com/products/10534">RF Link Transmitter - 434MHz</a> <i>($3.95)</i></div>
<div>
<a href="http://www.adafruit.com/products/1315">Arduino Micro Board</a> <i> ($22.95)</i> </div>
<div>
<br />
<b>RF Receiver side data collection and processing:</b><br />
<a href="https://www.sparkfun.com/products/10532">RF Link Receiver - 4800bps (434MHz)</a> <i>($4.95)</i></div>
<div>
Arduino Mega 2560 I had this on hand, however a Micro, Uno or other Arduino board can be used instead as long as it has a UART + USB Serial (if you want to use it).</div>
<div>
<br />
<br /></div>
<div>
<b>Total Estimated Cost ~ ($29 for Transmitter +$28 for Receiver)</b><br />
<b><br /></b>
<a href="https://github.com/codergirljp/434MHz-RF-Link-Temperature-Sensor-Data">Click here to get the code for this project</a><br />
<br />
<br />
<br />
<h2>
Circuit Setup</h2>
The RF Link receiver and transmitter pair are the interesting part of this project. With these two guys, you can add one way communications with only a UART on each side. I choose to use the Arduino board serial since I happened to have a couple of boards on hand and using the serial interface from these boards is very easy compared to the other ways of getting the serial data these components (i.e. software serial or virtual wire). This RF Link pair gets A LOT of noise, and that noise comes in as garbage data that has to be filtered out using a protocol that is robust enough to recognize the data you want to send and receive. The protocol and filtering is the key to getting reliable data from these guys!<br />
<br />
<br />
<h3>
Hooking up the RF Link Receiver</h3>
<br />
Here is the pin out for the RF Link receiver from the <a href="http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/General/RWS-371-6_433.92MHz_ASK_RF_Receiver_Module_Data_Sheet.pdf">datasheet</a>. Even though it has 8 pins, It's really four connections, Ground, 5V power, Digital Out to the RX of the serial port and the antenna on Pin 8.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOR9X-MV8ieP5opODYofpuDWQrgjMFxs_Tm21lAfqGTqQsWaB8Qp_8CEae7RV-cHxKpNuAseWAvHxOgZzJdLaELfyatB6TC8BwbpDS9huO2T0nM-IW5YxWZPpAml68kMDB-AgWQrbZEuoh/s1600/434MHzRF_ReceiverPinOut.PNG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhOR9X-MV8ieP5opODYofpuDWQrgjMFxs_Tm21lAfqGTqQsWaB8Qp_8CEae7RV-cHxKpNuAseWAvHxOgZzJdLaELfyatB6TC8BwbpDS9huO2T0nM-IW5YxWZPpAml68kMDB-AgWQrbZEuoh/s1600/434MHzRF_ReceiverPinOut.PNG" height="153" width="320" /></a></div>
<br />
<br />
<b>Connections</b>:<br />
Pins 1, 6, 8 -> Ground from Arduino Mega<br />
Pin 8 -> 13 cm wire to act as an antenna<br />
Pins 4, 5 -> 5V from Arduino Mega<br />
Pin 2 -> Connected to RX3 (pin 15 on the Arduino Mega)<br />
<br />
<br />
<br />
<h3>
</h3>
<h3>
Hooking up the RF Link Transmitter to the Arduino Micro</h3>
<br />
Here is the <a href="http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Wireless/General/TWS-BS-3_433.92MHz_ASK_RF_Transmitter_Module_Data_Sheet.pdf">datasheet</a> for the RF Transmitter module. This module only has 4 pins so it's pretty easy to hookup. I used 5V to power it from the Micro but it can actually take up to 12V if you want better range!<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW-OjCrUAK7aPuQ6R1s6NkHIgjnNUceFASU1zKp5ybTn9jtTyAtdN6H76Asx3n7WRRurIWtuJIhCKSszbhmQLZw7wNeXJamgYfjV3yTvfiFFKz3Eqvr23CXQ5XsKKDp-Hh1eqniRm9egVP/s1600/434MHzRFTransmitter.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjW-OjCrUAK7aPuQ6R1s6NkHIgjnNUceFASU1zKp5ybTn9jtTyAtdN6H76Asx3n7WRRurIWtuJIhCKSszbhmQLZw7wNeXJamgYfjV3yTvfiFFKz3Eqvr23CXQ5XsKKDp-Hh1eqniRm9egVP/s1600/434MHzRFTransmitter.jpg" /></a></div>
<br />
<b>Connections</b>:<br />
GND -> Ground on Arduino Micro<br />
DataIn -> TX pin on Arduino Micro<br />
Vcc -> 5V from Arduino Micro<br />
ANT -> 13 cm wire used as an antenna<br />
<br />
<br />
<h3>
Hooking up the TMP36 Temperature Sensor</h3>
Adafruit has an excellent tutorial to explain how to hook up the temperature sensor and much more <a href="http://learn.adafruit.com/tmp36-temperature-sensor">Adafruit TMP36 sensor tutorial</a>.<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYabitrd_M5atLu1HZeuqZt9UP8pBBbliYbaVQAl65A7vJ1Z7QS1tGIpXDmewSEOIO-r-4mAh3sO36MmrurZuW5x-2wW-x8ccD05j_5-HMm_6xP1ay9KgUq2BeqlpJVl-x2ic9RAO5BaMB/s1600/tmp36pinout.gif" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiYabitrd_M5atLu1HZeuqZt9UP8pBBbliYbaVQAl65A7vJ1Z7QS1tGIpXDmewSEOIO-r-4mAh3sO36MmrurZuW5x-2wW-x8ccD05j_5-HMm_6xP1ay9KgUq2BeqlpJVl-x2ic9RAO5BaMB/s1600/tmp36pinout.gif" height="188" width="200" /></a></div>
<br />
<br />
<b>Connections:</b><br />
Vcc -> 3.3V on Arduino Micro (TMP36 Pin 1 on left when looking at flat side of sensor)<br />
Vout -> A0 analog input on Arduino Micro (TMP36 Center Pin)<br />
Gnd -> Ground on Arduino Micro (TMP36 Pin 3 on right when looking at flat side of sensor)<br />
<br />
The datasheet also shows a 0.1uF power supply coupling capacitor from the supply voltage pin to ground. I added this directly accross the leads on the TMP36 to help regulate any input voltage fluctuation. (not shown in picture below).<br />
I also used the Analog Reference voltage at 3.3V instead of the 5V default by connecting the 3.3V pin on the Micro to the AREF pin (just to the right of the 3.3V pin).<br />
<br />
CAUTION: If you connect the GND pins and Vcc pins backwards, your TMP36 will get very very hot and eventually this will burn out your sensor!<br />
<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu_NuwP93FEz658ET8BAFzbXPDTzO1jWh2npoRTYEp6Px72hEMkBUHNbhVaNopIF7gbdkHuzKdxH74MTMtcHPoYbZMOQWIY0GEUGcijn2dYQZ41Y9EdFSXUXszmHJ40k9vTQB7dHODbUIW/s1600/MicroRFTmpCircuit.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhu_NuwP93FEz658ET8BAFzbXPDTzO1jWh2npoRTYEp6Px72hEMkBUHNbhVaNopIF7gbdkHuzKdxH74MTMtcHPoYbZMOQWIY0GEUGcijn2dYQZ41Y9EdFSXUXszmHJ40k9vTQB7dHODbUIW/s1600/MicroRFTmpCircuit.jpg" height="179" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;"><span style="font-size: small; text-align: start;">RF Transmitter and Temperature Sensor Circuit</span></td></tr>
</tbody></table>
<br />
<h2>
The Code</h2>
The challenge in creating an RF link with these components is filtering out the bad data so that you can more reliably get the data you want! These guys make a pretty noisy RF link so you can expect to get lots of garbage data (at least when using 5V to power the transmitter). The way to filter out the garbage data is to establishing a protocol for sending and receiving data.<br />
<br />
Basically, a protocol is an agreed upon data format that is unlikely to occur in random data. Having a protocol allows the receiving code to know what to expect. There are a lot of ways to do this. You might send begin and end markers around the data and check to make sure you got both on the receiving side. A protocol may also send and check the size of the data packet along with the data to help the receiving side verify that the amount of data received is correct. The transmission could include the CRC of the data packet and the receiver could check it on the other end to verify that the data received is what was expected.<br />
You can't prevent the receiver from getting bad data, but you can decide what the receiver will do with it.<br />
<br />
I choose to establish a very simple protocol for my project using the word "Temp" as a sequence of characters that will proceed each temperature reading sent by the Transmitter. The temperature reading is a decimal and can be either a positive or negative number. So the only valid data the receiver should ever expect to get would look something like:<br />
<div style="text-align: center;">
Temp70.58</div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
The receiving code will exclude all data that doesn't match the expected data format established above. <a href="http://www.asciitable.com/">Ascii character codes</a> are used for filter data. If the word Temp is not received or if bad data that doesn't meet the criteria for expected data, the data should be ignored. The received data is not always perfect so validation still needs to be added to ensure that only good data is used. Also, the transmitter is set to send a new value every 5 seconds, this is probably more often then I would like but it is good for testing!<br />
<br /></div>
<div style="text-align: left;">
<br /></div>
<div style="text-align: left;">
<a href="https://github.com/codergirljp/434MHz-RF-Link-Temperature-Sensor-Data">Click here to get the code for this project</a></div>
<div style="text-align: left;">
<br /></div>
</div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-55199316322646415862014-01-23T17:47:00.001-08:002014-01-23T17:47:41.529-08:00Fast Fourier Transform FFT in C++Hi Everyone,<div>
<br /><div>
So not too long ago I was playing around with doing some FFT's from mic data I collected. I found a rather simple C algorithm and made made a C++ class out of it. Also I added the ability to load the data from a file so it would be simple to get results for given data set. Of course I'm sure there are tons of FFT classes out there but this pretty much sticks to the basics so you build what you want on top. I also just got a git hub account and so this is also my first git hub post. Cheers!</div>
<div>
<br /></div>
<div>
<a href="https://github.com/codergirljp/FFT-Class">FFT Class in C++</a> </div>
</div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-82142886570265880812014-01-14T20:12:00.004-08:002014-01-14T20:12:42.981-08:00Electric Imp Battery PowerI really wanted my motion sensor to be battery operated. The Imp takes ALOT of power. 90mA for the WiFi alone! Which does not yet have a low power mode option. So how long can it go on a Battery anyway? I add a <a href="http://www.adafruit.com/products/328">Lithium Ion Polymer Battery - 3.7v 2500mAh</a> ($14.95) to my motion sensor project to test this out. I connected a fully charged rechargable LiPo battery to the P+ and P- terminals on the April board to run the motion sensor imp project I had.<br />
<br />
Here's how you connect the battery:<br />
<ol>
<li style="text-align: left;">Remove the Imp from the April board and unplug it from the USB before connecting external power. </li>
<li style="text-align: left;">Make sure you move the Jumper to the Battery position. </li>
<li style="text-align: left;">Connect the battery + to the P+ solder point and the battery - to the P- solder point on the April board. Don't use Vin and Ground to connect the battery power, they are not safe!</li>
</ol>
<div style="text-align: left;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm6bS3CJOmAjVEQMD2UB5gGbvTDkttkpV-Jvdvoi2I-POW4fr6hcfMdqgrcjXuSXUjTZJNJh_FZM1QviKNgu0l6Lz8ul9Z31PwXJE88IDXcsANcbpEgLirItVtit8ZVVx_p8sMTxhOPeXg/s1600/ImpPower.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjm6bS3CJOmAjVEQMD2UB5gGbvTDkttkpV-Jvdvoi2I-POW4fr6hcfMdqgrcjXuSXUjTZJNJh_FZM1QviKNgu0l6Lz8ul9Z31PwXJE88IDXcsANcbpEgLirItVtit8ZVVx_p8sMTxhOPeXg/s1600/ImpPower.jpg" height="284" width="320" /></a></div>
<br />
That's really all there is to it! If you are sure you did the above things correctly, put the Imp back in the April board and it should have power and connect to the WiFi as usual.<br />
<br />
Keep in mind though, this solution will only provide power for a few days at a time! In my first test with the battery connected, the battery lasted for a little over 2 days.<br />
<br />
<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
</div>
<br />codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-27836371385819028422014-01-14T19:38:00.000-08:002014-01-14T19:38:44.670-08:00Electric Imp - Hello World Motion Sensor to EmailI recently decided to re-do a motion sensor project I had previously with an Arduino Board, but this time using the <a href="https://electricimp.com/">Electric Imp</a>. The Electric Imp looks just like an SD card, but don't be fooled - it won't work in an actual SD card slot. You need an April board or similar breakout for this little devil.<br />
<div>
<br /></div>
<div>
You might feel a bit nutty if you use one! That's because the Electric Imp - IDE is through the Electric Imp cloud site with all of the code written in <a href="https://electricimp.com/docs/resources/learningsquirrel/">Squirrel</a>. This is great for projects that you want to be Internet accessible.<br />
<br />
This Electric Imp IDE makes this project easy! The IDE runs entirely from their website and which also provides server side processing capability for your Imp projects. First you have to register the Electric Imp and set the network credentials using the blink up procedures found in the <a href="https://electricimp.com/docs/">Getting Started Guide and Documents</a>.<br />
<br />
<h3>
The Electric Imp Motion Sensor</h3>
I wanted to hook up my motion sensor to my Electric Imp an have it Email me when motion was detected. <br />
I also wanted to hook up battery power so it would be wireless.</div>
<div>
<h4>
Here is the full parts list:</h4>
<ol>
<li><a href="http://www.adafruit.com/products/1129">Electric Imp</a> ($29.95)</li>
<li><a href="http://www.adafruit.com/products/1130">Electric Imp April Board basic breakout</a> (12.95)</li>
<li><a href="http://www.parallax.com/product/555-28027">PIR Motion Sensor</a> ( $10.99)</li>
<li><a href="http://www.adafruit.com/products/1608">Small Perma-Proto board</a> I had on hand ($2.95)</li>
<li>Some wire that I had on hand to make the connections (~$3.00) </li>
<li>(optional) <a href="http://www.adafruit.com/products/64">Small Breadboard for prototyping</a> I had on hand ($5.00)</li>
<li>(optional) <a href="http://www.adafruit.com/products/328">Lithium Ion Polymer Battery - 3.7v 2500mAh</a> ($14.95)</li>
</ol>
</div>
<div>
The total cost to make the project (not including the battery) is about $60 + taxes and shipping.</div>
<div>
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHIkWF0fQfrex9TecAHuwfK1k_0UI7_h-zqeQlP2R6kqGTnLW8o61j30pV-llvuuJXhJR-cvGfk4F9zqEuyTmlENBOgrUcvxwPrToQI2H7IKrNzEC6lK4rXpvy9QClqrCoaB91YQ9UPrli/s1600/ImpMotionSensorProj.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhHIkWF0fQfrex9TecAHuwfK1k_0UI7_h-zqeQlP2R6kqGTnLW8o61j30pV-llvuuJXhJR-cvGfk4F9zqEuyTmlENBOgrUcvxwPrToQI2H7IKrNzEC6lK4rXpvy9QClqrCoaB91YQ9UPrli/s1600/ImpMotionSensorProj.jpg" height="320" width="180" /></a></div>
<div>
<br /></div>
<div>
The PIR Motion sensor pin is connected to pin 1 of the Imp, configured for input. The other two pins on the motion sensor just provide power (connected to Vcc and ground). And that's really the whole circuit for the motion sensor. It's important to use pin 1 for it's wake up feature. This let's the Imp sleep until pin 1 changes, so no looping! The Imp also has built in light detector capability and it can tell you it's voltage supply too. So I decided to have it email me all three when the motion detector is triggered. </div>
<div>
<br /></div>
<div>
<b>Here is the device code:</b><br />
<blockquote class="tr_bq">
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;">motion <- hardware.pin1;</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">function readPin()</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">{</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> if(motion.read() == 1)</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> {</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> local current_light = hardware.lightlevel();</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> local voltage = hardware.voltage();</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> server.log("Motion Detected - Light Level:" + current_light + " - Voltage:" + voltage);</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> agent.send("motionDetected", "Motion Detected - Light Level:" + current_light + " - Voltage:" + voltage);</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> } </span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">}</span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;"><br /></span><span style="font-family: Courier New, Courier, monospace; font-size: x-small;">motion.configure(DIGITAL_IN_WAKEUP, readPin); </span></blockquote>
</div>
<div>
<br />
The line in the device code of the form:<br />
<span style="font-family: Courier New, Courier, monospace; font-size: x-small;"> agent.send(agentMethodToCall, objectToPassToAgentMethod); </span><br />
tells the agent code on the server to call the specified method (in this case the <span style="font-family: Courier New, Courier, monospace; font-size: x-small;">motionDetected </span>method).<br />
<br />
I wanted my motion sensor to send an email message when motion is detected. On the Arduino I used the serial port to talk to a c# application on my computer that used SMP to send an email. However, I want to take advantage of the server side processing on the Imp for this feature. This turned out to be very simply if you use a free emailing service such as MailGun. A very complete guide for writing the agent code to send mail using MailGun can be found <a href="http://captain-slow.dk/2014/01/07/using-mailgun-with-electric-imp/">Using MailGun with Electric Imp</a>.<br />
<br />
<br />
<br />
<br />
<div>
</div>
<div>
</div>
<!-----></div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com4tag:blogger.com,1999:blog-9059385354812982139.post-48247565192290683942014-01-11T16:28:00.002-08:002014-02-01T13:44:11.143-08:00Trinket - Color by Sound RGB NeoPixelsI wanted to experiment with the NeoPixels and the Trinket so I decided to make sound reactive lights. The Adafruit NeoPixels are nice. They can be chained together and require only one IO pin to stream data to a chained strand. I chained 4 of them together for this project I also used an microphone breakout available from Adafruit.<br />
<br />
<h4>
Here is the full parts list:</h4>
<ol>
<li> <a href="http://www.adafruit.com/products/1500">Adafruit Trinket 3V Logic</a> <i>( $7.95)</i></li>
<li><a href="http://www.adafruit.com/products/1063">Max 4466 Mic Amp</a> <i>($6.95)</i></li>
<li>Some wire that I had on hand to make the connections <i>(~$3.00)</i> </li>
<li><i>(optional)</i> <a href="http://www.adafruit.com/products/64">Small Breadboard for prototyping</a> I had on hand <i>($5.00)</i></li>
<li><i>(optional)</i> An <a href="http://www.adafruit.com/products/1315">Arduino Micro Board</a> I used for collecting data and prototyping<i> ($22.95)</i> </li>
</ol>
<br />
The total cost to make the project is about $20 + taxes and shipping.<br />
<br />
<br />
<a href="https://github.com/codergirljp/Trinket-Color-By-Sound-RGB-NeoPixels" target="_blank">Get the Trinket code for this project here.. </a><br />
<br />
<h3>
<b>The Project</b></h3>
<div>
I wanted to set the color of the lights based on the frequency of the sound detected, or something close to that using the Trinket. To do real frequency detection I was thinking I'd need to do FFT (Fast Fourier Transform) processing in real time. This seemed like it might be too much calculation for the little trinket so I decided to do something a little less intensive, I took a look at the Mic data to see what might be possible. I used the Arduino Micro to do data collection from the Mic because it has something the Trinket doesn't have, USB Serial communications.<br />
<br />
<h4>
Data Collection</h4>
First, I collected Mic sample data using the Arduino Micro's USB Serial to see what the data looked like. I wrote some code in the setup method to output data collections of 2048 samples of the Mic data collected directly from analog input on pin 8 of the Micro. I collected data for three situations: quiet ambient noise, Heavy Metal music playing, and some rather average music playing. The sample data is shown below.</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY92oOO19ndJG9yj8S7FzzDKGCjCFJ92W4WSJ1QKV9KRrPVgLLqhYE8Gdn5Km_ij4YNtmS8cB8-hv_N7BiHZOjd351Hzw6FBLnKKuuaMf4HPP-WRaX02MdylbAV02qSCZ5E0F_QxCpzO6B/s1600/QuietNoiseData.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY92oOO19ndJG9yj8S7FzzDKGCjCFJ92W4WSJ1QKV9KRrPVgLLqhYE8Gdn5Km_ij4YNtmS8cB8-hv_N7BiHZOjd351Hzw6FBLnKKuuaMf4HPP-WRaX02MdylbAV02qSCZ5E0F_QxCpzO6B/s1600/QuietNoiseData.PNG" height="62" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Quiet Noise (2046 Samples)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmBH43dP_i7yRiepoih5QGlZi3NahqIKsIB4JY_eyc0WEJvEE4FnMAmt4MTTrUrjVWWUkagJ-nSlpXV5zvRYmxtnDOMIiyW3YxcYcFhgmYxKjmZsIZo-r6RF8pEzGb0WIumkgf96UOmU3c/s1600/HeavyMetalMusicData.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgmBH43dP_i7yRiepoih5QGlZi3NahqIKsIB4JY_eyc0WEJvEE4FnMAmt4MTTrUrjVWWUkagJ-nSlpXV5zvRYmxtnDOMIiyW3YxcYcFhgmYxKjmZsIZo-r6RF8pEzGb0WIumkgf96UOmU3c/s1600/HeavyMetalMusicData.PNG" height="111" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Heavy Metal (2048 Samples)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyVu4bDGyiIkNU6FfontKFYN-fGwBTByAw6UQ-m-SpL66fMYQxDiN71NcdnBav1Npe92DFq-rMxdBqtI19LpnXBXEd5Hhk2Mfdnj1p_vcvPdePm3J0HX4iY1rWCGxj5nBoIHpVain63NLg/s1600/AverageMusicData.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiyVu4bDGyiIkNU6FfontKFYN-fGwBTByAw6UQ-m-SpL66fMYQxDiN71NcdnBav1Npe92DFq-rMxdBqtI19LpnXBXEd5Hhk2Mfdnj1p_vcvPdePm3J0HX4iY1rWCGxj5nBoIHpVain63NLg/s1600/AverageMusicData.PNG" height="100" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Average Music (2048 Samples)</td></tr>
</tbody></table>
The data showed that the baseline Mic noise level was always about the same, roughly just above 500. Of course, there was a lot of variation in the heavy metal data and a less variation in the average music data with the quiet ambient data being pretty predictable. The samples were polled every 5 ms.<br />
<br />
<h4>
<b>A look at the Slope</b></h4>
<div class="separator" style="clear: both; text-align: center;">
</div>
<div class="separator" style="clear: both; text-align: center;">
</div>
The following graph shows the slope calculation from the data collected for average music shown above.<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6lKxErfJItHlCUjYNyY617m6WYgJLcYOz3Ru7PLS41K5m9m4eVTWOVZq9sYsePRAzpCzqrWjf_gqBfjfKFcPzCOr_w3PvDT6lJWdrsgDZX7i-JUGy9G2VX2atGYHAJxLSZ7JzxB1MH1bf/s1600/AverageMusicSlopeData.PNG" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh6lKxErfJItHlCUjYNyY617m6WYgJLcYOz3Ru7PLS41K5m9m4eVTWOVZq9sYsePRAzpCzqrWjf_gqBfjfKFcPzCOr_w3PvDT6lJWdrsgDZX7i-JUGy9G2VX2atGYHAJxLSZ7JzxB1MH1bf/s1600/AverageMusicSlopeData.PNG" height="118" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Average Music Slope (2048 Samples)</td></tr>
</tbody></table>
<br />
The nice thing about the slope over the raw data is that it is centered around 0. So no offset level prediction is needed. However, if I change the color of the lights too often, the lights may not update quickly enough nor will my eyes be able to perceive the intended color.<br />
<br />
To ensure the lights will be OFF when there is no interesting sound, I exclude slope changes below 100 to make sure it would be above the value typically seen by quiet noise. To keep the lights from changing color too much or too often, I choose to fade the LEDs in and out.<br />
<h4>
<b><br /></b></h4>
<h4>
<b>The Period Dependency</b></h4>
The final variable in this project is the Period between the slope level detection. The get a loose frequency dependency, I track the period of time between slope calculations that exceed 100. Each time the Period changes, the Period is mapped to the colors on the color wheel (0-255) with some scaling to make things more interesting. <br />
<br />
Of course, this is not an exact frequency mapping to the sound but it does provides interesting color variation that depends on the sound playing. </div>
<div>
<br /></div>
<div>
<a href="https://github.com/codergirljp/Trinket-Color-By-Sound-RGB-NeoPixels" target="_blank">Get the code for this project here..</a></div>
codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-25615419669253694772014-01-07T18:09:00.003-08:002014-02-02T18:49:59.691-08:00Trinket Pin Mapping for AnalogRead and AnalogWriteThe simple answer to using AnalogRead and AnalogWrite on the Trinket, the pins numbers are not the same as the labeled digital pin numbers. Also not all of the pins that can be used for AnalogRead, can be used for AnalogWrite. The pins are labeled for digital Read and Write. Here is the mapping:<br />
<br />
Digital Pin 0 -> analogWrite(0)<br />
Digital Pin 1 -> analogWrite(1)<br />
Digital Pin 2 -> analogRead(1)<br />
Digital Pin 3 -> analogRead(3)<br />
Digital Pin 4 -> analogRead(2)<br />
<br />
More information on the pins and can be found here:<br />
<a href="http://learn.adafruit.com/introducing-trinket/pinouts">http://learn.adafruit.com/introducing-trinket/pinouts</a><br />
<div>
<br /></div>
<br />
<br />
<br />codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0tag:blogger.com,1999:blog-9059385354812982139.post-70130019952689579252014-01-05T13:06:00.002-08:002014-01-19T08:23:40.307-08:00Programming the Trinket with the Arduino IDE in WindowsI am using the Windows Arduino IDE to program the Trinket. This has been trying at times so I thought I'd share my experiences here. You can find a lot of information on solving problems on the Adafruit website, but I find it takes a while to get to what your looking for. Hopefully this will save some headaches for others who might also like to use the Trinket.<br />
<h4>
To get started, make sure you've done these things:</h4>
<br />
<ol>
<li>Updated the ATTiny85 section of your avrdude.conf file.</li>
<li>For windows, make sure to install the USBtiny drivers </li>
<li>Under Tools->Board Menu select the Adafruit Trinket 8MHz</li>
<li>Under Tools->Programmer select USBtinyISP</li>
</ol>
<br />
<i><span style="color: #073763;"> Note: The Trinket doesn't have a USB Serial interface so you won't see a COM port for it.</span></i><br />
<h4>
</h4>
<h4>
To upload to the Trinket, these instructions are handy: </h4>
1) Under Tools->Board Menu Adafruit Trinket 8MHz is selected.<br />
2) Under Tools->Programmer USBtinyISP is selected.<br />
<br />
<b>The next steps are timing critical:</b><br />
3) Press Ctrl+Shift+U to Upload code using the programmer. (The sketch will start compiling)<br />
4) Press the button (don't hold it down!) on the Trinket toward the end of the sketch compiling, you want the red LED to be blinking when the code is trying to upload.<br />
5) The red LED on the Trinket should pulse. This means it is ready to receive the sketch.<br />
6) WATCH the RED LED!! If your sketch is uploaded, it should turn solid briefly before going off.<br />
If the red LED turns solid, it is likely that your sketch uploaded even if you get an error. <span class="Apple-tab-span" style="white-space: pre;"> </span><br />
<br />
<h4>
Problems I had and things I did to fix them: </h4>
<b style="background-color: white;"><span style="color: #cc0000;"> Problem: </span></b><br />
The red LED does not flash when I press the reset button and I always get the error message below when trying to upload.<br />
<i>avrdude: Error: Could not find USBtiny device (0x1781/0xc9f)</i><br />
<b> Try: </b><br />
- Unplug the Trinket and plug it back in.<br />
- If using a USB port on your computer, try using an old USB 2.0 HUB if you have one. This has been much more reliable for me. An error is usually reported but the sketch still uploads and runs.<br />
<b><span style="color: #cc0000;">Problem</span>: </b><br />
When trying to upload, the red LED was flashing but it did not turn solid, my code did not upload and I got an error:<br />
<i> avrdude: Error: Could not find USBtiny device (0x1781/0xc9f) </i><br />
<b>Try</b>:<br />
- You probably missed the time window for the upload. Try again, and wait longer before pressing the button the Trinket. (This happens A LOT!)<br />
<br />
<span style="color: #cc0000;"><b>Problem:</b></span> <br />
When trying to upload, the red LED was flashing but I got an error:<br />
<i>avrdude: error: usbtiny_receive: usb_control_msg: sending control message failed, win error: A device attached to the system is not functioning.</i><i> (expected 4, got -5)</i><br />
<b>Try</b>:<br />
- Did the red LED turn solid? If so, your sketch is likely to have uploaded anyway.<br />
- If not, make sure your avrdude.conf is updated.<br />
<br />
<span style="color: #cc0000;"><b>Problem:</b></span><br />
When trying to upload, the red LED was flashing but it did not turn solid, my code did not upload and I got an error:<br />
<i>error at ... avrdude.conf:1524 unrecognized character: "i"</i><br />
<b>Try</b>:<br />
- Comment out line 1524 in the avrdude.conf file which reads in my file:<br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> <span style="color: #38761d;"> is_at90s1200 = yes;</span><br />
<span class="Apple-tab-span" style="white-space: pre;"> </span> ( you can comment out the line by putting a # sign in front of it. )<br />
<br />
<a href="https://www.adafruit.com/forums/viewtopic.php?f=25&t=44466&start=15"> More avrdude problem solving for the Trinket ( or Gemma) ...</a>codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com3tag:blogger.com,1999:blog-9059385354812982139.post-27887748287532557082014-01-04T20:56:00.001-08:002014-01-04T20:56:29.419-08:00Experimenting with the Adafruit Trinket ATTINY85 I've been doing some projects with this board testing it out. For under $8 the Trinket offers 8MHz (overclocking to 16 MHz is software possible on the 5V version). It has 8K of memory which is enough to do a lot of smaller projects. With it's 5 multi-purpose digital pins it's very versatile and an easy choice for inexpensive projects. The best resource for getting started with the board is of course on the Adafruit site: <a href="http://learn.adafruit.com/introducing-trinket/introduction">http://learn.adafruit.com/introducing-trinket/introduction</a>.<br />
<br />
However, I would not recommend this board as the first board to try for someone new to micro controllers. The programming process a bit tricky compared to other boards like the Arduino Mega, Uno, and Micro for example. Also, the board does not have Serial USB capability like other boards have so it's very difficult to debug on this board. For anything that is more complex, I have found myself prototyping with the Arduino Micro and then porting it to the Trinket.<br />
<br />codergirljphttp://www.blogger.com/profile/14525630621165404656noreply@blogger.com0