Id
stringlengths
1
5
Tags
stringlengths
3
75
Title
stringlengths
15
150
CreationDate
stringlengths
23
23
Body
stringlengths
51
27.6k
Answer
stringlengths
42
31k
598
|interrupt|rotary-encoder|
How precise can I get Arduino using rotary encoders?
2014-03-04T02:50:55.353
<p>Stepper motors are often pricey for a large motor. However, with a powerful, standard DC motor and a rotary encoder, you can "simulate" a stepper motor. <strong>How accurate are rotary encoders with Arduino just with a basic loop and not much other code?</strong> Is it going to "miss a pulse" and not record enough rotation often? How can I handle this with much more code? Is there a better way to do this? Would interrupts help? Is there some sort of circuit that would help with this problem?</p> <p>Note: It will probably not exceed 4 rotations a second... <em>(That may be a lot but if you're doing a lead screw type mechanism that would only be 24 inches a minute if there is 10 rotations per inch of linear motion.)</em></p>
<p>Adding some references to already-written libraries and examples, to enable comparison between different approaches, and experiences with speed versus susceptibility to missing steps.</p> <p>Reading rotary encoders: <a href="http://playground.arduino.cc/Main/RotaryEncoders" rel="nofollow">http://playground.arduino.cc/Main/RotaryEncoders</a></p> <p>Quadrature Encoder too Fast for Arduino (with Solution): <a href="http://www.hessmer.org/blog/2011/01/30/quadrature-encoder-too-fast-for-arduino/" rel="nofollow">http://www.hessmer.org/blog/2011/01/30/quadrature-encoder-too-fast-for-arduino/</a></p> <p>Teensy Encoder library: <a href="https://www.pjrc.com/teensy/td_libs_Encoder.html" rel="nofollow">https://www.pjrc.com/teensy/td_libs_Encoder.html</a></p> <p>Reading rotary encoder on Arduino: <a href="http://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino/" rel="nofollow">http://www.circuitsathome.com/mcu/reading-rotary-encoder-on-arduino/</a></p>
601
|sensors|
Grove sensors without a Grove shield
2014-03-04T12:59:01.943
<p>There exists a large variety of sensors in the <a href="http://www.seeedstudio.com/wiki/GROVE_System">Grove System</a>. Usually these are accessed via a special shield (Grove base shield). </p> <p>Can I access these sensor directly without a shield. In particular I am interested in using them with an Arduino Pro Mini. My guess is that one definitely needs the 5V version of the Mini, but other than this? How fiddly is it to use these sensors directly? </p> <p>I am interested in using the <a href="http://www.seeedstudio.com/wiki/Grove_-_Dust_Sensor">Grove dust sensor</a>, but I am also would like to operate a <a href="http://www.seeedstudio.com/wiki/Grove_-_4-Digit_Display">Grove 4 digit display</a>.</p>
<p>I'm pretty sure you could just take the signal cable from the dust sensor and plug it directly into your mcu digital pin of choice and then wire the Vcc and Gnd as well. I'm working with a CO2 sensor and don't really want the shield overhead.</p>
602
|arduino-uno|uploading|atmega328|
Is my Arduino dead or is it just its processor?
2014-03-04T13:26:36.847
<p>I have a problem with my Arduino. I can't upload any sketches to it (it gives me the error <code>avrdude: verification error; content mismatch</code>), but the LEDs are still blinking. Do you think that the whole Arduino is dead or is it just the chip ?</p> <p>EDIT : I tried an other USB cable but it changed nothing.</p> <p>EDIT : Here is the output of verbose mode while uploading : </p> <pre><code>Taille binaire du croquis : 1 084 octets (d'un max de 32 256 octets) /Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/cu.usbmodem641 -b115200 -D -Uflash:w:/var/folders/56/7b6d3xm14n31kjrw8609ywjw0000gn/T/build1168987322216849272.tmp/Blink.cpp.hex:i avrdude: Version 5.11, compiled on Sep 2 2011 at 18:52:52 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch System wide configuration file is "/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf" User configuration file is "/Users/trevorannedenise/.avrduderc" User configuration file does not exist or is not a regular file, skipping Using Port : /dev/cu.usbmodem641 Using Programmer : arduino Overriding Baud Rate : 115200 avrdude: Send: 0 [30] [20] avrdude: Send: 0 [30] [20] avrdude: Send: 0 [30] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] AVR Part : ATMEGA328P Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PC2 RESET disposition : dedicated RETRY pulse : SCK serial program mode : yes parallel program mode : yes Timeout : 200 StabDelay : 100 CmdexeDelay : 25 SyncLoops : 32 ByteDelay : 0 PollIndex : 3 PollValue : 0x53 Memory Detail : Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- eeprom 65 20 4 0 no 1024 4 0 3600 3600 0xff 0xff Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- flash 65 6 128 0 yes 32768 128 256 4500 4500 0xff 0xff Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- lfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- hfuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- efuse 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- lock 0 0 0 0 no 1 0 0 4500 4500 0x00 0x00 Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00 Block Poll Page Polled Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- --------- signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00 Programmer Type : Arduino Description : Arduino avrdude: Send: A [41] . [80] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] avrdude: Send: A [41] . [81] [20] avrdude: Recv: . [14] avrdude: Recv: . [04] avrdude: Recv: . [10] avrdude: Send: A [41] . [82] [20] avrdude: Recv: . [14] avrdude: Recv: . [04] avrdude: Recv: . [10] avrdude: Send: A [41] . [98] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] Hardware Version: 3 Firmware Version: 4.4 avrdude: Send: A [41] . [84] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] avrdude: Send: A [41] . [85] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] avrdude: Send: A [41] . [86] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] avrdude: Send: A [41] . [87] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] avrdude: Send: A [41] . [89] [20] avrdude: Recv: . [14] avrdude: Recv: . [03] avrdude: Recv: . [10] Vtarget : 0.3 V Varef : 0.3 V Oscillator : 28.800 kHz SCK period : 3.3 us avrdude: Send: A [41] . [81] [20] avrdude: Recv: . [14] avrdude: Recv: . [04] avrdude: Recv: . [10] avrdude: Send: A [41] . [82] [20] avrdude: Recv: . [14] avrdude: Recv: . [04] avrdude: Recv: . [10] avrdude: Send: B [42] . [86] . [00] . [00] . [01] . [01] . [01] . [01] . [03] . [ff] . [ff] . [ff] . [ff] . [00] . [80] . [04] . [00] . [00] . [00] . [80] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: E [45] . [05] . [04] . [d7] . [c2] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: P [50] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: AVR device initialized and ready to accept instructions Reading | avrdude: Send: u [75] [20] avrdude: Recv: . [14] . [1e] . [95] . [0f] . [10] ################################################## | 100% 0.00s avrdude: Device signature = 0x1e950f avrdude: Send: V [56] . [a0] . [03] . [fc] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [00] avrdude: Recv: . [10] avrdude: Send: V [56] . [a0] . [03] . [fd] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [00] avrdude: Recv: . [10] avrdude: Send: V [56] . [a0] . [03] . [fe] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [00] avrdude: Recv: . [10] avrdude: Send: V [56] . [a0] . [03] . [ff] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [00] avrdude: Recv: . [10] avrdude: reading input file "/var/folders/56/7b6d3xm14n31kjrw8609ywjw0000gn/T/build1168987322216849272.tmp/Blink.cpp.hex" avrdude: writing flash (1084 bytes): Writing | avrdude: Send: U [55] . [00] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [0c] . [94] a [61] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] . [9d] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [0c] . [94] ~ [7e] . [00] . [00] . [00] . [00] . [00] $ [24] . [00] ' [27] . [00] * [2a] . [00] . [00] . [00] . [00] . [00] % [25] . [00] ( [28] . [00] + [2b] . [00] . [00] . [00] . [00] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] #####avrdude: Send: U [55] @ [40] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] # [23] . [00] &amp; [26] . [00] ) [29] . [00] . [04] . [04] . [04] . [04] . [04] . [04] . [04] . [04] . [02] . [02] . [02] . [02] . [02] . [02] . [03] . [03] . [03] . [03] . [03] . [03] . [01] . [02] . [04] . [08] . [10] [20] @ [40] . [80] . [01] . [02] . [04] . [08] . [10] [20] . [01] . [02] . [04] . [08] . [10] [20] . [00] . [00] . [00] . [07] . [00] . [02] . [01] . [00] . [00] . [03] . [04] . [06] . [00] . [00] . [00] . [00] . [00] . [00] . [00] . [00] . [11] $ [24] . [1f] . [be] . [cf] . [ef] . [d8] . [e0] . [de] . [bf] . [cd] . [bf] . [11] . [e0] . [a0] . [e0] . [b1] . [e0] . [ea] . [e3] . [f4] . [e0] . [02] . [c0] . [05] . [90] . [0d] . [92] . [a2] 0 [30] . [b1] . [07] . [d9] . [f7] . [11] . [e0] . [a2] . [e0] . [b1] . [e0] . [01] . [c0] . [1d] . [92] . [ab] 0 [30] . [b1] . [07] . [e1] . [f7] . [0e] . [94] . [0c] . [02] . [0c] . [94] . [1b] . [02] . [0c] . [94] . [00] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [80] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [80] . [91] . [00] . [01] a [61] . [e0] . [0e] . [94] . [b8] . [01] h [68] . [ee] s [73] . [e0] . [80] . [e0] . [90] . [e0] . [0e] . [94] . [e5] . [00] . [80] . [91] . [00] . [01] ` [60] . [e0] . [0e] . [94] . [b8] . [01] h [68] . [ee] s [73] . [e0] . [80] . [e0] . [90] . [e0] . [0e] . [94] . [e5] . [00] . [08] . [95] . [80] . [91] . [00] . [01] a [61] . [e0] . [0e] . [94] y [79] . [01] . [08] . [95] . [1f] . [92] . [0f] . [92] . [0f] . [b6] . [0f] . [92] . [11] $ [24] / [2f] . [93] ? [3f] . [93] . [8f] . [93] . [9f] . [93] . [af] . [93] . [bf] . [93] . [80] . [91] . [06] . [01] . [90] . [91] . [07] . [01] . [a0] . [91] . [08] . [01] . [b0] . [91] . [09] . [01] 0 [30] . [91] . [0a] . [01] . [01] . [96] . [a1] . [1d] . [b1] . [1d] # [23] / [2f] - [2d] _ [5f] - [2d] 7 [37] [20] . [f0] - [2d] W [57] . [01] . [96] . [a1] . [1d] . [b1] . [1d] [20] . [93] . [0a] . [01] . [80] . [93] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [c0] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [06] . [01] . [90] . [93] . [07] . [01] . [a0] . [93] . [08] . [01] . [b0] . [93] . [09] . [01] . [80] . [91] . [02] . [01] . [90] . [91] . [03] . [01] . [a0] . [91] . [04] . [01] . [b0] . [91] . [05] . [01] . [01] . [96] . [a1] . [1d] . [b1] . [1d] . [80] . [93] . [02] . [01] . [90] . [93] . [03] . [01] . [a0] . [93] . [04] . [01] . [b0] . [93] . [05] . [01] . [bf] . [91] . [af] . [91] . [9f] . [91] . [8f] . [91] ? [3f] . [91] / [2f] . [91] . [0f] . [90] . [0f] . [be] . [0f] . [90] . [1f] . [90] . [18] . [95] . [9b] . [01] . [ac] . [01] . [7f] . [b7] . [f8] . [94] . [80] . [91] . [02] . [01] . [90] . [91] . [03] . [01] . [a0] . [91] . [04] . [01] . [b0] . [91] . [05] . [01] f [66] . [b5] . [a8] . [9b] . [05] . [c0] o [6f] ? [3f] . [19] . [f0] . [01] . [96] . [a1] . [1d] . [b1] . [1d] . [7f] . [bf] . [ba] / [2f] . [a9] / [2f] . [98] / [2f] . [88] ' [27] . [86] . [0f] . [91] . [1d] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [00] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [a1] . [1d] . [b1] . [1d] b [62] . [e0] . [88] . [0f] . [99] . [1f] . [aa] . [1f] . [bb] . [1f] j [6a] . [95] . [d1] . [f7] . [bc] . [01] - [2d] . [c0] . [ff] . [b7] . [f8] . [94] . [80] . [91] . [02] . [01] . [90] . [91] . [03] . [01] . [a0] . [91] . [04] . [01] . [b0] . [91] . [05] . [01] . [e6] . [b5] . [a8] . [9b] . [05] . [c0] . [ef] ? [3f] . [19] . [f0] . [01] . [96] . [a1] . [1d] . [b1] . [1d] . [ff] . [bf] . [ba] / [2f] . [a9] / [2f] . [98] / [2f] . [88] ' [27] . [8e] . [0f] . [91] . [1d] . [a1] . [1d] . [b1] . [1d] . [e2] . [e0] . [88] . [0f] . [99] . [1f] . [aa] . [1f] . [bb] . [1f] . [ea] . [95] . [d1] . [f7] . [86] . [1b] . [97] . [0b] . [88] ^ [5e] . [93] @ [40] . [c8] . [f2] ! [21] P [50] 0 [30] @ [40] @ [40] @ [40] P [50] @ [40] h [68] Q [51] | [7c] O [4f] ! [21] . [15] 1 [31] . [05] A [41] . [05] Q [51] . [05] q [71] . [f6] . [08] . [95] x [78] . [94] . [84] . [b5] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] @ [40] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [82] ` [60] . [84] . [bd] . [84] . [b5] . [81] ` [60] . [84] . [bd] . [85] . [b5] . [82] ` [60] . [85] . [bd] . [85] . [b5] . [81] ` [60] . [85] . [bd] . [ee] . [e6] . [f0] . [e0] . [80] . [81] . [81] ` [60] . [80] . [83] . [e1] . [e8] . [f0] . [e0] . [10] . [82] . [80] . [81] . [82] ` [60] . [80] . [83] . [80] . [81] . [81] ` [60] . [80] . [83] . [e0] . [e8] . [f0] . [e0] . [80] . [81] . [81] ` [60] . [80] . [83] . [e1] . [eb] . [f0] . [e0] . [80] . [81] . [84] ` [60] . [80] . [83] . [e0] . [eb] . [f0] . [e0] . [80] . [81] . [81] ` [60] . [80] . [83] . [ea] . [e7] . [f0] . [e0] . [80] . [81] . [84] ` [60] . [80] . [83] . [80] . [81] . [82] ` [60] . [80] . [83] . [80] . [81] . [81] ` [60] . [80] . [83] . [80] . [81] . [80] h [68] . [80] . [83] . [10] . [92] . [c1] . [00] . [08] . [95] . [cf] . [93] . [df] . [93] H [48] / [2f] P [50] . [e0] . [ca] . [01] . [86] V [56] . [9f] O [4f] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [80] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [fc] . [01] 4 [34] . [91] J [4a] W [57] _ [5f] O [4f] . [fa] . [01] . [84] . [91] . [88] # [23] i [69] . [f1] . [90] . [e0] . [88] . [0f] . [99] . [1f] . [fc] . [01] . [e8] Y [59] . [ff] O [4f] . [a5] . [91] . [b4] . [91] . [fc] . [01] . [ee] X [58] . [ff] O [4f] . [c5] . [91] . [d4] . [91] f [66] # [23] Q [51] . [f4] / [2f] . [b7] . [f8] . [94] . [8c] . [91] . [93] / [2f] . [90] . [95] . [89] # [23] . [8c] . [93] . [88] . [81] . [89] # [23] . [0b] . [c0] b [62] 0 [30] a [61] . [f4] / [2f] . [b7] . [f8] . [94] . [8c] . [91] . [93] / [2f] . [90] . [95] . [89] # [23] . [8c] . [93] . [88] . [81] . [83] + [2b] . [88] . [83] / [2f] . [bf] . [06] . [c0] . [9f] . [b7] . [f8] . [94] . [8c] . [91] . [83] + [2b] . [8c] . [93] . [9f] . [bf] . [df] . [91] . [cf] . [91] . [08] . [95] H [48] / [2f] P [50] . [e0] . [ca] . [01] . [82] U [55] . [9f] O [4f] . [fc] . [01] $ [24] . [91] . [ca] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [c0] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] . [80] F [46] . [86] V [56] . [9f] O [4f] . [fc] . [01] . [94] . [91] J [4a] W [57] _ [5f] O [4f] . [fa] . [01] 4 [34] . [91] 3 [33] # [23] . [09] . [f4] @ [40] . [c0] " [22] # [23] Q [51] . [f1] # [23] 0 [30] q [71] . [f0] $ [24] 0 [30] ( [28] . [f4] ! [21] 0 [30] . [a1] . [f0] " [22] 0 [30] . [11] . [f5] . [14] . [c0] &amp; [26] 0 [30] . [b1] . [f0] ' [27] 0 [30] . [c1] . [f0] $ [24] 0 [30] . [d9] . [f4] . [04] . [c0] . [80] . [91] . [80] . [00] . [8f] w [77] . [03] . [c0] . [80] . [91] . [80] . [00] . [8f] } [7d] . [80] . [93] . [80] . [00] . [10] . [c0] . [84] . [b5] . [8f] w [77] . [02] . [c0] . [84] . [b5] . [8f] } [7d] . [84] . [bd] . [09] . [c0] . [80] . [91] . [b0] . [00] . [8f] w [77] . [03] . [c0] . [80] . [91] . [b0] . [00] . [8f] } [7d] . [80] . [93] . [b0] . [00] . [e3] / [2f] . [f0] . [e0] . [ee] . [0f] . [ff] . [1f] . [ee] X [58] . [ff] O [4f] . [a5] . [91] . [b4] . [91] / [2f] . [b7] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [00] . [02] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: d [64] . [00] &lt; [3c] F [46] . [f8] . [94] f [66] # [23] ! [21] . [f4] . [8c] . [91] . [90] . [95] . [89] # [23] . [02] . [c0] . [8c] . [91] . [89] + [2b] . [8c] . [93] / [2f] . [bf] . [08] . [95] . [cf] . [93] . [df] . [93] . [0e] . [94] &gt; [3e] . [01] . [0e] . [94] . [97] . [00] . [c0] . [e0] . [d0] . [e0] . [0e] . [94] . [80] . [00] [20] . [97] . [e1] . [f3] . [0e] . [94] . [00] . [00] . [f9] . [cf] . [f8] . [94] . [ff] . [cf] . [0d] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] ### | 100% 0.21s avrdude: 1084 bytes of flash written avrdude: verifying flash memory against /var/folders/56/7b6d3xm14n31kjrw8609ywjw0000gn/T/build1168987322216849272.tmp/Blink.cpp.hex: avrdude: load data flash data from input file /var/folders/56/7b6d3xm14n31kjrw8609ywjw0000gn/T/build1168987322216849272.tmp/Blink.cpp.hex: avrdude: input file /var/folders/56/7b6d3xm14n31kjrw8609ywjw0000gn/T/build1168987322216849272.tmp/Blink.cpp.hex contains 1084 bytes avrdude: reading on-chip flash data: Reading | avrdude: Send: U [55] . [00] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] #####avrdude: Send: U [55] @ [40] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [80] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [c0] . [00] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [00] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] @ [40] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [80] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [c0] . [01] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] . [80] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ######avrdude: Send: U [55] . [00] . [02] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude: Send: t [74] . [00] &lt; [3c] F [46] [20] avrdude: Recv: . [14] avrdude: Recv: . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] . [ff] avrdude: Recv: . [10] ### | 100% 0.16s avrdude: verifying ... avrdude: verification error, first mismatch at byte 0x0000 0x0c != 0xff avrdude: verification error; content mismatch avrdude: Send: Q [51] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude done. Thank you. </code></pre>
<p>I had faced similar problems and the solution that worked for me was to power the burning circuit with the Arduino onboard 5 volt. 3.3 Volt does work but at times it gives these errors especially while burning the bootloader. </p>
604
|pins|shields|motor|
Arduino motor shield orange/white pin usage
2014-03-04T14:05:45.620
<p>I have an Arduino motor shield like this one plugged into my Mega board.</p> <p><img src="https://i.stack.imgur.com/cKBqi.jpg" alt="Arduino motor shield"></p> <p>I would like to know some more information about the orange and white pin blocks on the board. The <a href="http://arduino.cc/en/Main/ArduinoMotorShieldR3#.UxXT9vl_skI" rel="noreferrer">Arduino website</a> has the following information, but it doesn't give any explanation of what is best to use them for or which pins are mapped to the data pins etc. </p> <ul> <li>TinkerKit connectors for two Analog Inputs (in white), connected to A2 and A3. </li> <li>TinkerKit connectors for two Aanlog Outputs (in orange in the middle), connected to PWM outputs on pins D5 and D6. </li> <li>TinkerKit connectors for the TWI interface (in white with 4 pins), one for input and the other one for output.</li> </ul> <p>What I want to do is connect a servo up to the board and was hoping I could use one of the orange <code>OUT</code> blocks. I haven't been successful in finding any examples of this which leaves me in doubt as to whether it is possible or not. I would just plug it in, but I'm afraid of frying the shield/mega/servo. Probably an irrational fear, but I can't afford another one of any at the moment!</p> <p>I don't know which pins in the block are assigned to the data, vcc and out, so if anyone know I would be grateful for the answer.</p> <p>Also, just because it is annoying not to understand, what are the <code>TWI</code> connectors for?</p> <p>I hope this isn't too general a question as I could really use some answers!</p>
<p>Although the 'Orange' (Out) pins of the Deek-Robot Motor Shield can be used to drive a servo by swapping the '+5vdc' and 'Signal' wires at the servo harness plug it is best to not do as this. This is because the current drive for the servo is drawn from the Arduino UNO. Given that an individual servo can draw well in access of 125ma the current draw may/will exceed the current sink limitations of the associated Arduino UNO circuitry. It is best to use an external power source, properly filtered for electrical noise, as the current source for the servo(s). This has been documented/recommended in multiple information sources.</p>
611
|library|flash|
What are the FLASH_ARRAY/FLASH_TABLE macros in this code?
2014-03-04T22:35:36.890
<p>In this <a href="https://code.google.com/p/heating-monitor/source/browse/HeatingMonitor/consts.h" rel="nofollow">code</a> for heating monitor, there appears to be macros called <code>FLASH_ARRAY</code> and <code>FLASH_TABLE</code>. I can't find any reference to them either in this code, Arduino, or on the Internet. What do they do?</p> <pre><code>FLASH_ARRAY(byte, VARIABLE_DEVICE_TABLE, DEVICE_LADDNING_RETUR, DEVICE_LADDNING_UT, DEVICE_TANK1, DEVICE_TANK2, ... VARIABLE_ID_LOAD, VARIABLE_ID_TIME_EMPTY); </code></pre> <p>and</p> <pre><code>FLASH_TABLE(byte, NUMBER_TEMP_TABLE, 7, {DEVICE_LADDNING_RETUR, 99, 5, 10, 7, MAIN_TYPE_TEXT_CELCIUS, 2}, {DEVICE_LADDNING_UT, 99, 43, 10, 7, MAIN_TYPE_TEXT_CELCIUS, 2}, ... {DEVICE_UTE, 0, 55, 15, 7, MAIN_TYPE_TEXT_CELCIUS_WITH_NEGATIVE, 103}, {VARIABLE_ID_EFFECT, 114, 29, 10, 7, MAIN_TYPE_TEXT_VARIABLE, 2}); </code></pre>
<p>The flash array is from Mikal Hart's <a href="https://github.com/mikalhart/Flash/blob/master/Flash.h#L39" rel="nofollow noreferrer">flash library</a> as you show, and what it does is that they declare an array or a matrix (table) object in the PROGMEM memory:</p> <pre class="lang-cpp prettyprint-override"><code>#define FLASH_ARRAY(type, name, values...) \ static const type name##_flash[] PROGMEM = { values }; \ _FLASH_ARRAY&lt;type&gt; name(name##_flash, sizeof(name##_flash) / sizeof(type)); </code></pre> <p>which is an instance of the <code>_FLASH_ARRAY</code> class defined in that same file, which is a facility to access PROGMEM/Flash memory.</p> <p>Basically, it's a lot of boilerplate for what already does the <code>PSTR()</code> macro amongst other from <code>pgmspace.h</code>. I personally would avoid using that and prefer to use the original macros along with my own index and pointers.</p> <p>BTW, except for some Arduono IDE magic, I don't think that can compile, as the <code>Flash.h</code> is not included.</p> <p>EDIT:</p> <p>To make another point against the <code>FLASH_TABLE</code>/<code>FLASH_ARRAY</code> boilerplate/overhead, since avc-gcc 4.8 has been introduced the <a href="http://gcc.gnu.org/onlinedocs/gcc/Named-Address-Spaces.html" rel="nofollow noreferrer"><code>__flash</code> qualifier</a> which is a replacement for the <code>PROGMEM</code> macro, simplifying the whole stuff:</p> <pre class="lang-cpp prettyprint-override"><code>// to use string literals without having to cast #define FSTR(X) ((const __flash char[]) { X }) // create string pstr in the .progmem.data address space const __flash char* pstr = FSTR ("foo"); </code></pre> <p>and no more use of the <code>pgm_read_*()</code> functions, you can now access the content of the flash memory using <code>*pstr</code>, as shown is <a href="http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=viewtopic&amp;p=1129848" rel="nofollow noreferrer">this thread</a>. In case you want to keep a code compatible with older version of avr-gcc, <a href="https://codereview.stackexchange.com/questions/33883/embedded-conditional-code-compaction">here's a post</a> that offers macros to deal with both systems.</p>
615
|sensors|temperature-sensor|
How can I sense very high temperatures with Arduino?
2014-03-05T02:04:47.267
<p>I've seen many temperature sensors, but the highest temperature they go up to is 125 degrees C (257 degrees F). I want to reach <em>higher</em> temperatures than that. I'm thinking about rigging up a closed loop sensor for my soldering iron (for a convenient LCD display), but I can't find out how to sense the temperature of the tip due to the higher operating temperature than most sensors.</p>
<p>You probably want to use a <a href="http://en.wikipedia.org/wiki/Thermocouple" rel="noreferrer">thermocouple</a>. It'll give you the ability to measure much higher temps than regular temperature sensor. You'll also need a IC like the <a href="http://www.maximintegrated.com/datasheet/index.mvp/id/3149" rel="noreferrer">MAX6675</a> to interface with it.</p> <blockquote> <p>The MAX6675 performs cold-junction compensation and digitizes the signal from a type-K thermocouple. The data is output in a 12-bit resolution, SPI™-compatible, read-only format.</p> <p>This converter resolves temperatures to 0.25°C, allows readings as high as +1024°C, and exhibits thermocouple accuracy of 8 LSBs for temperatures ranging from 0°C to +700°C.</p> </blockquote> <p><img src="https://i.stack.imgur.com/pyNbk.gif" alt="enter image description here"></p> <p><a href="http://datasheets.maximintegrated.com/en/ds/MAX6675.pdf" rel="noreferrer">Page 6 of the datasheet</a> has the serial interface protocol information and. You can really just set the Chip Select line and it'll give you 16 bits of information, 12 of which will be the temperature.</p>
619
|arduino-uno|
Redirecting Arduino Serial Output to a File
2014-03-05T07:03:24.243
<p>I am integrating the MPU-6050 Accelerometer + Gyro sensor into a large project that contains 12 Arduino boards and 6 Raspberry Pis. At some point, I will have to load the output of my MPU-6050 sensor into another application through command line. The process is to be all done with Python and Bash (on the Raspberry Pi side), and so what I need is a way to store the output of my Arduino boards. </p> <p>What I am currently looking at is the python program <code>ino</code>. I have used the product for about a year now, and as far as I am aware of, the only way to exit out of serial mode in <code>ino</code> is by closing the command-line window! </p> <p>Is there a way I can achieve what I've discussed above? Essentially, all I want is a way to hold the output of my Arduino serial output so I can use it later in other parts of my project.</p>
<p>Well, I don't know about your <code>ino</code> program, but here's how I'd do it:</p> <p>get_serial.py</p> <pre><code>import serial, sys with serial.Serial(port=sys.argv[1], baudrate=sys.argv[2]) as ser: while ser.isOpen(): print(ser.readline()) </code></pre> <p>The idea, here, is to print on <code>stdout</code> the data coming on the serial line:</p> <pre><code>python get_serial.py /dev/ttyACM0 115200 &gt; output.log </code></pre> <p>or you can do it this way:</p> <p>get_serial.py</p> <pre><code>import serial, sys with open(sys.argv[3]) as f: with serial.Serial(port=sys.argv[1], baudrate=sys.argv[2]) as ser: while ser.isOpen(): f.write(ser.readline()) </code></pre> <p>which is ran:</p> <pre><code>python get_serial.py /dev/ttyACM0 115200 output.log </code></pre> <p>Hope this helps!</p>
620
|pins|arduino-due|current|
A digital I/O pin as ground
2014-03-05T10:05:42.047
<p>I want an I/O pin to return current in a circuit, similarly to the function of ground.</p> <p>Which of these will achieve what I require?</p> <pre><code>pinMode(pinnumber, OUTPUT) digitalWrite(pinnumber, LOW) </code></pre> <p>or</p> <pre><code>pinMode(pinnumber, input) </code></pre>
<p>Your first snippet is the correct solution.</p> <pre><code>pinMode(pinnumber,OUTPUT) digitalWrite(pinnumber,LOW) </code></pre> <p>Be careful though, you can only sink up to 6mA or 9mA per pin (as per the <a href="http://arduino.cc/en/Main/ArduinoBoardDue">documentation</a> ["Input and Output" section], I never tried more). If you need more current, use a transistor (<a href="http://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/transistors">this</a> looks like a good example, you just need to invert the output pin to <code>HIGH</code>).</p> <p>When the pin is configured as input it is supposed to be high impedance, not what you want.</p>
623
|progmem|pointer|
Why can I not use pointers instead of array with PROGMEM?
2014-03-05T11:52:44.643
<p>I'm currently changing some libraries to use flash instead of RAM for string storage so that I do not run out of SRAM on a project.</p> <p>Some strings in the library are declared in this manner:</p> <pre><code>const char *testStringA = "ABC"; </code></pre> <p>This is different to how I normally see this done:</p> <pre><code>const char testStringB[] = "DEF"; </code></pre> <p>However, I think that these two are equivalent when declared const and initialised in the declaration. Both work fine in code.</p> <p>I attempted to move these to flash:</p> <pre><code>const prog_char *testStringC PROGMEM = "GHI"; </code></pre> <p>I then found that this didn't work. It was producing gobbledegook when printed.</p> <p>However, following the more usual pattern of:</p> <pre><code>const prog_char testStringD[] PROGMEM = "JKL"; </code></pre> <p>works fine.</p> <p>I can see in the disassembly:</p> <pre><code>00000068 &lt;testStringC&gt;: 68: 04 01 .. 0000006a &lt;_ZL11testStringD&gt;: 6a: 4a 4b 4c 00 JKL. </code></pre> <p>So it is clear the pointer and PROGMEM results in the string/array not being initialised.</p> <p>Why is this?</p> <p>Example code:</p> <pre><code>#include &lt;avr/pgmspace.h&gt; const int BUFFER_LEN = 20; const char *testStringA = "ABC"; const char testStringB[] = "DEF"; const prog_char *testStringC PROGMEM = "GHI"; const prog_char testStringD[] PROGMEM = "JKL"; void setup() { Serial.begin(9600); } void loop() { char buffer[BUFFER_LEN]; Serial.println(testStringA); Serial.println(testStringB); strncpy_P(buffer, testStringC, BUFFER_LEN); Serial.println(buffer); strncpy_P(buffer, testStringD, BUFFER_LEN); Serial.println(buffer); delay(1000); } </code></pre>
<p>Well, this question has been wisely answered in <a href="https://stackoverflow.com/a/1335836/1290438">an answer to Stack&nbsp;Overflow question <em>C: differences between char pointer and array</em></a>.</p> <p>Basically, what you're declaring as PROGMEM with,</p> <pre><code>const prog_char testStringD[] PROGMEM = "JKL"; </code></pre> <p>is both the array and the memory it points to, that is, the elements of the array, both in current's scope stack. Whereas with:</p> <pre><code>const prog_char* testStringC PROGMEM = "GHI"; </code></pre> <p>you declare a PROGMEM pointer to a constant string that may stay elsewhere in memory, but not declared as a PROGMEM string.</p> <p>Though I did <em>not</em> test that, but you should try to declare:</p> <pre><code>const prog_char* testStringC PROGMEM = F("GHI"); </code></pre> <p>to actually allocate the pointed string within the PROGMEM space. I <em>guess</em> it should be working, using Arduino's <a href="http://andybrown.me.uk/wk/wp-content/images//avr-gcc-4.7.0/WString.h" rel="nofollow noreferrer"><code>F()</code> macro</a>, which adds a lot of boilerplate code to actually have the same result as the array declaration.</p> <p>As said in comments, if not in a global context, the <code>PSTR()</code> macro could be used instead of the <code>F()</code> macro.</p> <p>Simpler is better: use the array declaration, not the pointer one!</p> <p>Cf <a href="https://arduino.stackexchange.com/a/614/379">that other answer</a>, the <code>__flash</code> qualifier is a third solution ;-)</p>
626
|arduino-uno|ethernet|networking|
Webserver on Arduino
2014-03-05T13:48:35.653
<p>How can I run a webserver in a Arduino Uno? I want to use my Arduino to monitor things in my home such as temperature. I want to be able to access this data through the internet.</p>
<p>The <a href="http://arduino.cc/en/Main/ArduinoBoardYun" rel="nofollow">Arduino Yún</a> has been made with this use case in mind. The <a href="http://arduino.cc/en/Reference/YunBridgeLibrary" rel="nofollow">Bridge library</a> allows your sketch to publish data such as sensor readings: this data is available through a REST api.</p> <p>Say you want to publish the temperature of your living room: you'll write something like</p> <p><code>Bridge.put("living_room", String(19)); //celsius</code></p> <p>You can then access the data via web with a URL like</p> <p><code>http://arduino.local/data/get/living_room</code></p> <p>You can get all sensor readings without specifying the key name, with</p> <p><code>http://arduino.local/data/get</code></p>
630
|pins|
All voltage directed to pin 3 when multiple pins are set to out put
2014-03-05T16:23:32.863
<p>I just finished testing a haptic device at university, and when I took it home I got the joy of finding the device not working. Here's what I can trace the problem to: when multiple pins are set to output (pin 2~11), pin 3 writes constantly to high and there is nothing I can do to make it stop.</p> <p>Using a blinker program one pin at a time produces no problems, however when I run a blinker program that cycles through all pins, pin 3 is set to constant high. My actual code is similar in function but more complex. This program below though gets the same error.</p> <pre><code>void setup() { for (int c =2; c&lt;12; c++){ pinMode(c, OUTPUT); } } void loop() { for (int c =2; c&lt;12 ; c++){ digitalWrite(c, HIGH); delay(100); digitalWrite(c, LOW); delay(100); } } </code></pre> <p>Is this a sign my arduino died? My device had been working for weeks on my prior code with no problem (and no updates). </p>
<p>It is probably a dead chip. Try getting a new ATmega chip for the Arduino (easily found online for ~$5) and see if that fixes it.</p>
633
|safety|arduino-uno-smd|
How cold or hot can my Arduino Uno get?
2014-03-06T00:46:02.330
<p><a href="http://arduino.cc/en/Main/arduinoBoardUno">The Arduino Uno Page</a> doesn't say the temperatures that it can operate in. I'm thinking about placing it outdoors. How can I make sure my Arduino Uno is safe in weather that can reach -20 to 105 degrees Fahrenheit? (-26 to 40 degrees Celsius).</p>
<p>If you must place your device outside, I would suggest a diecast box. The main heat generating component is probably the regulator (Think about it - at 12V, the reg drops 7V, where the micro runs on 5V or maybe 3V3). So running the lowest voltage into the arduino is recommended, I think its good to 7V (for a 5V unit). If you can connect a heat pathway from the chip surface to the case, good (Use heavy guage - at least 2mm thick). Take care you do not connect to the reg tab - use mica or thin mylar and heatsink paste (Avoid galvanic interations). Normal finned heatsinks on the outside of the box actually do the job of shedding heat to the atmosphere. This whole thing should be in a slatted wooden white painted container (A stevenson screen) so direct sun (and rain/dew) dont hit the containing box. This would be a solution for extreme environments. Remember that any heat build from the board must get to the box internal environment - using trapped air you get a very poor thermal contact. Then it has to get through the box and into the air again. Dont forget that current sinks you use on the chip generate some (small) heat in the process.</p>
638
|power|battery|
Powering Arduino with car batteries
2014-03-06T08:57:06.017
<p>Presumably, one powers an Arduino board with car batteries for long-term operation away from the power grid.</p> <p>How can this be done, and what are the most (1) economic, and (2) reliable ways to do this? Specifically, do any additional risks to short the board with an extraneous discharge exist?</p>
<p>Standard car batteries are 12.6 volts there are 6 2.1V cells. AGM batteries (i.e. Optima batteries, some interstates, and many other brands make AGM), in my experience with AGM batteries they are around 12.8 volts (I do not know the technical voltage). Without the car running you do not need to worry about voltage spikes <strong>AS LONG AS THE WIRES TO AND FROM THE BATTERY ARE SHORT</strong>. When the car is running the serpentine belt turns the alternator which is an AC generator. The alternator is connected to a rectifier to change it back to DC and the unit has a voltage regulator. When the car is running the alternator runs the electrical system and charges the battery. When you connect to the battery while the car is running you are actually connected to the alternator. When connected to the alternator there is a ton of electrical noise, voltage spikes, etc.</p> <p>I have always had success connecting straight from the battery to the Arduino through its barrel jack connector, I have not tried any analog read function when the car is running. On the Arduino website it recommends 7-12V, however the limits (as listed on the Arduino website below the recommended) are 6-20. I have actually experienced problems with lower input voltages. If you feel uncomfortable just buy a 5 volt regulator and power through the usb. </p>
640
|arduino-uno|serial|python|reset|
Arduino serial port reset in Serial monitor & Python
2014-03-06T11:16:52.390
<p>So am I using an Arduino with a shield to gain some voltage values for an ECG. I am then plotting that data in Python. However whenever I "observe" the serial port, be that through the Arduino serial monitor or in attempting to plot the values of time (using millis()) against ECG (voltage) the values reset, so millis() resets the zero, which is fine, except that some of the older values still show up. Now this is especially a problem in Python because it means the plot is malfunctioning at the start of the script, because it is plotting some of the older values and then after a couple of seconds it resets and the plot looks normal again.</p> <p>To demonstrate this I have recorded it on video and put it on YouTube, here it is:</p> <p><a href="https://www.youtube.com/watch?v=dNpUakcRPec">https://www.youtube.com/watch?v=dNpUakcRPec</a></p> <p>Now initially I thought the problem was with Python or the Pyserial module so I labelled the video as such, but since it occurs in the serial monitor I realised the solution would be in the Arduino sketch. I have tried flushing, didn't work, I have tried even to not start the data till I send a start byte, but this didn't work on Python.</p> <p>Ideally I could start the Python plotting script and it would skip, or ignore those initial values from the serial port before beginning again.</p> <p>Here is the Arduino sketch I am using:</p> <pre><code>#include &lt;eHealth.h&gt; unsigned long time; // The setup routine runs once when you press reset: void setup() { Serial.begin(9600); } // The loop routine runs over and over again forever: void loop() { float ECG = eHealth.getECG(); time = millis(); Serial.print(time); Serial.print(" "); Serial.print(ECG, 3); Serial.println(""); delay(50); // wait for 50 millisecond } </code></pre>
<p>I the answer from @TheDoctor. An alternative is for the client listening on serial port to wait for a &quot;successful reset&quot; signal from the Arduino.</p> <pre><code>void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); while (!Serial) { ; // wait for serial port to connect. } Serial.println('reset successful') } </code></pre> <p>There are pros and cons to each solution. In the @TheDoctor solution, it seems like there is an edge cases where the Arduino is already sending when the client connects and you'll get some junk before the reset occurs.</p>
649
|interrupt|timers|
Two Timer Interrupts, One Incorrect?
2014-03-07T01:35:18.833
<p>I'm trying to replicate a waveform exactly using external and timing interrupts. I've got an external that's setup as a 0ms reference, TIMER1 which is used to determine on time, and TIMER2, which sets the low period. Unfortunately, I can't get the pin low for 2ms. TIMER2 must have something wrong with it, but I can't find it. Instead of banging my head against the wall, I thought I'd ask you guys. Anyone know the answer? </p> <pre><code>//3 is interrupt for Timing //4 through 11 are Time dependent receivers //3-11 Pins 12-19 //Current Serial Byte(Letter or Number) char incomingByte = 0; //Previous Byte in the Serial Chain char previousByte = 0; //Iterator for Interrupt Values volatile unsigned int maincount = 0; //Time of High Period or Timer Duration volatile unsigned int timerhigh; //Output Pin for Timer Waveform volatile unsigned int waveout; //Time for Timer Delay in milliseconds, default tim volatile unsigned int groundtime = 0; //Receiver Pins in an Array, except for 3, which serves as 0 source reference int pins[9] = { 3,4,5,6,7,8,9,10,11 }; void rising() { // set up Timer 1 TCCR1A = 0; // normal mode TCCR1B = bit(WGM12) | bit(CS11); // CTC, scale to clock / 8 OCR1A = timerhigh; // time before timer fires TIMSK1 = bit (OCIE1A); // interrupt on Compare A Match } //Sets Pin Low, then sets up another timer interrupt for the jump back to high ISR(TIMER1_COMPA_vect) { //Brings Pin Low for Keypress //Serial.println("We're in Timer 1"); pinMode(waveout,OUTPUT); digitalWrite(waveout, LOW); //Stop Timer 1 TCCR1B = 0; // stop timer TIMSK1 = 0; // cancel timer interrupt //Disables Interrupts Before Messing cli(); // set up Timer 2 TCCR2A = 0; // normal mode TCCR2B = 0; // TCCR2A = bit(WGM21) | bit(CS21); // CTC, scale to clock / 8 TCCR2A = (1 &lt;&lt; WGM21); //Enables CTC for timer TCCR2B = (1 &lt;&lt; CS21); //Sets 8 bit prescaler OCR2A = groundtime; // time before timer fires TIMSK2 = (1 &lt;&lt; OCIE2A); //Cancel Rising Interrupt on D3 EIFR = bit (INTF1); //Reenables interrupts sei(); } //Timer Interrupt for Low Period ISR(TIMER2_COMPA_vect) { //Serial.println("WE'RE IN TIMER2"); //Brings Output pin high digitalWrite(waveout, HIGH); //Stop Timer 2 TCCR2B = 0; // stop timer TIMSK2 = 0; // cancel timer interrupt //Cancel Rising Interrupt on D3 EIFR = bit (INTF1); } void setup() { // put your setup code here, to run once: //Sets all the pins for output use for(int i=0;i&lt;8;i++) { pinMode(pins[i], INPUT); } //Sets Reference Pin as Input pinMode(3,INPUT); //Begins Serial Serial.begin(115200); //Cancels Timer 1 TCCR1A = 0; // normal mode TCCR1B = 0; // stop timer TIMSK1 = 0; // cancel timer interrupt //Cancels Timer 2 TCCR2A = 0; TCCR2B = 0; // stop timer TIMSK2 = 0; // cancel timer interrupt detachInterrupt(1); } void loop() { //Time of Ground Drop(2 mS), Universal for all letters and offsets groundtime = 40000; // spark time (4000 * 500 nS) = 2 mS // because of prescaler of 8, each unit is 500 nS (0.5 µS) if(Serial.available()&gt; 0); { //Reads Serial Value and assigns to incomingByte incomingByte = Serial.read(); attachInterrupt(1,rising,RISING); } // noInterrupts (); // atomic change of the time amount //In this area, we'll set the output pin to be used by the timing interrupt, //and the time delay off the default waveform present on pin 4 //We can use switch case arrangement, don't know if that's the optimal setup though switch(incomingByte) { default: //Do Nothing break; //Cases FOR ALL THE LETTERS case 'a': break; case 'b': break; case 'c': break; case 'd': break; case 'e': break; case 'f': break; case 'g': break; case 'h': break; case 'i': break; case 'j': break; case 'k': break; case 'l': break; case 'm': break; case 'n': break; case 'o': break; case 'p': break; case 'q': break; case 'r': //Output pin 17 Frequency Pin 10 //microseconds timerhigh=8000; waveout=9; break; case 's': break; case 't': break; case 'u': break; case 'v': break; case 'w': break; case 'x': break; case 'y': break; case 'z': break; //Cases FOR ALL THE NUMBERS case '0': break; case '1': break; case '2': break; case '3': break; case '4': break; case '5': break; case '6': break; case '7': break; case '8': break; case '9': break; //Cases FOR ALL THE PUNCTUATION case '.': break; case ',': break; case '!': break; case '"': break; case '#': break; case '$': break; case '%': break; } //Enables Rising Interrupt for 0ms detection //attachInterrupt(1,rising,RISING); //Reenables interrupts after offset time change //interrupts (); } </code></pre>
<p>Turns out the problem was that timer 0 and 2 on the arduino uno are 8 bit. Set a different prescaler and I'm golden</p> <pre><code>// set up Timer 2 TCCR2A = 0; // normal mode TCCR2B = 0; // TCCR2A = bit(WGM21) | bit(CS21); // CTC, scale to clock / 8 TCCR2A = (1 &lt;&lt; WGM21); //Enables CTC for timer TCCR2B |= (1 &lt;&lt; CS21); TCCR2B |= (1 &lt;&lt; CS22); //Sets 256 bit prescaler TCCR2B |= (0 &lt;&lt; CS20); OCR2A = groundtime; // time before rising edge TIMSK2 = (1 &lt;&lt; OCIE2A); //Cancel Rising Interrupt on D3 EIFR = bit (INTF1); //Reinables interrupts </code></pre>
650
|arduino-uno|pins|
Have I fried my A2 port?
2014-03-07T06:34:12.020
<p>I'm playing around with a SparkFun Redboard (essentially, an Arduino UNO).</p> <p>I have a simple 5V sensor that I'd been trying to get to work with A2 and analogRead(). Nothing seemed to work. It's supposed to be cycling from 0 to 5V, which should give me values from 0 to 1023, and instead I get constant values of around 260.</p> <p>In desperation, I tried using other ports. On A0, A1, and A3 I get the signals I expect. On A2, still nada.</p> <p>So, the question. Is there something I could have done in configuring things that would have made A2 and only A2 stop reading correctly? If so, how can I reset it?</p> <p>Or is there some other function that I might be using that could interfere with A2? Currently, I'm only using Serial over USB - could that interfere with A2?</p> <p>Or could I simply have fried the port?</p>
<p>I wrote a simple program that used all six analog pins as digital outputs, and wired up an LED. All of the pins except A2 would blink the LED. So yes, it is fried. Thanks.</p>
658
|programming|c++|struct|class|
What overheads and other considerations are there when using a struct vs a class?
2014-03-07T12:29:32.300
<p>C on embedded systems has traditionally use structs to hold structured data.</p> <p>Arduino brings C++ to the table, so we can use classes instead.</p> <p>Lets say we have two different data structures which could be considered very similar:</p> <pre><code>typedef struct { int valueOne; int valueTwo; int valueThree; } value_t; </code></pre> <p>and:</p> <pre><code>class Value { public: int valueOne; int valueTwo; int valueThree; } </code></pre> <p>In terms of memory, what difference will this make? </p> <p>I still see the struct technique being used heavily - why is this?</p>
<blockquote> <p>In terms of memory, what difference will this make?</p> </blockquote> <p>None. Structs and classes are the same thing, differing only in protection levels, and instantiating either creates an 'object'.</p> <blockquote> <p>still see the struct technique being used heavily - why is this?</p> </blockquote> <p>Less typing if you're not trying to hide data members.</p>
665
|power|solar|
Powering Arduino with Solar Panels
2014-03-07T16:13:28.637
<p>Clearly, an Arduino can be powered with solar panels. </p> <ol> <li>What is the most optimal configuration? </li> <li>Can you recharge and discharge at the same time?</li> <li>Is LiPO the best battery cache technology, or is there something more durable out there, for fielded deployment?</li> <li>What are the most economic, and reliable ways to do this? </li> </ol>
<p>I would actually suggest LiFePo4 for anything DIY. Not only is it safer so one false move won't cause an inferno, but it will last two to four times as long at the CONST of a little extra size and weight.</p> <p>Since you are just running an arduino, I would use only 1 single cell, and avoid cell balance woes.</p> <p>I would use a boost regulator to step up the voltage from the cell to the required 5v.</p> <p>To actually charge the cell, I would probably use a cheap ebay CC-CV charger board, and set the voltage for about 0.15V below the max for your lifepo(you only lose 10% of the energy but You make the battery last much longer), and set the current as appropriate for your panel and battery.</p> <p>If your circuit is drawing power while the charger is charging, your circuit will take what it needs and any extra the charger puts out will go into the battery.</p> <p>You might need a diode, to make the battery not discharge back through the charger.</p> <p>Use a protection pcb like you can get from batteryspace, or better yet a protected lifepo with the pcb built it.</p> <p>Remember to size your solar panel so that there is enough energy to keep the circuit running. Even with the protected cells overdischarge kills.</p> <p>What I'd really like to do is design a lifepo4 charge control board that had all this in one unit since everyone seems to want it...</p>
672
|programming|led|arduino-nano|
Arduino LED matrix and 2D array, data seems to be corrupting
2014-03-08T04:04:14.447
<p>Duplicate of <a href="https://electronics.stackexchange.com/q/102224/38392">this question</a></p> <p>I'm trying to drive an 8x8 LED matrix with an arduino nano, but I can't get the LEDs to display what I tell it to.</p> <p>I'm using <a href="http://www.aliexpress.com/store/product/Free-shipping-10-pcs-8-8-3-75MM-Red-16P-dot-matrix-module-Dimensions-38-38/605870_879542981.html" rel="nofollow noreferrer">this</a> LED Matrix</p> <p>Here's my code:</p> <pre class="lang-cpp prettyprint-override"><code>int row1 = 2; int row2 = 3; int row3 = 4; int row4 = 5; int row5 = 6; int row6 = 7; int row7 = 8; int row8 = 9; int col1 = 10; int col2 = 11; int col3 = 12; int col4 = 18; int col5 = 14; int col6 = 15; int col7 = 16; int col8 = 17; void setup() { int i; for(i = 2; i &lt;= 18; i++) { pinMode(i,OUTPUT); } for(i = 2; i &lt;= 9; i++) { digitalWrite(i, HIGH); } } void loop() { int display [8][8] = { {1,0,0,0,0,0,0,0}, {0,1,0,0,0,0,0,0}, {0,0,1,0,0,0,0,0}, {0,0,0,1,0,0,0,0}, {0,0,0,0,1,0,0,0}, {0,0,0,0,0,1,0,0}, {0,0,0,0,0,0,1,0}, {0,0,0,0,0,0,0,1} }; updateScreen(display); } void updateScreen(int screen[8][8]) { Serial.begin(9600); int i; for (i = row1; i &lt;= row8; i++) { Serial.println(i-1); digitalWrite(i, LOW); digitalWrite(col8, screen[i-2][0]); Serial.print(screen[i-2][0]); Serial.print("|"); digitalWrite(col7, screen[i-2][1]); Serial.print(screen[i-2][1]); Serial.print("|"); digitalWrite(col6, screen[i-2][2]); Serial.print(screen[i-2][2]); Serial.print("|"); digitalWrite(col5, screen[i-2][3]); Serial.print(screen[i-2][3]); Serial.print("|"); digitalWrite(col4, screen[i-2][4]); Serial.print(screen[i-2][4]); Serial.print("|"); digitalWrite(col3, screen[i-2][5]); Serial.print(screen[i-2][5]); Serial.print("|"); digitalWrite(col2, screen[i-2][6]); Serial.print(screen[i-2][6]); Serial.print("|"); digitalWrite(col1, screen[i-2][7]); Serial.println(screen[i-2][7]); delay(1); blank(); digitalWrite(i, HIGH); } } void blank() { digitalWrite(col1, LOW); digitalWrite(col2, LOW); digitalWrite(col3, LOW); digitalWrite(col4, LOW); digitalWrite(col5, LOW); digitalWrite(col6, LOW); digitalWrite(col7, LOW); digitalWrite(col8, LOW); } </code></pre> <p>And here is the output:</p> <pre class="lang-cpp prettyprint-override"><code>1 1|0|0|0|0|0|0|0 2 0|1|0|0|0|0|0|0 3 0|0|1|0|0|0|0|0 4 0|0|0|1|0|0|0|0 5 0|0|0|0|1|0|0¾j 6 0|0|0|0|0|1|0|0 7 0|0|0|0|0|0|1|0 8 0|0|0|0|0|0|0|1 </code></pre> <p>So I can tell that the error (probably) isn't my wiring, because those array values are clearly wrong, I have no idea where the <code>¾j</code> is coming from.</p>
<p>Because of my psychic abilities*, I am able to tell that you actually used <code>.</code> in a few places you should have used <code>,</code> in your array initialization. Replacing the <code>,</code>s with <code>.</code>s should fix the problem.</p> <p><sup><sup>*<a href="https://arduino.stackexchange.com/questions/672/arduino-led-matrix-and-2d-array-data-seems-to-be-corrupting#comment1193_672">Okay, okay, not really.</a></sup></sup></p>
678
|relay|transistor|
Connecting Something Big to an Arduino - Sending more than 5V
2014-03-02T13:13:16.097
<p>So I am turning a relay on and off with my Arduino. I am using python to control it but wrote the simple basic code in the Arduino IDE. I am able to send 5 or 0 volts to the pin. My question is, how can I turn something on and off that requires more than 5 volts to turn on?</p> <p>Thank you. </p>
<p>Use a transistor, amplifier, opto-isolator or if you can drive a 5V relay use that relay to drive a higher voltage/current item item.</p>
702
|uploading|voltage-level|isp|
How to use a Pololu 5v AVR ISP Programmer to program an AVR at 3.3v
2014-03-10T23:01:37.753
<p>I have a <a href="http://www.pololu.com/product/1300" rel="nofollow">Pololu 5v AVR ISP</a> which I have successfully used to program several Arduinos (a Mega, an Uno and a Pro Mini 5v). I now have a new Arduino compatible clone which is basically a clone of the pro mini 3.3V.</p> <p>I am wondering if anyone else has used this programmer to program a 3.3V board without issues. I've seen a forum post on <a href="http://forum.pololu.com/viewtopic.php?f=3&amp;t=7368" rel="nofollow">pololu's forum</a> which discusses modifications required - but I don't really understand what is necessary.</p> <p>I've also found the software tool mentioned in the above forum post <a href="http://www.pololu.com/docs/0J41" rel="nofollow">here</a> and I have downloaded it and built it.</p> <p>When I run the aforementioned tool I get these options:</p> <pre><code>PgmCmd: Configuration and status utility for the Pololu USB AVR Programmer. Version: 1.0.1.0 Options: -l, --list list available devices -d, --device SERIALNUM (optional) select device with given serial number -s, --status display complete device status --freq NUM sets the ISP frequency (in units of kHz) --linea ID or --lineb ID set serial control signal associated with line A or B. Valid IDs are: none, cd, dsr, ri, dtr, rts. Warning: dtr and rts are outputs: -f option is required --swminor HEXNUM AVR ISP software version minor (in hex, e.g. A) --swmajor HEXNUM AVR ISP software version major (in hex) --hw HEXNUM AVR ISP software hardware version (in hex) --vddmin NUM set minimum allowed target vdd (units of mV) --vddmaxrange NUM set maximum allowed target vdd range (units of mV) --restoredefaults restore factory settings --bootloader put device in to bootloader (firmware upgrade) mode </code></pre> <p>I then ran the --status option with the serial number of my programmer and got this:</p> <pre><code>Serial number: 00048632 Firmware version: 1.07 Settings: ISP Frequency: 200 kHz Line A Identity: None Line B Identity: None AVR ISP hardware version: F AVR ISP software version: 2.A Target VDD allowed minimum: 4384 mV Target VDD allowed max range: 512 mV Last programming: Error: None Measured Target VDD Minimum: N/A Measured Target VDD Range: N/A SLO-scope: State: Off Line A output: Off Line B output: Off </code></pre> <p>From this I deduced that my programmer is currently set at between about 4.38V and 4.89V which I presume corresponds to the 5V approximate voltage of the normal Arduino chips.</p> <p>Given that the utility program allows me to set both the target minimum V<sub>dd</sub> and the target V<sub>dd</sub> max range should I therefore set it to something like a minimum of 2704 with a max range of 512 which should put the signal voltages at up to ~3.2V.</p> <p>Is that all I have to do to get this to work?</p>
<p>Since AVR ISP is simply a modified form of SPI, the most universal way to handle this is to use a 3/1 level translator such as the <a href="http://www.maximintegrated.com/datasheet/index.mvp/id/3253" rel="nofollow">MAX3392E</a>. Once you provide it with 5V on V<sub>CC</sub> and 3V3 on V<sub>L</sub> it will translate the MOSI, SCK, and nRESET signals to 3V3 and the MISO signal to 5V.</p>
724
|programming|
Attiny84 and 2-Axis Joystick
2014-03-13T01:36:25.043
<p>I have a <a href="http://www.radioshack.com/product/index.jsp?productId=12345958" rel="nofollow">Parallax 27800 2-Axis Joystick</a> wired up to a <a href="https://www.sparkfun.com/products/11232" rel="nofollow">AVR 14 Pin 20MHz 8K 12A/D - ATtiny84</a>. The joy stick sends out a x y analog signal. I have programmed the Attiny84 to read the signals and set one of the attiny84 pins (high or low) depending on the direction of the joystick. In this example, each pin is wired up to a LED. The problem I am having is there is about a 1 second delay for the LED to light. The Attiny84 has a built in 8MHz clock. Would connecting an external 20MHz crystal fix this issue?</p> <pre><code>int UD = 0; int LR = 0; int DWN = 0; int UP = 1; int LEFT = 4; int RT = 5; int LRMID = 0; int UPMID = 0; void setup(){ pinMode(DWN, OUTPUT); pinMode(UP, OUTPUT); pinMode(LEFT, OUTPUT); pinMode(RT, OUTPUT); digitalWrite(DWN, LOW); digitalWrite(UP, LOW); digitalWrite(LEFT, LOW); digitalWrite(RT, LOW); //calabrate center LRMID = analogRead(3); UPMID = analogRead(2); } void loop(){ UD = analogRead(2); LR = analogRead(3); // UP-DOWN if(UD &lt; UPMID - 5){ digitalWrite(DWN, HIGH); }else{ digitalWrite(DWN, LOW); } if(UD &gt; UPMID + 5){ digitalWrite(UP, HIGH); }else{ digitalWrite(UP, LOW); } // LEFT-RIGHT if(LR &lt; LRMID-5){ digitalWrite(LEFT, HIGH); }else{ digitalWrite(LEFT, LOW); } if(LR &gt; LRMID +5){ digitalWrite(RT, HIGH); }else{ digitalWrite(RT, LOW); } delay(100); } </code></pre>
<p>While @alexan_e’s suggestion fixed your practical problem, I would argue that it did not address your root cause, which is that whatever board setting you’re working from in boards.txt assumes a clock rate of 8MHz, while in reality your fuses are set to boot the microcontroller at 1MHz. This caused your delay(100) to take 800ms, and was the entire reason for the slowdown. </p> <p>Instead of fixing this at runtime, as aleman_e suggested, it seems more natural to me to bring your fuse settings into alignment with your compiler settings, using the “burn boot loader” Arduino command (which on Attinys generally does NOT burn a boot loader, but only sets the fuses to be in sync with the compiler settings).</p> <p>If your application is not going to become much more complex, running at 1MHz might be a more efficient choice than running at 8MHz. </p>
725
|battery|
Bootup on lower power not functioning
2014-03-13T02:17:11.663
<p>I have a custom Arduino ATMega328 board that generally runs at 5V @ 8MHz (using the Arduino Pro 3.3V 8MHz profile and bootloader). The main reason I'm using this setup is so that I can put the board to sleep when main power is disconnected and it starts being run off of battery power (3V from a coin cell). The 5V and 3V sources are diode OR'ed together and the 5V input is tied to INT0. In code, when it detects that INT0 has fallen low, it initializes sleep mode and everything powers down with the exception of the watchdog timer that keeps a 1Hz cycle to keep an internal count and check it the chip should be woken back up. This works <em>beautifully</em> when 5V power is applied first, then the battery is inserted, <em>then</em> 5V is disconnected. It goes to sleep and when 5V is brought back it wakes up and I can see it hasn't lost count.</p> <p>However, the problem comes when 3V is applied <em>first</em>. I'm honestly not sure if it's even booting. But what it is supposed to do is boot, check if INT0 (Digital 2) is low and, if so, go right to sleep. By watching the current draw I see that it powers up to a few mA for a couple seconds, then drops to about 0.3mA (still higher than it should be in sleep mode). But when I re-apply 5V, <em>nothing</em>. The power draw goes back up but it is unresponsive (over FTDI serial).</p> <p>Is there maybe something I'm missing that it can't be booted on 3V... in theory it should run just fine. </p> <p><strong>Update:</strong> I dropped an LED onto D13 and tried the blink sketch. Works fine when starting from 3V or 5V. However, when I run my firmware and start it from 3V, the LED just starts flashing wildly. I have no idea what's causing it since I never even setup D13 as anything in my code. But it makes me thing it's something to do with the bootloader...</p>
<p>So... turned out what was happening was all in code. Turns out that I was initializing an interrupt on INT0, when it was low, at the very beginning of my code. Problem was that when it started up on 3V backup power, INT0 was always low because INT0 is tied to the 5V line (it's how it knows to go to sleep). Because INT0 was low and the interrupt was triggering on low it was causing a constant interrupt to occur, never giving the rest of the program any time to run. Switched to enabling that interrupt only once I've entered full waking mode and it works fine now.</p>
736
|programming|led|
Digital RGB LED animation
2014-03-14T10:41:10.037
<p>I've been trying to get colours fade into each other for a project I'm working on. I have achieved this with the rainbow effect that some from Adafruit's example code, however I want to be able to choose the colours (eg. dark blue into light blue).</p> <p>I've got the colours changing and fading, however the fade turns off all the LEDs and starts to increase the brightness of the new colour. I need the colours to blend rather than fade out and increase in brightness.</p> <p>Is anyone able to point me in the right direction?</p> <pre><code>#include "LPD8806.h" #include "SPI.h" #define stripSize 64 int nLEDs = 160; int dataPin = 2; int clockPin = 3; // First parameter is the number of LEDs in the strand. The LED strips // are 32 LEDs per meter but you can extend or cut the strip. Next two // parameters are SPI data and clock pins: LPD8806 strip = LPD8806(64, dataPin, clockPin); // You can optionally use hardware SPI for faster writes, just leave out // the data and clock pin parameters. But this does limit use to very // specific pins on the Arduino. For "classic" Arduinos (Uno, Duemilanove, // etc.), data = pin 11, clock = pin 13. For Arduino Mega, data = pin 51, // clock = pin 52. For 32u4 Breakout Board+ and Teensy, data = pin B2, // clock = pin B1. For Leonardo, this can ONLY be done on the ICSP pins. //LPD8806 strip = LPD8806(nLEDs); void setup() { // Start up the LED strip strip.begin(); // Update the strip, to start they are all 'off' strip.show(); } void loop() { //turnAllOn(strip.Color(30,30,30),4000); fade(0, 127, 0, 100); //red, green, blue, delay - fade up all pixels one color //turnAllOn(strip.Color(30,100,30),4000); fade(50, 127, 02,100); //red, green, blue, delay - fade up all pixels one color //turnAllOn(strip.Color(100,30,100),4000); fade(50, 127, 50, 100); //red, green, blue, delay - fade up all pixels one color } void fade(uint32_t r, uint32_t g, uint32_t b, uint32_t wait) { int i, j; for (j=0; j &lt; 384; j++) { for (i=0; i &lt; strip.numPixels(); i++) { strip.setPixelColor(i, strip.Color((r*j)/1000,(g*j)/1000,(b*j)/1000)); } strip.show(); } delay(wait); } void turnAllOn(uint32_t c, uint32_t wait) { int i; for (i=0; i &lt; strip.numPixels(); i++) { strip.setPixelColor(i, c); // turn all pixels on } strip.show(); // write all the pixels out delay(wait); } uint32_t Wheel(uint16_t WheelPos) { byte r, g, b; switch(WheelPos / 128) { case 0: r = 127 - WheelPos % 128; //Red down g = WheelPos % 128; // Green up b = 0; //blue off break; case 1: g = 127 - WheelPos % 128; //green down b = WheelPos % 128; //blue up r = 0; //red off break; case 2: b = 127 - WheelPos % 128; //blue down r = WheelPos % 128; //red up g = 0; //green off break; } return(strip.Color(r,g,b)); } </code></pre>
<p>Currently, your fade function is starting at 0 and effectively interpolating up to the desired colour. To fade between colours, you would need the sketch to remember the previous colour it used, and start fading from that instead of from 0.</p> <p>The approach I'd use is to start by calculating how much each component needs to change by on each step. For example, if you want to fade from 100 to 200 across 50 steps, then it needs to change by +2 on every step. If you wanted to do the same in reverse (200 to 100) then it would have to change by -2.</p> <p>One of the problems is that each component will probably be changing by a different amount (red might go from 0 to 200, but blue might only go from 50 to 70). If you're using integers all the time then it could result in some uneven transitions, so I'd recommend using floating point instead. It's technically slower (less efficient), but probably not enough to worry about.</p> <p>This is how I'd probably write it:</p> <pre><code>void fade(uint8_t oldR, uint8_t oldG, uint8_t oldB, uint8_t newR, uint8_t newG, uint8_t newB, uint32_t numSteps, uint32_t waitPerStep) { // Guard against division by zero if (numSteps == 0) numSteps = 1; // Calculate how how much each colour needs to change on each step const float stepR = (newR - oldR) / (float)numSteps, stepG = (newG - oldG) / (float)numSteps, stepB = (newB - oldB) / (float)numSteps; // These values will store our colours on the way along float r = oldR, g = oldG, b = oldB; uint8_t byteR = oldR, byteG = oldG, byteB = oldB; // Go through each fade step const uint16_t numPixels = strip.numPixels(); for (uint32_t step = 0; step &lt; numSteps; ++step) { // Move one step towards the target colour r += stepR; g += stepG; b += stepB; // Round the colours to integers here so we don't have to do it repeatedly in the loop below byteR = (uint8_t)(r + 0.5f); byteG = (uint8_t)(g + 0.5f); byteB = (uint8_t)(b + 0.5f); // Apply the colour to each pixel for (uint16_t pixel = 0; pixel &lt; numPixels; ++pixel) { strip.setPixelColor(pixel, byteR, byteG, byteB); } strip.show(); delay(waitPerStep); } } </code></pre> <p>As you can see, you pass it the old colour (which you're fading <em>from</em>) and the new colour (which you're fading <em>to</em>). As I mentioned above, this means your sketch has to remember which colour it previously used, as I don't think the library provides a way to read the current colour back.</p> <p>I've included some optimisations in there to make it run faster. There's more you could do to optimise it even further, if necessary.</p> <p>To use this, you'd do something like this:</p> <pre><code>// Fade from black to red and pause briefly fade(0, 0, 0, 255, 0, 0, 100, 10); delay(500); // Fade from red to purple and pause briefly fade(255, 0, 0, 255, 0, 255, 100, 10); delay(500); // Fade from purple to green and pause briefly fade(255, 0, 255, 0, 255, 0, 100, 10); delay(500); </code></pre> <p>I've made a couple of other changes compared to your own fade function function. First of all, I've made it so that you can set the number of steps to fade over. This can be quite useful because bigger colour changes will need more steps to look smooth.</p> <p>I've also modified the <code>wait</code> parameter. In your code, you put the delay after the entire fade was complete, which seems like an odd approach. It makes more sense to allow a small delay between each step of the fade, so you can control how fast it goes.</p> <p>In my example above, you can see the <code>100, 10</code> parameters at the end of each call to <code>fade()</code>. That means it will divide the colour change into 100 steps, with a delay of 10ms between each step. The result is that each fade will take roughly 1 second (not counting the time taken to actually update the LED strip).</p>
744
|library|sketch|
Arduino error message that I don't understand
2014-03-15T19:33:42.287
<p>I downloaded Arduino code from this: <a href="https://github.com/BabyWrassler/MissionControl/" rel="nofollow">https://github.com/BabyWrassler/MissionControl/</a> Github, and got the error message below.</p> <p>It is designed to work with a Raspberry Pi, and I installed the two Adafruit libraries. I also have not hooked it up to either the Pi, or the two Adafruit devices, but that is partly because I cannot get it to run without the error message.</p> <p>Update: Here is what was highlighted: <code>Adafruit_LEDBackpack matrixA = Adafruit_LEDBackpack();</code> The orange bar says: Variable or field ‘matrixOff‘ declared void I cannot tell what of the following was from before, but here is the entire console log:</p> <pre><code> mcDesk.ino:2:53: error: Adafruit_LEDBackpack.h: No such file or directory mcDesk.ino:3:45: error: Adafruit_GFX.h: No such file or directory mcDesk:11: error: variable or field 'matrixOff' declared void mcDesk:11: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:11: error: expected primary-expression before 'buffer' mcDesk:12: error: variable or field 'ledOn' declared void mcDesk:12: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:12: error: expected primary-expression before 'buffer' mcDesk:12: error: expected primary-expression before 'cat' mcDesk:12: error: expected primary-expression before 'an' mcDesk:13: error: variable or field 'ledOff' declared void mcDesk:13: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:13: error: expected primary-expression before 'buffer' mcDesk:13: error: expected primary-expression before 'cat' mcDesk:13: error: expected primary-expression before 'an' mcDesk:14: error: variable or field 'dispMat' declared void mcDesk:14: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:14: error: expected primary-expression before 'buffer' mcDesk:17: error: variable or field 'threeDigitDisp' declared void mcDesk:17: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:17: error: expected primary-expression before 'buffer' mcDesk:17: error: expected primary-expression before 'cats' mcDesk:17: error: expected primary-expression before 'ans' mcDesk:17: error: expected primary-expression before 'number' mcDesk:18: error: variable or field 'digitDisp' declared void mcDesk:18: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:18: error: expected primary-expression before 'buffer' mcDesk:18: error: expected primary-expression before 'pos' mcDesk:18: error: expected primary-expression before 'cat' mcDesk:18: error: expected primary-expression before 'an' mcDesk:18: error: expected primary-expression before 'num' mcDesk:23: error: variable or field 'switchBars' declared void mcDesk:23: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:23: error: expected primary-expression before 'buffer' mcDesk:23: error: expected primary-expression before 'grphCats' mcDesk:23: error: expected primary-expression before 'grphAns' mcDesk:23: error: expected primary-expression before 'cmnd' mcDesk:23: error: expected primary-expression before 'offset' mcDesk:24: error: variable or field 'barDisp' declared void mcDesk:24: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:24: error: expected primary-expression before 'buffer' mcDesk:24: error: expected primary-expression before 'grphCats' mcDesk:24: error: expected primary-expression before 'grphAns' mcDesk:24: error: expected primary-expression before 'pos' mcDesk:24: error: expected primary-expression before 'offset' mcDesk:25: error: variable or field 'cBarDisp' declared void mcDesk:25: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:25: error: expected primary-expression before 'buffer' mcDesk:25: error: expected primary-expression before 'grphCats' mcDesk:25: error: expected primary-expression before 'grphAns' mcDesk:25: error: expected primary-expression before 'pos' mcDesk:25: error: expected primary-expression before 'offset' mcDesk:11: error: 'Adafruit_LEDBackpack' does not name a type mcDesk:12: error: 'Adafruit_LEDBackpack' does not name a type mcDesk:13: error: 'Adafruit_LEDBackpack' does not name a type mcDesk:14: error: 'Adafruit_LEDBackpack' does not name a type mcDesk:15: error: 'Adafruit_LEDBackpack' does not name a type mcDesk.ino: In function 'void decodeCommand()': mcDesk:193: error: 'matrixE' was not declared in this scope mcDesk:193: error: 'ledOn' was not declared in this scope mcDesk:199: error: 'matrixE' was not declared in this scope mcDesk:199: error: 'ledOff' was not declared in this scope mcDesk:204: error: 'matrixC' was not declared in this scope mcDesk:204: error: 'cBarDisp' was not declared in this scope mcDesk.ino: In function 'void allMatrixOff()': mcDesk:213: error: 'matrixA' was not declared in this scope mcDesk:213: error: 'matrixOff' was not declared in this scope mcDesk:214: error: 'matrixB' was not declared in this scope mcDesk:215: error: 'matrixC' was not declared in this scope mcDesk:216: error: 'matrixD' was not declared in this scope mcDesk:217: error: 'matrixE' was not declared in this scope mcDesk.ino: At global scope: mcDesk:220: error: variable or field 'matrixOff' declared void mcDesk:220: error: 'Adafruit_LEDBackpack' was not declared in this scope mcDesk:220: error: expected primary-expression before 'buffer' </code></pre>
<p>It seems to me that those Adafruit libraries were not correctly installed on your PC or your sketch.</p> <p>In addition to downloading and installing the library onto the Arduino library directory (on Windows, that's normally <code>C:\Users\UserName\Documents\Arduino\libraries</code>), when you want to use that library with Arduino IDE, you must add the library for your sketch with the menu command "<strong>Sketch -> Import Library...</strong>"</p> <p><strong>Important note</strong>: it seems just adding <code>#include "library.h"</code> does not work with Arduino IDE, you absolutely need to use the menu.</p>
750
|clones|voltage-level|arduino-pro-mini|
Arduino Pro Mini (3.3V version) input voltage range / tolerance
2014-03-16T01:33:14.700
<p>I have a few Arduino Pro Mini clones (cheap Chinese stuff) and would like to power them with 12V power supply (same as fan voltage). According to the <a href="http://arduino.cc/en/Main/ArduinoBoardProMini#.UyT9APl_sz0">Arduino Pro Mini spec</a> the RAW pin can take 3.35-12V (3.3V model). In practice this means a 12V PSU cannot be used as they are almost always over 12V with low load. I read that the voltage regulator in this board is capable up to 16V input. I tried plugging in a cheap 12V power adapter that read 15.1V with no load but a component on the arduino clone board actually exploded instantly. The board seems to work still when powered from usb programmer. Component that burned out is just above VCC, RST and GND pins.</p> <p>Why did this happen? What did I just damage and most importantly what is a safe voltage level to use? I already have a few 12V switching power supplies it would be a shame if I could not use them.</p> <p>Solution:</p> <p>In the end it seems to have been a faulty arduino clone, faulty or poor quality power adapter or the fact that I powered the power supply before plugging it to the board's RAW input pin. The cheap 12V switching power supplies work just fine even though my multimeter registers a voltage spike as high as 30V during power up.</p>
<p>Although this thread is old, people has to be aware that some clone boards uses 4B2X regulator and they support maximum 10v (<a href="https://epstik.com/p744820729-xc6204b332mr-4b2x-stabilizator.html" rel="nofollow noreferrer">https://epstik.com/p744820729-xc6204b332mr-4b2x-stabilizator.html</a> , <a href="https://www.mcucity.com/product/3240/xc6204b332mr-g-3-3v-4b2x-4b2y-positive-voltage-regulator" rel="nofollow noreferrer">https://www.mcucity.com/product/3240/xc6204b332mr-g-3-3v-4b2x-4b2y-positive-voltage-regulator</a>). Theses clones are extremely common on ebay and another marketplaces.</p>
759
|battery|system-design|
Most power efficient way to constantly save 2 kilobytes of data per second
2014-03-16T13:54:12.883
<p>I would like to constantly save data coming from sensors (for an activity tracker) while consuming as less battery as possible (I'd like to have a 4/5 days autonomy on a 3000 mAh battery) but I can't find the best way to save about 2 kBytes/s on a memory large enough to contain several days of data.</p> <p>Sensors would be read at a rate of 20 times per second and produce about 100 bytes each time.</p> <p>What options do I have in order to:</p> <ul> <li>store such an amount of data (hardware)?</li> <li>ensure the system can work properly with required autonomy?</li> </ul>
<p>There are two constraints here, and I think it might back you into a corner. Size and then power.</p> <p>2Kbyte/s is 2*60*60*24/1024 = 168.75Mbyte/day. This is a lot. The only readily available technology that can be used with a small microprocessor that can store this volume of data is an SD card. There are no serial EEPROM or flash chips this large, and the Arduino, as far as I know, can't deal with the NAND flash used in USB sticks and SD cards.</p> <p>However, SD cards can be relatively power hungry. They draw between 5mA and 100mA when writing, typically around 30-50mA. The SD spec says the maximum is 200mA. Writing is also quite lengthy as they operate on blocks of data rather than individual cells. I've never done a full analysis of how much power they use, but it is not insignificant and much, much more than serial EEPROM or flash.</p> <p>So your only choice, if you have to store that much, is to go with SD cards.</p> <p>I would investigate compressing the data. Even very basic schemes can make a huge difference.</p>
763
|sram|
I'm using too much RAM. How can this be measured?
2014-03-16T15:00:54.307
<p>I would like to know how much RAM I am using in my project, as far as I can tell, there's no way to actually work that out (other than going through and calculating it myself). I have got to a stage in a rather large project where I have determined that I am running out of RAM. </p> <p>I have determined this because I can add a section and then all hell breaks loose <strong>somewhere else in my code</strong> for no apparent reason. If I <code>#ifndef</code> something else out, it works again. There is nothing programatically wrong with the new code. </p> <p>I suspected for a while that I was getting to the end of available RAM. I don't think I'm using too much stack (although it's possible), what is the best way to determine how much RAM I am actually using?</p> <p>Going through and trying to work it out, I have problems when I get to enums and structs; how much memory do they cost? </p> <p><em>first</em> edit: ALSO, I have edited my sketch so much since starting, these are not the actual results I initially got, but they are what I am getting now. </p> <pre><code> text data bss dec hex filename 17554 844 449 18847 499f HA15_20140317w.cpp.elf 16316 694 409 17419 440b HA15_20140317w.cpp.elf 17346 790 426 18562 4882 HA15_20140317w.cpp.elf </code></pre> <p>The first line (with text 17554) was not working, after much editing, the second line (with text 16316) is working as it should. </p> <p><em>edit: the third line has everything working, serial reading, my new functions, etc. I essentially removed some global variables and duplicate code. I mention this because (as suspected) it's not about this code per sae, it has to be about the RAM usage. Which brings me back to the original question, "how to best measure it" I'm still checking out some answers, thanks.</em></p> <p>How do I actually interpret the above information? </p> <p>So far my understanding is: </p> <pre><code>`TEXT` is program instruction memory `DATA` is variables (unitialised?) in program memory `BSS` is variables occupying RAM </code></pre> <p>since BSS is considerably less than 1024 bytes, why does the second work, but the first doesn't? If it's <code>DATA+BSS</code> then both occupy more than 1024. </p> <p><strong><em>re-edit:</em> I edited the question to include the code, but now I've removed it because it really had nothing to do with the problem (other than maybe poor coding practices, variable declarations and the like). You can review the code by looking back through the edits if you <em>really</em> want to see it. I wanted to get back to the question at hand, which was more based around: How to measure RAM usage.</strong></p>
<p>There is a program called <a href="http://arduinodev.com/arduino-uploader/" rel="nofollow noreferrer">Arduino Builder</a> that provides a neat visualization of the amount of flash, SRAM and EEPROM your program is using.</p> <p><a href="https://i.stack.imgur.com/rwDID.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/rwDID.png" alt="Arduino Builder"></a> </p> <p>The Arduino builder makes up part of the <a href="http://arduinodev.com/codeblocks/" rel="nofollow noreferrer">CodeBlocks Arduino IDE</a> solution. It can be used as either a standalone program or through the CodeBlocks Arduino IDE.</p> <p>Unfortunately Arduino Builder is a little <a href="http://arduinodev.com/arduino-builder-updated/" rel="nofollow noreferrer">old</a> but it should work for most programs and most Arduinos, such as the Uno.</p>
771
|arduino-uno|progmem|
Unrecognizable Message From PROGMEM char*
2014-03-16T18:30:53.387
<p>I'm using a PROGMEM char* to store a massive array. When I try to print a certain part of the array, the message comes out mangled. How do I fix this?</p> <p>The output should be "Poliwag", but it comes out as "arow".</p> <pre class="lang-c prettyprint-override"><code>#include &lt;TrueRandom.h&gt; #include &lt;EEPROM.h&gt; #define numPokemon 151 PROGMEM char* nameArray[] = {"MISSINGNO","Bulbasaur","Ivysaur","Venusaur","Charmander","Charmeleon","Charizard","Squirtle", "Wartortle","Blastoise","Caterpie","Metapod","Butterfree","Weedle","Kakuna","Beedrill","Pidgey","Pidgeotto", "Pidgeot","Rattata","Raticate","Spearow","Fearow","Ekans","Arbok","Pikachu","Raichu","Sandshrew","Sandslash", "Nidoran♀","Nidorina","Nidoqueen","Nidoran♂","Nidorino","Nidoking","Clefairy","Clefable","Vulpix","Ninetales","Jigglypuff", "Wigglytuff","Zubat","Golbat","Oddish","Gloom","Vileplume","Paras","Parasect","Venonat","Venomoth","Diglett","Dugtrio","Meowth", "Persian","Psyduck","Golduck","Mankey","Primeape","Growlithe","Arcanine","Poliwag","Poliwhirl","Poliwrath","Abra","Kadabra","Alakazam", "Machop","Machoke","Machamp","Bellsprout","Weepinbell","Victreebel","Tentacool","Tentacruel","Geodude","Graveler","Golem","Ponyta","Rapidash", "Slowpoke","Slowbro","Magnemite","Magneton","Farfetch`d","Doduo","Dodrio","Seel","Dewgong","Grimer","Muk","Shellder","Cloyster","Gastly","Haunter", "Gengar","Onix","Drowzee","Hypno","Krabby","Kingler","Voltorb","Electrode","Exeggcute","Exeggutor","Cubone","Marowak","Hitmonlee","Hitmonchan","Lickitung", "Koffing","Weezing","Rhyhorn","Rhydon","Chansey","Tangela","Kangaskhan","Horsea","Seadra","Goldeen","Seaking","Staryu","Starmie","Mr. Mime","Scyther","Jynx", "Electabuzz","Magmar","Pinsir","Tauros","Magikarp","Gyarados","Lapras","Ditto","Eevee","Vaporeon","Jolteon","Flareon","Porygon","Omanyte","Omastar","Kabuto","Kabutops", "Aerodactyl","Snorlax","Articuno","Zapdos","Moltres","Dratini","Dragonair","Dragonite","Mewtwo","Mew" }; int a = 0; int b = 0; int value; String pokemonName = "Missingno"; int currentID = TrueRandom.random(1,numPokemon+1); // a = CurrentID void setup(){ Serial.begin(9600); if (EEPROM.read(a)!=0){ currentID = EEPROM.read(a); Serial.print("The Stored ID is "); Serial.println(EEPROM.read(a)); Serial.println("Stored = true"); }else{ value = EEPROM.read(a); Serial.println(value); EEPROM.write(a,currentID); value = EEPROM.read(a); Serial.println(value); Serial.println("Stored = false"); } pokemonName = nameArray[currentID]; Serial.println(pokemonName); } void loop(){ } </code></pre>
<p>The way you've written in, the <em>pointer</em> is stored in flash, but the strings are stored in <em>SRAM</em>. Read <a href="http://www.nongnu.org/avr-libc/user-manual/pgmspace.html">the appropriate documentation</a> (also found in the <a href="http://arduino.cc/en/Reference/PROGMEM">Arduino reference</a>) more closely, and do as it says.</p> <pre><code>char nmPokemon0[] PROGMEM = "MISSINGNO"; char nmPokemon1[] PROGMEM = "Bulbasaur"; ... PGM_P nameArray[] PROGMEM = { nmPokemon0, nmPokemon1, ... }; </code></pre> <p>And don't forget to copy the string to SRAM as shown further down before outputting it, since <code>Serial.println()</code> can't work directly with flash.</p>
775
|arduino-uno|progmem|
PROGMEM char* mangled text
2014-03-16T22:30:21.940
<p>I wrote a program using PROGMEM for massive string arrays. One of the arrays worked, but when I added the second one, the serial output only puts out "th".</p> <p>Pastebin Code: <a href="http://pastebin.com/9U7QZQKn" rel="nofollow">http://pastebin.com/9U7QZQKn</a></p>
<p>I see one major flaw in your code, related to index usage on arrays.</p> <p>Arrays in C and C++ are using a <strong>0-based index</strong>, meaning that, for an array containing <code>N</code> elements:</p> <ul> <li>the first element is accessible with index <code>0</code></li> <li>the last element is accessible with index <code>(N-1)</code></li> </ul> <p>However, your code uses <code>TrueRandom.random(1,numPokemon+1);</code> which means you'll get an index between <code>1</code> and <code>numPokemon</code> (included), if you get the <code>numPokemon</code> value for your index, then you'll get garbage as it will try access some other part of memory.</p> <p>Maybe that is not the only problem in your code, but this one is a major bug.</p>
779
|arduino-uno|safety|uploading|atmega328|oscillator-clock|
Can I program a 3.3v chip on a 5v board?
2014-03-17T11:16:07.667
<p>I bought a Gertboard a while ago, and one of the features it has on-board is an ATMega328 (DIP). However, since the Gertboard is designed for use with the Raspberry Pi, it only operates at 3.3v, so the clock speed is limited to ~12MHz.</p> <p>Programming it via the Raspberry Pi is quite cumbersome though. Instead, I'd like to transfer the chip to an Arduino Uno board so I can upload sketches from my desktop PC. I would then transfer it back to the Gertboard for normal operation.</p> <p>The problem is that my Uno operates at the more typical 5v / 16MHz.</p> <p>Is it safe to attempt this? Do I need to make any configuration changes in the IDE to tell it to account for a different clock speed?</p>
<p>The clock speed selected will affect both <code>delay*()</code> and <code>millis()</code>/<code>micros()</code> as well as the functions in <code>&lt;util/delay.h&gt;</code>, therefore you <em>must</em> use the target system's correct clock speed if you are using any of these functions. This can be easily done by editing <code>boards.txt</code> and copying an existing entry for the Uno and changing the value of the <code>f_cpu</code> parameter to match the target system (in this case, <code>12000000</code>).</p> <p>The difference in voltage does not matter, since the chip can run at either voltage and no connection is being made between the 5V system and the 3.3V system.</p>
784
|programming|
Expected Unqualified-ID Before 'do'(and 'while')
2014-03-17T18:45:41.993
<p>I am getting the error "error: expected unqualified-id before 'do'" multiple times for every do{ }while(); loop I have... Any help?</p> <p>Pastebin:<a href="http://pastebin.com/DubuAEUs" rel="nofollow">http://pastebin.com/DubuAEUs</a></p>
<p>The do whiles are outside of the setup() or loop(), so they won't work. </p> <p>I would suggest doing a simple C/C++ tutorial like <a href="http://www.learn-c.org" rel="nofollow">this one</a> to get up to speed with how things work.</p>
789
|sensors|temperature-sensor|
My DS18B20 is reading high. How can I get it to return the correct temperature?
2014-03-18T00:21:02.903
<p>I am working on a heating control system for my home, but having problems with the temperature sensor reading higher than I expect.</p> <p>I have a 5V Arduino Mini Pro clone hooked up to a relay module, an HD47780 display and a Tiny RTC module, with a DS18B20 attached to it.</p> <p>The DS18B20 is powered from the 5v Vcc applied to the Tiny RTC module rather than using parasitic power on the DQ line (as I wasn't sure if the Onewire libraries supported this mode of operation) and the <a href="http://datasheets.maximintegrated.com/en/ds/DS18B20.pdf" rel="noreferrer">DS18B20 datasheet</a> says that Vcc may be between 3.0v and 5.5v. I measured the regulated power from the Mini Pro's being at 5.2v.</p> <p>I am comparing the temperature from the DS with the existing room thermostat (bi-metallic), an RS desktop temperature monitor with two sensors, a small <a href="http://i01.i.aliimg.com/photo/v4/376190273/In_out_Thermo_Hygrometer_HC520.jpg" rel="noreferrer">'thermo-hygrometer'</a> and a <a href="http://ecx.images-amazon.com/images/I/71sVnFU5AQL._SL1436_.jpg" rel="noreferrer">bi-metallic fridge thermometer</a> (in the upper quarter of its temperature range)<sup>&dagger;</sup>. The readout from the DS is always around 1-2 degrees higher than the readout from the other sensors, which are within a degree of each other.</p> <p><sup>&dagger; Not the actual one, but something similar.</sup></p> <p>Reading various forums I have heard that these sensors are quite accurate but can suffer from localised heating from components near them, so I moved the sensor onto a 20cm cable and positioned it well away from the rest of the electronics. This made no difference.</p> <p>I then read that the DS can become self heating if it is supplied with too high a Vcc voltage, so I added a Red LED with 1.7v drop and measured the new voltage over the DS as 3.5v, but again, after waiting for the temperatures to stabilise once more, this made no difference.</p> <p>Can anyone suggest why the DS may be reading high and what I can can do to prevent this?</p>
<p>I've made some experiments. If DS18B20 was on short cable &lt;1cm to my Arduino Pro Micro the readings was 5 degrees more than environment was. On cable lenght >10cm from arduino board and no matter where the resistor was mounted (near arduino or near DS18B20) the readings was fine.</p>
790
|arduino-pro-mini|
Corrupted output from HC-05 Bluetooth module
2014-03-18T00:38:24.110
<p>I have arduino Pro Mini 3.3V version with hc-05 module connected to 3.3V/GND and RXI/TX0 pins. I am then using my android phone to connect to the module. It shows up and pairs fine. Then I use BlueTerm app to view the output. I am seeing output that is occasionally as expected but mostly partially corrupted (characters replaced with random characters). </p> <p>I am using 9600 baud rate and trasmitting the following:</p> <pre><code>void serialTransmit(int data){ // send to raspberry pi or other device(s). Serial.print("Serial Transmit: "); Serial.println(data); // this is hard coded as "12" for testing } </code></pre> <p>I tried switching rx/tx pins around but got same corrupt output. Tried changing baud rate but then it wouldn't transmit anything at all and default rate is 9600 so that was expected.</p> <p>What could be the cause?</p>
<p>I have the same problem with arduino pro mini and HC-06, only change the baud rate of your BTserial port... try diferent baud rates in my case:</p> <pre><code>Serial.begin(9600); Serial.println("AT"); BTSerial.begin(2400); BTSerial.println("AT"); </code></pre> <p>Works fine, it happens because the arduino try to "understand" the module, but if the module speaks other leanguage, the arduino will never understand the command.</p> <p>like me... sorry for my bad english. se ya.</p>
795
|sensors|arduino-due|
How to connect 5V sensors to 3.3V digital input (Due)?
2014-03-18T16:09:01.827
<p>I'm completely new with Arduino and microcontrollers in general.</p> <p>I have several 5V sensors, and need 3.3V because that's the max for the Due. Is it possible to use a resistor to connect it to the Arduino? Do I have to measure the current from the sensor and calculate the needed resistor like this?</p> <pre><code>$$\frac{5.0 - 3.3}{\text{Measured current}}$$ (5.0 - 3.3)/(Measured current) </code></pre>
<p>Well if you're not sure of what you're doing, you can always go with <strong>level-converters</strong> for your sensors (that does not apply to shields though)</p> <p>Level-converters (sometimes called <strong>level-shifters</strong>) come in different flavors:</p> <ul> <li>breakout board (the easiest to work with)</li> <li>IC</li> <li>DIY circuits with a few components</li> </ul> <p>Some are "one-way": they have pin-pairs with converters 3.3V -> 5V, and other pin-pairs with 5V -> 3.3V conversion; others are bi-directional, i.e. you can use the same pair of pins in 2 directions 3.3V &lt;-> 5V.</p> <p>There are plenty of these converters, and they are rather cheap; here are just a few examples:</p> <ul> <li><a href="https://www.sparkfun.com/products/11978" rel="nofollow">one-way breakout</a> usable with 4 pairs of pins</li> <li><a href="https://www.sparkfun.com/products/12009" rel="nofollow">bi-directional breakout</a> usable with 4 pairs of pins</li> <li>74HC4050 IC discussed <a href="http://forum.arduino.cc/index.php?topic=109493.0" rel="nofollow">here</a></li> </ul>
796
|spi|uart|
Is there a transmission protocol library for SPI?
2014-03-17T13:43:20.593
<p>When communicating over SPI, one byte is sent at a time. Is there a library (C or C++) that allows for sending strings? Essentially it would be a protocol library handling the start and the end of a message, as well as integrity checking. (I'm using an Arduino.)</p>
<p>Each spi peripheral has its own protocol in the sense of commands and addresses if any and data. Spi simply makes a common ground for chip select vs clocks and clocks vs data and separate miso and mosi data lines.</p> <p>So a general purpose library doesnt make sense.</p> <p>Also spi certainly is not limited to a byte, many peripherals and many spi controllers allow for long sequences of data, you are also not strictly limited to multiples of 8 bits either although that is the norm.</p> <p>Your arduino spi master may have its limitations but that has nothing to do with spi in general.</p> <p>Integrity testing is not part of the spi protocol, you get what you get. Ideally all of the parts are soldered down on the same board or through known connectors and the margins have been designed in. You would need to do something outside the spi protocol, for example if it is a spi flash then after you read a chunk of data you can do a checksum and compare it with a checksum you have embedded in the data (or crc). If it is a spi ethernet part you may choose to leave the frame checksums in the frames and re-validate each frame yourself. If you create your own peripheral (hardware design or cpld or fpga) then certainly you can add a crc or checksum to every transfer if you wish.</p>
804
|programming|serial|uploading|sketch|arduino-nano|
Arduino Nano uploading gives error: avrdude: stk500_recv(): programmer is not responding
2014-03-18T21:01:57.920
<p>I have a <a href="http://rads.stackoverflow.com/amzn/click/B00761NDHI">Arduino Nano (Sainsmart)</a> that I'm trying to upload a sketch to. Under the Arduino IDE, the device selected was <code>Arduino Nano w/ ATmega328</code>. </p> <p>However uploading the sketch gives me the error</p> <pre><code>avrdude: stk500_recv(): programmer is not responding </code></pre> <p>I tried both USB ports (<code>/dev/tty.usbserial</code> &amp; <code>/dev/cu.usbserial</code>) but the same error persist. The Arduino is connected to a Macbook Air via the USB cable, and the <code>PWR</code> LED indicator light on the Arduino is turned on and the <code>L</code> indicator LED blinks. There was no problem uploading to a Arduino Uno.</p> <p>Retried after installing the latest FTDI drivers (MAC OSX, x64, v2.2.18, FTDIUSBSerialDriver_10_4_10_5_10_6_10_7.mpkg) from <a href="http://www.ftdichip.com/Drivers/VCP.htm">http://www.ftdichip.com/Drivers/VCP.htm</a>. However that did not help.</p> <p>What could have gone wrong?</p>
<p>Ok. I had the same <code>programmer is not responding</code> error on Arduino Nano on Atmel MEGA168PA, USB chip: CH340G. Macbook Pro under macOS 10.14.2. </p> <p>It hand Blink example installed and the port wasn't visible in the list. </p> <p>I was trying to figured out, whats wrong and connected my <strong>Arduino Due</strong> through the programming port. After 2 attempts the sketch was uploaded... Then I connected the Nano back, the port was visible this time (actually two of them: <code>/dev/cu.wchusbserial14120</code> and <code>/dev/cu.usbserial-14120</code>) and guess what, the upload had been successful!</p> <p>Magic!</p>
810
|programming|sketch|sketch-size|
Should I try to make my sketches as small as possible, even when I have enough room?
2014-03-19T00:15:29.617
<p>There has been a lot of talk about shrinking sketches recently, but if you don't need the room, should it be done? Will it speed up my program?</p> <p>Take this code:</p> <pre><code>int led = 13; int val; void setup() { pinMode(led, OUTPUT); } void loop() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second val = digitalRead(10); } </code></pre> <p>1,396 bytes on Arduino Uno. Now let's shrink it a bit:</p> <pre><code>int led = 13; int val; void setup() { pinMode(led, OUTPUT); } void loop() { blink(); val = digitalRead(10); } void blink() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } </code></pre> <p>1,270 bytes. A 10% decrease! It could be shrunk even more. <strong>I have the space... is it more efficient (as far as speed) to make it the most compact I can or leave it "uncompressed?"</strong> I would imagine that it would be a little more work (not much) calling <code>blink();</code>, therefore slowing down my code. Is this true? Are there other advantages/disadvantages of making it as small as possible (besides storage/distribution of C++ files)?</p>
<p>When considering optimization, think carefully about what resource is most valuable.</p> <p>You can optimize for code size; this will let you put more code onto your processor. What will the rest of the space be used for? If your code doesn't fit onto your arduino, and your alternative is buying a larger chip, then this is worth the effort.</p> <p>You can optimize for speed - you can run more code in the same amount of time. If you are sampling data once per second, and sleeping the rest of the time, then this won't help.</p> <p>You can optimize for power usage - very important if you're on a battery, less important if you are on mains. This might also not just be power consumed by the arduino, but also sensors &amp; motors - can they be turned off for a while?</p> <p>There are two optimizations that a lot of programmers forget - optimizing for development time, and optimizing for readability.</p> <p>Any optimization for one thing will tend to de-optimize for at least one (often several) other things. If you don't know which optimization is going to be most useful, then go for readability, then development time (because today's readability = tomorrow's development time x 10!)</p> <p>Usually, the most expensive thing is the development time (i.e. YOUR time, especially if you are on the clock for a customer). Most other optimization has a threshold - so long as you are over (under?) a specific threshold, further optimization doesn't help. Code size and execution speed (except when shared between competing tasks) are like this - if your code fits on the chip, then it is small enough. If it needs to do something else later, you can optimize it then. If your program can do all it needs to (assuming it is real-time; calculating Pi is a different case), then that's as fast as it needs to be.</p>
812
|arduino-uno|
What are some steps to attach an Arduino to an electric heater?
2014-03-19T04:22:10.897
<p>I have the below portable electric heater, but I would love to control it's start AND stop time using an Arduino. As-is, it does not come with a stop feature. SO, I have a burning question. How can I get an Arduino to start and stop this heater at specific times of the day?</p> <p>As you can see, it does have a start time, but it does not have a stop time. The power button is a simple push button. I suspect I would need to 'interject' into that and the board by using a switch? Apologies if the terminology is off, but I'm very green. Where would a noob begin?</p> <p>-EDIT- The unit is always off when it's plugged back in. That likely means I cannot put a timer on the power cord. </p> <p><img src="https://i.stack.imgur.com/ybUjr.jpg" alt="enter image description here"></p>
<p>The following will work and meets the requirement that the heater does not auto turn on when powered up. You need to turn the heater on manually, so no different from existing, and this then allow you to either </p> <ul> <li><p>Power it down at a preselected time of day, provided the Arduino is able to keep track of time, or </p></li> <li><p>The Arduino will turn it off a set period after it has started to heat. </p></li> </ul> <p>The latter is easier to do and meets the need well enough.<br> The only technical requirements are</p> <ul> <li><p>Able to sense current drawn by heater.</p></li> <li><p>Able to turn a heater control relay on/off </p></li> <li><p>Able to set or select a time delay on Arduino.</p></li> </ul> <p>Of these, the current detection is hardest and even then, not very hard. Possible means include:</p> <ul> <li><p>Current transformer connected to heater lead.</p></li> <li><p>Opto isolator with LED in series with lead with suitable parallel resistor across opto LED to drop enough voltage to trigger opto on voltage peaks when heater is on, and backwards diode across opto LED for reverse mains cycles. This provides a series of pulses to Arduino when heater is on.</p></li> </ul> <p><strong>Equipment:</strong></p> <p>Arduino controlled external relay or solid state relay. </p> <p>Some means of detecting that heater is drawing current - timer mode only. </p> <p>Arduino. </p> <hr> <p><strong>Arduino cct can:</strong> </p> <ul> <li><p>Detect current draw.</p></li> <li><p>Turn relay off/on </p></li> <li><p>Be programmed to either stop time or run time. </p></li> <li><p>Drives external relay or solid state relay. </p></li> <li><p>Optional: Relay defaults on. </p></li> </ul> <p><strong>Then:</strong></p> <p>Set external Arduino timer to desired time.<br> Arduino sets relay ON.<br> Set heater to desired start time.<br> When heater start Arduino sees current and starts timing, or in time of day mode just turns off power at correct time.</p> <p>This keeps all circuitry external.</p>
815
|arduino-uno|power|arduino-nano|arduino-pro-mini|electricity|
Most compact method of powering Arduino from wall socket
2014-03-19T14:26:44.540
<p>There are a lot of methods to power an Arduino from a large range of voltages:</p> <ul> <li>USB cable from PC or from a phone charger or an USB hub</li> <li>step down converters</li> <li>step up converters</li> <li>switching power supply</li> <li>batteries (connected to the power jack or USB or to Vin)</li> </ul> <p>What I can't seem to find is a small 220V-5V converter. I'd like to put an Arduino in the wall, under a light switch, so size matters. </p> <p>The last resort option is to open a 5V phone charger and replace the metal prongs that go in a socket with two wires, and replace the USB socket with another pair of wires that go the Arduino board, but still, an Arduino Pro Mini or an Arduino Nano is smaller than the phone charger. </p>
<p>It's entirely dependent on whether or not you want to isolate the circuit from the mains. You could use a drop resistor a rectifier and a 5v zener diode but I do not recommend this if you are a hobbyist, in fact I don't recommend this at all, but it is done by some manufacturers with appropriate circuit protection. </p>
816
|c++|arduino-ide|
C++ vs. The Arduino Language?
2014-03-19T14:34:30.793
<p>What are the advantages of each language when using the Arduino?</p> <p>I'm thinking this is a good general question, but I'll add a bit about why I'm asking if anyone wants to give me a tip.</p> <p>I'm experienced in preprocessed languages like JavaScript, PHP, and have fiddled with languages like Java and Visual Basic. In other words I know programming techniques and both classical and prototypal object orientation, but nothing about communicating directly with hardware.</p> <p>I'm making an octocopter, and am thinking that an object oriented approach will be the easiest. (The software will have very many features...) However I have never written in C++.</p> <p>Since this is a Q&amp;A site that's supposed to help others, only the general question presented at the beginning is of much importance, but I'd appreciate any comments on my situation.</p>
<h2>Arduino <em>is</em> C and C++ (it is a mix of the two, linked together); there is no &quot;Arduino&quot; programming language</h2> <p><strong>The Arduino language <em>is</em> C++</strong> (albeit usually implemented in a style more like &quot;C with classes,&quot; which is actually fairly common in the embedded systems microcontroller world). <strong>End of story.</strong> Enough with people thinking it's a different language already! It uses the g++ compiler.</p> <h2>Proof:</h2> <p><strong>Enable verbose output during compilation in the Preferences and upload and you'll learn a lot just reading those lines.</strong></p> <h2>Here's some additional insight:</h2> <h3>My own words:</h3> <p><strong>Arduino code <em>is</em> C++.</strong> The Arduino <a href="https://www.arduino.cc/reference/en/" rel="nofollow noreferrer">core functions</a> are simply a set of C++ classes and libraries you can use. It is built and compiled using the <a href="https://en.wikipedia.org/wiki/GNU_Compiler_Collection" rel="nofollow noreferrer">GNU gcc/g++ compiler</a>. Your <code>setup()</code> and <code>loop()</code> functions are simply placed into the mandatory (meaning: required by both C and C++ in order to even be considered a valid program) <code>main()</code> function (<a href="https://github.com/arduino/ArduinoCore-avr/blob/master/cores/arduino/main.cpp#L33" rel="nofollow noreferrer">right here actually</a>--notice the file is <code>main.cpp</code>, which is a C++ source file) automatically for you and there is some extra preprocessing done to make sure it is a valid C++ program (ex: scanning for all function prototypes [aka: declarations] for you so you can use a function even though its prototype comes later in your <code>.ino</code> file). Much of Arduino is written in C, however, and therefore requires the <code># extern &quot;C&quot; {}</code> braces around it to prevent C++ from <a href="https://www.geeksforgeeks.org/extern-c-in-c/" rel="nofollow noreferrer">&quot;name-mangling&quot;</a> (also known as <a href="https://en.wikipedia.org/wiki/Name_mangling" rel="nofollow noreferrer">&quot;name decorating/name decoration&quot;</a>) function calls to C functions implemented by <a href="https://www.nongnu.org/avr-libc/" rel="nofollow noreferrer">AVR-libc</a>, which is the C implementation for the ATmega328 and other <a href="https://en.wikipedia.org/wiki/Atmel_AVR" rel="nofollow noreferrer">AVR-architecture</a> microcontrollers.</p> <h3>Arduino's words:</h3> <blockquote> <p>&quot;<a href="https://support.arduino.cc/hc/en-us/articles/360018448219-Can-I-program-the-Arduino-board-in-C-" rel="nofollow noreferrer">Can I program the Arduino board in C?</a><br /> In fact, you already are; the Arduino language is merely a set of C/C++ functions that can be called from your code. Your sketch undergoes minor changes (e.g. automatic generation of function prototypes) and then is passed directly to a C/C++ compiler (avr-g++). All standard C and C++ constructs <a href="https://www.nongnu.org/avr-libc/user-manual/FAQ.html#faq_cplusplus" rel="nofollow noreferrer">supported by avr-g++</a> should work in Arduino. For more details, see the page on the <a href="https://www.arduino.cc/en/Hacking/BuildProcess" rel="nofollow noreferrer">Arduino build process</a>.&quot;</p> </blockquote> <p>Source: <a href="https://support.arduino.cc/hc/en-us/articles/360018448219-Can-I-program-the-Arduino-board-in-C-" rel="nofollow noreferrer">https://support.arduino.cc/hc/en-us/articles/360018448219-Can-I-program-the-Arduino-board-in-C-</a></p> <h2>When to use the <a href="https://www.arduino.cc/reference/en/" rel="nofollow noreferrer">Arduino library</a> vs pure C or C++?</h2> <p>So, use the Arduino language where it simplifies things, and write your own functions where you need more specialization. I do recommend getting away from the IDE quickly though for writing code--just use it for compilation. Set the IDE preferences to use &quot;External Editor.&quot; Then use a professional source code editor/IDE such as <a href="https://www.sublimetext.com/3" rel="nofollow noreferrer">Sublime Text 3</a>, <a href="https://atom.io/" rel="nofollow noreferrer">Atom</a>, <a href="https://code.visualstudio.com/" rel="nofollow noreferrer">Visual Studio Code</a>, or <a href="https://www.eclipse.org/cdt/" rel="nofollow noreferrer">Eclipse CDT</a> to write your code. You can then click back to the Arduino IDE to compile and upload. If you go with Eclipse, there are ways to do that in Eclipse (see the other answers here, and see the <a href="http://playground.arduino.cc/Code/Eclipse" rel="nofollow noreferrer">Arduino playground Eclipse article</a> here too) so consider using those techniques too.</p> <h2>Update: Eclipse setup</h2> <p>See <a href="https://arduino.stackexchange.com/a/75491/7727">my answer here</a> and my document here: <a href="https://docs.google.com/document/d/1LbuxOsDHfpMksGdpX5X-7l7o_TIIVFPkH2eD23cXUmA/edit?usp=sharing" rel="nofollow noreferrer">Eclipse setup instructions on a new Linux (or other OS) computer</a>. I wrote a detailed PDF to describe setup.</p>
821
|programming|serial|sketch|arduino-nano|xbee|
Arduino unable to read from XBee Series 2
2014-03-19T15:27:47.403
<p>An XBee Series 2 is set to <code>Router AT</code> whose <code>TX</code> and <code>RX</code> pins are connected to an Arduino Nano's <code>Rx</code> and <code>Tx</code> pins respectively. The Arduino is connected to a Mac OSX via USB.</p> <p>A second XBee Series 2 is connected to a Windows system via USB. It is set to <code>Coordinator API</code> mode.</p> <p>Using the sketch below on the Arduino, a packet is sent from the <code>Router AT</code> XBee to the <code>Coordinator API</code> XBee, which is seen by <code>XCTU</code> as a Explicit RX frame. However the Arduino LED should blink once if it received a reply packet (should it?)</p> <p>On another test, I wrote a script to send a frame for the <code>Coordinator API</code> XBee to send to the <code>Router AT</code> XBee. Once again the Arduino LED does not blink, and nothing is seen using Arduino's Serial Monitor.</p> <p><strong>Testing the <code>Coordinator API</code> XBee</strong></p> <p>Using the same script to send a packet from <code>Coordinator API</code> XBee to itself, the packet was received as well as a delivery confirmation packet. This shows that both the <code>Coordinator API</code> XBee and the script are working.</p> <pre class="lang-none prettyprint-override"><code>// Delivery confirmation received: { type: 144, remote64: '0013a20040a74613', remote16: '0000', receiveOptions: 1, data: [ 116 ] } // Received the packet sent to itself received: { type: 139, id: 1, remote16: '0000', transmitRetryCount: 0, deliveryStatus: 0, discoveryStatus: 0 } </code></pre> <p><strong>Testing the Arduino Sketch Code</strong></p> <p>Using the same Arduino sketch which continuously sends API frames to the <code>Coordinator</code>, I connected the <code>Router AT</code> XBee's <code>RX</code> pin to Arduino's <code>RX</code> pin, so the frames the Arduino are sending out are going back into its <code>RX</code> pin.</p> <p>This causes the Arduino's LED to light up! So there is nothing wrong with the code.</p> <p><strong>Problem:</strong> Does this mean the <code>Router AT</code> XBee is not configured properly? I do not think its <code>TX</code> pin is damaged because <code>XCTU</code> can still read the settings off this XBee. Any ideas on how we can troubleshoot this?</p> <p><strong>Arduino Sketch (Connected to Router Xbee)</strong></p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;XBee.h&gt; XBee xbee = XBee(); uint8_t payload[] = { 0, 0 }; // SH + SL Address of receiving XBee XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40a74613); ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload)); ZBTxStatusResponse txStatus = ZBTxStatusResponse(); void setup() { pinMode(13, OUTPUT); Serial.begin(9600); xbee.setSerial(Serial); } void loop() { xbee.send(zbTx); delay(1000); xbee.readPacket(); if (xbee.getResponse().isAvailable()) { // Response received, blink LED once Serial.println('resposne!'); digitalWrite(13, HIGH); delay(1000); digitalWrite(13, LOW); delay(1000); } } </code></pre>
<p><code>#include &lt;XBee.h&gt; uint8_t text[] = {'H', 'e', 'l', 'l', 'o',' ','T','H','I','S',' ','I','S',' ', 'A','R','D','U','I','N','O'}; XBee xbee = XBee(); XBeeAddress64 remoteAddress = XBeeAddress64(0x00000000, 0x0000FFFF);//64 address of remote xbee: ZBTxRequest zbTx = ZBTxRequest(remoteAddress, text, sizeof(text));// api 2 Tx request frame ZBRxResponse zbRx = ZBRxResponse();// reading remote xbee response: void setup() { Serial.begin(9600); xbee.setSerial(Serial); Serial.println("starting up yo!"); } void loop () {<br> xbee.readPacket();// This will read any data that is available: if (xbee.getResponse().isAvailable())//Now, to check if a packet was received: {<br> if (xbee.getResponse().getApiId() == ZB_RX_RESPONSE) { xbee.send(zbTx);//sending data to remote xbee: } } }</code></p>
825
|programming|uploading|isp|
Arduino as ISP without a computer
2014-03-19T17:10:02.733
<p>Has anyone seen or know of a method of preloading (using a computer or whatever) a firmware as data onto one arduino set up to operate as an isp and then using that arduino plug the isp interface into another and upload the firmware.</p> <p>To be clear - i'm looking for a way to make uploading arduino sketches possible without a direct connection to a full blown computer.</p> <p>Ideally the steps involved would be:</p> <ol> <li>Write new sketch/firmware</li> <li>Compile firmware</li> <li>Write a copy firmware onto Arduino A as data (Arduino A is set up to work as ISP)</li> <li>Detach Arduino A from the computer</li> <li>In a seperate location attach Arduino A to Arduino B using ISP headers</li> <li>Using some method (maybe a pushbutton) trigger Arduino A to upload the preloaded firmware onto Arduino B.</li> </ol> <p>I'm assuming that theoretically it could work because uploading firmware is just an exchange of bytes across the SPI interface but i'm not sure about the reality.</p> <p>The scenario for which I'm considering is if I were to install an arduino (permanently) in a location that is remote from my computer (I don't have a laptop nor do I want to get one) it would be troublesome to reprogram it.</p> <p>The other method I have considered is using the DIL packaged ATMEGA which I can then remove from the board and program at the computer and return to the board - however I would much prefer not to risk bending of pins and the hassle of having to remove the chip each time I want to reprogram.</p>
<p>I think <a href="http://mdiy.pl/uprog-maly-szybki-przenosny-programator-avr-z-sd/?lang=en" rel="noreferrer">µProg – tiny, fast, portable AVR programmer with SD</a> does what you want. You can store multiple files in the SD card (hex, eep etc) and select from the device menu which one to write to the target MCU without any need for a PC.<br /> The best part is that it's available for free (PCB, schematic, firmware etc).</p> <blockquote> <p>One of a kind, portable AVR programmer! Helps wherever you need to update the device firmware, where target device is in a hard-to-reach location and you can’t (or don’t want to) bring your laptop with a bunch of wires with you. Trivially easy to use, super cheap to make, super small, super fast, uses SD cards…</p> <p>Features:</p> <ul> <li>super small – dimensions 44 x 39 x 5,5 mm</li> <li>super fast – write up to 12,5kB/s, read up to 14,5kB/s</li> <li>uses cheap storage medium – small MICRO SD cards</li> <li>supports FAT16 and FAT32 file systems</li> <li>can read, write, verify flash and eeprom memory</li> <li>can read, write, verify fusebits and lockbits</li> <li>write and read to BIN, HEX, and TXT files</li> <li>can set default values of fusebits, erase memories</li> <li>cheap, easy to obtain, LPH7779 graphic display</li> <li>shows funny animations after every operation</li> <li>standard programming header – Atmel 6-PIN ISP</li> <li>has a function of auto-update its own firmware (from SD)</li> <li>very simple to use, 4 buttons navigation</li> <li>user-setting menu</li> <li>programming speed auto-selection (up to 4MHz)</li> <li>Operates at 3V, programs chips supplied from 3V to 5V</li> </ul> </blockquote> <p>Supported chip list</p> <p><img src="https://i.stack.imgur.com/XZRUr.jpg" alt="enter image description here" /></p>
830
|arduino-uno|c++|timers|
Timer2 does not work as it should
2014-03-19T20:33:20.310
<p>I am currently playing with Arduino timers (on UNO currently) and I am building a library that has a function that must be called every millisecond.</p> <p>There is plenty of code samples on Internet so I went with something that seemed perfect for my needs. I have then updated it to make it a reusable C++ class. </p> <p>Here is my code (simplified to just isolate the issue):</p> <pre><code>#define BIT(x) (0x01 &lt;&lt; (x)) static volatile uint32_t milliseconds = 0; class Timer { public: Timer() { // Disable interrupts uint8_t savedStatus = SREG; cli(); // Use Timer2 with 1 ms interrupts // OC2A &amp; OC2B disconnected, mode 2 (CTC, Clear Timer on Compare match) TCCR2A = BIT(WGM21); // Don't force output compare (FOCA &amp; FOCB), mode 2, Clock Select clk/128 (CS = 5) TCCR2B = BIT(CS22) | BIT(CS20); // Set timer counter compare match (when value reached, 1ms has elapsed) OCR2A = 125 - 1; // Reset Timer2 counter TCNT2 = 0; // Set Timer2 interrupt mode (Set interrupt on OCR2A compare match) TIMSK2 = BIT(OCIE2A); // Restore interrupt enabling state SREG = savedStatus; } }; static void callEveryMillisecond(uint32_t ms) { // Do something here } // Attach interrupt routine to the Timer Compare Interrupt ISR(TIMER2_COMPA_vect) { milliseconds++; callEveryMillisecond(milliseconds); } </code></pre> <p>After checking <a href="http://www.atmel.com/Images/doc8161.pdf" rel="nofollow">ATmega328 datasheet</a> (section 17) several times, I came to the conclusion that what I do in <code>Timer</code> class constructor above is correct, and for Arduino UNO, the values used must lead to one call of the ISR every ms:</p> <ul> <li>CPU frequency = <strong>16MHz</strong></li> <li>Prescaler = <strong>128</strong></li> <li>-> timer frequency = <strong>16MHz/128 = 125KHz</strong></li> <li>-> max counter value = <strong>125</strong></li> </ul> <p>I decided to use the <strong>CTC</strong> (Clear Timer on Compare match) mode, which means that when the timer <code>TCNT2</code> (which is incremented at 125KHz frequency), reaches <code>OCR2A</code> value, then it will trigger the ISR, and then will be reset on next tick; the additional tick to reset the counter explains why we use <code>125 - 1</code> for <code>OCR2A</code> and not just <code>125</code>.</p> <p>Now comes the weird stuff. In order to check that my code worked, I decided to blink the LED on pin 13 every 10 seconds, hence I have added the following code to my program:</p> <pre><code>static void callEveryMillisecond(uint32_t ms) { if (ms % 10000 == 0) digitalWrite(13, digitalRead(13) ^ 1); } static Timer timer; void setup() { pinMode(13, OUTPUT); } void loop() { } </code></pre> <p>Then I measured the time during which pin 13 LED is lit on (or off, both measures are the same). Measures are not very accurate (I just used my wristwatch) but good enough for my check.</p> <p>I was surprised to see the measured time to be about <strong>20 seconds instead of 10s</strong>.</p> <p>Initially I thought about a mismatch in CPU frequency, but after performing a lot of small changes, here is what I found which worked perfectly:</p> <pre><code>//static Timer timer; void setup() { static Timer timer; pinMode(13, OUTPUT); } </code></pre> <p>Just moving the <code>Timer</code> instance into <code>setup()</code> did the trick: my measures rightly indicated <strong>10 seconds</strong> between 2 states of the pin 13 LED.</p> <p><strong>Now my questions are:</strong></p> <ol> <li><p>Why the second code sample works perfectly, whereas the first does not?</p></li> <li><p>Is there, in standard Arduino included code, some code that would overwrite some of the settings I perform for Timer2 in <code>Timer::Timer()</code>?</p></li> <li><p>Is there a way to make the first code sample work? Note that I don't like the second sample because it does not seem natural coding, also, I will need access to <code>Timer</code> <code>timer</code> instance in several locations of my future program, hence it can't be possible if it is declared in the scope of <code>setup()</code>.</p></li> </ol>
<p>The way most of the libraries do this is to put an instance of (in your case) Timer in the Timer.cpp file, and reference it with an extern definition when needed - typically in your main cpp file. Also you are calling digitalWrite() and digitalRead() during an ISR. This can be bad since those functions are slow, and may not be guaranteed to behave when interrupts are disabled (as they are during an ISR). A safer approach is for your ISR to set a flag in your Timer class that can be read by an Timer.isExpired() or similar method in your loop() code.</p>
854
|arduino-uno|serial|software|
How to use RS-232 sheild as software serial port?
2014-03-20T20:17:25.960
<p>I would like to be able to use a USB port at the same time as an RS-232 port with my Arduino Uno board. I unwittingly bought a shield that (I think?) overrides the USB port when it is mounted to the Arduino board:</p> <p><a href="http://www.dfrobot.com/wiki/index.php/RS232_Shield">http://www.dfrobot.com/wiki/index.php/RS232_Shield</a></p> <p>Would anyone be able to give me any advice on how to connect the hardware so that I can have two serial ports accessible from my Arduino Uno? The format I was thinking was (Arduino => RS-232 Sheild):</p> <p>GND => GND 5V => 5V Digital Pin 2 => 232RXD Digital Pin 3 => 232TXD</p> <p>The accompanying code for initializing the serial port which I've written:</p> <pre><code>const int rxpin = 2; // pin used to receive const int txpin = 3; // pin used to send SoftwareSerial Serial_rs232(rxpin, txpin); // new serial port </code></pre> <p>Any ideas as to why this may or may not be a good method of using the hardware I have available for the purpose I had in mind?</p>
<blockquote> <p>GND => GND 5V => 5V Digital Pin 2 => 232RXD Digital Pin 3 => 232TXD</p> </blockquote> <p>A better choice of board would be the Leonardo, since you could connect such a shield <em>and</em> use the USB port right out of the box. However, since you have the Uno, there is a solution.</p> <p><em>From <a href="http://arduino.cc/en/Reference/SoftwareSerial" rel="noreferrer">Arduino</a>:</em></p> <blockquote> <p>The SoftwareSerial library has been developed to allow serial communication on other digital pins of the Arduino, using software to replicate the functionality (hence the name "SoftwareSerial"). It is possible to have multiple software serial ports with speeds up to 115200 bps. A parameter enables inverted signaling for devices which require that protocol.</p> </blockquote> <p>It then goes on to reccomend the library <a href="http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html" rel="noreferrer">AltSoftSerial</a>.</p> <p>Here is some example code from the link above:</p> <pre><code>#include &lt;AltSoftSerial.h&gt; AltSoftSerial altSerial; void setup() { Serial.begin(9600); Serial.println("AltSoftSerial Test Begin"); altSerial.begin(9600); altSerial.println("Hello World"); } void loop() { char c; if (Serial.available()) { c = Serial.read(); altSerial.print(c); } if (altSerial.available()) { c = altSerial.read(); Serial.print(c); } } </code></pre> <p>It acts like a standard serial port, only you declare the connection as a variable first. This code is written for a board with an additional serial port, like you have.</p> <h2>All is good, except for one problem:</h2> <p>The problem is the shield is wired to connect to pins 0 and 1: the ones used by the USB adapter. The AltSoftSerial library uses pins 8 for TX and 9 for RX. (Note: You cannot use PWM on pin 10 on the Uno... it should still work as a digital pin.) In that case you would <strong>not attach the shield by plugging it into the Arduino</strong>, and you would wire it like this:</p> <blockquote> <p>GND => GND | 5V => 5V | Digital Pin 8 => 232RXD pin 0 on the shield headers | Digital Pin 9 => 232TXD 1 on the shield headers</p> </blockquote> <p>So then, you would be manually wiring the shield to the Arduino with jumpers. As long as it doesn't connect to any other Arduino pins I'm not aware of (it shouldn't besides maybe 13 for a LED or something like that), it should function like it would stacked and using pins 0 and 1.</p> <p>Note: (Obviously) You cannot connect anything to the headers on the shield (You cannot connect to pin 5 and get a signal).</p>
857
|arduino-uno|programming|software|
How to build (concat) a string with big numbers
2014-03-20T22:39:51.870
<p>new to arduino I'm struggling with what sounds like fairly n00b problem... I've wired up a adafruit GPS-board to my Arduino and it is working as it spits out GPS data to the serial port with <code>Serial.print(GPS.latitude, DEC)</code></p> <p>I Now want to concat a string which I can process (read: I want to sent it via an ethernet client.) This is what I got already:</p> <pre><code>...... String vnnt = "$VNNT,"; if (GPS.fix) { vnnt += "GPS,"; //this works: vnnt.concat(GPS.fix); //but this not: vnnt.concat(GPS.latitude); }else{ vnnt += "INFO,Acquiring Sats"; } Serial.println(vnnt); </code></pre> <p>The error message is: <code>Call of overloaded 'concat(float&amp;)' is ambiguous</code> When I <code>Serial.print(GPS.latitude, DEC)</code> it results in: <code>4418.5937996050</code></p> <p>So it is probably to big or something... </p> <p><strong>How can I concat the vars and create the long string?</strong></p>
<p>The concat function does not implement a float version, but some of char, int, unsigneds...</p> <pre><code>unsigned char String::concat(long unsigned int) unsigned char String::concat(unsigned int) unsigned char String::concat(int) ... </code></pre> <p>so the compiler does not know how to cast (truncating probably the float) to integer, as there are several options. </p> <p>You have to convert first your float to string, use dtostrf() or sprintf() then concat to your string.</p> <pre><code>char outstr[25]; sprintf(outstr, "%f", GPS.latitude); </code></pre> <p>or</p> <pre><code>dtostrf(GPS.latitude, 6, 2, outstr); //check docs for 6, 2 values, and set them for your needs </code></pre> <p>And then: </p> <pre><code>vnnt.concat(outstr) </code></pre> <p>Also note that sprintf is very handy for compact creation of a (char) string:</p> <pre><code>char msg[80]; sprintf(msg, "$VNNT,GPS, %s %f", GPS.fix, GPS.latitude); </code></pre>
860
|library|core-libraries|
How can I get the source files for Arduino libraries?
2014-03-21T17:48:44.647
<p>I've been looking for a while inside Arduino's files to find the core library. However, I haven't found them yet. <strong>Where on my hard drive can I obtain the core library files (.cpp and .h) necessary for all Arduino code?</strong></p> <p>Looking around on Google, I couldn't find a way to find the above files. I did see something about getting an .a file while Arduino is compiling, however, that isn't what I want. I want to browse the code and look at functions such as delay to see how they would react when given the values not expected. (i.e. Will my code stall if I use <code>delay(-200);</code> by not being to exit the loop, or will it create a black hole and disrupt the space-time continuum?)</p>
<p>I think this may have changed in newer versions. On my Mac Big Sur, Arduino 1.8.15 they are here: <code>/Applications/Arduino.app/Contents/Java/libraries</code></p>
865
|uploading|safety|avrdude|
Can I corrupt my Arduino if it's unplugged during an upload?
2014-03-22T01:32:16.627
<p>When messing around with code and uploading a sketch to my Arduino board, I almost accidentally pulled out the USB cord. Everything is fine, but then I started thinking what would've happened if I had pulled it out.</p> <p>How safe is avrdude? Could it damage or brick the board? I'd imagine that you would just have to upload code to it again... but what would happen before you upload the new code? I've seen something about how you can always upload new code if the bootloader is intact, but I would imagine that there would be some problems. If this were to happen, should I unplug everything connected in case Arduino writes a HIGH to an input (or similar) that would damage the component?</p>
<p>One safety feature that hasn't been mentioned so far is that the ATmega328 has a set of lock bits that prevent read/write access to certain areas. To the best of my knowledge, the way Arduinos are set up, those bits are always set to prevent writing to the boot loader area unless the "Burn Bootloader" command is currently active, and since you can only use that command with an external programmer, you can always write a new bootloader if something goes wrong.</p> <p>I think the only way of bricking the board (in the sense of leaving the MCU in a state that is functional, yet almost irrepairably unresponsive) is writing bad fuse settings. </p>
877
|pins|sensors|arduino-nano|
Opamp for amplifying 1V signal voltage to 2V
2014-03-23T03:19:02.423
<p>I'm doing my first electronics project where a signal that varies between -1 to 1 V is going into an analog pin on the Arduino. The amplified signal has to be read as fast as possible by Arduino. The source signal is at 60 Hz.</p> <p>Will <a href="http://www.digikey.com/product-detail/en/LM324N/296-1391-5-ND/277627" rel="nofollow">this LM324</a> be a suitable 4-channel opamp for my needs? How concerned should I be about the 2 mV input offset and 20 nA input current bias?</p> <p>To make full use of the 10bit ADC, would you recommend using an opamp with gain of 2 and biasing the signal by +2.5V? If so, will it be better to create the bias using a potential divider across +5V and GND, or using a 2.5V voltage regulator?</p> <p>Or would it be better to set AREF to 2V and bias the signal by +1V? In this case, will it be better to use a 2V voltage regulator, or a voltage divider across Arduino's 3V3 and GND using 20M and 33M resistors? </p>
<p>Just an alternate idea I saw: If you dont need high accuracy, you can use a voltage divider to bias -1 to +1 into 0 to 1, and set the analog reference to 1.2, and get almost the same result but skip the op amp.</p> <p>A voltage divider with 2 equal resistors will give you the voltage halfway between its two inputs. If the bottom of the voltage divider is at 1v, and the top input is at -1, you get 0 out.</p> <p>If the bottom is at +1, you get 1 out.</p> <p>I saw a really clever design using 2 1 megaohm resistors, and actually using the aref pin as an output to provide the bias for the divider, setting the reference to the 1.2v setting, putting the signal in the top of the divider and ground and connecting the adc to the output of the divider.</p> <p>Aref wasnt meant as a current source, but they use 1meg resistors so the current draw will be at most a few microamps.</p> <p>A filter cap on aref probably draws more than that if vcc is noisy(if there wasnt current to filter we wouldnt need the cap!) So a few uA should be fine.</p> <p>They put a 1nf capacitor betcan the input and ground to fix the issues with the ADC input current causing voltage drop. It worked up to 100hz. They never tested accuracy because it wasnt needed though. I'd guess that the adc internal reference was the major error source, probably a few percent.</p> <p>You can also actually bias with a voltage divider to the 5V supply, and get a 0 to ~1.6V output, it's just a little harder to understand.</p> <p>This simulation explains the concept(5v version) <a href="http://www.falstad.com/circuit/#%24+1+5.0E-6+81.92041607667615+50+5.0+50%0Ar+304+160+304+224+0+1000.0%0Ar+304+224+304+304+0+5000.0%0AR+304+304+256+304+0+0+40.0+5.0+0.0+0.0+0.5%0AR+304+160+208+160+0+1+40.0+1.0+0.0+0.0+0.5%0Aw+304+224+400+224+0%0Ax+368+208+456+214+0+24+To+ADC%0Ao+3+64+0+35+2.5+0.00625+0+-1%0Ao+4+64+0+35+2.5+9.765625E-5+1+-1%0A" rel="nofollow">http://www.falstad.com/circuit/#%24+1+5.0E-6+81.92041607667615+50+5.0+50%0Ar+304+160+304+224+0+1000.0%0Ar+304+224+304+304+0+5000.0%0AR+304+304+256+304+0+0+40.0+5.0+0.0+0.0+0.5%0AR+304+160+208+160+0+1+40.0+1.0+0.0+0.0+0.5%0Aw+304+224+400+224+0%0Ax+368+208+456+214+0+24+To+ADC%0Ao+3+64+0+35+2.5+0.00625+0+-1%0Ao+4+64+0+35+2.5+9.765625E-5+1+-1%0A</a></p> <p>Left click the output, use view in scope.</p>
883
|arduino-uno|sensors|
Ultrasonic Sensor scanning too often resulting in a whirring noise
2014-03-23T15:41:51.263
<p>I am using an HC-SRO4 ultrasonic sensor for a wall-avoidance, maze-solving robot. However, I have recently run into an issue where I am getting a whirring noise from the sensor because it is taking measurements way too often.</p> <p>This is the code I have right now:</p> <pre><code>const int serialPeriod = 250; // only print to the serial console every 1/4 second unsigned long timeSerialDelay = 0; const int loopPeriod = 20; // a period of 20ms = a frequency of 50Hz unsigned long timeLoopDelay = 0; // specify the trig &amp; echo pins used for the ultrasonic sensors const int ultrasonic2TrigPin = 8; const int ultrasonic2EchoPin = 9; int ultrasonic2Distance; int ultrasonic2Duration; void setup() { Serial.begin(9600); // ultrasonic sensor pin configurations pinMode(ultrasonic2TrigPin, OUTPUT); pinMode(ultrasonic2EchoPin, INPUT); } void loop() { debugOutput(); // prints debugging messages to the serial console if(millis() - timeLoopDelay &gt;= loopPeriod) { readUltrasonicSensors(); // read and store the measured distances timeLoopDelay = millis(); } } void readUltrasonicSensors() { // ultrasonic 2 digitalWrite(ultrasonic2TrigPin, HIGH); delayMicroseconds(10); // must keep the trig pin high for at least 10us digitalWrite(ultrasonic2TrigPin, LOW); ultrasonic2Duration = pulseIn(ultrasonic2EchoPin, HIGH); ultrasonic2Distance = (ultrasonic2Duration/2)/29; } void debugOutput() { Serial.print("timeSerialDelay: "); Serial.print(timeSerialDelay); Serial.println(); if((millis() - timeSerialDelay) &gt; serialPeriod) { Serial.print("ultrasonic2Distance: "); Serial.print(ultrasonic2Distance); Serial.print("cm: "); Serial.println(); timeSerialDelay = millis(); } } </code></pre> <p>and my wiring:</p> <p><img src="https://i.stack.imgur.com/yzG9F.jpg" alt="breadboard wiring"></p> <p><a href="https://www.foxytronics.com/products/181-4-pin-female-to-female-cable" rel="noreferrer">Link to product</a></p> <p>Does anyone know why the scanning is happening constantly? It should only be happening every 1/4 of a second, not constantly. The weird thing is that this wasn't happening earlier before I started using the cable. </p> <p>I believe it has something to do with the 8.5" extension cable I have (needed because I can't mount three sensors, one facing to each side and one in front, on a single breadboard). This is because when I mounted the sensor directly onto the breadboard, the delay was correct and the whirring was not present. However, as I just mentioned, I <em>need</em> the extension cable to be able to have the three sensors.</p> <p>Does anyone have a solution for this?</p> <p>Thanks!</p>
<p>If you want to sample at 4Hz (4 times per second), you need to change your headers accordingly:</p> <pre><code>const int serialPeriod = 250; // only print to the serial console every 1/4 second unsigned long timeSerialDelay = 0; const int loopPeriod = 250; // a period of 250ms = a frequency of 4Hz unsigned long timeLoopDelay = 0; </code></pre>
893
|arduino-uno|power|
What happens if I power the Arduino with both the USB and external power voltage simultaneously?
2014-03-24T10:22:29.783
<p>I am a new Arduino user. I am not sure whether I can connect both USB and external supply through power adaptor to Arduino simultaneously. Would this burn the controller?</p> <p>Basically, I want to automatically shut down the computer after saving all open documents before my UPS battery goes out whenever I am not there to manually shut it down. I am trying to notify the computer about the power failures of main supply - AC 220V 50 Hz (notification/signal sent when power goes out) via USB using Arduino. I am thinking that this can be done by using the external voltage power supply pin. Whenever power goes out in the mains, the external voltage power supply pin will drop to 0 V from 7 V. The value of the voltage can be read using software ( I am unclear about this: Can it be done? If yes, how?). The Arduino will still be powered up as it is connected to USB of computer and thereby communicates to the computer about the power failure.</p>
<blockquote> <p>I am a novice user of Arduino. I am not sure whether I can connect both USB and external supply through power adaptor to Arduino simultaneously. Would this burn the controller?</p> </blockquote> <p>Lets study the schematic of <a href="http://arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf" rel="noreferrer">Arduino UNO R3</a></p> <p>The input from the power supply plug (PWRIN, the power jack) goes through a diode D1 (to prevent reverse polarity), and feeds a <a href="http://www.onsemi.com/pub/Collateral/NCP1117-D.PDF" rel="noreferrer">NCP1117</a> regulator that down converts it to the 5v supply that feeds the 5v parts. </p> <p><img src="https://i.stack.imgur.com/bNsoC.jpg" alt="Power input"></p> <p>The alternative supply comes from the USB plug (USBVCC). The relevant circuit is shown below</p> <p><img src="https://i.stack.imgur.com/r9NgC.gif" alt="enter image description here"></p> <p>The USB power lines goes through a P-mosfet (T1) that operates as a switch and then goes to the +5V node (that is the +5v regulator output as shown in the first schematic).</p> <p>The mosfet is controlled by an <a href="http://www.onsemi.com/pub/Collateral/LMV321-LMV358-LMV324-D.PDF" rel="noreferrer">LMV358</a> operational amplifier (OPAMP) that operates as a comparator.<br> The negative input of the opamp is tied to 3.3V and the positive one fed through a voltage divider with half the Vin supply level.</p> <ul> <li><p>When Vin >6.6V then the + input of the opamp become higher than the - input and the opamp turns the mosfet off.</p></li> <li><p>When Vin &lt;6.6V then the + input of the opamp become lower than the - input and the opamp turns the mosfet on.</p></li> </ul> <p>Note that Vin is after the input diode so it's about 0.6V lower than the external connected power supply level. So when there is power supply connected to the power input that is higher than 6.6V+0.6V (where 0.6V is the diode D1 voltage drop), then the USB supply line is cutoff (because the mosfet turns off) and the power is provided from the power plug. Connecting or disconnecting the USB supply in this case will not make a difference, so you can have both power supplies connected simultaneously, only when the power input drops below the specified level (about 6.6V+0.6V=7.2V), the USB will start powering the board.</p>
899
|time|arduino-yun|
Arduino Yun does it have a RTC?
2014-03-24T20:25:52.473
<p>Does the Arduino Yun does it have a RTC?</p> <p>And if so is it connected to the Atheros AR9331 or the ATmega32u4?</p> <p>If there there is no RTC, can I connect a DS1307 to the Atheros AR9331?</p>
<p>What happens with your Arduino YUN is that it has an internal clock which sincronizes with a computer (at least this is what I do). However I have read that it can be automatically but I could not do that; have you got a probable solution?</p>
900
|arduino-yun|linux|compile|
Can I compile c/c++ code on the linux part of the Arduino Yun?
2014-03-24T20:31:15.207
<p>Can I compile c/c++ code on the linux part of the Arduino Yun?</p> <p>How complete is the linux part of the Arduino Yun? Can I scp some c/c++ code onto the Atheros AR9331 chip compile it?</p> <p>Or must I first crosscompile all software and then put them onto the Atheros?</p>
<p>The Yun's OS (Linino) is based on OpenWRT, and the official toolchain from OpenWRT does not appear to have changed much. It could probably be done, the question is if you'd really want to though.</p> <p>The limited resources (storage, RAM, CPU) means you would most likely not fit all the parts of the toolchain for C/C++ compilation (perhaps with the exception of very basic programs without many dependencies). The YUN's package manager (opkg) should contain pre-built packackes if they exist, but given that even the list of packages is only kept in RAM to conserve space, I doubt the entire toolchain with libraries needed to compile useful stuff would fit.</p> <p>The official way to build things for OpenWRT appears to be cross-compilation on a much beefier machine, if only because it takes a fraction of the time needed by a native compiler. All in all, you're also very likely to save time and resources by cross-compiling and have more resources left on the YUN itself.</p>
906
|arduino-mega|timers|
Should a delay be expected to cause deadlock?
2014-03-24T22:14:27.140
<p>I have made a simple program using the <code>int main() {}</code> function. It has a delay in it. It is evident the code before the delay is running, but the delay never seems to time out and let the next instructions through. Is this by design?</p> <p>If I rename the method and call it exactly once from the <code>loop() {}</code> function though, it does work.</p> <p><strong>Edit:</strong></p> <p>The code borrowed the 'main()' function and I suppose redefined it:</p> <pre><code>int main() { Forward(); delay(3000); Reverse(); } void Forward() { //... } void Reverse() { //... } </code></pre> <p>I can see this redefinition of <code>main()</code> could cause some serious issues based on the answer below.</p>
<p>You don't seem to use standard Arduino stuff since you defined your own <code>main()</code> which is normally avoided when programming Arduino.</p> <p>If you take a look at Arduino provided <code>main()</code> (in <strong>hardware/cores/arduino/main.cpp</strong>), you'll see how it is defined:</p> <pre><code>#include &lt;Arduino.h&gt; int main(void) { init(); #if defined(USBCON) USBDevice.attach(); #endif setup(); for (;;) { loop(); if (serialEventRun) serialEventRun(); } return 0; } </code></pre> <p>Did you notice the <code>init()</code> function call at the beginning?</p> <p>Its code is defined in <strong>hardware/cores/arduino/wiring.c</strong>; what it does is setup all timers used by Arduino functions, in particular a timer that is needed by <code>delay()</code>.</p> <p>In the same <strong>wiring.c</strong> file, you can also find the definition of <code>delay()</code>:</p> <pre><code>void delay(unsigned long ms) { uint16_t start = (uint16_t)micros(); while (ms &gt; 0) { if (((uint16_t)micros() - start) &gt;= 1000) { ms--; start += 1000; } } } </code></pre> <p>This will turn into an infinite loop if <code>micros()</code> always return the same value, and it does so if <code>init()</code> has never been called before.</p> <p>This is what happens with your code.</p>
910
|serial|arduino-leonardo|
Serial.read has garbled data after a Serial.write
2014-03-25T09:26:50.040
<p>I'm using the <code>Serial1</code> of the Arduino Leonardo to send and receive data with another MCU. The following code will always retrieve garbled data:</p> <pre><code>byte streamReadResponse; Serial1.begin(115200); Serial1.setTimeout(9000); Serial1.print(cmd); Serial1.print('\r'); Serial1.flush(); //wait for all the data to be sent to the serial streamReadResponse = Serial1.readBytesUntil('&gt;', data, dataLength); </code></pre> <p>But, if I add a <code>delay(50)</code> before the Serial1 read, I would get the expected output. The value 50 was found by trial and error.</p> <p>What am I missing? Why is the <code>flush()</code> command not working as expected?</p>
<p>I've finally found that when the MCU to which Arduino is talking to was initialized, it would send spurious data to the Serial - I guess it would start first with a lower baud rate, and then switch to the programmed baud rate of 115200.</p> <p>To fix this, I had to <code>flush</code> the Arduino serial RX before sending any data. So:</p> <pre><code>byte streamReadResponse; Serial1.begin(115200); Serial1.setTimeout(9000); while (Serial1.read() &gt;= 0) ; // do nothing Serial1.print(cmd); Serial1.print('\r'); Serial1.flush(); //wait for all the data to be sent to the serial streamReadResponse = Serial1.readBytesUntil('&gt;', data, dataLength); </code></pre>
911
|arduino-uno|compile|
Warning Arduino CMakeLists "Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES"
2014-03-25T12:24:10.450
<p>I'm trying to build an Arduino example without using its IDE. My OS is <strong>Windows 8.1</strong> and I'm using the last version of <strong>CMake (2.8.12.2)</strong> and <strong>MinGW (GNU Make 3.82.90)</strong>. </p> <p>I downloaded <a href="https://github.com/queezythegreat/arduino-cmake">the Arduino CMakeLists</a> and I learned all about <code>make/upload</code> any firmware in my Arduino. I'm using <strong>Arduino UNO</strong>.</p> <p>Then, if I modify the CMakeLists saved in <code>~/arduino-cmake-master/example/CMakeLists.txt</code> (<strong><em>arduino-cmake-master</em></strong> is the repository folder) to build the WiFi example <strong><em>WiFiWebClient</em></strong> too:</p> <pre><code>... #Add the WiFi example -&gt; WiFiWebClient generate_arduino_example(wifi_example LIBRARY WiFi EXAMPLE WiFiWebClient) ... </code></pre> <p>And execute:</p> <pre><code> $ cmake -G "MinGW Makefiles" ... CMake Warning (dev) in example/CMakeLists.txt: Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link interface. Run "cmake --help-policy CMP0022" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "uno_example" has an INTERFACE_LINK_LIBRARIES property. This should be preferred as the source of the link interface for this library but because CMP0022 is not set CMake is ignoring the property and using the link implementation as the link interface instead. INTERFACE_LINK_LIBRARIES: uno_CORE;uno_example;uno_Wire Link implementation: uno_CORE;uno_Wire This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) in example/CMakeLists.txt: Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link interface. Run "cmake --help-policy CMP0022" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "uno_Wire" has an INTERFACE_LINK_LIBRARIES property. This should be preferred as the source of the link interface for this library but because CMP0022 is not set CMake is ignoring the property and using the link implementation as the link interface instead. INTERFACE_LINK_LIBRARIES: uno_CORE;uno_Wire Link implementation: uno_CORE This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) in example/CMakeLists.txt: Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link interface. Run "cmake --help-policy CMP0022" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "uno_SPI" has an INTERFACE_LINK_LIBRARIES property. This should be preferred as the source of the link interface for this library but because CMP0022 is not set CMake is ignoring the property and using the link implementation as the link interface instead. INTERFACE_LINK_LIBRARIES: uno_CORE;uno_SPI Link implementation: uno_CORE This warning is for project developers. Use -Wno-dev to suppress it. CMake Warning (dev) in example/CMakeLists.txt: Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES defines the link interface. Run "cmake --help-policy CMP0022" for policy details. Use the cmake_policy command to set the policy and suppress this warning. Target "uno_WiFi" has an INTERFACE_LINK_LIBRARIES property. This should be preferred as the source of the link interface for this library but because CMP0022 is not set CMake is ignoring the property and using the link implementation as the link interface instead. INTERFACE_LINK_LIBRARIES: uno_CORE;uno_WiFi Link implementation: uno_CORE This warning is for project developers. Use -Wno-dev to suppress it. -- Generating done -- Build files have been written to: ~/arduino-cmake-master </code></pre> <p>Later I execute:</p> <pre><code>$ mingw32-make ... Linking CXX static library libuno_WiFi.a [ 89%] Built target uno_WiFi Scanning dependencies of target wifi_example [ 92%] Building CXX object example/CMakeFiles/wifi_example.dir/wifi_example_WiFiWebClient.cpp.obj Linking CXX executable wifi_example.elf libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::status()': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:160: undefined reference to `ServerDrv::getClientState(unsigned char)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::stop()': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:131: undefined reference to `ServerDrv::stopClient(unsigned char)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::peek()': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:117: undefined reference to `ServerDrv::getData(unsigned char, unsigned char*, unsigned char)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::read()': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:101: undefined reference to `ServerDrv::getData(unsigned char, unsigned char*, unsigned char)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::read(unsigned char*, unsigned int)': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:107: undefined reference to `ServerDrv::getDataBuf(unsigned char, unsigned char*, unsigned int*)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::available()': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:90: undefined reference to `ServerDrv::availData(unsigned char)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::write(unsigned char const*, unsigned int)': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:73: undefined reference to `ServerDrv::sendData(unsigned char, unsigned char const*, unsigned int)' C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:78: undefined reference to `ServerDrv::checkDataSent(unsigned char)' libuno_WiFi.a(WiFiClient.cpp.obj): In function `WiFiClient::connect(IPAddress, unsigned int)': C:\Program Files\Arduino\libraries\WiFi/WiFiClient.cpp:36: undefined reference to `ServerDrv::startClient(unsigned long, unsigned int, unsigned char, unsigned char)' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::hostByName(char const*, IPAddress&amp;)': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:228: undefined reference to `WiFiDrv::getHostByName(char const*, IPAddress&amp;)' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::status()': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:223: undefined reference to `WiFiDrv::getConnectionStatus()' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::RSSI()': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:181: undefined reference to `WiFiDrv::getCurrentRSSI()' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::SSID()': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:169: undefined reference to `WiFiDrv::getCurrentSSID()' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::localIP()': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:149: undefined reference to `WiFiDrv::getIpAddress(IPAddress&amp;)' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::begin(char*, char const*)': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:87: undefined reference to `WiFiDrv::wifiSetPassphrase(char*, unsigned char, char const*, unsigned char)' C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:92: undefined reference to `WiFiDrv::getConnectionStatus()' libuno_WiFi.a(WiFi.cpp.obj): In function `WiFiClass::init()': C:\Program Files\Arduino\libraries\WiFi/WiFi.cpp:22: undefined reference to `WiFiDrv::wifiDriverInit()' example\CMakeFiles\wifi_example.dir\build.make:95: recipe for target 'example/wifi_example.elf' failed mingw32-make[2]: *** [example/wifi_example.elf] Error 1 CMakeFiles\Makefile2:748: recipe for target 'example/CMakeFiles/wifi_example.dir/all' failed mingw32-make[1]: *** [example/CMakeFiles/wifi_example.dir/all] Error 2 Makefile:74: recipe for target 'all' failed mingw32-make: *** [all] Error 2 </code></pre> <p>The problem is the Arduino.cmake because it's not linking correctly with the library WiFi, but it links with the Wire library.</p> <p>Anyone knows why that warning appears and why Wire links ok but WiFi doesn't?</p> <p>Thanks!</p> <p><strong>Note</strong>: I'm using original code which is in the repository example, I've not modified this one.</p>
<p>Your question actually has 2 distinct parts:</p> <ol> <li>Why does arduino-cmake generate the warning "Policy CMP0022 is not set: INTERFACE_LINK_LIBRARIES..."?</li> <li>Why does <code>make</code>, using the generated MakeFile, fail when building WiFi example?</li> </ol> <p><strong>First off</strong>, the arduino-cmake "<strong>Policy CMP0022</strong>" is just a warning, not an error. As per <a href="https://github.com/Kitware/CMake/blob/master/Help/policy/CMP0022.rst" rel="nofollow noreferrer">this cmake article</a>, that CMP policy has been only recently introduced in <strong>CMake 2.8.12</strong>.</p> <p>You get this warning simply because arduino-cmake has been created based on an older version of cmake and thus does not specifically support this new policy.</p> <p>In order to get rid of this warning, the documentation mentions you should add the <code>cmake_policy(SET CMP0022 OLD)</code> command to your cmake configuration.</p> <p>Unfortunately I tried it in the example <code>CMakeLists.txt</code> to no avail; maybe it has to be set directly in arduino-cmake files (which I have not tested).</p> <p>Thus, if you want to get rid of this boring warning, it seems the only solution you are left with is to disable all warnings when launching cmake:</p> <blockquote> <p>cmake -G "MinGW Makefiles" -Wno-dev</p> </blockquote> <p>This works fine and has removed all warnings..</p> <p><strong>Your second problem</strong> (the real one I would say) is due to to the structure of WiFi library: <img src="https://i.stack.imgur.com/JUqed.png" alt="enter image description here"></p> <p>Indeed, as you can see above, it has a <code>utility</code> subdirectory that contains additional source code that <strong>cannot be found by arduino-cmake</strong>, as by default it searches for source code files only at first level directory.</p> <p>How to solve it? Just tell arduino-cmake to do a <strong>recursive search for the WiFi library</strong>; in your <code>CMakeLists.txt</code>, ensure you add the following line:</p> <pre><code>set(WiFi_RECURSE True) generate_arduino_example(wifi_example LIBRARY WiFi EXAMPLE WiFiWebClient) </code></pre> <p>The added <code>set(WiFi_RECURSE True)</code> line just tells arduino-cmake that, for WiFi library, it should recurse through subdirectories when looking for source code.</p> <p>I have checked it with "Unix Makefiles" (not "MinGW Makefiles" but I guess that won't make any difference) and it worked fine.</p>
935
|serial|c++|library|
Writing First Library - Serial Stream Object
2014-03-26T20:44:02.157
<p>I have done quite a few projects with Arduino, but have never done more than a "Hello World" in C. I am writing my first library, and a lot of the object oriented stuff is going over my head. Anyway, my library is working as it is supposed to, I pass a float to my function and it formats it properly and sends it out over serial. However, I implemented it in a clunky way. The <a href="http://arduino.cc/en/Reference/APIStyleGuide">Arduino API Style Guide</a> mentions a way that seems much better:</p> <blockquote> <p>When using serial communication, allow the user to specify any Stream object, rather than hard-coding "Serial". This will make your library compatible all serial ports on Mega and the Due, and can also use alternate interfaces like SoftwareSerial. The Stream object can be passed to your library's constructor or to a begin() function (as a reference, not a pointer). See Firmata 2.3 or XBee 0.4 for examples of each approach.</p> </blockquote> <p>Can anybody elaborate on how to do this, or show me some code?</p>
<p>Here is a simple example (built and tested with a mega2560), with a class that can be passed a Stream object, and sends a Hello over this generic stream object. When constructing the object, you can pass the Stream object you want to actually communicate:</p> <pre><code>#include "Arduino.h" class MyProtocol { public: MyProtocol(Stream&amp; s):serial(s){} void send(){ serial.println("Hello"); } private: Stream&amp; serial; }; MyProtocol p(Serial); void setup() { Serial.begin(9600); } void loop() { delay(1000); p.send(); } </code></pre> <p>NOTE: The serial.println() is not the Serial global object, note the lower case, it is the internal Stream class variable.</p> <p>If you are confused with the OO and classes, take into account (while you gain more knowledge about it) that this approach can be also used with a simple function, you can pass the serial parameter. Furthermore, it is not necessary to hardwire the Serial interface for ever, you can in fact switch in run time and use a different channel depending on some condition:</p> <pre><code>#include "Arduino.h" void send(Stream&amp; serial){ serial.println("Hello"); } void setup() { Serial.begin(9600); Serial1.begin(9600); } void loop() { delay(1000); if(someCondition) send(Serial); else send(Serial1); } </code></pre>
939
|motor|
Which type of Motor Drivers to drive Unipolar Stepper Motors?
2014-03-27T02:22:22.547
<p>I hope this question is specific enough. Basically I want to know if it matters a great deal what kind of Motor Driver IC(s) or pre-assembled kits you use to drive a Unipolar Stepper Motor.</p> <p>For example: Can the following Driver be used to control this Stepper Motor?</p> <p>Driver: <a href="https://www.sparkfun.com/products/9670" rel="nofollow">https://www.sparkfun.com/products/9670</a></p> <p>Motor: <a href="http://www.jaycar.com.au/productView.asp?ID=YM2754" rel="nofollow">http://www.jaycar.com.au/productView.asp?ID=YM2754</a></p> <p>Thanks!</p>
<p>It does matter. There are pros and cons to each different driver setup. </p> <p>If you wire the motor as a bipolar, which I'm not sure that you can, you can use the driver that you linked, but it is not very good for driving stepper motors. <a href="https://www.sparkfun.com/products/11876" rel="nofollow">https://www.sparkfun.com/products/11876</a> is a better driver for steppers for half the price. (still have to wire it bipolar)</p> <p>If you need to stick with unipolar wiring, <a href="http://www.pcbheaven.com/circuitpages/Simple_Unipolar_Stepper_Motor_Full_Step_Controller/" rel="nofollow">PCBheaven.com</a> shows an example using a CD4017, MOSFETs, and diodes to run a unipolar motor. It will only turn one direction. Instead you could use a micro-controller, such as an Arduino, in place of the CD4017 along with logic-level MOSFETs to go both directions.</p> <p>A tutorial on the Arduino site uses a ULN2003A, which is not powerful enough to drive your motor to its full potential (does it need to turn, or turn well?) and doesn't have the diodes (important to protect your IC!), but the Arduino sketches would still work using the schematic from PCBheaven.</p> <p>A couple of complete driver boards:</p> <p><a href="http://www.electronickits.com/kit/complete/motor/ck1405.htm" rel="nofollow">UNIPOLAR STEPPER MOTOR DRIVER</a></p> <p><a href="http://www.stepperboard.com/SS1010.htm" rel="nofollow">FANCY UNIPOLAR STEPPER MOTOR DRIVER</a></p>
946
|arduino-uno|software|c|
How to call C functions from Arduino sketch?
2014-03-27T12:00:56.460
<p>I would like to know if there is a way to call functions that are contained within C files using an Arduino sketch? </p> <p>My C file declares and defines a function. To save putting the messy function definition into my Arduino sketch, I'd like to call the function straight from the sketch. </p> <p>Is there a standard way to do this using Arduino and C? Here is the sketch: </p> <pre><code>#include "crc16.h"; void setup(){ } void loop(){ CalculateCRC16("&lt;09M", 4); } </code></pre> <p>and this is the trimmed down C file:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdint.h&gt; uint16_t crctable[256] = { 0x0000, 0x1189,..... uint16_t // Returns Calculated CRC value CalculateCRC16( // Call example CalculateCRC16("&lt;09M", 4); const void *c_ptr, // Pointer to byte array to perform CRC on size_t len) // Number of bytes to CRC { uint16_t crc = 0xFFFF // Seed for CRC calculation const uint8_t *c = c_ptr; while (len--) crc = (crc &lt;&lt; 8) ^ crctable[((crc &gt;&gt; 8) ^ *c++)]; return crc; } </code></pre>
<p>You can extern "C" #include like the following:</p> <pre><code>extern "C"{ #include "crc16.h" }; void setup(){ } void loop(){ CalculateCRC16("&lt;09M", 4); } </code></pre> <p>And the crc16.h file could be (some minor fixes, the #pragma once, a cast):</p> <pre><code>#pragma once #include &lt;stdio.h&gt; #include &lt;stdint.h&gt; uint16_t crctable[2] ={ 0x0000, 0x1189}; uint16_t CalculateCRC16( // Call example CalculateCRC16("&lt;09M", 4); const void *c_ptr, // Pointer to byte array to perform CRC on size_t len) // Number of bytes to CRC { uint16_t crc = 0xFFFF; // Seed for CRC calculation const uint8_t *c = (const uint8_t *)c_ptr; while (len--) crc = (crc &lt;&lt; 8) ^ crctable[((crc &gt;&gt; 8) ^ *c++)]; return crc; } </code></pre>
950
|led|
Program stops working after a minute
2014-03-27T16:17:04.193
<p>I have made this small program to lighten up in sequence 8 LEDs, it starts fine, but it stops working after a minute or so and the first 2 LEDs stay permanently ON, its like the chip stoped, here is the code :</p> <pre><code>// Initialize an array with all 8 leds // and give them the corresponding // digital number. const byte led[8] = {0,1,2,3,4,5,6,7}; // the setup routine runs once when you press reset: void setup() { // initialize all 8 digital I/O pins as outputs. for (byte i = 0; i&lt;9; i++) { pinMode(led[i], OUTPUT); } pinMode(13, OUTPUT); } void left (void); void right (void); // the loop routine runs over and over again forever: void loop() { right(); left(); } void left (void) { for (byte i = 0; i&lt;9; i++) { digitalWrite(led[i], HIGH); delay(50); digitalWrite(led[i], LOW); } } void right (void) { for (byte i = 8; i&gt;0; i--) { digitalWrite(led[i], HIGH); delay(50); digitalWrite(led[i], LOW); } } </code></pre> <p>I am using a very old arduino duemilanove.</p>
<p>Thank you guys, its fixed now, i just dont understand why i cant use byte if i do, i>=0, this way i never goes to 255 anyway and if does, it doesn matter, unless im missing something. Here goes the final working code :</p> <pre><code>/* Blink Turns on all 8 leds in sequence back and forth. */ // Initialize an array with all 8 leds // and give them the corresponding // digital number. const char led[8] = {0,1,2,3,4,5,6,7}; #define speed 40 // the setup routine runs once when you press reset: void setup() { // initialize all 8 digital I/O pins as outputs. for (int i = 0; i&lt;8; i++) { pinMode(led[i], OUTPUT); } pinMode(13, OUTPUT); } void left (void); void right (void); // the loop routine runs over and over again forever: void loop() { // Turn off the buzzer on pin 13 digitalWrite(13, LOW); while(1) { right(); left(); } } void left (void) { for (int i = 0; i&lt;8; i++) { digitalWrite(led[i], HIGH); delay(speed); digitalWrite(led[i], LOW); } } void right (void) { for (int i = 7; i&gt;=0; i--) { digitalWrite(led[i], HIGH); delay(speed); digitalWrite(led[i], LOW); } } </code></pre>
954
|arduino-uno|uploading|
"Broken Pipe" when uploading to Arduino UNO
2014-03-27T19:55:06.863
<p>I just got my Arduino UNO and I'm trying to upload the blink example but the upload fails with</p> <pre><code>ioctl("TIOCMSET"): Broken pipe ioctl("TIOCMSET"): Broken pipe avrdude: stk500_recv(): programmer is not responding ioctl("TIOCMSET"): Broken pipe </code></pre> <p>I have tried both Arduino IDE 1.0.1 (which I installed via my package manager) as well as version 1.0.5 which I downloaded from the arduino.cc website. I'm running Ubuntu Linux 12.10 if that makes a difference. </p> <p>I'd appreciate any and all help in getting my arduino up and running!</p>
<h2>It sounds like you have incorrect drivers or the wrong COM port (USB) selected in the IDE</h2> <p>Both are easy to fix. I'd imagine that it would be the COM port.</p> <p><img src="https://i.stack.imgur.com/esLpV.png" alt="IDE"></p> <p>To do this:</p> <blockquote> <p>Tools → Serial Port → [COM port... try a few different ones. Also you can use device manager to see which one disappears when you unplug your Arduino]</p> </blockquote> <p>Few notes on photo:</p> <p>#1. The selector for the COM port. Choose which one your board is on.</p> <p>#2. That shows the COM port selected and board. I don't have my UNO connected: ignore that the COM port isn't showing up on the menu.</p>
976
|led|shields|
LEDs on TX/RX lines interfering with the programmig of the device
2014-03-28T23:29:06.877
<p>I have recently designed a shield to my Arduino Duemilanove, which has 8 LEDs, on the digital GPIO, from 0 to 7, but it won't program with the shield on because the voltage drop is too much on the RX and TX lines. My question is: can I have a LED on the TX/RX line with a minimum resistor value that allows me to program the Arduino?</p>
<p>I just found this reference (<a href="http://www.avrfreaks.net/index.php?name=PNphpBB2&amp;file=printview&amp;t=70515&amp;start=0" rel="nofollow">using ICSP for output as well as programming</a> -- essentially the same thing), and it suggests a 4.7kOhm.</p> <p>I didn't have a 4.7k handy, and used a 15k instead and it works. </p> <p>In my scenario, I have run a sketch with a polarized buzzer connected between RX (digital 0) and <code>GND</code>. When connected directly (with no resistor) the sketch fails to load (but the buzzer works as expected). </p> <p>If I put the resistor in series with it, the sketch uploads without fail. </p> <p>You also probably realise, but mentioning for clarity/completeness, you will lose all serial port functionality for debugging purposes and won't be able to use <code>Serial.[anything]</code>. Make sure to not even initialise the port. </p>
981
|tcpip|
Ethernet shield and IPv6 support
2014-03-29T12:02:09.650
<p>Have you heard about support for IPv6 protocol for any Ethernet shield? As far as I know only IPv4 is supported. Maybe some one would like to write library?</p>
<p>I have been working on an IPv6 library for Arduino, called EtherSia, that works with the ENC28J60 chip, but with a lower overhead compared with libraries that use Contiki / uIP. It is comparable to the EtherCard library for IPv4.</p> <p><a href="https://github.com/njh/ethersia" rel="nofollow noreferrer">https://github.com/njh/ethersia</a></p> <p>While the Wiznet chips do not support IPv6 natively, they do have a MACRAW mode that allows you to send Layer 2 Ethernet frames directly. I have managed to get IPv6 working with the Wiznet W5100 and W5500 chips, which is what the official Arduino Ethernet Shield and Ethernet Shield 2 use.</p> <p>So it is possible...</p>
986
|arduino-uno|icsp|
What's the 2nd ICSP header for in Arduino Uno R3?
2014-03-29T18:33:39.723
<p>Looking at my Arduino Uno R3 board and its <a href="http://arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf" rel="noreferrer">reference design schematic</a> I noticed that there's a second ICSP 6-pin header. In the schematic, the connector I'm referring to is named ICSP1. </p> <p><strong>What's that for?</strong> What useful things can an average Arduino user like me do with it?</p> <p>The relevant part of the schematic is below (marked in red).</p> <p><img src="https://i.stack.imgur.com/2QP5f.png" alt="Arduino Uno R3"></p>
<p>It's for the other MCU on the board.</p> <p>The main MCU on the Uno is labelled "ZIC1". This is the one that is programmed when you press "Upload" in the IDE. But unlike other Arduinos that use a FTDI chip to connect to the serial port on the main MCU, the Uno uses another MCU instead, labelled "U3" on the left. This MCU runs a small bit of code that acts as a serial port via USB and passes through the bytes to its USART1. This then connects to the USART on the main MCU, where the bootloader on that chip accepts the bytes coming through and writes to flash and EEPROM on the main MCU.</p> <p>You can use this additional MCU as you would any other, but the only I/O it has available are the USB connection, the SPI connection via its ICSP header, the UART1 connection to both the main MCU and pins 0 and 1, and two LEDs on PD4 and PD5.</p>
991
|arduino-uno|programming|
Can the 2nd MCU on the UNO R3 be used for keyboard emulation?
2014-03-29T21:53:49.723
<p>Following on from <a href="https://arduino.stackexchange.com/questions/986/whats-the-2nd-icsp-header-for-in-arduino-uno-r3">What&#39;s the 2nd ICSP header for in Arduino Uno R3?</a> I was wondering how this could be hacked to our advantage. </p> <p>For example, could that firmware be rewritten to have the UNO recognised as a mouse/keyboard input? Could this be done after the boot loader process and leave the uploading process in tact?</p> <p>Given the limited IO, it seems it's functions might be limited. Plus I have no idea how much code is space is available. </p>
<p>The second MCU is similar to that used in the Leonardo, but is smaller and less capable (<a href="http://www.atmel.com/devices/atmega16u2.aspx" rel="nofollow">ATmega16U2</a> vs. <a href="http://www.atmel.com/devices/atmega32u4.aspx" rel="nofollow">ATmega32U4</a>). It is certainly possible to reprogram it to do what you like, but its limits means that you can have fewer USB "devices" at the same time.</p> <p>I have not looked at the existing firmware, but it should certainly be possible to add your own custom code into it such that both the normal serial connection to the main MCU as well as your additional code can coexist.</p>
999
|lcd|
What is the point of D0-D3 on LCD?
2014-03-30T11:01:29.997
<p>The <a href="http://arduino.cc/en/Reference/LiquidCrystalConstructor">Arduino LiquidCrystal library</a> has 4 constructors with different arguments:</p> <pre><code>LiquidCrystal(rs, enable, d4, d5, d6, d7) LiquidCrystal(rs, rw, enable, d4, d5, d6, d7) LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7) LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7) </code></pre> <p>The following comments are stated for the constructor arguments:</p> <blockquote> <p>[...] d0, d1, d2, and d3 are optional; if omitted, the LCD will be controlled using only the four data lines (d4, d5, d6, d7).</p> </blockquote> <p>What is the point of <code>d0-d3</code> if they are not needed? Will they decrease the response time?</p>
<p>The presence of those pins is a requirement of the technique that had to be used to interface the LCD to the microprocessors that were available back when the HD44780U controller chip was developed.</p> <p>Single chip microcontrollers as we know them were still in the future and the LCD had to be interfaced to the 8-bit microprocessor chips of the times using the same techniques as any other 8-bit I/O or memory device which was an 8-bit bus. </p>
1002
|arduino-uno|serial|arduino-ide|bootloader|
How to reduce serial speed on Arduino bootloader (optiboot) and on the IDE?
2014-03-30T13:05:38.427
<p>I'm <a href="https://electronics.stackexchange.com/q/104466/29792">debugging a couple of RS232-to-TTL converter boards</a> that I'm trying to use to program my Arduinos and one thing I would like to try would be to reduce the upload serial speed from 115200 to 19200. </p> <p><strong>How do I do that?</strong></p> <p>I imagine that there's a setting that can be easily changed on the Arduino IDE preferences. But where is it? But then the bootloader speed would have to match that? <strong>How do I change the serial upload speed on optiboot, too?</strong></p>
<p>On Arduino IDE side, the upload speed is coded in <code>hardware/arduino/boards.txt</code> </p> <pre><code>uno.upload.speed=115200 ... </code></pre> <p>for every kind of board; you cannot change it directly from the IDE (that would be too dangerous as that value must match the <strong>expected speed for the actual bootloader</strong> of every board).</p> <p>Now as per the optiboot loader side, the upload speed is defined in <code>BAUD_RATE</code> macro, in <code>optiboot.c</code>:</p> <pre><code>/* set the UART baud rate defaults */ #ifndef BAUD_RATE #if F_CPU &gt;= 8000000L #define BAUD_RATE 115200L // Highest rate Avrdude win32 will support #elsif F_CPU &gt;= 1000000L #define BAUD_RATE 9600L // 19200 also supported, but with significant error #elsif F_CPU &gt;= 128000L #define BAUD_RATE 4800L // Good for 128kHz internal RC #else #define BAUD_RATE 1200L // Good even at 32768Hz #endif #endif </code></pre> <p>So I guess you can:</p> <ol> <li><code>#define BAUD_RATE 19200</code> before that block of code</li> <li>recompile the optiboot loader</li> <li>upload your own new bootloader version</li> <li>update <code>uno.upload.speed</code> accordingly in <code>boards.txt</code></li> <li>check it on the usual blink sketch and cross your fingers :-)</li> </ol> <p>Please note that this kind of task is not for beginners, you need to know what you're doing. Also note that I disclaim any responsibility if you get unable to upload programs to your Arduino afterwards!</p>
1003
|arduino-uno|icsp|arduinoisp|
Can the Arduino Uno become an AVR programmer and use the ICSP header to program the target board
2014-03-30T13:21:02.950
<p>The Arduino Uno has an ICSP header that I imagine is for programming the board using a separate ICSP programmer. That is, its ICSP header turn the board into a target.</p> <p><strong>Can one use that same ICSP to program other boards, turning the Arduino Uno effectively into a ICSP AVR programmer? How?</strong></p> <p>I'm assuming that the target boards would also be Arduinos and wanted the Uno to program them using the Arduino IDE. Is that possible?</p> <p>Reading the <a href="http://www.atmel.in/Images/doc0943.pdf">AVR In-System Programming Application Note</a> it looks to me that the only issue would be to make the programmer (the Arduino Uno) control the target board reset line. I've seen something like that in ArduinoISP sketch, but in that sketch, the target reset is controlled by port D10. But one could program the reset line to be an output, right? So could we change the ArduinoISP sketch to use its own reset line as output to control the target board reset line? If not, <strong>why not?</strong></p>
<p>To answer my own question, just to report that I found something close to what I was looking for, which I link and describe briefly below.</p> <p><a href="http://www.gammon.com.au/forum/?id=11635" rel="nofollow noreferrer">Gammon Software Solutions forum - Atmega Bootloader Programmer - Programming Cable</a></p> <p>On that page, the author suggest that we cut pin 5 from the 6-pin ICSP programming cable, solder a pin to it, and wire it to pin D10. Like so:</p> <p><img src="https://i.stack.imgur.com/tMAP4.jpg" alt="Modified ICSP programming cable"> </p> <p>Then, you can load the Arduino Uno with the ArduinoISP sketch and program the target board as usual.</p>
1007
|wifi|
Client or WiFiClient wrapper for adafruit CC3000 wifi
2014-03-30T23:14:46.567
<p>I have a CC3000 wifi module from adafruit that is working OK. Now, I am trying to use it together with an external service, which code requires me to pass a Client (from Arduino SDK) reference, but the Adafruit_CC3000_Client does not inherit from Client nor WifiClient.</p> <p>I am looking for an appropiate wrapper, but unable to find one. Does anyone know about such wrapper?</p>
<p>As I didn't get any answer, and further search for an existing solution failed, I decided to roll my own. The class header is very straightforward, I decided to go for single inheritance and composition of Adafruit_CC3000_Client:</p> <pre><code>class CC3000Client: public WiFiClient { public: CC3000Client(Adafruit_CC3000&amp; cc, Stream&amp; stream=Serial); virtual ~CC3000Client(); virtual int connect(IPAddress ip, uint16_t port); virtual int connect(const char *host, uint16_t port); virtual uint8_t connected(); virtual int available(); virtual void stop(); virtual void flush(); virtual int peek(); virtual int read(); virtual size_t write(uint8_t v); virtual size_t write(const uint8_t *buf, size_t size); virtual int read(uint8_t *buf, size_t size); virtual operator bool(); private: Adafruit_CC3000&amp; cc3000; Adafruit_CC3000_Client client; bool peeked; int peeked_byte; Stream&amp; stream; }; </code></pre> <p>The implementation is a bit tricky (or I didn't manage to find a better way), as the Adafruit client does not have peek() functionality, so this wrapper class have to implement it.</p> <pre><code>CC3000Client::CC3000Client(Adafruit_CC3000&amp; cc, Stream&amp; stre) : cc3000(cc), peeked(false), stream(stre), peeked_byte(0) { } CC3000Client::~CC3000Client() { } int CC3000Client::connect(IPAddress ip, uint16_t port) { client = cc3000.connectTCP((uint32_t) ip, port); peeked = false; if (client.connected()) return 1; return 0; } int CC3000Client::connect(const char *host, uint16_t port) { uint32_t ip = 0; if (!cc3000.getHostByName((char*) host, &amp;ip)) { stream.println(F("Couldn't resolve!")); return 0; } client = cc3000.connectTCP(ip, port); peeked = false; if (client.connected()) { return 1; } return 0; } uint8_t CC3000Client::connected() { return (uint8_t) client.connected(); } int CC3000Client::available() { if(peeked) return 1; return (int) client.available(); } void CC3000Client::stop() { peeked = false; flush(); while (client.connected()){ client.close(); delay(10); } } void CC3000Client::flush() { peeked = false; while (connected() &amp;&amp; available()) read(); } int CC3000Client::peek() { if (!peeked) { if (available()) { peeked_byte = read(); peeked = true; } else return -1; } return peeked_byte; } int CC3000Client::read() { if (peeked) { peeked = false; return peeked_byte; } return (int) client.read(); } size_t CC3000Client::write(uint8_t v) { return (size_t) client.write(v); } size_t CC3000Client::write(const uint8_t *buf, size_t size) { return client.write(buf, size); } int CC3000Client::read(uint8_t *buf, size_t size) { if(peeked){ buf[0]=peeked_byte; peeked=false; return client.read(buf+1, size-1); } return client.read(buf, size); } CC3000Client::operator bool() { stream.println("Error, bool() not implemented"); return true; } </code></pre> <p>Both files are available <a href="https://www.biicode.com/diego/blocks/diego/ardunet/branches/master">here</a>, if you are using <a href="http://www.biicode.com">biicode</a> all you have to do in your code is to put an include like the following and run "bii find", that will also retrieve and install the cc3000 library:</p> <pre><code>#include "diego/ardunet/cc3000client.h" </code></pre> <p>I have used and tested it with a simple http_get call (also <a href="https://www.biicode.com/diego/blocks/diego/ardunet/branches/master">here</a>) and with the <a href="http://www.temboo.com">temboo</a> service, and it has worked OK for sending emails from a Gmail account from an Arduino Mega2560 connected to the CC3000. This temboo service uses via the SDK Client interface most methods of this wrapper, but the bool() operator and the CC3000Client::write(const uint8_t *buf, size_t size) method. </p>
1008
|arduino-uno|programming|string|
Nothng Written to Serial when using sprintf
2014-03-31T00:55:16.420
<p>I'm using <code>sprintf</code> to use a format specifier <code>myTemplate</code> with some strings. The result will then be written to Serial. Although the sketch compiles fine, it does not write any thing to the serial, nothing is seen in the Serial monitor.</p> <p>Is <code>sprintf</code> being used wrongly here?</p> <pre><code>char* result; char* myTemplate; void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { myTemplate = "Welcome %s. You have slept %s times"; sprintf(result, myTemplate, "Jane", "many"); Serial.println(result); Serial.println("hello"); } </code></pre> <hr> <p>When I try the follwing sketch and write something to the Serial monitor, I receive gibberish echoed back to me! Why is this?</p> <p><strong>Sketch</strong></p> <pre><code>char received; char* message = ""; void setup() { Serial.begin(9600); } void loop() { // Echos back if(Serial.available() &gt; 0) { received = Serial.read(); Serial.println(message); if(received == '\n') { message = ""; } else { message += received; } } } </code></pre>
<p>When you use <code>sprintf()</code>, you need to have some space allocated for it to write the result to. At the moment, you're just passing an uninitialised pointer (<code>result</code>), meaning the behaviour of <code>sprintf()</code> is undefined. It might appear to work under some circumstances, but not others (and even if it did seem to work, it could have some nasty side effects on other parts of your code).</p> <p>The simplest approach is to allocate a static <code>char</code> buffer. You need to be sure it's big enough to contain all of the text you want it to store though (plus an extra null character at the end).</p> <p>For example:</p> <pre><code>char* myTemplate = ""; char result[64] = {0}; void setup() { Serial.begin(9600); } void loop() { myTemplate = "Welcome %s. You have slept %s times"; sprintf(result, myTemplate, "Jane", "many"); Serial.println(result); Serial.println("hello"); } </code></pre> <p>As a side note, it's usually a good idea to initialise your variables. This is especially true for pointers.</p>
1013
|serial|arduino-mega|string|
How do I split an incoming string?
2014-03-31T06:35:44.493
<p>I am sending a list of servo positions via the serial connection to the arduino in the following format</p> <pre><code>1:90&amp;2:80&amp;3:180 </code></pre> <p>Which would be parsed as:</p> <p><code>servoId : Position &amp; servoId : Position &amp; servoId : Position</code></p> <p>How would I split these values up, and convert them to an integer?</p>
<p>It's not an answer to your question but it may be useful for someone. If your string has a specific prefix, then you can use simply <code>startsWith</code> and <code>substring</code>. E.g.</p> <pre><code>void loop () if(Serial.available()){ command = Serial.readStringUntil('\n'); Serial.println("Received command: " + command); if(command.startsWith("height")) { Serial.println(command.substring(7)); } } } </code></pre> <p>And then send <code>height 10</code> what will extract <code>10</code>.</p>
1024
|lcd|display|
Save some arduino pins when driving a 4 digits 7 segments display
2014-03-31T12:56:56.303
<p>I built a simple clock using a 4 digits 7 segments LCD display. I display one digit at a time, switching on and off very quicky and cycling through digits.</p> <p>Everything is ok, but I used 8 + 4 = 12 arduino pins. I need 2 more pins for other features and I don't want to use 0 and 1 as I need onboard programming features of Arduino Mini.</p> <p>I used I2C for RTC clock, I could add some interface here (like a PCF8574) and get some pins from here. But I'd like a different (and more educational, for me) approach.</p> <p>Is there an IC that sends an HIGH output on one of four output pins driven by 2 input pins? I need this:</p> <pre><code>IN OUT P0 P1 D0 D1 D2 D3 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 0 1 0 1 1 0 0 0 1 </code></pre> <p>This way I can connect OUT to digit selection and spare 2 pins.</p> <p>Thanks for your hints.</p>
<p>Are you using your analog pins? Did you know <a href="http://arduino.cc/en/Tutorial/AnalogInputPins" rel="nofollow noreferrer">they can be used as digital pins</a>?</p> <blockquote> <p>The analog pins can be used identically to the digital pins, using the aliases A0 (for analog input 0), A1, etc. For example, the code would look like this to set analog pin 0 to an output, and to set it HIGH:</p> <pre><code>pinMode(A0, OUTPUT); digitalWrite(A0, HIGH); </code></pre> </blockquote> <p>This is your best bet if you aren't using all your analog pins.</p>
1030
|c++|
What is the library m in C++ linker?
2014-03-31T16:09:26.943
<p>Following <a href="http://playground.arduino.cc/Code/Eclipse#.UzgDN_nEKG4" rel="nofollow">this guide</a>, it says to include a library in the C++ Linker called <code>m</code>. What is this for?</p> <p>Specifically, <a href="http://playground.arduino.cc/Code/Eclipse#YourSecondArduinoProject" rel="nofollow">Your second Arduino project</a>. </p> <p>4) <strong>Configure project</strong></p> <p>5th dot point:</p> <blockquote> <p>AVR C++ Linker -> Libraries: Under libraries, add arduino_core and m (in that order). Under path, add the path to the correct core library, e.g. "<code>${workspace_loc:/arduino_core/328P_16MHz}</code>"</p> </blockquote>
<p>The m library is the "math" library. You have to link with it in most flavours of gnu compilers (it is typically not required in other, as it is included in the standard lib) when using functions and stuff from the header file "math.h".</p>
1034
|arduino-uno|wifi|firmware|
updating firmware on arduino wifi shield
2014-04-01T00:08:17.063
<p>I'm trying to upgrade firmware on my wifi shield by following the <a href="http://arduino.cc/en/Hacking/WiFiShieldFirmwareUpgrading" rel="nofollow">upgrade instructions for Mac</a>. I was wondering what this means?:</p> <blockquote> <p>Connect a jumper on the J3 connector, that put the shield in the programming mode. Then connect the USB cable to the shield USB mini socket</p> </blockquote> <p><strong>How can I do this?</strong></p>
<p>The jumper is only neccesary if your device is not R3 (revision 3) Be carefully if you connect the shield and your computer does not recognice the port. You gonna need a driver in the link below there are all the steps include other links to download software as Flip 3.4.7 who has the executable batchisp which one you can made the changes read the web site: </p> <p><a href="http://www.dfrobot.com/community/?p=3760" rel="nofollow">http://www.dfrobot.com/community/?p=3760</a></p> <p>and extra information about that in official site of arduino WiFi Shield Firmware Upgrading</p> <p>there you gonna have an idea how to do it.</p> <p>for me was more clear as in this site describe everything and also teach to probe if there is an update having sucess in the process to installing something it could be as a question answered with non the specific thing you need.</p> <p><a href="http://www.binarytaskforce.com/Weblog/2013/09/21/arduino-wifi-firmware-update/" rel="nofollow">http://www.binarytaskforce.com/Weblog/2013/09/21/arduino-wifi-firmware-update/</a></p> <p>I am also in the process to update my device if I will have success I will write to how I do it. At the moment reading a bunch of differents forums beacuse arduino team itself appearently had some troubles to provided a guided how to do it sucessfully.</p>
1045
|serial|android|
How to create a serial communication connection between Cubieboard running Android and Arduino
2014-04-01T14:01:43.577
<p>I am connecting my Arduino to my Cubieboard that is running Android.</p> <p>I tested this originally with my android tablet and USB cable. This worked successfully for the most part using the firmata kit but I don't want to use firmata.</p> <p>I want a basic function library written in Java for use with Unity (eg <a href="https://www.dropbox.com/s/i1mera8850cp6u8/Creating%20a%20Simple%20Unity%20plugin%20to%20Android.mp4" rel="nofollow">Library Tutorial Video</a>) to connect to the Arduino via the USB serial port connection much like a connection with my Windows computer.</p> <p><strong>I'd like basic command functions like:</strong></p> <ul> <li>Connect / Open</li> <li>Write</li> <li>Read</li> <li>Flush</li> <li>Close</li> </ul> <p>I was thinking maybe of using this library <a href="https://github.com/mik3y/usb-serial-for-android" rel="nofollow">here</a> but I am unsure how to go about this. I know similar discussion have already taken place on the forum claiming it may not be possible, but it is very clear that it is. It has been done many times. All I need to do is send strings with serial after finding the Arduino's COM port and reading from the serial.</p>
<p>Totally insane thought here but.....</p> <p>Have you tried writing a chrome App to talk to your Arduino?</p> <p>I did it on the Mac - had chrome monitoring things happening on the network and sending Serial Commands to the Arduino over USB.</p> <p>You can find samples in the Chrome samples / docs</p> <p><a href="https://developer.chrome.com/apps/serial" rel="nofollow">https://developer.chrome.com/apps/serial</a></p>
1046
|arduino-uno|atmega328|
Why my Arduino Uno R3 doesn't work with a recompiled optiboot with BAUD_RATE=57600
2014-04-01T14:10:24.757
<p>This is a follow on question from <a href="https://arduino.stackexchange.com/questions/1002/how-to-reduce-serial-speed-on-arduino-bootloader-optiboot-and-on-the-ide">How to reduce serial speed on Arduino bootloader (optiboot) and on the IDE?</a></p> <p>I did manage recompile optiboot bootloader to work at 57600 bps and uploaded it to a couple of ATmega328-PUs. I just changed the <code>BAUD_RATE</code> to <code>57600L</code> in Makefile and recompiled it.</p> <p>They worked just fine with my <a href="http://arduino.cc/en/Main/ArduinoBoardSerialSingleSided3" rel="nofollow noreferrer">Arduino Single Sided Serial (Severino)</a> and a couple of custom standalone Arduino boards with FTDI-like header.</p> <p>However, I couldn't program the same MCUs using my Arduino Uno R3. When I try to upload a sketch, avrdude just sits there waiting for a response that doesn't come. The output I got is something like this:</p> <pre><code>avrdude: Version 5.11, compiled on Sep 2 2011 at 19:38:36 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch System wide configuration file is "C:\Users\Ricardo\arduino-1.0.5\hardware/tools/avr/etc/avrdude.conf" Using Port : \\.\COM3 Using Programmer : arduino Overriding Baud Rate : 57600 avrdude: Send: 0 [30] [20] avrdude: Send: 0 [30] [20] avrdude: Send: 0 [30] [20] avrdude: Recv: avrdude: stk500_getsync(): not in sync: resp=0x00 avrdude done. Thank you. </code></pre> <p>Would that have anything to do with the 2nd MCU that acts as the USB driver on the Uno - the <a href="http://www.atmel.com/devices/atmega16u2.aspx" rel="nofollow noreferrer">ATmega16U2</a>? Do I have to patch it, too?</p> <p>So, my questions are: </p> <p><strong>1. Why my recompiled optiboot didn't work with my Arduino Uno R3?</strong> </p> <p><strong>2. What can I do to check what's wrong with the upload process using my new bootloader?</strong></p>
<p>Chris Stratton's comments helped me find a workaround for my problem. It looks like the version of optiboot I was working with (see <a href="http://pastebin.com/d8NUirfZ" rel="nofollow">source-code here</a>) doesn't work properly at 57600 BAUD with Arduino Uno without modifications (that I don't know how to make). So I compiled the bootloader with 76800 BAUD, configured the IDE accordingly, and all my boards started to work fine with it.</p> <p>It is still unclear to me the reason I one can't use 57600 BAUD, but I'm too pragmatic and too little knowledgeable to go after the true answer. So, I'll take Chris' word for it. He said this: </p> <blockquote> <p>Basically, 57600 does not divide in 16 MHz nicely when the 8x or 16x oversampling of the hardware UART is taken into account. My gut feeling is that different implementation are using different approximations. If they used the same approximation then even if "wrong" things would be basically fine (especially as the hardware design is similar), but if they are are off in opposite directions it could be unreliable. If you post the exact bootloader source you used we can see for sure - some optiboot source I just looked at seems to actually be using a software UART for 57600.</p> </blockquote> <p>That's the end of it for me.</p>
1075
|avrdude|avr|programmer|
Change Options for the AVR Programmer via Arduino IDE
2014-04-03T19:03:39.057
<p>I want to program an ATtiny through the Arduino IDE. I have a somehow strange programmer. But I can upload via avrdude by </p> <blockquote> <p>avrdude -p attiny13 -P /dev/cu.usbmodemfa131 -c stk500v2 -F -B20 -U flash:w:programm.hex </p> </blockquote> <p>It took a while to figure out that I had to slow the baud rate via the -B20 switch. If I try to upload via the arduino 1.0.5 IDE avrdude is executed as follows.</p> <blockquote> <p>/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -C/Applications/Adafruit Arduino 1.0.5.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -pattiny13 -cstk500v1 -P/dev/tty.usbmodemfa131 -Uflash:w:/var/folders/9t/5jldfq752fs1x74_rhn2plz80000gn/T/build7680201613426497544.tmp/attinytest.cpp.hex:i </p> </blockquote> <p>My question is, how can I change the preferences such that I have control over the avrdude parameters? Say I want to add a -B20 switch and change stk500v1 to stk500v2. </p>
<p><strong>Short answer</strong>: I'm afraid you can't do it with Arduino IDE 1.0.5.</p> <p><strong>Long answer</strong>:</p> <p>First of all, be aware that <code>-B20</code> does not specify the baud rate but the bitclock period (in us); this is specific to <code>stk500v2</code> programmer.</p> <p>Normally, enabling your programmer should only be a matter of adding it to the list of programmers known by Arduino IDE; that list can be found in <code>hardware/arduino/programmers.txt</code>. You would then append the following lines at the end of this file:</p> <pre><code>strangeprogrammer.name=Somehow Strange Programmer strangeprogrammer.communication=serial strangeprogrammer.protocol=stk500v2 strangeprogrammer.force=true strangeprogrammer.speed=????? </code></pre> <p>However, the problem here is that Arduino IDE does not seem to be able to use flag <code>-B</code> (bitclock period) but only flag <code>-b</code> (baud rate) which value is set to whatever you will put to <code>strangeprogrammer.speed</code>. </p> <p>At least that's what I could find out by inspecting Arduino IDE source code: <code>AvrdudeUploader.java</code> never adds that flag to the <code>avrdude</code> command-line :-(</p> <p>That means your options are:</p> <ol> <li><p>Rebuild the Arduino IDE 1.0 on your own after modifying <code>AvrdudeUploader.java</code> to support <code>-B</code> flag; code should be quite easy (about 2 more lines of Java code).</p></li> <li><p>Switch to Arduino IDE 1.5 and follow <a href="https://arduino.stackexchange.com/questions/1075/change-options-for-the-avr-programmer-via-arduino-ide/1077#1077">Federico's answer</a> :-)</p></li> <li><p>Use another IDE, something that deserves the <strong>IDE</strong> name. I use Eclipse with this <a href="http://eclipse.baeyens.it/UsethePlugin.html" rel="nofollow noreferrer">Arduino plugin</a> and it works fine for me. As a bonus, avrdude support seems better as you can see on the screenshot below:</p></li> </ol> <p><img src="https://i.stack.imgur.com/gUqsS.png" alt="enter image description here"></p>
1087
|arduino-yun|web-server|
How do I use Arduino and node.js?
2014-04-05T00:04:48.990
<p>I am new to Arduino, however I have experience in web development, lately I have been using, meteor js and the mean stack for different projects. However, I am open to trying any language for development.</p> <p>What I am trying to do is build a simple application to control the LED on the Arduino over the web.</p> <p>I am working with another person, and the Arduino will be behind a firewall so I am not sure how to access it via the internet. I do have access to an Arduino Uun that I can use for testing at home which does have linio connected via bridge, which I don't quite understand what that does.</p> <p>I've also heard of <a href="https://www.yaler.net/">this</a>, but would like to stay away from third party builds as much as possible if I can do it myself.</p> <p>Whats the common way to do this with an Arduino behind a firewall? How do I do this with a Arduino Yun? Is it easier with a Yun?</p>
<p>I am working on similar project that uses internet to communicate with external device (mobile). I am reading data from sensors and passing them over the web with web sockets. I am using Arduino Yun for this project and Spacebrew (for web sockets communication). It's very interesting approach but quite a challenge in some cases. You will probably run into asynchronous/synchronous problem, which in my case lead me to running some Python scripts on Yun triggered from Processing code. I am currently running Spacebrew server on my VPN, so I can connect my Yun left at home and use my iphone from everywhere to get the readings.</p> <p>It's also worth mentioning Yun comes with pre-installed Temboo library, which is great starting point for web communication. The configuration is really easy and quick. You will also find official documentation very handy and easy to understand. It's really great starting point for experimenting with web-like applications integrated with Arduino Yun.</p> <h3>Spacebrew</h3> <ul> <li><p><a href="http://docs.spacebrew.cc/" rel="nofollow">http://docs.spacebrew.cc/</a></p> <p>Spacebrew is an open, dynamically re-routable software toolkit for choreographing interactive spaces. Or, in other words, a simple way to connect interactive things to one another. Every element you hook up to the system can subscribe to, and publish data feeds.</p></li> <li><p><a href="http://github.com/Spacebrew/pySpacebrew" rel="nofollow">http://github.com/Spacebrew/pySpacebrew</a></p> <p>This repo contains the Spacebrew Library for Python along with documentation and example apps.</p></li> <li><p><a href="http://github.com/julioterra/yunSpacebrew" rel="nofollow">http://github.com/julioterra/yunSpacebrew</a></p> <p>The Spacebrew Yun library features two main components - a set of python scripts that run on the linino, and a library that runs on the atmel chip. You find there information how to install both of these components so that you can connect to Spacebrew from an Arduino sketch.</p></li> </ul> <h3>Temboo</h3> <p>Yun has also build in Temboo library, it's a great way to start experimenting, once you prove the concept you can start narrowing your environment and moving away if you don't want to use 3rd parties software.</p> <ul> <li><p><a href="http://www.temboo.com/arduino" rel="nofollow">http://www.temboo.com/arduino</a></p> <p>The Temboo Library makes it easy to connect to over 100 web-based resources and services with Processing. Currently you can find libraries for Android, Arduino, iOS, Java, Node.js, PHP, Processing, Python, REST API, Ruby, Twyla</p></li> </ul> <h3>Node.js</h3> <p>You can also run node.js on the Yun itself, here's good article and some packages ready to install:</p> <ul> <li><a href="http://giorgiocefaro.com/blog/installing-node-js-on-arduino-yun" rel="nofollow">http://giorgiocefaro.com/blog/installing-node-js-on-arduino-yun</a></li> <li><p><a href="https://github.com/giorrrgio/nodejs-linino" rel="nofollow">https://github.com/giorrrgio/nodejs-linino</a></p> <p>This is an openwrt package for node. It probably only works on mips (not mipsel, or arm). It runs an outdated v8 as well.</p></li> </ul> <h3>What is Bridge library for Arduino Yun?</h3> <p>You also asked about Bridge library. As you know Yun has two processors on board, one is running your Processing code, the other one has Linux on it (Linino). Bridge basically simplifies communication between them so they can "talk" to eachother, more information here:</p> <ul> <li><p><a href="http://arduino.cc/en/Reference/YunBridgeLibrary" rel="nofollow">http://arduino.cc/en/Reference/YunBridgeLibrary</a></p> <p>(Taken from arduino.cc documentation:)</p> <p>The Arduino Yún has two processors on board. One is an ATmega32U4 like on the Arduino Leonardo. The other is an Atheros 9331, running Linux and the OpenWRT wireless stack, which enables the board to connect to WiFi and Ethernet networks. It is possible to call programs or custom scripts on the Linux system through the Arduino to connect with various internet services.</p> <p>The Bridge library simplifies communication between the ATmega32U4 and the AR9331. It inherits from Stream, and many of the methods should be familiar from Serial and other derivatives of Stream.</p> <p>Bridge commands from the 32U4 are interpreted by Python on the AR9331. Its role is to execute programs on the GNU/Linux side when asked by Arduino, provide a shared storage space for sharing data like sensor readings between the Arduino and the Internet, and receiving commands from the Internet and passing them directly to the Arduino.</p> <p>Bridge allows communication in both directions, acting as an interface to the the Linino command line. </p></li> </ul> <h3>Where to start?</h3> <p>I would start with Temboo if I were you, it's a great learning curve and quite simple step to start. You will also learn and understand how the board works and how you can communicate with "external world". Once you have proof of concept, start experimenting with different libraries and improving the approach. Perhaps you will find Spacebrew more handy later or even discover different solutions.</p>
1092
|arduino-uno|shields|wifi|
Parse JSON with arduino to turn on LED
2014-04-06T00:41:43.590
<p>Hi i'm trying to parse JSON resposne from webserver in my arduino in order to turn on and off a LED light. I'm using the wifi client repeating example to make a get request to my server:</p> <p><a href="http://arduino.cc/en/Tutorial/WiFiWebClientRepeating">http://arduino.cc/en/Tutorial/WiFiWebClientRepeating</a></p> <p>Here is what I get printed back from the serial port</p> <pre><code>connecting... HTTP/1.1 200 OK Date: Sun, 06 Apr 2014 01:14:37 GMT Server: Apache X-Powered-By: PHP/5.5.10 Cache-Control: no-cache X-Frame-Options: SAMEORIGIN Set-Cookie: expires=Sun, 06-Apr-2014 03:14:37 GMT; Max-Age=7200; path=/; httponly Connection: close Transfer-Encoding: chunked Content-Type: application/json 19 {"lightstatus":"on"} 0 </code></pre> <p>How do i parse the JSON portion of this response only so that I can use it to control my LED?</p> <p>Thanks</p>
<p>I wrote a simple JSON-RPC library (on top of aJson) with example of how to turn a led on with JSON-RPC procedure call:</p> <ul> <li>Code: <a href="https://github.com/cloud-rocket/arduino-json-rpc" rel="nofollow">https://github.com/cloud-rocket/arduino-json-rpc</a></li> <li>Documentation: <a href="http://www.cloud-rocket.com/2014/03/serial-json-rpc-server-arduino/" rel="nofollow">http://www.cloud-rocket.com/2014/03/serial-json-rpc-server-arduino/</a></li> </ul>
1104
|library|
How do I connect a PS4 controller connected to an Arduino that's connected to a laptop to another Arduino?
2014-04-07T01:57:08.037
<p>My high school is entering an ROV competition and for next year's competition we want to try and set it up so that we can control it using a PS4 controller. I have done research and found <a href="http://www.circuitsathome.com/products-page/arduino-shields/usb-host-shield-2-0-for-arduino-assembled" rel="nofollow">this</a> shield for Arduino and <a href="https://github.com/felis/USB_Host_Shield_2.0" rel="nofollow">this</a> library that allows you to connect it to an Arduino. I plan to then connect the Arduino to a computer via USB and then send each button press to a Processing program via serial. Would it then be possible to send this from Processing to another Arduino out of the laptop? I'm just wondering how feasible this project is.</p> <p>We initially had just a single Arduino at the top with the Ethernet shield and took inputs from standard joystick potentiometers. We want to add in using the PS4 controller this year for easier control. We found the USB Host Shield that gives us that capability, but uses the same pins as the Ethernet shield. So we added another Arduino, connecting the laptop as the bridge also allows to have a GUI. The Ethernet is wired, by the way. We need the laptop, it's not just for a bridge.</p>
<p><strong>This project is very simple.</strong> As I understand it, this is your setup:</p> <pre><code>+–––––––––––––––––––––––––––––––––––––––––+ | | | Arduino 1-––––––––––-PS4 Controller | | | (W. Shield attached) | | |USB | | | | | Computer | | | | | |[Wireless] | | | | | Arduino 2 | | | +–––––––––––––––––––––––––––––––––––––––––+ </code></pre> <p><em><a href="http://asciiflow.com" rel="nofollow">Made with ASCIIFlow</a></em></p> <p>If you have a very small range (I'd say 10-20 feet max), I recommend using Bluetooth. The <a href="http://rads.stackoverflow.com/amzn/click/B0093XAV4U" rel="nofollow">HC 06 Bluetooth module looks like a good choice</a>. There's also a less powerful HC05 if I remember correctly. I had one once but accidentally destroyed it before I could connect with a bad soldering job :). The one linked on Amazon luckily comes with a "backplane" already soldered so you just need to attach 5V, GND, and the TX/RX pins to the Arduino, accordingly. Then, you can select the BT module (wherever it appears on your OS; search online for this) and then you can connect to it and add the password 1234. After that, it should function like a normal COM port.</p> <p>You would connect this to the HC06 to Arduino 2, and wirelessly the HC06 to the computer. The computer would then be connected to Arduino 1, who would receive the PS4 signals, with the shield. You would use Processing to receive the PS4 signals and to send data to the second Arduino board. I'm not an expert on Processing, but I found <a href="https://www.processing.org/reference/libraries/serial/Serial.html" rel="nofollow">this serial library</a>.</p> <p>I <strong><em>do not</em></strong> recommend using Xbee because one Arduino needs to talk to the computer and the other at the same time. That's not practical with the way it's set up on most boards. The OP would need another UART connection, even so the Xbee and the USB to UART chip use the same pins on all standard boards. </p>
1105
|arduino-uno|shields|wifi|
Controlling LED from web server
2014-04-07T06:11:31.823
<p>I have a LED attached to my Arduino wifi shield that I want to control from my PHP web server. In terms of communication, should I </p> <ol> <li><p>Make my Arduino a web server and then communicate with PHP web server via HTTP</p></li> <li><p>Make my Arduino a web client and receive commands from my PHP web service. I would parse the JSON response</p></li> </ol> <p>Also my other question is should I communicate with JSON between my PHP web server or is there a better way to send commands to my LED light? </p>
<p>The REST protocol is ideal for this and there's a nice Sketch already written, called RESTduino on Github: <a href="https://github.com/jjg/RESTduino" rel="nofollow">https://github.com/jjg/RESTduino</a></p> <p>Basically (and loosely) REST treats a URL as a command. Quoting from the RESTduino doc's:</p> <p>"To turn on the LED attached to pin #9 (currently case sensitive!):</p> <pre><code>http://192.168.1.177/9/HIGH </code></pre> <p>This will set the pin to the HIGH state and the LED should light. Next try this:</p> <pre><code> http://192.168.1.177/100 </code></pre> <p>This will use PWM to illuminate the LED at around 50% brightness (valid PWM values are 0-255)."</p>
1118
|sensors|arduino-mega|
Can anyone explain how to use MPL sensor with Arduino MEGA?
2014-04-07T23:11:25.913
<p>I am trying to connect a MPL3115A2 Altitude/Pressure/Temp Sensor Breakout which I bought from Hobbytronics to my Arduino Mega. What I had in mind was (Breakout -> Arduino):</p> <p><code>3.3V -&gt; 3.3 V</code> <code>GND -&gt; GND</code> <code>SDA -&gt; A4</code> <code>SCL -&gt; A5</code></p> <p>The information which I've found so far is very conflicting and I'm not sure whether or not I should be using pull-up or in-line resistors, and if so, what value? </p> <p>The code which the product page links to also differs, with one stating that the Wire library is unsafe to use with a 3.3V rated sensor due to the internal pull-ups, but the other code uses the Wire library? </p> <p>If anyone could advise me on how best to use this sensor without frying it, it would be much appreciated!</p> <ul> <li><a href="http://www.hobbytronics.co.uk/mpl3115a2-pressure-temp-sensor" rel="nofollow">Product information</a></li> <li><a href="https://github.com/sparkfun/MPL3115A2_Breakout/tree/master/firmware" rel="nofollow">Code</a></li> </ul>
<p>Since the device is 3.3V and the Arduino is 5V, you <em>will</em> need a I<sup>2</sup>C level converter such as the <a href="http://www.ti.com/product/tca9517" rel="nofollow">TCA9517</a>. Simply supply the Mega side with 5V and the device side with 3.3V and attach 4.7kohm pull-ups to 5V on the Mega side, and it will convert both SDA and SCL for you. You won't need pull-ups on the device side since it includes pull-ups on the board.</p> <p>For I1 and I2 (push-pull outputs) you can use either normal level converters or you can use a <a href="http://www.ti.com/product/sn74lvc2g07" rel="nofollow">SN74LVC2G07</a> along with the pull-ups found on the Mega inputs.</p>
1128
|timers|
Calibrate Watchdog Timer
2014-04-09T03:31:11.847
<p>Is there any good way to calibrate the watchdog timer? I'm trying to use it as a time source, even when asleep, but it's woefully inaccurate. Some simple testing showed it loosing 2 minutes every <em>hour</em>!</p>
<p>Not only is it uncalibrateable, but it's actually pretty rubbish (as you've discovered). If you check the datasheet you'll see that it can vary between about 109kHz and 119kHz, even though its nominal frequency is 128kHz.</p> <p>With the ATmegaXX8(A/P) you can reconfigure the system to run its CPU off the internal RC oscillator and timer 2 from a crystal across TOSC1/TOSC2 (pins 9/10 [DIP] or 7/8 [TQFP]) by setting ASSR[6:5] to 0b01 and changing the CKSEL[3:0] fuse bits to 0b0010. Take careful note of the warning on AS2 in the datasheet though. If you want to use a watch crystal instead of prescaling the existing crystal on an Arduino board then you'll need some soldering skill as well.</p> <p>If you need crystal accuracy for the CPU as well then you'll need to move up to an AVR family that has a separate asynchronous timer that can be supplied with a watch crystal, such as the ATmegaXX4(P) (Sanguino) or ATmegaXXX0 (Mega/Mega 2560).</p>
1138
|arduino-mega|shields|lcd|
2.4" TFT LCD Shield isn't working on Arduino Mega
2014-04-10T21:01:52.340
<p>Even on ebay's <a href="http://www.ebay.com/itm/2-4-TFT-LCD-Shield-Touch-Panel-Display-TF-Reader-For-Arduino-UNO-R2-R3-A137-/390631788477" rel="noreferrer">website</a> it is mentioned that I can't use 2.4" TFT LCD Shield display on attach to Arduino Mega. The problem is that I bought this shield by mistake. I want to put this shield onto Arduino Mega 2560. Is there a way to combine Mega and 2.4" Display Shield?</p> <p>note: I tried on my friend's Arduino Uno. Shield is working very good.</p> <p>note: The photo below is determining my question. The display not runs my Arduino's code. It only runs its LED.</p> <p><img src="https://i.stack.imgur.com/DGkHU.jpg" alt="enter image description here"></p> <pre><code> // UTFT_Demo_320x240 (C)2012 Henning Karlsen // web: http://www.henningkarlsen.com/electronics // // This program is a demo of how to use most of the functions // of the library with a supported display modules. // // This demo was made for modules with a screen resolution // of 320x240 pixels. // // This program requires the UTFT library. // #include &lt;UTFT.h&gt; #define ILI9320_16 18 // Declare which fonts we will be using extern uint8_t SmallFont[]; // Uncomment the next line for Arduino 2009/Uno //UTFT myGLCD(UNO_24,A2,A1,A3,A4); // Remember to change the model parameter to suit your display module! // Uncomment the next line for Arduino Mega UTFT myGLCD(ILI9320_16,38,39,40,41); // Remember to change the model parameter to suit your display module! void setup() { randomSeed(analogRead(0)); // Setup the LCD pinMode(A0,OUTPUT); // for the UNO_SHIELD_1IN1 digitalWrite(A0,HIGH); // the RD pin must be set high myGLCD.InitLCD(); myGLCD.setFont(SmallFont); } void loop() { int buf[318]; int x, x2; int y, y2; int r; // Clear the screen and draw the frame myGLCD.clrScr(); myGLCD.setColor(255, 0, 0); myGLCD.fillRect(0, 0, 319, 13); myGLCD.setColor(64, 64, 64); myGLCD.fillRect(0, 226, 319, 239); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(255, 0, 0); myGLCD.print("* Universal Color TFT Display Library *", CENTER, 1); myGLCD.setBackColor(64, 64, 64); myGLCD.setColor(255,255,0); myGLCD.print("&lt;http://electronics.henningkarlsen.com&gt;", CENTER, 227); myGLCD.setColor(0, 0, 255); myGLCD.drawRect(0, 14, 319, 225); // Draw crosshairs myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.drawLine(159, 15, 159, 224); myGLCD.drawLine(1, 119, 318, 119); for (int i=9; i&lt;310; i+=10) myGLCD.drawLine(i, 117, i, 121); for (int i=19; i&lt;220; i+=10) myGLCD.drawLine(157, i, 161, i); // Draw sin-, cos- and tan-lines myGLCD.setColor(0,255,255); myGLCD.print("Sin", 5, 15); for (int i=1; i&lt;318; i++) { myGLCD.drawPixel(i,119+(sin(((i*1.13)*3.14)/180)*95)); } myGLCD.setColor(255,0,0); myGLCD.print("Cos", 5, 27); for (int i=1; i&lt;318; i++) { myGLCD.drawPixel(i,119+(cos(((i*1.13)*3.14)/180)*95)); } myGLCD.setColor(255,255,0); myGLCD.print("Tan", 5, 39); for (int i=1; i&lt;318; i++) { myGLCD.drawPixel(i,119+(tan(((i*1.13)*3.14)/180))); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); myGLCD.setColor(0, 0, 255); myGLCD.setBackColor(0, 0, 0); myGLCD.drawLine(159, 15, 159, 224); myGLCD.drawLine(1, 119, 318, 119); // Draw a moving sinewave x=1; for (int i=1; i&lt;(318*20); i++) { x++; if (x==319) x=1; if (i&gt;319) { if ((x==159)||(buf[x-1]==119)) myGLCD.setColor(0,0,255); else myGLCD.setColor(0,0,0); myGLCD.drawPixel(x,buf[x-1]); } myGLCD.setColor(0,255,255); y=119+(sin(((i*1.1)*3.14)/180)*(90-(i / 100))); myGLCD.drawPixel(x,y); buf[x-1]=y; } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some filled rectangles for (int i=1; i&lt;6; i++) { switch (i) { case 1: myGLCD.setColor(255,0,255); break; case 2: myGLCD.setColor(255,0,0); break; case 3: myGLCD.setColor(0,255,0); break; case 4: myGLCD.setColor(0,0,255); break; case 5: myGLCD.setColor(255,255,0); break; } myGLCD.fillRect(70+(i*20), 30+(i*20), 130+(i*20), 90+(i*20)); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some filled, rounded rectangles for (int i=1; i&lt;6; i++) { switch (i) { case 1: myGLCD.setColor(255,0,255); break; case 2: myGLCD.setColor(255,0,0); break; case 3: myGLCD.setColor(0,255,0); break; case 4: myGLCD.setColor(0,0,255); break; case 5: myGLCD.setColor(255,255,0); break; } myGLCD.fillRoundRect(190-(i*20), 30+(i*20), 250-(i*20), 90+(i*20)); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some filled circles for (int i=1; i&lt;6; i++) { switch (i) { case 1: myGLCD.setColor(255,0,255); break; case 2: myGLCD.setColor(255,0,0); break; case 3: myGLCD.setColor(0,255,0); break; case 4: myGLCD.setColor(0,0,255); break; case 5: myGLCD.setColor(255,255,0); break; } myGLCD.fillCircle(100+(i*20),60+(i*20), 30); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some lines in a pattern myGLCD.setColor (255,0,0); for (int i=15; i&lt;224; i+=5) { myGLCD.drawLine(1, i, (i*1.44)-10, 224); } myGLCD.setColor (255,0,0); for (int i=224; i&gt;15; i-=5) { myGLCD.drawLine(318, i, (i*1.44)-11, 15); } myGLCD.setColor (0,255,255); for (int i=224; i&gt;15; i-=5) { myGLCD.drawLine(1, i, 331-(i*1.44), 15); } myGLCD.setColor (0,255,255); for (int i=15; i&lt;224; i+=5) { myGLCD.drawLine(318, i, 330-(i*1.44), 224); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some random circles for (int i=0; i&lt;100; i++) { myGLCD.setColor(random(255), random(255), random(255)); x=32+random(256); y=45+random(146); r=random(30); myGLCD.drawCircle(x, y, r); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some random rectangles for (int i=0; i&lt;100; i++) { myGLCD.setColor(random(255), random(255), random(255)); x=2+random(316); y=16+random(207); x2=2+random(316); y2=16+random(207); myGLCD.drawRect(x, y, x2, y2); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); // Draw some random rounded rectangles for (int i=0; i&lt;100; i++) { myGLCD.setColor(random(255), random(255), random(255)); x=2+random(316); y=16+random(207); x2=2+random(316); y2=16+random(207); myGLCD.drawRoundRect(x, y, x2, y2); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); for (int i=0; i&lt;100; i++) { myGLCD.setColor(random(255), random(255), random(255)); x=2+random(316); y=16+random(209); x2=2+random(316); y2=16+random(209); myGLCD.drawLine(x, y, x2, y2); } delay(2000); myGLCD.setColor(0,0,0); myGLCD.fillRect(1,15,318,224); for (int i=0; i&lt;10000; i++) { myGLCD.setColor(random(255), random(255), random(255)); myGLCD.drawPixel(2+random(316), 16+random(209)); } delay(2000); myGLCD.fillScr(0, 0, 255); myGLCD.setColor(255, 0, 0); myGLCD.fillRoundRect(80, 70, 239, 169); myGLCD.setColor(255, 255, 255); myGLCD.setBackColor(255, 0, 0); myGLCD.print("That's it!", CENTER, 93); myGLCD.print("Restarting in a", CENTER, 119); myGLCD.print("few seconds...", CENTER, 132); myGLCD.setColor(0, 255, 0); myGLCD.setBackColor(0, 0, 255); myGLCD.print("Runtime: (msecs)", CENTER, 210); myGLCD.printNumI(millis(), CENTER, 225); delay (10000); } </code></pre>
<p>I just happened to buy the same LCD Shields a few days ago, looking for a library to use it with a MEGA 2560 board I found <a href="https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code">https://github.com/Smoke-And-Wires/TFT-Shield-Example-Code</a> which supports both <strong>UNO</strong> and <strong>MEGA</strong> boards.</p> <p>Usage is very, simple if we want to use it for <strong>MEGA</strong> we should change the header <code>#include "uno_24_shield.h"</code> in <strong>SWTFT.cpp</strong> to <code>#include "mega_24_shield.h"</code></p> <p><strong>Description (useful for adding suppport for the shield in other libraries):</strong></p> <p>Incompatibility comes from different Port mappings for Arduino pin-out between Mega and UNO.</p> <p>in <strong>UNO</strong> LCD shield will be connected through:</p> <pre><code>+---------------+-----+-----+-----+-----+-----+-----+-----+-----+ | LCD Data Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +---------------+-----+-----+-----+-----+-----+-----+-----+-----+ | Digital pin # | 7 | 6 | 5 | 4 | 3 | 2 | 9 | 8 | +---------------+-----+-----+-----+-----+-----+-----+-----+-----+ | Uno port/pin | PD7 | PD6 | PD5 | PD4 | PD3 | PD2 | PB1 | PB0 | +---------------+-----+-----+-----+-----+-----+-----+-----+-----+ </code></pre> <p>in <strong>MEGA</strong> it will be connected through:</p> <pre><code>+---------------+-----+-----+-----+-----+-----+-----+-----+-----+ | LCD Data Bit | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | +---------------+-----+-----+-----+-----+-----+-----+-----+-----+ | Digital pin # | 7 | 6 | 5 | 4 | 3 | 2 | 9 | 8 | +---------------+-----+-----+-----+-----+-----+-----+-----+-----+ | MEGA port/pin | PH4 | PH3 | PE3 | PG5 | PE5 | PE4 | PH6 | PH5 | +---------------+-----+-----+-----+-----+-----+-----+-----+-----+ </code></pre>
1144
|programming|library|sketch|arduino-yun|web|
It is possible to program Linino to send HTTP requests and then use the returned values in sketch?
2014-04-11T18:09:40.020
<p>I am new to using Arduino Yun and I would like to know if it is possible to run a command from the Arduino sketch in order to make (probably, through the Bridge Library) Linino to execute a HTTP Request to a remote server. Then I would like to know if it is possible to use the returned values in that Arduino sketch.</p> <p>In other words, I would like to delegate the task of retrieving values from the web to the Linux side and the usage of the retrieved data to the sketch.</p> <p>If it is possible, how to do that?</p>
<p>Take a look at <a href="http://arduino.cc/en/Tutorial/Bridge" rel="nofollow">Bridge example</a> or <a href="http://arduino.cc/en/Tutorial/TemperatureWebPanel" rel="nofollow">TemperatureWebPanel example</a>: you see you can receive kind of "commands" and react "doing things".</p> <p>Then take a look at <a href="http://arduino.cc/en/Tutorial/HttpClient" rel="nofollow">HTTP Client example</a>, where you delegate an HTTP call to the linux side.</p> <p>Now mix the two: you can make HTTP calls after receiving a command from outside your Yun.</p> <p>A short test can be done by cutting and pasting the examples above.</p>
1146
|programming|sketch|arduino-yun|web|
It is possible to run an entire script on the Linux side? If so, how, what and where to do that?
2014-04-11T19:48:47.153
<p>I am new to using Arduino Yun and I would like to know if it is possible to run an entire script on the Linux side. In my case the script should execute a HTTP request to a remote server, parse the subsequent HTTP response and return some value that then can be used in the Arduino sketch.</p> <p>If it is possible, what I have to do? For example, how should I write and run script files? what programming language should I use? where I should put those script files on the Linux side?</p>
<p>Arduino Yun ships with python pre installed. You can copy python scripts from your pc to the yun with <code>scp</code> (or WinSCP or <code>putty</code>, if you're on windows). Once copied, just run it using Process from your sketch. As they are scripts, program name is <code>python</code> and the path to your script is its first argument (you can do that in a different way, but that would require some linux magic, which I suggest to postpone if you're new to it).</p> <p>Other pre installed options include <a href="http://www.lua.org/" rel="nofollow">lua</a> and bash. Other languages such as ruby, erlang and php are available as optional packages.</p>
1151
|arduino-yun|
Accessing Arduino Yun from Internet
2014-02-26T17:18:22.927
<p>I am trying to access my Arduino Yun from the internet, and it's not quite working. I have correctly port forwarded the port 5555 from the router to the Yun (verified I am able to access my many other NAT'd resources). </p> <p>I can access the Yun from my internal network. </p> <p>In the Arduino sketch I have this (among many other things). Mainly taken from example sketches.</p> <pre><code>#include &lt;Bridge.h&gt; #include &lt;HttpClient.h&gt; #include &lt;YunServer.h&gt; #include &lt;YunClient.h&gt; YunServer server; void setup { // Listen for incoming connections on port 5555 server.noListenOnLocalhost(); server.begin(); } </code></pre> <p>Is <code>server.noListenOnLocalhost();</code> the right one to use to access from the outside world?</p>
<p>Well, I'm not familiar with the Yun, but the first thing that stands out is the missing</p> <pre><code>Bridge.begin(); </code></pre> <p>line apparently needed to initialize the Bridge library that you use.</p> <p>And you do have something like</p> <pre><code>YunClient client = server.accept(); </code></pre> <p>and "more" in the main loop (or a function where applicable) of your code, right ?</p> <p>And yes, <code>noListenOnLocalhost()</code> is the correct function for serving external clients.</p>
1158
|electricity|
How can Arduino control with a servo with only one wire?
2014-04-13T08:08:26.073
<p>I was playing with getting my servos to be on dedicated power, separate form the Arduino entirely, but obviously controlled by the Arduino. I originally had the ground of the Arduino joined with the <code>-</code> of the battery, but to my surprise my Arduino continued to control the servos when I remove the ground wire entirely from the Arduino. </p> <p>I was under the impression that all electricity must form a complete circuit, and be a closed loop. But my Arduino can obviously send a signal to a component that has no return path to itself.</p> <p>I feel like I'm missing something fundamental about a electricity. So my question is:</p> <p><strong>Why does this work?</strong></p> <p><img src="https://i.stack.imgur.com/n37I0.jpg" alt="arduino setup"></p>
<p>The return signal is probably the other wire's servo. This only works when the control pulses to both servos are not in sync. Pull one signal wire off the breadboard and both servos will stop working.</p> <p>You need to interconnect grounds or you will get strange effects sooner or later.</p>
1160
|arduino-due|bossa|ubuntu|
Why does command line BOSSA not recognize Arduino Due?
2014-04-13T12:32:51.317
<p>Running Ubuntu 12.04.4 LTS (64 bit) I try to upload my code to the Arduino Due through the Native port. I have tried both the <code>bossac</code> that ships with the Arduino IDE (which is a modified version of BOSSA), and the master BOSSA branch.</p> <p>Running this command:</p> <pre><code>sudo ./bossac -p /dev/ttyACM0 </code></pre> <p>I get this error:</p> <pre><code>No device found on /dev/ttyACM0 </code></pre> <p>However, it works perfectly inside the Arduino IDE.</p> <p>What can the problem be?</p>
<p>The Arduino CLI uses a slightly different version of bossa from the one that is on master:</p> <p><a href="https://github.com/shumatech/BOSSA/tree/arduino" rel="nofollow noreferrer">https://github.com/shumatech/BOSSA/tree/arduino</a></p> <p>On Linux, I was able to do the following:</p> <pre><code>$ git clone git@github.com:shumatech/BOSSA.git $ cd BOSSA $ make bin/bossac -j4 $ stty -F /dev/ttyACM0 1200 $ ./bin/bossac --port=/dev/ttyACM0 --force_usb_port=true -e -w -v -b /path/to/my/firmware.bin -R </code></pre> <p>(I got the answer from <a href="https://forum.arduino.cc/index.php?topic=150195.0" rel="nofollow noreferrer">this Arduino forum thread</a>.)</p>
1186
|serial|
What's the fastest way to periodically communicate via serial?
2014-04-15T20:33:26.320
<p>I will be using an Arduino as a bridge between a computer high-level Java client and some low-level hardware computing units (e.g. other Arduinos). I need to find a solution to <strong>periodically</strong> communicate in <strong>both</strong> ways. It should be possible to send digital, analog inputs to the PC and receive digital, analog outputs from the PC via serial.</p> <p>I have very specific requirements for my project to work: </p> <ol> <li><p>Lowest possible latency in both ways. High latency would cause instability of controlled systems.</p></li> <li><p>Extremely constant, possibly user-defined update period. Varying sample rate would cause inaccuracies in the control.</p></li> </ol> <p>I need a very fast solution possible for update frequency of 100 Hz and higher.</p> <p>So far I have tried to send data via Firmata to my java client using time interrupt.</p> <pre><code>ISR(TIMER1_COMPA_vect) { Firmata.sendAnalog(analog, analogRead(analog)); } </code></pre> <p>The messages however don't come at a very constant rate and are sometimes held up for twice the sample period or more which is unnaceptable. For higher frequencies this happens even more often. I suspect some kind of a buffer. Do you have any idea where should I look for bottlenecks? Would it be benefiting to design my own communication protocol and ditch Firmata?</p> <p>EDIT: Look at the attached <a href="https://i.stack.imgur.com/9K9L8.png" rel="nofollow noreferrer">diagram </a>. Blue lines are "inputs", green lines "outputs". Right now I am trying to design the "Arduino (Bridge)" <img src="https://i.stack.imgur.com/fAmud.png" alt="enter image description here"></p>
<p>could you be more specific with your question ? From what I understood:</p> <ul> <li>you have a client java program acting as the &quot;brain&quot; of your system</li> <li>your control is time sensitive. You have a PID or other regulation loop running on the pc</li> <li>you have or plan to have multiple arguing boards on your system and you need to communicate with them.</li> <li>you are dealing with analog IOs</li> </ul> <h2>bridging</h2> <p>If you want to stick to serial port,you have to use RS485 or RS422. Those can work as a bus. Protocol on top of that can be Modbus. Note that this has a higher latency and you need at least 2 serial ports on your bridge</p> <p>I2C. Lower latency 2 wires bus. Command oriented,runs at 400 kHz. So you have plenty of time to send/receive data</p> <p>SPI even lower latency as bytes are sent as stream .arduino mega has 5 pins for it. Note that you have to deal with the addressing yourself in this case.</p> <p>Arduino like many micro controllers is bad as doing many tasks at the same time like for the bridging case. I would avoid using an arduino in this case</p> <h2>latency</h2> <p>As already answered, ADC conversion takes time and you cannot nest interrupt. Your minimum latency can be computed from the specifications of the arduino. The maximum latency is a value you fix yourself. Knowing the amount of time to send one byte on the communication port, You can decide between options like</p> <ul> <li>run the AD conversion in a loop outside interrupt, put the value inside a variable and do the communication a synchronously inside an interrupt</li> <li>run the AD conversion interrupt based and the communication in the main loop of operation</li> </ul> <h2>conclusions</h2> <p>Don't do hardware in the loop using a PC. The latency and lack of strict timing possibilities worsened by the use of java make it a dead end with your current setup.</p> <p>Use a stronger micro controller like an AVR32 with USB running the brain of your system. You can also use a raspberries pi or a beaglebone. Those runs &quot;standard&quot; Linux distributions and so you can use a PC like approach.</p> <p>In any case guidelines are :</p> <ul> <li>try to stay as close to the micro controller as possible and avoid abstraction libraries and OSes</li> <li>don't use a pc for hardware in the loop</li> <li>try to make your task run a synchronously as much as possible</li> <li>keep your interrupt routines as small as possible</li> </ul>
1189
|button|led|debugging|potentiometer|
Why does my wired button always read HIGH?
2014-04-16T01:50:05.913
<p>I have made a simple Arduino program that uses a potentiometer to dim a LED.</p> <p>This program also makes a second LED blink.</p> <p>Finally, I have added a button that controls a third LED; this part of my program does not work: the 3rd LED is always lit as the button always reads HIGH.</p> <p>Here is the code:</p> <pre><code>//sensePin is wired up to the FSR int sensePin = 2; //this is wired up to an LED int ledPin = 9; //Wired up to a button int inputPin = 1; int val = 0; //I was broed so added the default Blink int ledPinX = 13; //Wired up to a second LED int ledPinY = 7; void setup() { Serial.begin(9600); pinMode(ledPin, OUTPUT); pinMode(inputPin, INPUT); pinMode(ledPinX, OUTPUT); pinMode(ledPinY, OUTPUT); val = digitalRead(inputPin); } void loop() { if (val == HIGH){ //This should ask "If your button is pressed, then do the code below digitalWrite(ledPinY, HIGH); //but for some reason the light is always on. I've tried it with more than one button } else if(val == LOW){ digitalWrite(ledPinY, LOW); } int value; /* The rest of this stuff works. Well, it did before adding in the button. Now the FSR acts as a digital input. Please help. */ value = analogRead(sensePin) / 4; analogWrite(ledPin, value); digitalWrite(ledPinX, HIGH); delay(500); digitalWrite(ledPinX, LOW); delay(500); } </code></pre> <p>What did I do wrong in this code?</p> <p>EDIT:: diagram and pic at: instagram.com/p/m3AmHWmp4e</p>
<p>Pin 1 is used for the serial output and can't be used if you enable serial using <code>serial.begin(9600)</code>.</p> <p>Change button to pin 2.</p>
1194
|shields|tcpip|gsm|
Which shield to use for GPRS?
2014-04-16T16:15:29.203
<p>I&#039;m planning to build a device that would read some sensor data and send it via GPRS, eg. once per day. (Not that original, yeah.) But my problem is choosing a GSM/GPRS shield.</p> <p>The official shield has a <a href="http://arduino.cc/en/Guide/ArduinoGSMShield#toc10"><strong>nice interface for doing an HTTP POST/GET</strong></a>. OTOH, the shield seems to be sold out (and would be quite expensive anyway).</p> <p>There seem to be other shields available, but their code examples tend to look <a href="http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0#A_Simple_Source_Code_Examples"><strong>quite hacky</strong></a>: the device waits for an arbitrary moment and then hopes that the server is done. That&#039;s IMO both inefficient or unreliable.</p> <p>My question: which GSM/GPRS shield would you recommend, with these features:</p> <ul><li>a sane library w/ examples, such as the official one</li><li>an external antenna</li><li>bonus: a competitive price</li><li>another bonus: hopefully a &quot;real&quot; shield, so no soldering required and a few pins still easily usable for the sensors.</li></ul>
<p>LinkitOne - ok not a shield but rather a compatible Arduino controller board with built-in GSM/GPRS/GPS/Wifi. comms library doesn't have as many diagnostic methods as e.g. the Adafruit one, but it was easy to setup and reliable. Main downside of the LinkitOne was that it uses a different processor from Arduinos so many of the Arduino libraries aren't compatible e.g. for I2C devices.</p> <p>Adafruit Fona SIM808 2G Shield version. shield layout but stackable headers have to be bought and soldered seperately. Default pinouts work with Uno, but mods required for Mega. Library has lots of handy diagnostic methods (battery voltage, signal strength, etc). worked with giffgaff prepaid SIM but not vodafone for some reason. SMS worked ok. I could connect to GPRS but getting html from a website didnt' work.</p> <p>DFRobot SIM808 GPS/GPRS/GSM Shield - Pre wired wirth stackable shield connectors, instructions to upload code and run the device are convoluted and vague. I Wasn't even able to get a basic connection to the Arduino to work. Either the library is very buggy or my device was faulty.</p> <p>SEEEDStudio 113030009 GPRS Shield with Antenna and External SIM Holder V3.0 I'll probably tets this next..</p> <p>Official Arduino GSM board DISCONTINUED</p> <p>Sparkfun GSM/GPRS Module - SM5100B DISCONTINUED</p>
1197
|programming|sketch|
strange behaviour of dtostrf()
2014-04-16T16:41:54.100
<p>I'm trying to program a little bit in Arduino, but I'm stuck with probably something trivial.</p> <p>This is what I have: </p> <pre><code>char ang[3], lat[9]; dtostrf(GPS.angle, 3, 0, ang); dtostrf(GPS.latitude, 9,5, lat); Serial.println(lat); Serial.println(ang); Serial.println("-------"); </code></pre> <p>I would expect the following in the serial monitor:</p> <pre><code>5111.60160 267 ------- </code></pre> <p>But instead, I'm getting this:</p> <pre><code>5111.60160 2675111.60160 ------- </code></pre> <p>So it looks like the <code>ang</code> holds both the angle and the latitude....</p> <p>Why is this happening? And how can I solve this?</p> <p>My goal is to make one big string, comma separated, from the data stored in <code>GPS</code></p>
<p>Your arrays are both too short for the strings they're meant to hold. In particular, ang has three digits and only three bytes. The string-terminator, NUL, ends up in the 1st byte of lat. Since you generated the ang string first, lat over-wrote ang's NUL character, effectively getting appended to ang.</p> <p>The lat string will need at least (10+1) bytes; ang will need (3+1) bytes, counting only the actual data in your question.</p> <p>I make it a habit to declare string arrays just as I wrote the sums above, to make it clear that I've counted both the contents and the NUL byte, so:</p> <blockquote> <p>char ang[3+1], lat[10+1];</p> </blockquote> <p>I doubt that you need to specifically add the NUL terminator; it would quite unusual (counter-conventional) for a C/C++ function that generates a string to leave off the terminator (except in a few special cases).</p> <p>Try increasing just your array sizes first; it'll probably work.</p>
1202
|serial|arduino-mega|
Arduino Mega's 4 Serial Ports?
2014-04-17T07:33:16.643
<p>I have been using only Arduino Uno. Now I am about to buy Mega. But a question rises. Are those 4 Serial Ports of Mega controlled still through one usb cable?</p>
<p>No. If Arduino ATmega microcontroller supports more than a single UART, then only the first one is available through the standard USB connection. Other UARTs use their own pins that you have to connect to on the board. Mind you these pins are TTL logic serial and need a converter for RS232 or similar. It is possible to use a second (third, ...) TTL-serial to USB cable to access the port on your PC.</p>
1210
|arduino-yun|wifi|networking|ethernet|
How to disable Arduino Yun to work as Access Point and set it to work as needed?
2014-04-17T15:12:06.210
<p>I am using Arduino Yun and I would like to disable it to work as Access Point. That is, I don't want that it is displayed in the list of available networks.</p> <p>Then I would like to set and use it (separately) in the following scenarios:</p> <p>a) Arduino Yun connected just over a given Wi-Fi network (Ethernet connection disabled).</p> <p>b) Arduino Yun connected just over Ethernet (Wi-Fi connection disabled).</p> <p>How can I make it?</p> <p><strong>Note</strong>: In my previous attempts I tried to customize and/or disable someway the Wi-Fi connection (through the LuCI panel) in order to reach what I am looking for but in all of these cases <a href="http://playground.arduino.cc/Hardware/Yun#restoring_a_yun" rel="noreferrer">I had to restore my Arduino Yun</a> from scratch because it did not work anymore.</p>
<p>Yun expects wifi to be working and, if it's not, it will reboot itself after 60 seconds and return in access point mode.</p> <p>In order to disable this check, edit file <code>/etc/rc.local</code> and turn <code>wifi-live-or-reset</code> into <code>#wifi-live-or-reset</code> (with a starting <code>#</code>).</p> <p>Once done, use LuCI (the advanced configuration panel) to configure network interfaces.</p>
1211
|robotics|arduino-galileo|
What are the main differences between the Arduino Tre and the Intel Galileo?
2014-04-17T19:55:03.580
<p>I'm looking to find a suitable board for a robot I'm developing (it'll involve computer vision, else I'd be using my Arduino Micro) and I've come across two possibilities: <a href="http://store.arduino.cc/index.php?main_page=product_info&amp;products_id=522" rel="nofollow">The Intel Galileo</a> and the <a href="http://arduino.cc/en/Main/ArduinoBoardTre" rel="nofollow">Arduino Tre</a>.</p> <p>Now as I understand it, the Intel Galileo has a 400MHz Quark processor, whilst the Arduino Tre has 2 processors, an onboard 16MHz standard ATmega32u4 with the Arduino bootloader and then another 1GHz TI processor with Linux installed on it.</p> <p>However, I'm not sure of the differences between both products, as price estimates appear to place them at approximately the same price (around $70) and the Intel Galileo doesn't appear to have any real advantage over the Arduino Tre (except for a full x86 instruction set).</p> <p>Does anyone have any information on comparison of the two boards so I can make a better informed decision?</p>
<h2>Biggest difference IMHO: Tre hasn't been released yet!</h2> <p>Besides that, there are a few different things that you should compare. Not much is available about the Tre as of now, but I'll update this post when it's released.</p> <hr> <h2><em>Basic Specs:</em> [First sub-bullet is TRE, second Galileo; better spec in bold]</h2> <ul> <li>Microcontroller: <ul> <li>Texas Instrument Sitara AM3359AZCZ100 (ARM Cortex-A8) (<strong>1 GHz,</strong> 32 bit), Atmel ATmega32u4 (16 MHz, Secondary, found on Leonardo)</li> <li>Intel® Quark SoC X1000 (400 MHz, 32 bit)</li> </ul></li> <li>RAM: <ul> <li>512 MB SRAM (2.5 KB ATmega32u4)</li> <li>512 MB SRAM</li> </ul></li> <li>Pins <ul> <li><strong>14 Digital 5V, 7 of which are PWM, 6 analog 5V (additional 6 multiplexed) (32u4); 12 Digital 3.3V, 4 of those are PWM (Sitara)</strong></li> <li>14 5V digital, 6 of those are PWM, 6 analog 5V</li> </ul></li> <li>Networking: <ul> <li>Ethernet 10/100</li> <li>Ethernet 10/100</li> </ul></li> <li>USB port: <ul> <li>1 USB as slave, 4 USB host ports</li> <li>Up to 128 devices as host, 1 USB slave</li> </ul></li> <li>Video <ul> <li><strong>HDMI (1920x1080), LCD header</strong></li> <li>None that I can find</li> </ul></li> <li>Audio <ul> <li>HDMI, stereo analog audio input and output</li> <li>None that I can find</li> </ul></li> <li>MicroSD card <ul> <li>Yes</li> <li>Yes</li> </ul></li> <li>PCIe Slot <ul> <li>No</li> <li><strong>Yes</strong></li> </ul></li> </ul> <p>Sources (I combined a bunch of data for this): <a href="https://arduino.cc/en/ArduinoCertified/IntelGalileo" rel="nofollow noreferrer">Galileo</a> &amp; <a href="https://arduino.cc/en/Main/ArduinoBoardTre" rel="nofollow noreferrer">Tre</a></p> <hr> <p><strong>Conclusion:</strong> If you need a board before the Tre comes out, which seems to be soon (Spring 2014), Galileo is your only option. Other than that, the Tre seems to be better all around in most aspects, minus the PCIe slot. I can't comment on power, but it seems like the Tre will be able to supply 4x the power per pin than the Galileo. The Galileo is getting older, and it doesn't seem like the Galileo can provide full Linux support like the Tre will.</p> <p>Personally, I'd wait for the Tre. The <em>only</em> thing I can think that the Galileo would be better for would be either a.) lower power usage or b.) the PCIe slot for a WiFi adapter that works decently. The second one could be solved by <a href="http://www.instructables.com/id/Cheap-and-Easy-Arduino-Wi-Fi-Hack/0" rel="nofollow noreferrer">doing a common WiFi router hack</a>.</p> <p>If you need a lot of processing power without the need of low latency, you should conciser sending data to a computer to process.</p> <blockquote> <p><img src="https://arduino.cc/en/uploads/Main/ArduinoTre_LandingPage.jpg"></p> </blockquote> <p><a href="https://arduino.cc/en/uploads/Main/ArduinoTre_LandingPage.jpg" rel="nofollow noreferrer">Source</a></p> <blockquote> <p><img src="https://arduino.cc/en/uploads/ArduinoCertified/IntelGalileo_fabD_Front.jpg"></p> </blockquote> <p><a href="https://arduino.cc/en/uploads/ArduinoCertified/IntelGalileo_fabD_Front.jpg" rel="nofollow noreferrer">Source</a></p>
1212
|bootloader|isp|attiny|
Changing pins used in ArduinoISP example
2014-04-17T20:33:47.877
<p>I have built my own ATTiny programmer, but made a bit of a mistake along the way - I didn't align the headers properly, and now instead of them plugging into pins 10, 11, 12 and 13 as per the ArduinoISP example - they now plug into pins 8, 9, 10 and 11.</p> <p>If I use some jumper cables to wire the pins to match the ArduinoISP example, it all works fine, meaning the wiring on the actual board is OK, however, I want to be able to just plug my board I have made straight in, and thus need to get the bootloader burning and the uploading to work via pins 8, 9, 10 and 11 instead.</p> <p>I have tried modifying the example myself by replacing the references to RESET, MOSI, MISO and SCK with my own pin numbers, but this doesn't seem to suffice. When I try to burn the bootloader now, I get the following error:</p> <pre><code>avrdude: stk500_program_enable(): protocol error, expect=0x14, resp=0x50 avrdude: initialization failed, rc=-1 Double check connections and try again, or use -F to override this check. avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x51 </code></pre> <p>If I try to upload a sketch using my version which has the custom pin numbers, I get this error:</p> <pre><code>avrdude: stk500_getsync(): not in sync: resp=0x00 </code></pre> <p>The wiring of my programmer is the same as can be found here: <a href="http://highlowtech.org/?p=1706" rel="noreferrer">http://highlowtech.org/?p=1706</a> except I want the programmer sketch to work with different pins.</p> <p>Thanks</p>
<p>As a practical matter, you're much better off correcting things so you're using the original pins, which correspond to hardware SPI. </p> <p>However, it's not terribly hard to implement SPI in software (at a lower performance, of course):</p> <pre><code>static uint8_t SPITransfer(uint8_t out) { uint8_t in = 0; for (int i=0; i&lt;8; ++i) { digitalWrite(MOSI, (out &amp; 0x80) != 0); out &lt;&lt;= 1; digitalWrite(SCK, HIGH); in = (in &lt;&lt; 1) | digitalRead(MISO); digitalWrite(SCK, LOW); } return in; } </code></pre> <p>There are several SPI modes, but this implements the one used for ISP.</p>
1221
|arduino-nano|system-design|arduino-pro-mini|arduino-pro-micro|
Arduino stopwatch, which board to use?
2014-04-18T14:14:26.397
<p>I am planning on making a simple stopwatch with:</p> <ul> <li>A display </li> <li>One or two additional buttons to start the stopwatch and stop the stopwatch and maybe reset it.</li> </ul> <p>The problem is that it has to be as small as possible. With all those different Arduino boards out there, I don't know which one I should buy (mini, micro, nano, ...).</p> <p>I am not sure how many pins I need for the LCD since I have read that in fact not all pins are mandatory for the LCD. I have done something earlier with an LCD and I found the pot meter for the LCD contrast level a bit of waste of space. Could I just replace it with a certain resistor or something?</p> <p>How many pins in the end would I need and which board would be fitting for this little project?</p>
<p><strong>By that <a href="http://arduino.cc/en/uploads/Tutorial/LCD_bb.png" rel="nofollow noreferrer">photo</a> you posted, you pretty much answered a decent part of your question.</strong> You'll need six pins for the LCD, and one or two for the button. That means that you need a <em>total</em> of 8 pins. That Uno pictured has 20 (analog can act as digital, too).</p> <p>As far as the boards, if you feel comfortable with some extra work, I'd recommend an ATtiny. From what I can find, it seems like you can drive a LCD with a 44 or an 84 (similar, but the 84 is more powerful).</p> <blockquote> <p><img src="https://i.stack.imgur.com/NUYiB.png"></p> </blockquote> <p><em><a href="http://highlowtech.org/?p=1695" rel="nofollow noreferrer">Source for image and how to program chip</a></em>. I'm not going to go into the details for this method, as the link has the necessary files...</p> <hr> <p>That's the smallest way to do this*, however, if you want to use a real Arduino board, then I'd recommend the Micro for a few reasons.</p> <p>First of all, it has the newer ATMEGA32u4 chip, found on the Leonardo. I do <em>not</em> recommend the Mini because, although it's the smallest of the three, it doesn't feature on board USB. You would have to buy another adapter to program it. If you're already using a breadboard, the extra 2cm (or so) is worth not having to spend <em>more</em> to buy both of those components. The Nano is the equivalent of the Mini, only with USB. Also, the Nano and the Micro are roughly the same size, one a little bit longer and one a little bit wider.</p> <p>However, the Nano and Micro are roughly the same as far as processing power, so I'd recommend that, if you can get one significantly cheaper, to go with that. It doesn't really matter that much.</p> <p><sub>*If you're building this on a breadboard, it won't be smaller. If you're transferring to a PCB, then you should use an ATtiny.</sub></p> <hr> <p>As far as the pot goes, I'd recommend getting a <em>trimmer</em> with an equivalent value. Some of them are very small, as I have one that fits on the USB connector part of my thumb drive. They need a screwdriver to adjust, but I would recommend it. I've had issues moving it from a dark room to in the sun and not being able to see it clearly. Spend the two cents and the 2 cm<sup>2</sup> and have an opportunity to change it if needed.</p> <p>For the battery, I would recommend any rechargeable battery (under ~3.5V) <strong>if and <em>only</em> if</strong> you add a proper chip to not waste energy in the conversion. I talked about this in <a href="https://arduino.stackexchange.com/questions/665/powering-arduino-with-solar-panels/667#667">this post</a>.</p>
1222
|arduino-uno|rotary-encoder|
Turning a DC motor a set number of Rotations using an encoder
2014-04-18T17:22:11.233
<p>I'm using an arduino UNO, and i want to turn a motor a set number of revolutions, i'm trying to read the clicks of the encoder which has a resolution of 360 clicks/ revolution, my logic is that i count the number of clicks until i get to the desired number which represents the the number of revolutions * the resolution of the encoder:</p> <p>1 revolution ==> 360 clicks<br> 5 revolutions ==> 360*5 (desired number)</p> <p>i'm a beginner with arduino so here is my code:</p> <pre><code>volatile int counter=0; int motor=5; // motor is connected to pin 5 void setup(){ pinMode(motor,OUTPUT); attachInterrupt(0, count,RISING); // attaching encoder on interrupt 0 } void loop(){ while(counter&lt; 360*5){ analogWrite(motor,255); } } void count(){ counter++; } </code></pre> <p>This code is not working at all, how can i fix it?</p>
<p>Since the Encoder resolution is high, the Arduino Uno misses some pulses hence you could not get the accurate reading from it. You could use the hardware quadrature decoder in Arduine Due board which can easily read the encoder values.</p> <p>Here is a code which can only be executed in arduino Due to Read one quadrature encoder. <a href="https://arduino.stackexchange.com/questions/28268/how-to-configure-2nd-quadrature-decoder-io-pins-in-arduino-ide">How to configure 2nd Quadrature Decoder IO pins in Arduino IDE</a></p>
1232
|arduino-due|compile|eclipse|
How to compile code for the Arduino Due?
2014-04-19T17:37:10.797
<p>I have set up Eclipse to compile for the Arduino Due using all the tools shipped with the Arduino IDE 1.5.6-r2. It compiles without errors, but when uploaded, the Arduino does nothing, and isn't recognized on the computer. It then has to be reset manually using the erase and reset buttons.</p> <p>There is one static library (ArduinoDueCore) consisting of the Arduino library (<code>core</code>), and other code (Atmel found in <code>lib</code>). The other Eclipse project is the TestProject. It contains one file blinking an LED on pin 13. All the files from the Arduino library are there.</p> <p>This is the output from Eclipse compiling the library itself: (excerpt of only one of each type of command)</p> <pre><code>18:31:36 **** Build of configuration Release for project ArduinoDueCore **** make all Building file: ../src/lib/variants/arduino_due_x/variant.cpp Invoking: ARM Sourcery Linux GCC C++ Compiler arm-none-eabi-g++ -DUSB_PRODUCT="Arduino Due" -DARDUINO=156 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/lib/variants/arduino_due_x/variant.o.lst" -fno-exceptions -fno-rtti -w -c -g -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -MMD -MP -MF"src/lib/variants/arduino_due_x/variant.d" -MT"src/lib/variants/arduino_due_x/variant.d" -mcpu=cortex-m3 -mthumb -o "src/lib/variants/arduino_due_x/variant.o" "../src/lib/variants/arduino_due_x/variant.cpp" Finished building: ../src/lib/variants/arduino_due_x/variant.cpp Building file: ../src/lib/libsam/source/adc.c Invoking: ARM Sourcery Linux GCC C Compiler arm-none-eabi-gcc -DARDUINO=156 -DARM_MATH_CM3 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PRODUCT="Arduino Due" -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/lib/libsam/source/adc.o.lst" -w -c -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -std=c99 -MMD -MP -MF"src/lib/libsam/source/adc.d" -MT"src/lib/libsam/source/adc.d" -mcpu=cortex-m3 -mthumb -o "src/lib/libsam/source/adc.o" "../src/lib/libsam/source/adc.c" Finished building: ../src/lib/libsam/source/adc.c Building file: ../src/core/USB/HID.cpp Invoking: ARM Sourcery Linux GCC C++ Compiler arm-none-eabi-g++ -DUSB_PRODUCT="Arduino Due" -DARDUINO=156 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/core/USB/HID.o.lst" -fno-exceptions -fno-rtti -w -c -g -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -MMD -MP -MF"src/core/USB/HID.d" -MT"src/core/USB/HID.d" -mcpu=cortex-m3 -mthumb -o "src/core/USB/HID.o" "../src/core/USB/HID.cpp" Finished building: ../src/core/USB/HID.cpp Building file: ../src/core/cortex_handlers.c Invoking: ARM Sourcery Linux GCC C Compiler arm-none-eabi-gcc -DARDUINO=156 -DARM_MATH_CM3 -DUSB_MANUFACTURER="Unknown" -DARDUINO_ARCH_SAM -DARDUINO_SAM_DUE -D__SAM3X8E__ -Dprintf=iprintf -DF_CPU=84000000L -DUSB_VID=0x2341 -DUSB_PRODUCT="Arduino Due" -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -Os -ffunction-sections -fdata-sections -Wall -Wa,-adhlns="src/core/cortex_handlers.o.lst" -w -c -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -std=c99 -MMD -MP -MF"src/core/cortex_handlers.d" -MT"src/core/cortex_handlers.d" -mcpu=cortex-m3 -mthumb -o "src/core/cortex_handlers.o" "../src/core/cortex_handlers.c" Finished building: ../src/core/cortex_handlers.c 18:31:39 Build Finished (took 2s.811ms) </code></pre> <p>Here is the project itself:</p> <pre><code>18:33:42 **** Build of configuration Release for project TestProject **** make all Building file: ../src/TestProject.cpp Invoking: ARM Sourcery Linux GCC C++ Compiler arm-none-eabi-g++ -DARDUINO=156 -DUSB_PRODUCT="Arduino Due" -DARDUINO_SAM_DUE -D__SAM3X8E__ -DARDUINO_ARCH_SAM -Dprintf=iprintf -DF_CPU=84000000L -DUSB_MANUFACTURER="Unknown" -DUSB_VID=0x2341 -DUSB_PID=0x003E -DUSBCON -I"/home/kim/workspace_juno/ArduinoDueCore/src/core" -I"/home/kim/workspace_juno/TestProject/src" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/libsam" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/CMSIS/Include" -I"/home/kim/workspace_juno/ArduinoDueCore/src/lib/CMSIS/Device/ATMEL/sam3xa/include" -Os -ffunction-sections -fdata-sections -Wall -fno-exceptions -fno-rtti -c -fmessage-length=0 --param max-inline-insns-single=500 -nostdlib -g -w -MMD -MP -MF"src/TestProject.d" -MT"src/TestProject.d" -mcpu=cortex-m3 -mthumb -o "src/TestProject.o" "../src/TestProject.cpp" Finished building: ../src/TestProject.cpp Building target: TestProject.elf Invoking: ARM Sourcery Linux GCC C++ Linker arm-none-eabi-g++ -T"/home/kim/workspace_juno/ArduinoDueCore/src/lib/variants/arduino_due_x/linker_scripts/gcc/flash.ld" -L"/home/kim/workspace_juno/ArduinoDueCore/Release" -Wl,-Map,TestProject.map -lm -lgcc -Wl,--cref -Wl,--check-sections -Wl,--gc-sections -Wl,--entry=Reset_Handler -Wl,--unresolved-symbols=report-all -Wl,--warn-common -Wl,--warn-section-align -Wl,--warn-unresolved-symbols -Wl,--gc-sections -mcpu=cortex-m3 -mthumb -o "TestProject.elf" -Wl,--start-group ./src/TestProject.o -lArduinoDueCore -Wl,--end-group Finished building target: TestProject.elf make --no-print-directory post-build /home/kim/arduino-1.5.6-r2/hardware/tools/g++_arm_none_eabi/bin/arm-none-eabi-objcopy -O binary TestProject.elf TestProject.bin Invoking: ARM Sourcery Linux GNU Create Listing arm-none-eabi-objdump -h -S TestProject.elf &gt; "TestProject.lst" Finished building: TestProject.lst Invoking: ARM Sourcery Linux GNU Print Size arm-none-eabi-size --format=berkeley TestProject.elf text data bss dec hex filename 10396 24 1188 11608 2d58 TestProject.elf Finished building: TestProject.siz 18:33:43 Build Finished (took 308ms) </code></pre> <p>Here is the upload command: (removed <code>readWord</code>, <code>go</code>, <code>write</code> and <code>writeWord</code> lines)</p> <pre><code>-i -d --port=ttyACM0 -U true -e -w -v -b ${project_loc}/Release/${project_name}.bin -R Set binary mode chipId=0x285e0a60 Connected at 921600 baud Erase flash Write 10420 bytes to flash [ ] 0% (0/41 pages) [======= ] 24% (10/41 pages) [============== ] 48% (20/41 pages) [===================== ] 73% (30/41 pages) [============================= ] 97% (40/41 pages) [==============================] 100% (41/41 pages) Verify 10420 bytes of flash [ ] 0% (0/41 pages) [======= ] 24% (10/41 pages) [============== ] 48% (20/41 pages) [===================== ] 73% (30/41 pages) [============================= ] 97% (40/41 pages) [==============================] 100% (41/41 pages) Verify successful Set boot flash true Device : ATSAM3X8 Chip ID : 285e0a60 version()=v1.1 Dec 15 2010 19:25:04 Version : v1.1 Dec 15 2010 19:25:04 Address : 524288 Pages : 2048 Page Size : 256 bytes Total Size : 512KB Planes : 2 Lock Regions : 32 Locked : none Security : false Boot Flash : true CPU reset. </code></pre> <p>TestProject.cpp:</p> <pre><code>#include "Arduino.h" void setup() { pinMode(13, OUTPUT); } void loop() { digitalWrite(13, HIGH); delay(50); digitalWrite(13, LOW); delay(950); } </code></pre>
<p>Using 1.5.6-r2 with Eclipse cause the Due to hung in Default_Handler function after entering main and polling a few times for the next SysTick gettin passed.</p> <p>Some weak symbol declarations are done twice (i.e. the SysTick_Handler function definitions). They appear to overwrite each others weak alias depending on the link time usage of the objects. All declarations (not only the failing SysTick_Hanlder) from cortex_handler.c are getting overwritten by weak symbol redeclaration inside startup_sam3xa.c.</p> <p>This commit seems to already address a weak symbol definition problem. <a href="https://github.com/arduino/Arduino/commit/65f00a69c74ca0def8d7f1d7597327945a04a33f" rel="nofollow">https://github.com/arduino/Arduino/commit/65f00a69c74ca0def8d7f1d7597327945a04a33f</a></p> <p>For now, to fix it. Just comment out the part in startup_sam3xa.c with the weak symbol declaration regarding the vectors. Lines 53 to 129.</p> <p>It should also work to just remove the file completely. The startup handler code and vector map should be provided by gcc arm built-in libraries instead.</p>