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
3952
|arduino-uno|programming|
Arduino Uno- Analog serial monitor not reading values over 174
2014-08-27T22:01:13.843
<p>I am simultaneously using a LEGO sound sensor in pin A5 and a RadioShack Tricolor LED Strip (Product #2760339) in pin A0.</p> <p>The sound sensor alone works as expected (producing values based on volume) running only code to read the value and output to the serial monitor. However when I upload the program to use the LED strip, read the sensor value and output to the serial monitor, the sensor value caps at 174. </p> <p>The program given to run the LED strip can be found at <a href="http://blog.radioshack.com/2013/06/tricolor-led-strip/" rel="nofollow">http://blog.radioshack.com/2013/06/tricolor-led-strip/</a> The code I added to this was pulled mostly directly from the AnalogInOutSerial example provided by Arduino. </p> <p>Here is the full code;</p> <pre><code>/***************************************************************************/ // Hardware: RadioShack Tricolor LED Strip // Arduino IDE: Arduino-1.0 // Date: April 17, 2013 // Copyright© 2013 RadioShack Corporation // // This library is free software; you can redistribute it and/or // modify it under the terms of the GNU Lesser General Public // License as published by the Free Software Foundation; either // version 2.1 of the License, or (at your option) any later version. // // This library is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public // License along with this library; if not, see &lt;http://www.gnu.org/licenses/&gt; // /*****************************************************************************/ #include &lt;avr/pgmspace.h&gt; // ******** DEBUG ==== should auto config to adapt different mother board ********* //#define DATA_1 (PORTF |= 0X01) // DATA 1 // for ATMEGA //#define DATA_0 (PORTF &amp;= 0XFE) // DATA 0 // for ATMEGA //#define STRIP_PINOUT DDRF=0xFF // for ATMEGA #define DATA_1 (PORTC |= 0X01) // DATA 1 // for UNO #define DATA_0 (PORTC &amp;= 0XFE) // DATA 0 // for UNO #define STRIP_PINOUT (DDRC=0xFF) // for UNO PROGMEM const unsigned long rainbow_full[5][10]={ {0xff0000,0x00ff00,0x0000ff,0xffff00,0xff00ff,0xffffff,0xff6622,0xff0000,0xff0000,0xff0000}, }; PROGMEM const unsigned long off[1][10] = { {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red1[1][10] = { {0xff0000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red2[1][10] = { {0xff0000,0xff0000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red3[1][10] = { {0xff0000,0xff0000,0xff0000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red4[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red5[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0x000000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red6[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0x000000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red7[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0x000000,0x000000,0x000000}, }; PROGMEM const unsigned long red8[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0x000000,0x000000}, }; PROGMEM const unsigned long red9[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0x000000}, }; PROGMEM const unsigned long redfull[1][10] = { {0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000,0xff0000}, }; /*PROGMEM const unsigned long pattern_test_blue[10][10]={ {0x00ff00,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x00ff00,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x00ff00,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x00ff00,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x00ff00,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x00ff00,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00ff00,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00ff00,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00ff00,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x00ff00}, }; PROGMEM const unsigned long pattern_test_green[10][10]={ {0x0000ff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x0000ff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x0000ff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x0000ff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x0000ff,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x0000ff,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000ff,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000ff,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000ff,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x0000ff}, }; PROGMEM const unsigned long pattern_test_white[10][10]={ {0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff}, }; PROGMEM const unsigned long pattern_test_comet1[][10]={ {0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000}, {0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xffffff}, }; PROGMEM const unsigned long pattern_test_comet2[][10]={ {0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000}, {0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000}, {0x111111,0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000}, {0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000}, {0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff}, {0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000}, {0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000}, {0x111111,0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000}, {0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000}, {0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0x111111,0x444444,0xffffff}, }; PROGMEM const unsigned long pattern_test_comet3[][10]={ {0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff}, {0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000,0x000000,0x000000,0xffffff,0x444444}, {0x111111,0x444444,0xffffff,0x000000,0x000000,0x000000,0x000000,0xffffff,0x444444,0x111111}, {0x000000,0x111111,0x444444,0xffffff,0x000000,0x000000,0xffffff,0x444444,0x111111,0x000000}, {0x000000,0x000000,0x111111,0x444444,0xffffff,0xffffff,0x444444,0x111111,0x000000,0x000000}, {0x000000,0x000000,0x111111,0x444444,0xffffff,0xffffff,0x444444,0x111111,0x000000,0x000000}, {0x000000,0x000000,0x000000,0xffffff,0x444444,0x444444,0xffffff,0x000000,0x000000,0x000000}, {0x000000,0x000000,0xffffff,0x444444,0x111111,0x111111,0x444444,0xffffff,0x000000,0x000000}, {0x000000,0xffffff,0x444444,0x111111,0x000000,0x000000,0x111111,0x444444,0xffffff,0x000000}, {0xffffff,0x444444,0x111111,0x000000,0x000000,0x000000,0x000000,0x111111,0x444444,0xffffff}, }; PROGMEM const unsigned long pattern_test_rainbow[10][10]={ {0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000}, {0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000}, {0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000}, {0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff}, {0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff}, {0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00,0x0000ff}, {0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00,0x00ff00}, {0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00,0xffff00}, {0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000,0xff7f00}, {0xff7f00,0xffff00,0x00ff00,0x0000ff,0x6f00ff,0x8f00ff,0x000000,0x000000,0x000000,0xff0000}, }; */ // *********************************************************************************************************** // * // * Power Up Init. // * // * // *********************************************************************************************************** int sensorvalue = 0; int outputvalue = 0; void setup() { STRIP_PINOUT; // set output pin - DEBUG: should auto detect which mother board for use reset_strip(); Serial.begin(9600); //noInterrupts(); } // *********************************************************************************************************** // * // * Main Loop // * // * // *********************************************************************************************************** void loop() { sensorvalue = analogRead(A5); outputvalue = map(sensorvalue, 0, 174, 0, 18); if(outputvalue == 0){ send_1M_pattern(off, 1, 20); } else if(outputvalue &gt; 0 &amp;&amp; outputvalue &lt;= 3){ send_1M_pattern(red1, 1, 20); } else if(outputvalue &gt; 3 &amp;&amp; outputvalue &lt;= 5){ send_1M_pattern(red2, 1, 20); } else if(outputvalue &gt; 5 &amp;&amp; outputvalue &lt;= 7){ send_1M_pattern(red3, 1, 20); } else if(outputvalue &gt; 7 &amp;&amp; outputvalue &lt;= 9){ send_1M_pattern(red4, 1, 20); } else if(outputvalue &gt; 9 &amp;&amp; outputvalue &lt;= 11){ send_1M_pattern(red5, 1, 20); } else if(outputvalue &gt; 11 &amp;&amp; outputvalue &lt;= 13){ send_1M_pattern(red6, 1, 20); } else if(outputvalue &gt; 13 &amp;&amp; outputvalue &lt;= 16){ send_1M_pattern(red9, 1, 20); } else if(outputvalue &gt; 16){ send_1M_pattern(rainbow_full, 1, 20); } Serial.print("sensor = " ); Serial.print(sensorvalue); Serial.print("\t output = "); Serial.println(outputvalue); delay(2); /* frame++; if(frame&lt;=10) LEDSTRIP_PATTERN_0(); if(10&lt;frame&lt;=20) LEDSTRIP_PATTERN_0(); if(20&lt;frame&lt;=30) LEDSTRIP_PATTERN_0(); if(frame&gt;30) frame=1; */ //delay(1); } /******************************************************************************* * Function Name : send_1M_pattern * Description : Transmit pattern to whole 1 meter strip * * Input : pointer to ROM pattern; pattern length; frame rate * * Output : None * Return : None *******************************************************************************/ void send_1M_pattern(const unsigned long data[][10], int pattern_no, int frame_rate) { int i=0; int j=0; uint32_t temp_data; for (i=0;i&lt;pattern_no;i++) { noInterrupts(); for (j=0;j&lt;10;j++) { temp_data=pgm_read_dword_near(&amp;data[i][j]); send_strip(temp_data); } interrupts(); delay(frame_rate); } } /******************************************************************************* * Function Name : send_strip * Description : Transmit 24 pulse to LED strip * * Input : 24-bit data for the strip * * Output : None * Return : None *******************************************************************************/ void send_strip(uint32_t data) { int i; unsigned long j=0x800000; for (i=0;i&lt;24;i++) { if (data &amp; j) { DATA_1; __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); /*----------------------------*/ __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); /*----------------------------*/ DATA_0; } else { DATA_1; __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); DATA_0; /*----------------------------*/ __asm__("nop\n\t"); __asm__("nop\n\t"); __asm__("nop\n\t"); /*----------------------------*/ } j&gt;&gt;=1; } } /******************************************************************************* * Function Name : reset_strip * Description : Send reset pulse to reset all color of the strip * * Input : None * * Output : None * Return : None *******************************************************************************/ void reset_strip() { DATA_0; delayMicroseconds(20); } </code></pre>
<p>A5 is PC5. Your code sets it as an output. Since you only need A0 (PC0) to be an output:</p> <pre><code>#define STRIP_PINOUT (DDRC = _BV(PC0)) </code></pre> <p><a href="http://arduino.cc/en/Hacking/PinMapping168" rel="nofollow">Uno pin mappings</a></p>
3959
|programming|lcd|
Scroll String Only On Second Line Using 2x16 LCD
2014-08-28T13:59:10.810
<p>I'm trying to scroll a string in the second row of the LCD while letting the string on the first row stay intact. I use Serial to run that part of the code as you can see. It work at first but when I try to make it run again it doesn't display anything on the second row.</p> <p>I borrowed the code from :</p> <p><a href="http://code.nishantarora.in/arduino-lcd-projects/src/3f10686e7464665c5c59d7be772c00af7a4a93e8/scrollOneLine/scrollOneLine.ino?at=master" rel="nofollow">http://code.nishantarora.in/arduino-lcd-projects/src/3f10686e7464665c5c59d7be772c00af7a4a93e8/scrollOneLine/scrollOneLine.ino?at=master</a></p> <p>And made some changes:</p> <pre><code>// include the library #include &lt;LiquidCrystal.h&gt; // init the lcd display according to the circuit LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // it's a 16x2 LCD so... int screenWidth = 16; int screenHeight = 2; String line1; String line2; int stringStart, stringStop = 0; int scrollCursor = screenWidth; String CompleteString; String stringArray[] = {"s=Plane", "i=Car", "h=Boat", "u=Rocket", "d=Jet", "p=Submarine", "l=Truck", "b=Bicycle", "m=Skate", "enter=Train"}; String string1 = "String"; int countMovement=0; int arraylimit = 9; void setup() { lcd.begin(screenWidth,screenHeight); Serial.begin(9600); } void loop(){ char ser = Serial.read(); if ( ser == 'c' ) { CompleteString=""; for (int i = 0 ; i &lt;= arraylimit; i++) { CompleteString += stringArray[i] + " "; // Convert String Array To Single String } roop(string1,CompleteString); } } void roop(String line1, String line2) { countMovement = 0; while ( ( countMovement ) &lt; (line2.length() + screenWidth ) ) { lcd.setCursor(scrollCursor, 1); lcd.print(line2.substring(stringStart,stringStop)); lcd.setCursor(4, 0); // 1 = word eat array of words very cool lcd.print(line1); delay(300); lcd.clear(); if(stringStart == 0 &amp;&amp; scrollCursor &gt; 0){ // Serial.println(scrollCursor); scrollCursor--; stringStop++; } else if (stringStart == stringStop){ stringStart = stringStop = 0; scrollCursor = screenWidth; } else if (stringStop == line1.length() &amp;&amp; scrollCursor == 0) { stringStart++; } else { stringStart++; stringStop++; } countMovement++; } lcd.setCursor(4, 0); lcd.print(line1); } </code></pre> <p>From what I can see using Serial as debugging is that the problem resides in the function "roop" and in specific the line:</p> <pre><code> if(stringStart == 0 &amp;&amp; scrollCursor &gt; 0){ </code></pre> <p>It seems that the statement is being pass on and so it doesn't move the string as it's suppose to. I could be wrong but placing a Serial call in there yields no result the second time the function is called but the first time it did.</p> <p>Any help would be much appreciated! And I know the community will be grateful too since it's difficult from what I can see in post to achieve this and make it autonomous so that no big modifications needs to be done. </p>
<p>The answer from the user Gerben worked perfect. So I'll be posting another solution I came upon and the one from my original question for feature reference.</p> <p>Original Code:</p> <pre><code>// include the library #include &lt;LiquidCrystal.h&gt; // init the lcd display according to the circuit LiquidCrystal lcd(9, 8, 7, 6, 5, 4); // it's a 16x2 LCD so... int screenWidth = 16; int screenHeight = 2; String line1; String line2; int stringStart, stringStop = 0; int scrollCursor = screenWidth; String CompleteString; String stringArray[] = {"s=Plane", "i=Car", "h=Boat", "u=Rocket", "d=Jet", "p=Submarine", "l=Truck", "b=Bicycle", "m=Skate", "enter=Train"}; String string1 = "String"; boolean ArrayRead = true; int countMovement=0; int arraylimit = 9; // most of the part is pretty basic void setup() { lcd.begin(screenWidth,screenHeight); Serial.begin(9600); } void loop(){ char ser = Serial.read(); if ( ser == 'c' ) { CompleteString=""; for (int i = 0 ; i &lt;= arraylimit; i++) { CompleteString += stringArray[i] + " "; // Convert String Array To Single String } roop(string1,CompleteString); } } void roop(String line1, String line2) { countMovement = 0; stringStart = 0; stringStop = 0; scrollCursor = screenWidth; while ( ( countMovement ) &lt; (line2.length() + screenWidth ) ) { lcd.clear(); lcd.setCursor(scrollCursor, 1); lcd.print(line2.substring(stringStart,stringStop)); lcd.setCursor(5, 0); // 1 = word eat array of words very cool lcd.print(line1); delay(300); lcd.clear(); if(stringStart == 0 &amp;&amp; scrollCursor &gt; 0){ scrollCursor--; stringStop++; } else if (stringStart == stringStop){ stringStart = stringStop = 0; scrollCursor = screenWidth; } else if (stringStop == line1.length() &amp;&amp; scrollCursor == 0) { stringStart++; } else { stringStart++; stringStop++; } countMovement++; } lcd.setCursor(4, 0); lcd.print(line1); } </code></pre> <p>The other code provided by the user "HazardsMind" for I2C LCD Module: The changes made are Serial communication and adapted for the 6 pin LCD Module.</p> <pre><code>// include the library #include &lt;LiquidCrystal.h&gt; // init the lcd display according to the circuit LiquidCrystal lcd(9, 8, 7, 6, 5, 4); //char * SerialComm[70]; //{"s = Plane i=Car h=Boat u=Rocket d=Jet p=Submarine l=Truck b=Bicycle m=Skate enter=Train"}; #define N_CHARS ((sizeof(MessageOut)/sizeof(MessageOut[0]))-1) #define N_CHARS2 ((sizeof(MessageOut2)/sizeof(MessageOut2[0]))-1) //int len = strlen(SerialComm); char MessageOut[30]; char MessageOut2[30]; int index = 19, index2 = 0; unsigned long oldTime = 0, oldTime2 = 0; byte indexer = 0; // Index into array; where to store the character char inData[58]; // Allocate some space for the string char inChar; // Where to store the character read void setup() { Serial.begin(9600); lcd.begin(16, 2); // initialize the lcd } void loop() while(Serial.available() &gt; 0) // Don't read unless // there you know there is data { if(indexer &lt; 57) // One less than the size of the array { inChar = Serial.read(); // Read a character inData[indexer] = inChar; // Store it indexer++; // Increment where to write next inData[indexer] = '\0'; // Null terminate the string } } // Now do something with the string (but not using ==) // Serial.print(inData); setHeadingRight("Royal", 0, 500); setHeadingLeft(inData, 1, 500); //setHeadingRight("Hello Welcome", 0, 1000); // message, row, duration // setHeadingLeft("Welcome", 1, 500); } void setHeadingRight(char * msg, byte row, unsigned long duration) { strncpy(MessageOut, msg, sizeof(MessageOut)); if(millis() - oldTime &gt; duration) // check the difference of the current time "millis()" to the previous time "oldTime" against the duration you want. { oldTime = millis(); // update oldTime with the current time if(index &gt;= 0) // make sure the index does not go under 0 { index--; // decrecment index by 1 for (int i = 0; i &lt; N_CHARS; i++) // this part here displays the message on the display { lcd.setCursor(i,row); // set the column to show the element in the array if(index == N_CHARS) index = 0; // set index back to 0 if the index has reached the arrays max size. if(MessageOut[index++] != NULL) // if the element @ index is anything but NULL, show it. lcd.print(MessageOut[index-1]); else lcd.print(' '); // if the element @ index is NULL, display a space. } } else index = 19; // if index is less than 0, then set it back to 19 } } void setHeadingLeft(char * msg, byte row, unsigned long duration2) { strncpy(MessageOut2, msg, sizeof(MessageOut2)); if(millis() - oldTime2 &gt; duration2) { oldTime2 = millis(); if(index2 &lt; 20) // check to see if index2 is under the array max size { index2++; // increment index for (int i = 0; i &lt; N_CHARS2; i++) // same as above { lcd.setCursor(i,row); if(index2 == N_CHARS2) index2 = 0; if(MessageOut2[index2++] != NULL) lcd.print(MessageOut2[index2-1]); else lcd.print(' '); } } else index2 = 0; // otherwise set it back to 0 } } </code></pre>
3962
|serial|string|
Print string from arduino to serial monitor
2014-08-28T21:09:49.777
<p>I want to send text over serial monitor to Arduino and make Arduino return that string back to me over serial monitor.</p> <p>I have made this function which reads from serial input and returns a string object.</p> <pre><code>String readSerial() { String input; while(Serial.available() &gt; 0) input.concat(Serial.read()); return input; } </code></pre> <p>In the <code>loop()</code> I have:</p> <pre><code>if(Serial.available()) Serial.print(readSerial()); </code></pre> <p>If I just do something like <code>Serial.print("Hello world!");</code> everything is fine. But, if I try to return string object I get lot's of numbers.</p> <p>I guess <code>Serial.print</code> doesn't know how to read <code>String</code> object and returns ASCII codes of characters or something?</p> <p><strong>[update]</strong> I have checked it, and it's indeed outputing ASCII codes. For <code>Hi</code> I get <code>72105</code>.</p> <p><strong>[update]</strong> I have updated my <code>readSerial</code> function to use this :</p> <pre><code>input += (char)Serial.read(); </code></pre> <p>But now I'm getting carriage return and new line after every character:</p> <pre><code>[SEND] Hi H(CR) i(CR) </code></pre> <p>So, how can I make it return my text so that is readable?</p>
<p>Answering the other part of the question:</p> <ul> <li>you're getting CRs because your readString is just wrong. </li> </ul> <p>The problem is that you don't wait for receiving a whole line of string. For example, if you press H on the serial monitor, then it is getting received and echoed back as if it would been the whole input, ending with a new line.</p> <p>You might wish to check my answer at <a href="https://arduino.stackexchange.com/questions/22474/get-strings-from-serial-read/22475#22475">Get strings from Serial.read()</a> that is use <a href="https://www.arduino.cc/en/Serial/ReadStringUntil" rel="nofollow noreferrer">https://www.arduino.cc/en/Serial/ReadStringUntil</a> which reads you the whole string until a separator (for example the whole string until it ends with a CR when you press Enter on the serial monitor).</p>
3964
|sensors|pins|
Two devices on one SDA input
2014-08-28T22:06:26.997
<p>I have two devices. Sensor for temperature and humidity and lcd screen. Both require SDA pin, and I have only one on my arduino.</p> <p>I want my display to show current temperature but I don't know how to connect two things on one pin.</p> <p>Can I somehow read from other pins maybe?</p> <p>Also, what can I do if I have only 1 5V source and I have two devices that require 5V?</p> <p>My arduino model is <a href="http://arduino.cc/en/Main/ArduinoBoardMega2560" rel="nofollow">Arduino Mega 2560 R3</a></p> <p>I have <a href="http://meteobox.tk/files/AM2301.pdf" rel="nofollow">this</a> aosong sensor (AM2301), and I have YwRobots 2 row LCD screen which I want to connect to my board along with sensor.</p> <p><strong>So... I'm not sure how to connect those two if both require SDA and I have only one.</strong></p>
<p>You can have multiple I<sup>2</sup>C devices on the same bus (sharing both SDA and SCL), as long as they have different addresses. The library used to access them should know (or be told, if required) what the address for the device is.</p> <p>If they are not I<sup>2</sup>C devices then they cannot both use SDA.</p> <p>The Aosong device is <em>not</em> an I<sup>2</sup>C device, but there is no need to connect its "SDA" pin to the Arduino's "SDA" pin; any unused digital pin should work, as long as the library is told which pin to find it on and as long as the electrical requirements of the connection are met.</p>
3968
|pins|
Arduino Shield Pin Conflict
2014-08-29T04:59:02.237
<p>I have a Freetronics <a href="http://littlebirdelectronics.com.au/products/etherten-100-arduino-compatible-with-onboard-ethernet" rel="nofollow">Etherten</a> and am trying to use the <a href="http://littlebirdelectronics.com.au/products/nfc-shield-v2-0" rel="nofollow">NFC Shield</a> - both the board and shield are trying to use Pins D10,D11,D12,D13</p> <p>So my question - Is there an elegant way to have these two work together. This really applies to any combination of shield with conflicting pins. I'm thinking maybe use some in between headers or M/F jumper wires?</p> <p>Is there a neat way to do it?</p>
<p>You need this: <a href="https://www.sparkfun.com/products/11002" rel="nofollow">https://www.sparkfun.com/products/11002</a><br> "The Go-Between Shield “goes between” two shields that aren’t compatible and effectively reassigns the pins. This trickery is achieved by isolating the top and bottom sides of the shield with surface mount headers and breaking them out into tables of jumpers that can be bridged to divert signals to and from different pins."</p>
3974
|gsm|
Code does not pass `gsmAccess.begin(PINNUMBER)==GSM_READY)`
2014-08-29T09:40:45.457
<p>I am not able to get my code to pass</p> <blockquote> <p>if(gsmAccess.begin(PINNUMBER)==GSM_READY) {</p> </blockquote> <p>I have modified the PIN number on my sim card to be <code>0000</code>, and yet its stuck on <code>begin</code>.</p> <p>How do I prepare the SIM CARD to pass the begin</p>
<p>Try putting the SIM card into a mobile phone in case it hasn't been initialised by your provider. Set up the PIN for the card using the settings on the phone, see the manual for instructions on how to do this.</p> <p>Now you can use the PIN you entered on the phone to unlock the SIM in your code.</p>
3981
|arduino-mega|
Mega2560 R3 pin functions
2014-08-30T11:48:29.533
<p>When I read about mega2560 I saw it has 54 digital that can be used as input or output.<br> later on I saw the some of them are used for things like communication.</p> <p>So I would like to know if the communication pin can still be used as output ? (to power leds)</p>
<p>Yes. <strong><em>Any</em> pin can be used as a digital input/output.</strong> However, you cannot use certain communications when using those pins.</p> <p><em>The types of communication and their effects on the pins:</em></p> <ul> <li><strong><a href="http://arduino.cc/en/Reference/SPI" rel="nofollow">SPI</a>:</strong> This protocol is used for certain communications with certain breakout boards and shields. For example, the ethernet shield uses SPI to connect. On the Mega(2560), it is pins 50-53.</li> <li><strong><a href="http://arduino.cc/en/reference/wire" rel="nofollow">I2C</a>:</strong> This protocol is also for connecting to external items. It is much slower than SPI, but uses only two pins. On the Mega, it uses pins 20/21.</li> <li><strong>UART/Serial:</strong> UART is a communication method that uses two wires and transmits bytes of data. It is often used to connect to things that don't need <em>extreme</em> amounts of data passed, but need a stable two way connection. <ul> <li>On all standard boards, the main UART is on pins 0 and 1. This is usually connected to a UART to USB chip which is sent to the computer. Note: you should still be able to upload sketches if they act as an <em>output</em> and random on/off won't hurt the device.</li> <li>The Mega(2560) also has UART on pins 14/15, 16/17, and 18/19.</li> </ul></li> </ul>
3986
|serial|string|
Slice string at “:”
2014-08-30T13:37:40.353
<p>I need to slice a string (eg- 4:288:18464:288:4) at ":" into an array({4, 288, 18464, 288, 4}) I used the following code, but its giving only '4' in the serial monitor when "4:288:18464:288:4," is given to arduino.</p> <pre><code>void displayString(char* s) { char* text = strtok(s,":"); while(text != NULL){ text = strtok(NULL,":");} } void loop() { if(Serial.available() &gt; 0) { str = Serial.readStringUntil(','); str.toCharArray(text,99); } displayString(text); Serial.println(text); } </code></pre>
<p>You don't use <code>strtok</code> the way it should:</p> <pre><code>char* text = strtok(s,":"); while(text != NULL){ text = strtok(NULL,":"); } </code></pre> <p>Your code just replaces, in <code>s</code>, all occurrences of <code>:</code> with <code>0</code> (i.e. a byte of value 0, not the ASCII value of <code>'0'</code>), thus terminating each substring.</p> <p>At the end of <code>displayString(text)</code> call from <code>loop()</code>, <code>text</code> still points to the 1st character of the original string (in your post <code>4:288:18464:288:4</code>), but that string now terminates at the position of the first <code>:</code>, which explains why <code>Serial.println(text)</code> prints just <code>4</code>.</p> <p>Now if you want to split the original string into an array of substrings, as asked in your question, you need to modify <code>displayString</code> this way:</p> <pre><code>// Maximum number of substrings expected const int MAX_SUBSTRINGS = 5; // Array of pointers to each substring after displayString() has been called static char* substrings[MAX_SUBSTRINGS]; void displayString(char* s) { // First clear the array of substrings for (int i = 0; i &lt; MAX_SUBSTRINGS; i++) substrings[i] = 0; // Now split the input string char* text = strtok(s,":"); int i = 0; while (text != 0 &amp;&amp; i &lt; MAX_SUBSTRINGS) { // A toekn was found: append it to the array of substrings substrings[i++] = text; text = strtok(0,":"); } } </code></pre> <p>After calling <code>displayString(text)</code>, you can use its result in <code>loop()</code> as follows:</p> <pre><code>void loop() { if (Serial.available() &gt; 0) { str = Serial.readStringUntil(','); str.toCharArray(text,99); } displayString(text); for (int i = 0; i &lt; MAX_SUBSTRINGS; i++) { if (substrings[i] != 0) Serial.println(substrings[i]); } } </code></pre> <p>Note that this will work <strong>ONLY</strong> if the original string contains no more than 5 substrings delimited by <code>:</code>. If the max number of substrings cannot be known at compile time, then you'll have to use dynamic allocation, <a href="https://arduino.stackexchange.com/questions/682/is-using-malloc-and-free-a-really-bad-idea-on-arduino/687#687">which is generally not a very good idea on embedded platforms</a>.</p>
3990
|arduino-uno|power|
Can I power an Arduino with a computer's motherboard?
2014-08-30T22:49:10.667
<p>I was thinking of using my Arduino to turn on and off a computer remotely. I would like to know if the 5v header pin on a computer's motherboard (which I’m using instead of a USB because the 5v pin provides a constant power supply) can power an Arduino UNO without frying it. If the Arduino can be powered where would the cable from the 5v motherboard pin go into the Arduino? <img src="https://i.stack.imgur.com/U2K3l.jpg" alt=""></p> <p>↑ These are the pins I would like to use </p>
<p>As stated by @mpflaga you can power your Arduino by the 5v power rail. As @ Gerben mentions in a comment, doing this will bypass the polyfuse. Because of this, I <a href="https://www.virtuabotix.com/bareduino328-plus-regulate-your-bareduino/" rel="nofollow noreferrer">create my own</a> Arduino for less than $10 (US) with a power regulator. Using a <code>L7805ACP</code> will regulate the power. </p> <p>Part List:</p> <pre><code>• 1 x P-DIP ATMEGA328P-PU programmed with Duemilanove Bootloader • 3 x Through-Hole 22pF Capacitors (2 for crystal and 1 for Analog power smoothing) • 1 x Through-Hole HC-49S 16 MHz Crystal (for clock) • 1 x 5 Volt regulator (peak current 2 A, nominal )(L7805ACP Input Voltage = 7.5 to 18 V Output Voltage Low 4.8 Volts Nominal 5 Volts High 5.2 Volts) • 1 x 22 uF Capacitor (to stabilize power rail during rapid current draw. </code></pre> <p><img src="https://i.stack.imgur.com/q0ymm.jpg" alt="Homemade Arduino "></p>
3992
|arduino-uno|power|pins|
Why does an Arduino UNO need two GND ports?
2014-08-31T05:44:49.050
<p>I have really bad eyesight, so whenever I plug in the power wire and the GND wire I always double check if I'm actually plugging in to the power port not one of the two GND ports. </p> <p>Why does an Arduino UNO have two GND ports, and for what application would one use both of them?</p>
<p>If you are not using a shield and are directly adding components to the arduino it is nice to have 2 ground so you can attach several components without having to add a bread board. </p> <p>To be precise, you have 3 ground, since the third is sitting on the left hand side of the board (looking in to the USB port)</p>
3996
|gsm|
Difference between SoftwareSerial and Serial
2014-08-31T09:58:18.260
<p>From the sample code </p> <pre><code>#include &lt;SoftwareSerial.h&gt; SoftwareSerial mySerial(10, 11); // RX, TX void setup() { // Open serial communications and wait for port to open: Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for Leonardo only } Serial.println("Goodnight moon!"); // set the data rate for the SoftwareSerial port mySerial.begin(4800); mySerial.println("Hello, world?"); } void loop() // run over and over { if (mySerial.available()) Serial.write(mySerial.read()); if (Serial.available()) mySerial.write(Serial.read()); } </code></pre> <p>What is the difference between, why use 2 types of calls to make AT command calls.</p> <blockquote> <p>SoftwareSerial mySerial (10,11) mySerial.begin(10,11)</p> </blockquote> <p>and</p> <blockquote> <p>Serial.begin(9600)</p> </blockquote> <p><strong>Edit, this answers my question in my own words based on @jfpoilpret response.</strong></p> <ol> <li>It is important to <strong>initialize both Serial and SoftwareSerial</strong>, since SoftwareSerial is used to send the actual commands to the GSM, and Serial is used to <code>view</code> all the commands and their responses on the debug port of the GSM</li> <li>The pins on the GSM and Arduino are used to connect the the 2, and pass on <strong>actual commands</strong>. While the RS232 is only used for debugging. We can however connect a RS232 to USB connector so as to connect the GSM to the desktop(or laptop)</li> <li>The code in the loop is essential to help <strong>convert</strong> all actual commands to the debugging RS232 port, and the other way around, so as to enable us to use a tool like <code>cutecom</code> (on ubuntu) to pass commands to the GSM serial input pins.</li> </ol> <blockquote> <p>Important Note : When using cutecom ensure that you select <strong>CR line end</strong> to send commands.</p> </blockquote>
<pre><code>#include &lt;SoftwareSerial.h&gt; SoftwareSerial GSMSerial(7, 8); //use pins 7 and 8 as RX and TX void setup() { GSMSerial.begin(19200); // the GPRS/GSM baud rate Serial.begin(19200); // the GPRS/GSM baud rate } void loop() { if(Serial.available()) { //to send commands received from Serial Monitor to GSM module GSMSerial.print((char)Serial.read()); } else if(GSMSerial.available()) { //To print data responded from GSM module to the Serial Monitor. Serial.print((char)GSMSerial.read()); } } </code></pre> <p>In the code above inside loop function first <code>if</code> statement is needed to talk to GMS module from Serial Monitor, e.g. when you type <code>AT</code> in the monitor and press enter your command gets sent to the GSM module.</p> <p>The second if statement <code>else if</code> is to print whatever is received or responded from GSM module e.g. GSM module responds the received command like <code>AT</code> and its result <code>OK</code> after you send command <code>AT</code> to the module.</p>
3997
|button|
Why does this button have a connection to ground?
2014-08-31T10:18:01.327
<p>I am testing this basic <a href="http://arduino.cc/en/tutorial/button" rel="noreferrer">button example </a> from the Arduino tutorial page.</p> <p>This circuit lets power flow to pin 2 when the button is pressed. When the button is not pressed, the power goes through the resistor to ground, but my question is: why would you even need the connection to ground?</p> <p>Can't you have power flow from 5V to pin2 or just have NO connection at all when the button is not pressed?</p> <p><img src="https://i.stack.imgur.com/d93mf.png" alt="Button"></p>
<p>In simple words, to avoid undefined state. This type of resistor arrangement is known as Pull Down Resistor. (Pull-Up also exists)</p>
4010
|nrf24l01+|
Can the nRF24L01+ CE and CSN pins be attached to Arduino pins A0 and A1?
2014-09-01T08:25:19.730
<p>This <a href="http://playground.arduino.cc/InterfacingWithHardware/Nrf24L01" rel="nofollow">documentation</a> states that the CE and CSN pins can be specified. Can I specify A0 and A1 as these pins?</p>
<p>Yes, you can. The <a href="https://github.com/aaronds/arduino-nrf24l01/blob/master/Mirf/Mirf.cpp#L85-86" rel="nofollow">mirf library</a> is using the regular arduino functions <code>pinMode</code> and <code>digitalWrite</code> to manipulate the pins. So A0 and A1 should work as expected.</p> <p>Please note that when you use SPI (which the NRF does), you have to use pin 10 (SS) as an OUTPUT (as to not put the AVR into SPI slave mode).</p>
4011
|digital|
Can I specify that analog pins be used for digital output?
2014-09-01T08:27:05.310
<p><a href="http://arduino.cc/en/Reference/pinMode" rel="nofollow">http://arduino.cc/en/Reference/pinMode</a> notes that</p> <blockquote> <p>The analog input pins can be used as digital pins, referred to as A0, A1, etc.</p> </blockquote> <p>Is it possible to configure these pins as digital output pins as well?</p>
<p>Yes.</p> <p><a href="http://arduino.cc/en/Tutorial/AnalogInputPins" rel="nofollow">http://arduino.cc/en/Tutorial/AnalogInputPins</a> states</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> </blockquote> <pre><code>pinMode(A0, OUTPUT); digitalWrite(A0, HIGH) </code></pre> <p>There are several caveats on that page regarding this.</p>
4022
|interrupt|timers|
When setting hardware timers as interrupts, should I prefer a lower prescaler value or a lower CTC?
2014-09-01T21:41:59.810
<p>I'm currently playing with Arduino's hardware timers, and a question came to my mind. Let me explain it a bit.</p> <p>Let's suppose I want a certain function to execute every 1024 clock ticks. AFAIK, I could achieve this in several ways, playing with the prescaler value for Timer2, and its CTC:</p> <ol> <li>Setting the prescaler to 1 and the CTC to 1024</li> <li>Setting the prescaler to 8 and the CTC to 128</li> <li>...</li> <li>Setting the prescaler to 1024 and the CTC to 1.</li> </ol> <p>All these ways would achieve what I want, but, which one is more efficient? Or it doesn't matter at all?</p> <p>Thanks in advance for sharing your knowledge :P</p>
<p>There is a trade-off between resolution and achievable frequencies. You mention Timer 2, but on the Atmega328P Timer 2 is an 8-bit timer, thus you would not be able to set the CTC to 1024.</p> <p>Let's assume we are talking about an 16-bit timer, like Timer 1 on the Atmega328P. With a prescaler of one, you can time (assuming a 16 MHz clock) from 1 to 65536 "ticks", that is 62.5 ns up to 4096 µs.</p> <p>This would be the most <em>precise</em> measurement because you are using one (processor) clock tick per timer tick (a prescaler of one).</p> <p>However if you plan to time for more than 4.096 ms then you need to bump up the prescaler. The next prescaler up on Timer 1 is 8, so now you can time for an interval 8 times as long (32768 µs) however your accuracy (precision) has now decreased by a factor of 8. The <em>granularity</em> of the timer has increased from 62.5 ns to 62.5 * 8 ns, which is 500 ns.</p> <p>If you need to time longer than 32.768 ms then the prescaler has to be larger again, the next one being 64. So now you can time up to 262144 µs, but with a granularity of 62.5 * 64, which is 4000 ns (4 µs).</p> <p>My suggestion would be to use the lowest prescaler that you can, but still get the interval you want. So obviously you can't use a prescaler of one to time 10 ms.</p> <hr> <p>I have a discussion about timers on <a href="http://www.gammon.com.au/timers" rel="nofollow noreferrer">http://www.gammon.com.au/timers</a>.</p> <p>On that page is a chart which helps visualize the effects of different prescalers:</p> <p><a href="https://i.stack.imgur.com/9dz8M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/9dz8M.png" alt="Timers and prescalers"></a></p> <p>The top part (count of one) effectively gives you the granularity of each prescaler. For example, a prescaler of 256 has a granularity of 16,000 ns (16 µs). Certain frequencies (powers of 2) will lend themselves to combinations (eg. prescaler of 1 with a count of 256, or prescaler of 256 with a count of 1).</p> <p>However for frequencies that don't have that property, the smaller prescaler will (if it can be used) give a finer granularity.</p>
4025
|pins|pwm|servo|
Difference between PWM and regular output port for servos?
2014-09-02T05:20:04.543
<p>I have been controlling my servomotors for a while now only using pin 0. After some research, it has became apparent to me that the ports with <code>~</code> are the PWM pins. </p> <p>I thought that all pins sent out PWM signals, therefore the motor was able to move back and forth. Now I'm really confused as to how the motor was able to turn without using a <code>~</code> pin like pin 5.</p> <p>Can someone explain why I should or should not use PWM signal when controlling a motor?</p>
<p>Servos does not use PWM, it uses PPM:</p> <ul> <li>PWM = Pulse width modulation, The pulse start at 0ms, and is high for the percentage of the time compared to the percentage of the voltage you want, 5v signal, if you want 1v, the pulse is 20ms High and 80ms Low.</li> <li>PPM = Pulse position modulation, The pulse length is always 5ms High and 95ms low, but the interesting part is if high starts after 5ms or 50ms (or any other).</li> </ul> <p>So PWM is to lower voltage, PPM is a signal pulse.</p> <p>This means that no matter what port you are using on the arduino you are able to control a servo since you only need High or Low, and not a lower voltage.</p> <p>What you need to be aware of in this case is on the arduino is a PPM signal is using up a timer. The arduino has 3 timers where of 2 is available, one is used internally. Though there is code where you can attach up to 3 servos on the same internal timer.</p>
4029
|voltage-level|battery|
Internal volts in arduino for percent battery
2014-09-02T20:12:58.013
<p>I'm working on a small project that is creating me a headache. I know arduimo (ATmega 328P .... etc. ..) has an internal voltage source code millivolts, but I would like to know how the full source code become percentage where 3 volts = 0% and 4.2 volts = % 100% ??? . I appreciate the help because in codes is not my forte. I leave the code so Help me complete. Thank you.</p> <pre><code>long readVcc() { long result; // Read 1.1V reference against AVcc ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Convert while (bit_is_set(ADCSRA,ADSC)); result = ADCL; result |= ADCH&lt;&lt;8; result = 1126400L / result; // Back-calculate AVcc in mV return result; } void setup() { Serial.begin(9600); } void loop() { Serial.println( readVcc(), DEC ); delay(1000); } </code></pre>
<p><a href="http://arduino.cc/en/reference/map" rel="nofollow"><code>map()</code></a></p> <pre><code>unsigned char level = map(readVcc(), 3000, 4200, 0, 100); </code></pre>
4031
|arduino-uno|programming|sketch|
Break statement terminating loop()
2014-09-02T22:58:54.123
<p>I am experiencing some very strange behavior with my arduino. I have a switch-case statement in the loop() method, and the break methods are not only breaking out of the case block, but also out of the loop() statement. Is this normal, and if so, how can I edit the structure so it doesn't do that? My code structure looks like this:</p> <pre><code>void loop(){ switch(int i){ case 1:{ //do something break;// this also breaks out of the loop() method. } } } </code></pre>
<p>I just realized it wasn't the sketch, but a faulty SD card reader on my computer corrupted my SD card. BIG TIME.</p>
4045
|arduino-uno|motor|robotics|arduino-motor-shield|
Arduino + simple DC motors? (4WD kit)
2014-09-04T05:43:43.213
<p>I am trying to connect 4 small DC motors to Arduino, like those in the following image: <img src="https://i.stack.imgur.com/3wWMY.jpg" alt="my kit, 4WD, with 4 simple motors"></p> <p>The specification for each of them is:</p> <blockquote> <p>Suggested Voltage: 3V DC;<br> No Load Speed: 65 ± 10rpm;<br> No Load Current: 125mA (170mA MAX).</p> </blockquote> <p>But I have no useful knowledge in electronics to do so... </p> <p>I would be really thankful if anyone could explain me why it is so difficult to connect DC motors to Arduino (I've heard about problems with the magnetic field, but I don't really understand why); and possible point me to an easy (and cheap) solution. I am, of course, willing to study (not expecting a complete solution). </p> <p>I'm aware there are some shields for doing this kind of connection, but they are really expensive, and I've seen some people using only transistors or components like SN754410.</p> <p>Thank you in advance! :-)</p>
<p>First you make 4 parallel H-Bridges, <a href="http://en.wikipedia.org/wiki/H_bridge" rel="nofollow">http://en.wikipedia.org/wiki/H_bridge</a> then you attach it to an external powersource ( or attach directly to the battery to prevent burning your arduino )</p> <p>Attach every up to a pin, making it high makes the motor running, you need 8 pins for this, eg pin 1 makes motor 1 go forward, pin 2 makes motor 1 go back and so.</p> <p>This is by far the most practical solution, but it is the easiest, and can be done with 8 PNP and 8 NPN transistors.</p> <p>If you don't know how transistors work i suggest <a href="https://www.youtube.com/watch?v=-td7YT-Pums" rel="nofollow">https://www.youtube.com/watch?v=-td7YT-Pums</a> collins lab, it is both educational and entertaining. </p>
4065
|led|relay|
Fade in UV lights connected to mains
2014-09-06T09:45:57.270
<p>I have a PIR motion sensor and would like some ultra bright UV led lights to fade in when this is triggered. It is one unit, consisting of 225 led lights connected to 240v mains (Australia). I bought a relay for the basic on/off function but was wondering if fading on and off can be done relatively easily - this is my first arduino project. I would value any suggestions.</p>
<p>Most LED lights can't be dimmed from the mains supply.</p> <p>In order to dim LEDs you have 2 choices: Limit the current through each LED or series string of LEDs, or pulse them very rapidly with a varying ratio of on/off times (known as a variable "duty cycle")</p> <p>It's usually easiest to pulse them. To do that you need to be able to control the flow of DC to the LED array. If you were to take apart your IR array you would very likely find an AC to DC power supply that then feeds the LEDs through current limiting resistors.</p> <p>If you can figure out the voltage and current that comes out of the DC power supply, you can select a power transistor (almost certainly a logic level power MOSFET) to wire in as an electronic switch that enables you to pulse the power to the LEDs using a logic signal from your Arduino.</p> <p>This is actually a lot simpler than it sounds. You would cut 1 wire inside your LED array, solder in a single transistor to the 2 ends of the cut wire, and run the third wire from the transistor out to your Arduino.</p> <p>Arduinos have several I/O lines that can be configured for PWM (Pulse Width Modulation) which is designed for this very purpose. You'd connect a PWM line to the gate of a logic level power MOSFET, and then send it a signal from 0 to 255, which would effectively dim the LED array in 255 brightness steps.</p> <p>There are beginner sample projects that let you dim single visible light LEDs using this very approach. (For a single LED you don't need a transistor though, so they are really easy to wire up. All you need is a current limiting resistor.) I suggest you find and build one of those projects to get a feel for how (and how well) it works.</p>
4067
|arduino-uno|led|wires|
Arduino starter kit example LEDS modification
2014-09-06T13:45:59.060
<p>I just begun with the Arduino starter kit, and in the second example I would like to test some changes to learn more.</p> <p>The point is to have a green LED shining, and when pressing the button the two red LEDs blink.</p> <p>This is the code:</p> <pre><code>int switchState = 0; void setup() { pinMode(2, INPUT); pinMode(3, OUTPUT); pinMode(4, OUTPUT); pinMode(5, OUTPUT); // the button is pressed digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, HIGH); delay(250); // wait for a quarter second // toggle the LEDs digitalWrite(4, HIGH); digitalWrite(5, LOW); delay(250); // wait fo a quarter second } void loop() { switchState = digitalRead(2); // this is a comment if(switchState == LOW) { // the button is not pressed digitalWrite(3, HIGH); // green LED digitalWrite(4, LOW); // red LED digitalWrite(5, LOW); // red LED } else { // the button is pressed digitalWrite(3, LOW); digitalWrite(4, LOW); digitalWrite(5, HIGH); delay(250); // wait for a quarter second // toggle the LEDs digitalWrite(4, HIGH); digitalWrite(5, LOW); delay(250); // wait fo a quarter second } } // go back to the beginning of the loop </code></pre> <p>I added a modification into the schema (a fourth LED in parallel with the green), like this:</p> <p><img src="https://i.stack.imgur.com/1jCas.jpg" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/ZcS7d.jpg" alt="enter image description here"></p> <p>But the added LED is not shining. It's a long time ago I finish school and I forgot a lot of things. Am I wiring the fourth LED incorrectly?</p>
<p>Blue LEDs have a higher V<sub>f</sub> than green LEDs, hence much less current will pass through it, not enough to make it visible. Give it its own resistor instead of sharing the resistor with the green.</p>
4070
|serial|arduino-ide|
Serial.println(): Where is the text printed?
2014-09-06T17:17:42.097
<p>When I used <code>Serial.println()</code> in the code I naively believed I would see the characters that I sent displayed on that little black area just under the interface (just like a terminal).</p> <pre><code>#include &lt;Servo.h&gt; int moveServo; Servo myservo; void setup() { myservo.attach(0); Serial.println(" Hello Earth"); Serial.println(); } void loop() { } </code></pre> <p>Can someone tell me just where <code>Hello Earth</code> would be displayed?</p>
<p>You can open the serial console in the Arduino IDE by pressing ctrl-shift-M (as in Monitor) or selecting it in the menu.</p> <p>Also, to use the serial interface, you have to initialize it using <code>Serial.begin(9600);</code> in <code>setup()</code> before calling any other function which writes to it. You can use any other baud rate - but this is the default in the Arduino IDE, if you change it, you should change it in the IDE too.</p>
4071
|serial|
Serial.begin(): Why not always use 28800?
2014-09-06T17:19:55.333
<p>In a lot of the sample code online people add the line <code>Serial.begin(9600)</code> in the setup block.</p> <p>When I look up what <code>Serial.begin()</code> is on the official documentation, it says that it controls the bit per second data transfer.</p> <p>So the obvious question is, why not use 28800, the highest transfer rate? Why do people settle for 9600? What is the limitation here?</p>
<p>In addition to all the interesting answers, it worth mentioning that setting the serial speed to <em>XXX</em> bits/s does not necessary imply <em>XXX</em> bits/s on the hardware.</p> <p>Clocks -- even quartz based -- are imperfect and subject to drift. In addition, as the serial clock is usually generated through a power-of-two pre-divisor and (integer) counter, all value cannot be accurately obtained given a base clock frequency. With the help of the start/stop bits, asynchronous serial communication may be tolerant to some clock drift. But this has limits.</p> <p>For example, if your ATmega328PA is running at 1MHz, you can achieve 9600b/s at 0.2% of error. But at 14400b/s the error is -3.5% (actually communicating at 13900b/s). And at 28800b/s, the error is +8.5% (actually communicating at 31200b/s). All those figures are from <em>ATmega48PA-88PA-168PA-328PA datasheet, p200</em>. </p> <p>This is <em>not</em> an issue when two identical devices communicate together (as there are in fact communicating at the <em>same</em> speed). It <em>might</em> be an issue when communicating between different devices.</p> <p>Increasing the base frequency does not necessary improve significantly the accuracy. For example, running the same ATmega328PA as above at 2MHz does not really give better results as those are mostly due to rounding errors. But running it 1.8432MHz give very accurate bps from 2400b/s up to 57.6kHz.</p>
4076
|servo|
What is commonly done to stop a servo after reaching desired position?
2014-09-06T19:18:52.017
<p>When I started Arduino, I did not expect that everything must be contained in an infinite loop. I thought I could just write something like: motor start -> motor stop. But in actuality, what I get is motor start -> motor stop -> motor start -> ... forever and ever.</p> <p>What is commonly done to stop a servo after it is in a desired position? Do I use <code>servo.write(desired position)</code> to keep it from turning? Do I detach the output wire?</p> <p>What are some of the risks involved?</p>
<p>The word <em>servo</em> has a vague definition and can encompass many types of subcomponents. If you want <strong>no-power position holding</strong> using an electromagnetic motor, then there are four options:</p> <ul> <li>High viscosity grease</li> <li>Dash pot</li> <li>Very high gear ratio</li> <li>magnetic brake shoe / brake band</li> </ul> <p>EDIT: There are some additional possibilities, but it's sort of an effect of some motor designs:</p> <ul> <li>Permanent magnet pole holding torque, or detent torque</li> <li>Permanent magnet drag torque</li> </ul> <p>&nbsp;</p> <p>The high viscosity grease and dash pot have similar functions; providing a high static friction to resist motion, which then breaks away into movement. (A dash pot is essentially a toothed gear inside a toothed wall container, and which is permanently filled with a high viscosity fluid.)</p> <p>However both of these will add to the motor load, and when they get hot they tend to become thin and runny and lose holding ability.</p> <p>&nbsp;</p> <p>A high gear ratio increases the torque required to back-spin the motor. Though note, if any gearbox could have a perfectly frictionless lubricant, no amount of gear reduction could stop back-spinning.</p> <p>So really this is similar to the thick grease and dash pot, but gear reduction allows just the normal thin lubrication to have enough static breakaway friction, to stop back-spinning.</p> <p>&nbsp;</p> <p>A magnetic brake gives you active control over the static breakaway friction, and can allow for very high holding ability vs intermittent load spikes on the output shaft. Typically with the power off, a spring engages the brake to hold position with no power.</p> <p>Note, there are two different kinds of braking: static position holding, and deceleration of a moving mechanism.</p> <p>The second type both dumps heat into the brake pads and friction plate, and wears down the pads and friction plate. If the brake overheats, the pads usually disintegrate, and the brake now won't hold position.</p> <p>Unless we're talking about large machinery, usually servo brakes are simple designs without replaceable parts. When the brake fails, you pull the whole thing off and replace it ... including possibly the entire servomotor and gearbox too.</p> <p>For long service life with magnetic braking, you need to actively decelerate the load using the servo, and then once it has stopped moving, then engage the brake to just do the job of holding position.</p> <p>&nbsp;</p> <p>Using a magnetic brake for no-power static load holding only, will look like this:</p> <ul> <li>Power up motor, get current position, and begin actively holding position.</li> <li>Energize brake to release it</li> <li>Accelerate and move to new position</li> <li>Decelerate motor and hold end position</li> <li>Remove power from brake to engage it</li> <li>Turn off power to motor</li> </ul> <p>The motor is powered up and goes into position holding first, so that the load doesn't suddenly slip in either direction, in the instant between the brake being released and the servomotor then becoming active.</p> <p>&nbsp;</p> <p><strong>EDIT #1</strong>: For some permanent magnet motors, even with the power off there is a resistance to rotation because in certain positions, the magnets and the pole pieces more closely attract to each other, known as <em>detent torque</em>.</p> <p>This pole positioning is like a low-energy valley and it takes a bit of force to overcome the magnetic attraction and move the rotor in either direction using an external torque. </p> <p>You can feel this in some brushless fans and stepper motors, where if you rotate the shaft unpowered, it resists continuous motion, and there seem to be high resistance points that the rotor does not want to cross. When spun, the rotor rapidly slows, and may fall into a back-forth oscillation as it settles into one of the magnetic attractive wells.</p> <p>This can be used to resist external torques without a brake, but making use if it requires stopping the rotor in one of the magnetic wells rather than a specific position you may want. But if combined with a gearbox, the exact specific stopping position may not matter too critically, and there may be a number of wells next to each other where the rotor can stop that provide an acceptable end-effector alignment.</p> <p>&nbsp;</p> <p><strong>EDIT #2</strong>: Permanent magnet drag torque is an effect of shorting all the power wires together. When this is done it takes considerably more force to rotate the shaft than with the stepper coil wires disconnected from each other.</p> <p>This is because with the coil wires all connected together, when the rotor turns it acts as a generator and current flows through the coils. This current flow creates what is known as counter electromotive force (CEMF), which counters the magnetic field of the permanent magnet.</p> <p>This CEMF can provide additional resistance against rotation when the servo is unpowered. Although CEMF won't prevent motion, it can help resist continued motion and provide instant deceleration when intermittent load spikes are applied that try to move the unpowered servo.</p> <p>&nbsp;</p> <p>All of the above is also generally true for linear motor servos. Those don't have gear reduction, but the motion carriage can be lubed with thick grease, be equipped with a dash pot, and have position holding magnetic brakes.</p>
4078
|arduino-uno|
Why does my Arduino seem to reboot every time that I open Serial Monitor?
2014-09-06T19:52:50.373
<p>Every time that I open the Serial Monitor, my <a href="http://arduino.cc/en/Main/ArduinoBoardUno" rel="nofollow">Arduino Uno</a>, seems to go back to <code>void setup()</code>. Is it a normal thing?</p>
<p>That is a normal feature of Arduinos, not an error. I find it mildly annoying sometimes, but it's nice for interactive programs that want some kind of menu message to be the first thing you see in the terminal. </p> <p>If you want help disabling the auto reset, your options are detailed in <em><a href="http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection" rel="nofollow">Disabling Auto Reset On Serial Connection</a></em>.</p>
4082
|arduino-uno|power|
Curious: What would happen if you connect 5V and GND port directly with a wire
2014-09-06T21:43:58.720
<p>Has anyone ever accidentally or inadvertently connected connected the supply port with the ground port with a wire? </p> <p>Does Arduino provide internal safety to prevent the circuit board from shorting out?</p>
<p>There is some protection.</p> <p>When powered from the USB port, the UNO has a 0.5 A fuse. This is a self resetting fuse that will trip when the current is high, and reset when it cools back down. These fuses are great for peripherals that might be exposed to occasional "oops". See the <a href="https://www.bourns.com/pdfs/mfmsmf.pdf">data sheet</a> for more details of the part on the UNO.</p> <p>When powered from the PWRIN plug, the voltage regulator provides some protection. The device on the UNO contains over current and over temperature protection, which is common for regulators such as this. The device will get very hot, and the protection will activate to limit the current (see <a href="http://www.onsemi.com/pub_link/Collateral/NCP1117-D.PDF">datasheet</a> for details). By design, the regulator chip should protect itself from being destroyed. </p> <p>So to first order, if you by mistake connect the +5 on the header to GND, all that will happen is Vcc will be reduced to near zero Volts. </p> <p>The caveat is that a small spark can be generated when you make this short to ground, especially if you have a bunch of capacitors on Vcc. That spark may cause a voltage transient that could damage a pin.</p>
4086
|arduino-uno|motor|
Keyboard Control Not Working As Intended
2014-09-07T03:42:15.423
<p>I'm trying to control a single motor. </p> <p>If I press 'a', then motor 1 should turn to 0, if I press 's', then motor 1 should turn to 180</p> <pre><code>#include &lt;Servo.h&gt; char key = 0; const unsigned int BAUD_RATE = 9600; Servo Servo_0; void setup() { Servo_0.attach(0); Servo_0.write(0); Serial.begin(BAUD_RATE); // Serial.println(" Arduino Serial Servo Control"); // Serial.println("Press &lt; or &gt; to move, spacebar to center"); // Serial.println(); } /* a - 97 s - 115 d - 100 f - 102 */ void loop() { if(Serial.available()&gt;0) { key = Serial.read(); Serial.print("I received: "); Serial.println(key, DEC); if(key == byte(97)) { Serial.print("Turning Motor 1 to 0 deg"); Servo_0.write(0); } else if(key==byte(115)) { Serial.print("Turning Motor 1 to 180 deg"); Servo_0.write(180); } delay(1000); } </code></pre> <p>But what is happening is that the motors are barely turning after I enter the key onto the Arduino monitor interface. Can anyone diagnose as to what might be happening?</p>
<p>The problem I see is that your servo is attached to pin 0.</p> <p>Pins 0 and 1 are used by arduino unos and megas for serial communication, so you can't output to a motor and send/receive serial at the same time. Try moving the servo to pin 3 and see what happens.</p> <p>In response to your comment, any character sent from any terminal (or other piece of hardware) will work; you do not need to use Processing to communicate with an arduino.</p>
4088
|gps|
Building a gps system
2014-09-07T11:12:53.893
<p>I'd like to build a simple GPS system. It should be very little. For the software side, I will build an API, so from my PC/smartphone/whatever else I could ask the GPS system where it is located (I think Google provides this kind of feature).</p> <p>How can I do this? My main problem is the GPS and the its building. I'd like to build the smallest thing possible, because I have to hide it. My idea is to hide this GPS system in my bike: I'd like to locate my bike if someone stole it. As you can see, internet is a problem.</p> <p>I'm not asking to design anything. I would only know what I need to build a basic GPS system that has just the feature described. What do I need? Is it possible to do it? Does GPS require Internet connection? I would know if I could make it or not without internet access.</p>
<p><strong><em>"Is it possible to do it?"</em></strong></p> <p>Well... everything is possible :-)</p> <p><strong><em>"Does GPS require Internet connection?"</em></strong></p> <p>GPS doesn't require internet. A GPS receiver (e.g. <a href="http://www.modulestek.com/prodts/GPS/Mars740-mini/Mars740-mini_SPEC.pdf" rel="nofollow">http://www.modulestek.com/prodts/GPS/Mars740-mini/Mars740-mini_SPEC.pdf</a>) is connected to the reading unit via USB or a RS232 interface. The protocol is very simple. However it only provides latitude and longitude. If you want to have an address, map data is required (for <em>this</em> you would need internet - or a large memory). </p> <p>And of course such a system requires good signals from the GPS satellites.</p> <p><strong><em>"What do I need?"</em></strong></p> <p>First you need a GPS receiver (see above).</p> <p>Second, you need a microcontroller unit which runs your application and does all the control of the external units.</p> <p>Third, you need a GSM module (e.g. <a href="http://www.exp-tech.de/Shields/Wireless/GSM-GPRS/adafruit-fona-mini-cellular-gsm-breakout-sma.html" rel="nofollow">http://www.exp-tech.de/Shields/Wireless/GSM-GPRS/adafruit-fona-mini-cellular-gsm-breakout-sma.html</a>) to send a message. Don't forget the antenna for connection to the mobile communication network.</p> <p>Fourth, you need a power supply. Ideally it has a battery which can be reloaded when driving.</p> <p>As you may see, if you put all this together you are far from the "smallest thing possible".</p> <p>Actually any modern smartphone could be enough. Mount it "invisible" under your saddle, connect it to a bike charger, find the proper App and that's it - although it might not be the smallest solution.</p> <p>I don't know any, but I'm sure there <em>are</em> products off the shelf that fulfil your requirements, designed and developed by experienced engineers, and thus smaller and maybe cheaper than what you ever could achieve on your own.</p>
4092
|ide|
Arduino Uno 3: Stuck at 'uploading...' sketches
2014-09-07T18:51:05.160
<p>I was playing around with my Arduino Uno R3 board with Sublime Text 2 &amp; 'Stino' as IDE<br> I am not sure if it is my code is the problem or if I broke something...<br> I pressed upload while another sketch didn't finish uploading, even the original Arduino IDE can't upload new sketches anymore!</p> <p>This is my code:</p> <pre><code>// singleServo.ino #include &lt;Servo.h&gt; Servo servo; const int button = 2; const int led = 13; const int buzzerPin = 10; const int duration = 180; int stateLED = LOW; int previous = LOW; void setup() { pinMode(led, OUTPUT); pinMode(button, INPUT); pinMode(buzzerPin, OUTPUT); Serial.begin(9600); } void loop() { int stateButton; stateButton = digitalRead(button); if (stateButton == LOW &amp;&amp; previous == LOW) { if (stateLED == HIGH) { stateLED = LOW; initAction(duration); } else { stateLED = HIGH; } } digitalWrite(led, stateLED); previous = stateButton; servo.detach(); } void initAction(int time_iA){ tone(buzzerPin, 523, 200); delay(200); shiftServo(180, time_iA); tone(buzzerPin, 262, 200); } void shiftServo(int angle, int time_sS) { servo.attach(9); delay(500); int position; for(position=0; position &lt;= angle; position += 1) { servo.write(position); delay(time_sS / 180); Serial.println(servo.read()); } // for(position=angle; position &gt;= 0; position -= 1) // { // servo.write(position); // delay(time_sS / 90); // } } </code></pre> <p>I am a newbie with all things Arduino - Please help!</p> <p>EDIT: After rebooting the system (Ubuntu Linux 14.04) everything was working just fine again!<br>But I'm going to take the serial functions out too.</p>
<p>I had the same problem with arduino uno r3 on win10. The solution was simple:</p> <ol> <li>open the task manager (Ctrl + Shift + Esc)</li> <li>stop all open COM processes and the arduino upload worked again.</li> </ol>
4095
|arduino-uno|servo|adafruit|
Sample code for using adafruit servo shield?
2014-09-08T03:10:08.710
<p>I would like to control 16 motors with a servo shield, however, I have found scant to nothing sample code online. The one I was able to find is...strange to say the least</p> <p><a href="https://github.com/kachok/arduino-libraries/blob/master/Adafruit_PWMServoDriver/examples/servo/servo.pde" rel="nofollow">https://github.com/kachok/arduino-libraries/blob/master/Adafruit_PWMServoDriver/examples/servo/servo.pde</a></p> <pre><code>#include &lt;Wire.h&gt; #include &lt;Adafruit_PWMServoDriver.h&gt; // called this way, it uses the default address 0x40 Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(); #define SERVOMIN 150 // this is the 'minimum' pulse length count (out of 4096) #define SERVOMAX 600 // this is the 'maximum' pulse length count (out of 4096) uint8_t servonum = 0; void setup() { Serial.begin(9600); Serial.println("16 channel Servo test!"); pwm.begin(); pwm.setPWMFreq(60); // Analog servos run at ~60 Hz updates } void loop() { // Drive each servo one at a time Serial.println(servonum); for (uint16_t pulselen = SERVOMIN; pulselen &lt; SERVOMAX; pulselen++) { pwm.setPWM(servonum, 0, pulselen); } delay(500); for (uint16_t pulselen = SERVOMAX; pulselen &gt; SERVOMIN; pulselen--) { pwm.setPWM(servonum, 0, pulselen); } delay(500); servonum ++; if (servonum &gt; 15) servonum = 0; } </code></pre> <p>Im used to controlling motors using servo.write, but with the shield, it doesn't seem very intuitive as to how I should control the motors. How does Servomin and Servomax map to 0 degree and 180 degree?</p> <p>Someone please elucidate!</p>
<p>The 2 values SERVOMIN and SERVOMAX define the pulse length, which tells the servo what angle to go to. The example uses 150 for SERVOMIN and 600 for SERVOMAX. When running the code, the servos travel 180 deg. I changed the code to read:</p> <pre><code>#define SERVOMIN 262 // this is the 'minimum' pulse length count (out of 4096) #define SERVOMAX 488 // this is the 'maximum' pulse length count (out of 4096) </code></pre> <p>and the servo now moved only 90 deg. centered at the same place as the original code.</p> <p>the tutorial provided by Adafruit describes a way to define the movement by angle:</p> <pre><code>pulselength = map(degrees, 0, 180, SERVOMIN, SERVOMAX); </code></pre> <p>found here: <a href="https://learn.adafruit.com/adafruit-16-channel-pwm-slash-servo-shield/using-the-adafruit-library" rel="nofollow">https://learn.adafruit.com/adafruit-16-channel-pwm-slash-servo-shield/using-the-adafruit-library</a></p> <p>hope this helps</p>
4099
|arduino-uno|motor|
Salvaged Stepper Motor Blues
2014-09-08T08:19:10.357
<p>So recently my company threw away some rather large and reasonably old laser printers. One was a LaserJet 9050dn the other was a Epson printer/scanner combination. Being a little industrial I thought let me salvage them and brought them home.</p> <p>I managed to salvage a couple of stepper motors. However I am having huge trouble is getting them to step properly. So lets get into the details.</p> <p>Components used:</p> <ul> <li>1x Freetronics eleven (Arduino Uno compatbile) </li> <li>1X H-Bridge driver shield(Freetronics rated for 40V/2A max). </li> <li>1X Old scanner power supply which has a output of 24V/2A.</li> </ul> <p>Currently there are two stepper motors I am interested in using. They have the following part numbers:</p> <ul> <li>1X MITSUMI M42SP-4N </li> <li>1X Minebea-Matshushita 17PM-J212-G2ST</li> </ul> <p>Just to keep this short I am going to focus on the Minebea-Matshushita 17PM-J212-G2ST. I have been unable to find exact matches on these serial numbers when looking for datasheets but I have managed to find the following sheets on the net.</p> <ol> <li><a href="http://www.eminebea.com/en/product/rotary/steppingmotor/hybrid/standard/data/17pm-k.pdf" rel="nofollow">Minebea-Matshushita 17PM-K</a> datasheets found from Minebea. However I cant match the model exactly.</li> <li><a href="http://www.theprojectasylum.com/electronicsprojects/componentdata/minebeasteppedatacirca1999.html" rel="nofollow">Minebea Stepper Motor Information &amp; Specifications</a> also carries some useful information.</li> </ol> <p>So it appears that these are 24V steppers(in both cases). The Minebea-Matshushita 17PM-J212-G2ST appears to have a step angle of 1.8 degrees which should give me 200 steps per revolution. I have not been able to find the current needed to drive this motor but judging by the looks of things it will be between 0.8A and 1.2A.</p> <p>I then used my multimeter to find the pairs of wires. It has 4 wires coming out (Bipolar motor I guess). The colours of the wires are red, yellow,orange and blue. First pair was red and yellow with red being positive/anode. Second pair orange blue with orange positive/anode side.</p> <p>I wired my power supply into my h-bridge and started using the <a href="http://www.freetronics.com/pages/hbridge-motor-driver-shield-quickstart-guide#.VA1jNfmvUrW" rel="nofollow">recipe and quickstart</a> found at the freetonics site. This is where the frustration begins. When asking the motor to do one complete revolution(360 degrees) it does more than 360 degrees at times and other times it does less. I tied a cable tie to the motor so I can confirm it.</p> <p>So I tried the one-step-at a time sketch to see if I can troubleshoot it. Here is what I have noticed. The steps are mostly correct one step at a time clockwise however every now and again it will jump counter clock wise and then clock wise again. I suppose you can call it a jitter.</p> <p>Interestingly both these motor show the same behaviour pretty good step action just every 25 degrees or so a jitter. So I suspect that this might not be bi-polar motors but uni-polar? <a href="http://josafatisai.blogspot.com.au/2013/04/wiring-mitsumi-stepper-m42sp-4np-with.html" rel="nofollow">This blog</a> entry points me to believe that this might be the case. However the datasheet in this case points to a M42SP-7.</p> <p>So my question would be simple how do I figure out if they are bi-polar or uni-polar? </p> <p>Can someone help me with a proper datasheet?</p> <p>Any tips would be really appreciated. </p> <p>Update:</p> <p>Note that I can get both motors to step clock-wise and counter clock-wise I just cant get them to do a whole 360 degrees without a jitter. Based on the <a href="http://josafatisai.blogspot.com.au/2013/04/wiring-mitsumi-stepper-m42sp-4np-with.html" rel="nofollow">Wiring Mitsumi stepper ( M42sp-4np) with arduino blog </a> it appears that the Mitsumi is a uni-polar motor with a 2-2 phase excitation. What stumps me is that the wires are paired thus it must be bi-polar?</p> <p>So last night I tried 2-2 phase excitation with the MITSUMI M42SP-4N and it appears to be solve the problem with this motor in particular. From early observations the motor now steps without jitter, however it was late so I will need to confirm this. </p> <p>I was previously using 1-1 phase excitation i.e.</p> <pre><code>Step number: 1a 1b 2a 2b 1 1 0 0 0 2 0 0 1 0 3 0 1 0 0 4 0 0 0 1 5 1 0 0 0 </code></pre> <p>When using 2-2 phase excitation I get a more steady step however this needs to be confirmed a bit more:</p> <pre><code>Step number 1a 1b 2a 2b 1 1 0 0 1 2 1 0 1 0 3 0 1 1 0 4 0 1 0 1 5 1 0 0 1 </code></pre> <p>Just some added observations. The headache continues but I am learning a LOT about steppers motors.</p> <p>Update:</p> <p>Not a 2-2 phase excitation these are definitely bi-polar. I am currently watching the Minebea-Matshushita 17PM-J212-G2ST do 360 degrees both clock and counter-clockwise. I hooked them up to a 12V/1A power supply both motors are running smoother and cooler and stepping relatively jitter free. I suspect the whole issue is a lack of a proper data-sheet.</p> <p>Will update as things progress and once solved add pictures and sketches so the next lucky sod wont loose as much hair as me.</p> <p>Update:</p> <p>Thanks to Chris who made me look at the sketch in detail again. These motors seem to have a minimum rpm of sorts. I was trying to go for a really slow rpm under 5rpm at this speed these motors show the jitter effect. However when moving the speed to 10rpm and up no jitter.</p>
<p>Keeping this here for future reference. It appears these motors have a minimum RPM of sorts and running them on a lower RPM causes the jitter effect described above.</p> <p>Like I mentioned in the updates when running at 10RPM or above these motors seem to perform very nicely.</p> <p>Update: I recently bought a ADAFruit motorshield and I am getting much more stable results with this shield and the stepper motors. I am even running them off 6V and they are working perfectly even at lower rpm.</p>
4114
|sensors|lcd|arduino-motor-shield|
Stacking Arduino Shield (Motor Shield, LCD Keypad, LED Sensor)
2014-09-09T06:31:51.920
<p>I'm building a line follower with arduino, here some part that I'm going to use</p> <ul> <li><p>Arduino Uno</p></li> <li><p>Motor Shield 2A <a href="http://www.dfrobot.com/index.php?route=product/product&amp;product_id=69" rel="noreferrer">http://www.dfrobot.com/index.php?route=product/product&amp;product_id=69</a></p></li> <li><p>LCD Keypad</p></li> <li><p>4 Channel Line Tracking Sensor <a href="http://www.aliexpress.com/item/4Channel-Infraed-Line-Tracking-Sensor-Module-w-Connector-Line/2021343637.html" rel="noreferrer">http://www.aliexpress.com/item/4Channel-Infraed-Line-Tracking-Sensor-Module-w-Connector-Line/2021343637.html</a></p></li> </ul> <p>I'm using LiPo Batteries 3 Cell 11.1v for power source.</p> <p>I'm new in here so I didn't know how to stack that shield, if I recall I can stack up Arduino and the LCD Keypad, and Arduino and the Motor Shield, but didnt know how to stack those 2 together and adding another sensor like that line tracking sensor. May I know how to resolve that? thanks.</p>
<p>The most elegant approach would probably be to use shields controlled by the I2C bus. I've found LCD+keypad and <a href="https://www.adafruit.com/products/1438" rel="nofollow">motor shield</a> offered by Adafruit for example.</p> <p>The I2C bus is shared by all slaves connected to it, and you should find microswitches on each shield to set its I2C address.</p> <p>Regular shields should not interfere with I2C lines, so as last resort you can put one shield controlled "traditional way".</p>
4121
|c|
Serial input parallel output shift registers with arduino
2014-09-09T17:05:53.097
<p>I need a way to rewrite the switch case part in a more efficient way.</p> <pre><code>int y , x ; byte dataArray[6]; void setup () { pinMode(8,OUTPUT); pinMode(11,OUTPUT); pinMode(12,OUTPUT); Serial.begin(9600); dataArray[0] = 0x3 ; //00000011 dataArray[1] = 0x5 ; //00000101 dataArray[2] = 0x9 ; //00001001 dataArray[3] = 0x11; //00010001 dataArray[4] = 0x21; //00100001 dataArray[5] = 0x41; //01000001 } void loop () { while (Serial.available()&gt;0) { y = Serial.read(); x = Serial.read(); switch ( x ) { case 1: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,dataArray[y]); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; case 2: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,dataArray[y]); shiftOut(11,12,LSBFIRST,0); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; case 3: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,dataArray[y]); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; case 4: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,dataArray[y]); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; case 5: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,dataArray[y]); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; case 6: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,dataArray[y]); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; default: digitalWrite(8,LOW); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); shiftOut(11,12,LSBFIRST,0); digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); break; } } } </code></pre>
<pre><code>unsigned char i; digitalWrite(8,LOW); for(i=0;i&lt;=6;i++){ if(x+i==6) shiftOut(11,12,LSBFIRST,dataArray[y]); else shiftOut(11,12,LSBFIRST,0); } digitalWrite(8,HIGH); delay(10); digitalWrite(8,LOW); </code></pre>
4127
|arduino-mega|uart|
Code to use an Arduino Mega 2560 to transfer UART <-> USB to debug an other Microcontroller
2014-09-10T11:03:09.840
<p>I have the following circuit and want to use the Arduino Mega 2560 as an debugger for an other Microcontroller. <img src="https://i.stack.imgur.com/uEZTh.png" alt="circuit"></p> <p>So I am looking for the code to redirect the UART input from "P17 (RX2)" to the serial USB and the data coming from the serial USB to the output of "P16 (TX2)"</p>
<p>A very simple sketch to pass serial through looks like this:</p> <pre><code>void setup(){ Serial1.begin(/*BAUD*/); Serial2.begin(/*BAUD*/); } void loop(){ if(Serial1.available()){ Serial2.print((char)Serial1.read()); } if(Serial2.available()){ Serial1.print((char)Serial2.read()); } } </code></pre> <p>I would advise both run at the same baud rate, otherwise you may need to do some extra buffering yourself if the arduino starts running out of buffer space. If you want to use the mega's USB connection instead of "Serial1" like your schematic, just switch "Serial1" to "Serial"</p>
4128
|analogread|
Analog Reference and Power Voltage
2014-09-10T12:06:27.523
<p>On the Arduino website it states that the analog pins read voltages from 0 to 5 volts (default) and return a value from 0 to 1023. One can also set the range with analogReference(). However, this is probably assuming the Arduino is running at 5 volts. If one powers the board with, say 4 volts, will the analog reference still be 5 volts default, or changed to the input voltage of 4 volts?</p>
<p>There is code published that shows how to read the internal voltage, I use that to correct my A/D readings. It is not perfect but close. You can of course select a lower reference voltage by changing the appropriate registers and use a different reference. This is much safer then supplying an external reference.</p>
4133
|power|arduino-pro-mini|
Budgeting Power for 5V Arduino Pro Mini
2014-09-10T18:35:41.930
<p>In my low power project, I'm using a Arduino Pro Mini (5V, 16 MHz, ATMEGA328) and a low wattage 3W power supply. Everything else on the system other than the Arduino uses a max of 1.98W.</p> <p>How much power should I budget for the Arduino Pro Mini (without any mods, ie: disconnecting the voltage regulator and LED)?</p>
<p>Arduino mini, and atmega328 in general use less than 10mA with default arduino code. Turning down unused component (ADC and so on), using deep sleep and optimizing pbc would lover this consumption a lot, in the land of uA</p>
4135
|arduino-uno|servo|map|
Arduino starter kit servo is shaking
2014-09-11T07:29:31.323
<p>In the example of the arduino starter kit the point is to use a potenciometer to control a servo.</p> <p>The code is </p> <pre><code>angle = map(potVal, 0, 1023, 0, 179); </code></pre> <p>The output in the serial</p> <pre><code>potVal: 1023, angle: 179 potVal: 1015, angle: 177 potVal: 1023, angle: 179 potVal: 1016, angle: 177 potVal: 1023, angle: 179 potVal: 1023, angle: 179 </code></pre> <p>I noticed that the servo is shaking like trying to go passing over the 179, when it is suppose to use an angle max 180º (0-179)</p> <p>What could be the problem?</p>
<p>Since the previous answers were all code-related, let me suggest you use a smoothing capacitor. In noisy environments, or where you want to get more consistent readings, place a capacitor across your signal lines (signal to ground). The result is less "spikes" in your readings, and can sometimes cause a slight delay in signal changes, as charge has to build up in the capacitor before the voltage goes up.</p> <p><a href="http://www.learningaboutelectronics.com/Articles/What-is-a-smoothing-capacitor" rel="nofollow">http://www.learningaboutelectronics.com/Articles/What-is-a-smoothing-capacitor</a></p>
4136
|arduino-uno|wifi|i2c|library|
Problem connecting Arduino Uno with Wifi and NFC
2014-09-11T08:24:58.630
<p>I'm new here and also new to Arduino.</p> <p>I've got a rather specific problem and I've posted to the official Forum on arduino.cc two days ago (<a href="http://forum.arduino.cc/index.php?topic=265800.0" rel="nofollow">original Post</a>)</p> <p>Sadly, I've yet to recieve any help and since it's a project for work, theres a (loose) schedule. So I've decided to post it here as well.</p> <p>If you have some ideas, it'd be really great!</p> <p>Also, if I've posted this question without acknowleding some forum rules please tell me so that I can write better posts in the future ;-)</p> <p>Regards,</p> <p>Patrick</p> <p><strong>Edit:</strong> The original Posts as Text :-)</p> <p><strong>Post # 1</strong></p> <p>Hello Guys,</p> <p>this is my first time posting in the forum since I'm new to Arduino, so please be kind smiley-wink. Me and a colleague of mine have been given a Project to create with arduino hardware.</p> <p>The Project is, that you should be able to read NFC tags with the arduino and send them to a server to be checked and eventually being written into a db.</p> <p>The hardware: Arduino Uno R3 (funduino.de/index.php/shop/product/view/2/4) Adafruit CC3000 (www.adafruit.com/products/1469) Adafruit PN532 (www.adafruit.com/products/789) Stepper Motor (not yet included and not relevant for the problem)</p> <p>Sorry about not using hyperlinks, but the forum says I'm not allowed to post more than 2 links at once...</p> <p>Now on to the Problem: When we're using the shields separately (meaning connecting the arduino to either of the shields by itself), the shields work fine. The cc3000 gets a connection and the PN532 reads cards. Now we've tried to stack them together for live use. That's where the trouble starts...</p> <p>If I connect the PN532 5V to the arduino 3.3V and CC3000 VIN to 5V arduino, the shields both do what they should with separate example sketches ('readMifare' and 'buildTest').</p> <p>If I put my sketch in (which combines both of those sketches and some other stuff) and comment out the initialization of either the PN532 or the CC3000, the other shield works.</p> <p>Now if I try to use both, the CC3000 and the PN532, the CC3000 tries to initialize, but falls into a loop of restarts. I've read that that (possibly) is because of the lack of power supply. (I've connected a 12V wall-wart by the way and it didn't work with that either)</p> <p>The manual says, that the CC3000 needs 5V, but can work on 3.3V too (though I didn't find a source to explain how) and the PN532 needs 3.3V to run.</p> <p>Am I doing something wrong, or is it a problem with the arduino? If I'm doing it wrong, how am I connecting these parts correctly?</p> <p>I really am not that good with electronics and didn't find a sollution to my problem nearly a days worth of searching the net. For your understanding I'll post the script I'm using and some pictures of the board setup. Thanks in advance for ANY help you guys can give me (even if it's just good guide for problems like mine) ^^</p> <p>Regards, Patrick</p> <p>The part of the sketch that initializes the components (and also where the CC3000 gets stuck...) Code:</p> <pre><code>//WLAN-Libraries #include &lt;Adafruit_CC3000.h&gt; #include &lt;ccspi.h&gt; #include &lt;SPI.h&gt; #include &lt;string.h&gt; #include "utility/debug.h" //NFC-Libraries #include &lt;Wire.h&gt; #include &lt;Adafruit_NFCShield_I2C.h&gt; //Motor-Libraries #include &lt;Stepper.h&gt; //NFC-shield PINs #define IRQ (2) #define RESET (4) // Not connected by default on the NFC Shield Adafruit_NFCShield_I2C nfc(IRQ, RESET); </code></pre> <p>//Motor-settings</p> <pre><code>const int stepsPerRevolution = 180; // change this to fit the number of steps per revolution // for your motor Stepper Motor(stepsPerRevolution, 6,7,8,9); // initialize the stepper library on pins 8 through 11: </code></pre> <p>//Wifi-settings</p> <pre><code>// These are the interrupt and control pins #define ADAFRUIT_CC3000_IRQ 3 // MUST be an interrupt pin! // These can be any two pins #define ADAFRUIT_CC3000_VBAT 5 #define ADAFRUIT_CC3000_CS 10 // Use hardware SPI for the remaining pins // On an UNO, SCK = 13, MISO = 12, and MOSI = 11 Adafruit_CC3000 cc3000 = Adafruit_CC3000(ADAFRUIT_CC3000_CS, ADAFRUIT_CC3000_IRQ, ADAFRUIT_CC3000_VBAT, SPI_CLOCK_DIV2); // you can change this clock speed #define WLAN_SSID "mySSID" // changed for your convenience #define WLAN_PASS "myPassphrase" // Security can be WLAN_SEC_UNSEC, WLAN_SEC_WEP, WLAN_SEC_WPA or WLAN_SEC_WPA2 #define WLAN_SECURITY WLAN_SEC_WPA2 Adafruit_CC3000_Client www; //defines how we will refer to the cc3000 connection object // What page to grab! #define WEBSITE "10.2.10.170" //NOTE: CC3000 doesn't seem to like the default localhost address of 127.0.0.1 - need to enter actual IP #define WEBPAGE "/index.php" //this is the counter that will be used for uploading data long pollCounter = 1; //used for storing data for upload //set it to the data type that suits your data int NFC_ID, Session_ID, UID_final; //used for commands received from base station int command_open, command_close; boolean pollFlag = false; //tells the sketch whether to poll or not //declare a variable to hold a numeric IP address //can be overridden below if you use lookup uint32_t ip = (192L &lt;&lt; 24) | (168L&lt;&lt;16) | (1&lt;&lt;8) | 13; /**************************************************************************/ /*! @brief Initialization of the modules (Motor, Wifi, NFC-Reader) */ /**************************************************************************/ void setup(void) { </code></pre> <p>//Set up the Motor for the lock</p> <pre><code> // set the Motor speed at 60 rpm: Motor.setSpeed(60); </code></pre> <p>//Set up the Wifi module</p> <pre><code> Serial.begin(115200); Serial.println(F("Hello, CC3000!\n")); Serial.print("Free RAM: "); Serial.println(getFreeRam(), DEC); /* Initialize the Wifi module */ Serial.println(F("\nInitializing...")); //&lt;======== Here the CC3000 gets stuck in a loop if (!cc3000.begin()) // when both shields are connected { Serial.println(F("Couldn't begin()! Check your wiring?")); while(1); } cc3000.connectToAP(WLAN_SSID, WLAN_PASS, WLAN_SECURITY); Serial.println(F("Connected!")); /* Wait for DHCP to complete */ Serial.println(F("Request DHCP")); while (!cc3000.checkDHCP()) { delay(100); // ToDo: Insert a DHCP timeout! } /* Display the IP address DNS, Gateway, etc. */ while (! displayConnectionDetails()) { delay(1000); } cc3000.printIPdotsRev(ip); </code></pre> <p>//Set up the NFC module if (pollFlag == true) { nfc.begin();</p> <pre><code> uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { Serial.print("Didn't find PN53x board"); while (1); // halt } // Got ok data, print it out! Serial.print("Found chip PN5"); Serial.println((versiondata&gt;&gt;24) &amp; 0xFF, HEX); Serial.print("Firmware ver. "); Serial.print((versiondata&gt;&gt;16) &amp; 0xFF, DEC); Serial.print('.'); Serial.println((versiondata&gt;&gt;8) &amp; 0xFF, DEC); // configure board to read RFID tags nfc.SAMConfig(); Serial.println("Waiting for an ISO14443A Card ..."); } else { Serial.println("Failed to initialize NFC-Reader... Sorry..."); } } </code></pre> <p>Hope I'm not messing up the image-uploads... (I kept the wiring-colors where I coul for you to see the connections easily)</p> <p>The boards connected via cables (both separately working) www.directupload.net/file/d/3740/j3y3tx38_jpg.htm</p> <p>The boards put together www.directupload.net/file/d/3740/yb9q6qla_jpg.htm</p> <p>The boards connected together with the Wifi in the picture. (You can't see the LED on the CC3000 light up, but I swear it does smiley-wink) www.directupload.net/file/d/3740/uorksjrj_jpg.htm</p> <p><strong>Post # 2</strong></p> <p>Ok, I got myself a multimeter today to measure if it is really a problem with the power supply.</p> <p>With the NFC-Reader running I measured 4.85V on the 5V-Pin and 3.32V on the 3.3V-Pin. This means, that the CC3000 should have enough Power to run.</p> <p>So I'm now looking for a possible address collision in the libraries (specifically I2C- and SPI-collisions). As I'm still new to this, help is really appreciated.</p> <p><strong>Edit #2:</strong></p> <p>Morning everyone! What I've found out since yesterday is, that the PN532 uses I2C while the CC3000 uses SPI to communicate. When I looked through the libraries I found out that the PN532 includes Wire.h which gets its address at "nfc.begin();"</p> <p>In the begin-function in Wire.cpp there is an address transmitted to the function, but I can't find it's source. Is it possible that that address collides with the one the CC3000 uses?</p> <p>When I uploaded an I2C-Scanner to the UNO, it said that the only device fount is the PN532 on address '0x24'.</p> <p>I don't really know what to do with that info though, since there are more libraries being included (like which in term calls others) and I cant even find these on the Mac I'm working on at the moment...</p> <p><strong>Edit #3:</strong></p> <p>The problem has been solved in the arduino.cc forum. The SRAM was overflowing, but applying the F()-macro to the strings being printed solved the issue! (Just in case someone has similar issues ^^)</p>
<p>The problem has been solved in the arduino.cc forum. The SRAM was overflowing, but applying the F()-macro to the strings being printed solved the issue! (Just in case someone has similar issues ^^)</p>
4138
|arduino-uno|gsm|
Not able to send SMS to Mobile using GSM900A and Arduino Uno
2014-09-11T10:24:13.073
<p>I tried the code shown below (<a href="http://letsplaywitharduino.blogspot.in/p/gsm-modem-with-arduino-uno.html" rel="nofollow">found here</a>)</p> <pre><code>void setup() { Serial.begin(9600); //Baud rate of the GSM/GPRS Module Serial.print("\r"); delay(1000); Serial.print("AT+CMGF=1\r"); delay(1000); Serial.print("AT+CMGS=\"+919449835011\"\r"); //Number to which you want to send the sms delay(1000); Serial.print("Test SMS -Jay\r"); //The text of the message to be sent delay(1000); Serial.write(0x1A); delay(1000); } void loop() { } </code></pre> <p>I interfaced my GSM SIM900A module to the Arduino UNO (connections - GSM Tx to Arduino Rx, GSM Rx to Arduino Tx, GSM provided with supply (12V) using external adapter, GSM gnd to Arduino gnd).</p> <p>I dumped the code into Arduino and then opened the Arduino IDE serial terminal. In the serial terminal, I get <code>AT+CMGF=1AT+CMGS="+919449835011"Test SMS -Jay\r</code> being displayed and I am not receiving any sms to my phone. I am not sure if its a problem with the code or connections.</p>
<p>looks like you should be using <code>Serial.begin(2400);</code></p> <p>also, I'm assuming your sms phone number isn't actually 919449835011 and that that's not actually the number you used in your code</p>
4139
|arduino-uno|pwm|
Sine Wave Inverter
2014-09-11T10:59:58.317
<p>I am working on building a pure sine wave inverter using an Arduino Uno to output two PWM signals for the top and bottom half of the wave. Currently I am outputting pre-calculated values with an interrupt as PWM. This seems to be working but I was wondering if anyone had any feedback on my design, and whether there is a better way to go about doing this. I will also need to incorporate feedback into this to vary the max PWM duty cycle, and I am worried the ATMEGA will not be able to keep up do this fast enough. </p> <p>Please let me know if you want any more details, thanks in advance!</p> <p>Olls</p> <p>The <a href="https://docs.google.com/spreadsheets/d/1iyveHnOxIzqg907T6pu4znsJE-6tg40juMihDvU8Tbg/edit?usp=sharing" rel="nofollow">spreadsheet</a> I'm using to calculate the values.</p> <pre><code>#include "TimerOne.h" int duty_cycle; int x = 0; // sin_table is made up of sin(0-400) values multiplied by PWM_PERIOD // https://docs.google.com/spreadsheets/d/1iyveHnOxIzqg907T6pu4znsJE-6tg40juMihDvU8Tbg/edit?usp=sharing uint8_t _sin[] = { // Calculated for 50Hz at 200 pulses per half wave. 0,0,0,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,9,10,10,10,11,11,12,12,12,13,13,13,14,14,14,15,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,19,19,20,20,20,20,21,21,21,21,21,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,20,20,20,20,19,19,19,19,19,18,18,18,17,17,17,17,16,16,16,15,15,15,15,14,14,14,13,13,13,12,12,12,11,11,10,10,10,9,9,9,8,8,8,7,7,6,6,6,5,5,5,4,4,3,3,3,2,2,1,1,1,0,0,0,0,0,1,1,1,2,2,3,3,3,4,4,5,5,5,6,6,6,7,7,8,8,8,9,9,9,10,10,10,11,11,12,12,12,13,13,13,14,14,14,15,15,15,15,16,16,16,17,17,17,17,18,18,18,19,19,19,19,19,20,20,20,20,21,21,21,21,21,22,22,22,22,22,22,23,23,23,23,23,23,23,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,25,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,24,23,23,23,23,23,23,23,22,22,22,22,22,22,21,21,21,21,21,20,20,20,20,19,19,19,19,19,18,18,18,17,17,17,17,16,16,16,15,15,15,15,14,14,14,13,13,13,12,12,12,11,11,10,10,10,9,9,9,8,8,8,7,7,6,6,6,5,5,5,4,4,3,3,3,2,2,1,1,1,0,0,0 }; void setup() { // Pin mode, and set low. DDRD = DDRD | B00011000; PORTD = B00000000; Timer1.initialize(47); Timer1.attachInterrupt(pwm); } void pwm() { if (PIND &amp; B00000100) { // Inhibit switch // Lower half or upper half of wave, start PWM pulse if (x &gt; 200) { PORTD = B00010000; } else { PORTD = B00001000; } duty_cycle = _sin[x]; if (duty_cycle &gt; 3) { delayMicroseconds(duty_cycle); } PORTD = B00000000; x++; if (x &gt; 400) { x = 0; } } } void loop() {} </code></pre>
<p><em>Comment by olls converted to an answer</em>:</p> <p>I did get it working. The schematic isn't mine to share unfortunately, but it consisted of some transistors to shift the PWM up to 20v, which then went into an inverter circuit (not made by me, quite complex) which merged the two PWM signals together into a AC signal. Then there was a transformer and RC filter to smooth out and amplify the PWM. Sorry I can't be more help, but it was a while ago, and I didn't make all of it.</p>
4146
|serial|arduino-duemilanove|
Receiving and sending on the Arduino Duemilanove with an MAX3232 chip
2014-09-12T01:04:52.837
<p>I have a <a href="http://datasheets.maximintegrated.com/en/ds/MAX3222-MAX3241.pdf" rel="nofollow noreferrer">max3232</a> hooked up to the RX and TX pins of the Arduino Due. I'm trying to write a simple program to relay messages received from USB and output as RS232 through the chip. Here is my code:</p> <pre><code>char readbyte; void setup(){ Serial.begin(115200); } void loop(){ while (Serial.available() &gt; 0 ) { readbyte = Serial.read(); Serial.print(readbyte); } } </code></pre> <p>This program works when I don't have the MAX2323 hooked up (e.g. I send "123" and get "123" echoed back), but when I hook up the MAX2323, the Arduino isn't sending back. I've written another test program that sends random data and it seems to work fine. I'm at a lost at what is wrong with my simple program, can anyone help?</p> <p>Here is the schematic: <img src="https://i.stack.imgur.com/PY27U.png" alt="Circuit"></p>
<p>With your final comment, the behavior is understandable. The schematic will help </p> <p><img src="https://i.stack.imgur.com/S0xch.jpg" alt="enter image description here"></p> <p>You have wired two devices to the single UART on the processor.</p> <p>The TX pin (output) on the ATMEGA8 is connected to the input pins of both your MAX2323 and the FT232 chip on the Ardiuno. That works okay because 1 output pin can easily drive 2 inputs.</p> <p>The RX pin (input) on the ATMEGA8 is connected to the <strong>output</strong> pins of both your MAX and FT. The two transceivers are both attempting to drive the single input -- this is a bad thing. When one output pin tries to drive logic 1 and the other is driving logic 0, one of the devices will win and one will lose. Whether any of the devices is physically damaged depends on whether one device can source enough current to damage the other.</p> <p>But you haven't broken anything because of the wise series resistors, R8, you see on the schematic. The series resistor limits the current to 5 mA even if you short the RX pin to ground. The series resistor is what creates the unequal behavior:</p> <ul> <li><p>The ability of the FT chip to source current and drive a logic 1 is limited. So when the FT chip tries to drive logic 1 and the MAX is output 0, a 5 V drop will be seen across R8. The RX pin is on the MAX side, so the Arduino sees 0.</p></li> <li><p>The MAX chip is not limited. When it drives 1 and the FT is at 0 there is still 5 V across the resistor. But the RX pin is on the MAX side and sees the 1's (data).</p></li> </ul> <p>If you want the Arduino to receive from two devices you need to "add" the data correctly with a circuit. There are several ways, here are two:</p> <ul> <li><p>Use an OR gate to combine the data. The serial bus is idle at zero. When data comes across it is a sequence of 1 bits. Remove R8 and connect the M8RXD side to the OR input. Connect the MAX to the other OR input. Connect the OR output to the RX input.</p></li> <li><p>Cheap and small is "wire or'd". Remove R8 and replace with small diode, pointing at RX. Connect small pull down resistor (10k) from RX to ground. Connect external MAX with diode pointing at RX. In this arrangement, either chip will source current towards the RX ping to drive a logic 1, but neither chip can sink current to drive the logic 0. Only the pull down resistor creates the 0.</p></li> </ul>
4149
|motor|
Powering motors
2014-09-12T09:24:42.913
<p>I'm trying to control two DC 3-6V motors with a HG7881 driver and an Arduino Nano, but the Nano is always resetting if it has the same power supply than the driver. I'm connecting the batteries to HG7881 Vcc and Nano Vin (and also same ground).</p> <p>If I power the Nano with USB and the driver with batteries then it works but that's not a good solution for me.</p> <p>So the question is, is there any way to make both driver and Nano work with the same power supply?</p> <p>Thanks!</p>
<p>If the reset is due to transients when the motor starts or stops, you can get by with isolating Nano power via a diode and capacitor. (See below.) If, on the other hand, the motor is dragging the supply voltage so low the Nano won't run, you may need to add a separate battery for the Nano or upgrade your batteries, as mentioned in Duncan's answer.</p> <p>To isolate Nano power from motor power, open the connection between battery V+ and Nano Vcc; connect the anode of a diode to V+; connect the cathode to the positive lead of a capacitor of a few hundred microfarads and to Nano Vcc. Connect the capacitor's negative lead to ground. If simple diode+capacitor filtering isn't enough, you probably should attach an oscilloscope and find out more exactly what's happening. Further options include series resistors, wound inductors, and ferrite beads, as seen in some <a href="https://www.google.com/search?q=power+supply+filtering&amp;biw=1140&amp;bih=640&amp;tbm=isch&amp;tbo=u&amp;source=univ&amp;sa=X&amp;ei=xxMTVM-0K4nGiwLW34GoBQ&amp;sqi=2&amp;ved=0CDQQsAQ" rel="nofollow">Google images</a> for power supply filtering.</p>
4152
|arduino-uno|led|ir|
How to power IR LEDs with arduino?
2014-09-12T14:24:21.903
<p>I need a circuit or something to power up IR leds as arduino only give 5v and IR leds needs 1.2V. Is there a way to make one arduino pin a power supply of 1.2 V code or something ?</p>
<p>Typically, rational control of an LED sets the amount of current that goes through the LED, rather than setting its voltage. You could add series resistors so that when the desired current is flowing through the LED, about 1.2 volts is across the LED and the rest (say 3.6–3.8V) is across the resistor. (See <a href="https://www.google.com/search?q=power+supply+filtering&amp;biw=1140&amp;bih=640&amp;tbm=isch&amp;tbo=u&amp;source=univ&amp;sa=X&amp;ei=xxMTVM-0K4nGiwLW34GoBQ&amp;sqi=2&amp;ved=0CDQQsAQ#tbm=isch&amp;q=Arduino+LED+series+resistor" rel="nofollow noreferrer">Google images</a> for typical circuits, and see various <a href="https://www.google.com/?gws_rd=ssl#q=arduino+led+resistor+calculator" rel="nofollow noreferrer">LED resistor</a> calculator, eg the <a href="http://www.hacktronics.com/Tools/led-resistor-calculator.html" rel="nofollow noreferrer">LED resistor calculator</a> at hacktronics.com.) It also is possible to use PWM to control LED brightness.</p> <p>Note that if you have 3.6V across a resistor and 1.2V across an LED, you are wasting 3/4 of the power expended. When LEDs are low voltage (ie, like 1.2V for your LEDs, vs. 1.6 for typical red or orange LEDs, vs 3+ V for white or blue) you can put several of them in series. For example, put three of your IR LEDs in series, and calculate R so that 1.2 V drops across a resistor and 3.6 across the series of LEDs. Also try four LEDs in series, and calculate R to drop 0.1 to 0.3 V.</p> <p><strong><em>Edit 1:</em></strong> Ignacio Vazquez-Abrams says, a little obscurely, “Getting warmer. But this is a IR LED” and also “Pull up the datasheet for a IR LED. Read it carefully. The AVR can't handle one of the numbers”, perhaps in reference to IR LED current requirements.</p> <p>Typical 5mm IR LEDs can handle several times more current than typical 5mm visible light LEDs. For example, a typical green LED might be rated 30 mA max sustained current and 20 mA recommended, while a typical IR LED might be rated 100 mA max and 50 mA recommended. Also note that 50 mA is 10 mA more than the 40 mA that most Arduino pins list as absolute max. A sustained current of 40 mA or more in or out of an Arduino i/o pin may damage the processor. If you want to drive a high-current IR LED, use an external driver (eg a transistor). See eg the answer to <a href="https://electronics.stackexchange.com/q/55823">How can I efficiently drive an LED?</a> in Electronics SE, which shows dropping resistor calculations, constant current sources, etc. Also see links given in <a href="https://electronics.stackexchange.com/a/56133/7479">JYelton's answer</a> to <a href="https://electronics.stackexchange.com/q/56131">Infra Red LEDs - Voltage Advice</a>.</p> <p>Treesrule14 points out “IR leds ... don't emit in the visible light range”, which is true; they emit infrared radiation, or heat. Note, using an IR LED in a remote control usually is incompatible with controlling its average brightness with PWM; the pulses used in PWM would conflict with the pulse train in typical <a href="http://en.wikipedia.org/wiki/RC-5" rel="nofollow noreferrer">36, 38, or 40 KHz IR control protocols</a>.</p>
4161
|virtualwire|
Using VirtualWire and RCSwitch in same PRoject
2014-09-13T00:06:54.973
<p>I have the problem, that I want some Arduinos communicate in a wireless mesh network using the VirtualWire library but also be able to receive (and send) codes for my rc sockets using the RCSwitch library.</p> <p>I have some Arduinos using VirtualWire and some devices using the hx2262 IC for RC-Decoding.</p> <p>I want to send and receive messages between the Arduinos (each message must be at least 10 bytes long) and also be able to send and receive messages from the hx2262 RC power sockets.</p> <p>My idea would be to use VirtualWire for inter Arduino communication and RCSwitch for the power sockets. Both work fine as long as I do not put both libraries on the same controller.</p> <p>Does anyone have an idea to solve that problem?</p>
<p>I finally found a solution: Just use both libraries. The problem I head: VirtualWire uses Pin numbering, RCSwitch uses Interrupt numbering. That was the reason, why it did not work.</p>
4169
|arduino-ide|compile|
Arduino IDE #ifdef
2014-09-13T12:38:19.667
<p>I use my Arduino IDE to either upload my sketch to a Arduino or ATTiny or ATmega328. As you know each device can have a different pinout. Does the Arduino compiler support <code>ifdef</code>, depending on the board I am connected to?</p> <p>For example</p> <pre><code>#ifdef Attiny85 a=0; b=1; c=2; #else // arduino a=9; b=10; c=11; #endif </code></pre>
<p>Yes. Here is the syntax:</p> <pre><code>#if defined(__AVR_ATmega328P__) || defined(__AVR_ATmega168__) //Code here #endif </code></pre> <p>You can also do something like this for the Mega:</p> <pre><code>#elif defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) //Code here #endif </code></pre> <p>Assuming the implementation for the ATtiny is correct, your code should be like this:</p> <pre><code>#if defined (__AVR_ATtiny85__) a=0; b=1; c=2; #else //Arduino a=9; b=10; c=11 #endif </code></pre>
4171
|arduino-ide|
What is the best way to get started?
2014-09-13T12:48:29.450
<p>I am interested in learning about arduino. What is the quickest and cheapest way to find out if this is something I can and want to do?</p>
<p>The starter kit would get you everything you need to do a whole set of projects. Alternatively there is a PDF on the Arduino site with a whole set of projects in it. You could go through it, put together an inventory of the parts you need, and order those parts from an electronics supplier like Mouser, DigiKey, Jameco, etc, and save some money. </p> <p>The starter kit is probably worth the extra money, though, because it has everything you need, plus an organized set of lessons that teach you the various skills you'll need.</p>
4175
|arduino-uno|serial|c|
Serial data to arduino problem
2014-09-13T15:29:50.823
<p><img src="https://i.stack.imgur.com/2LYkt.jpg" alt="enter image description here"></p> <p>I cant understand what is going on here , I was trying to find way to send through Serial a number for example 12 and then extract from it number 1 and 2 and store them in two different variables , but suddenly i was unable to make a simple division !!</p>
<p>Anonymous Penguin's code works for me on an Uno after fixing a couple of typos. It is often best to make sure that both the numerator and the denominator are floats to ensure that the result is also treated as a float. So please try the following where the 10 is replaced with a 10.0:</p> <pre><code>while(Serial.available()) { float number = (float)(Serial.read() - 48) / 10.0; Serial.println(number, 4); } </code></pre> <p>If you want to deal with each digit separately an array might be best but that will depend on your end goal. </p> <pre><code>const int MAX_LENGTH = 10; char buffer[MAX_LENGTH]; char lineFeed = 10; int length = Serial.readBytesUntil(lineFeed, buffer, MAX_LENGTH); int i = 0; while( i &lt; length ) { //do what ever needs to be done to each character here, I'll just convert them to an int and print them as an example Serial.println( buffer[i]-48 ); i++; } </code></pre>
4179
|pwm|voltage-level|system-design|
Using Arduino to control a 12v car light system?
2014-09-13T18:11:34.067
<p>I am new, but I am wondering what options I may have to control a 12v line that connects to a light with Arduino i/o.</p> <p>Given the voltage limitations of an arduino, I am thinking using some kind of 5v relay to switch a 12v line on/off ( if it exists )</p> <p>Though I was also hoping to be able to utilize the PWM pins in conjunction with a 12v line to 'reduce' it to 6v without using a resistor. (though I would have no idea how to go about this, or if it is even possible).</p> <p>Any help appreciated.</p>
<p>Yes, you can use a relay. However, you'll almost certainly need to drive the relay with a transistor because the current requirements of the relay will be too high for an Arduino pin.</p> <p>Better to use a logic MOSFET N-channel transistor as an electronic switch. You connect the Arduino's output pin to the gate of the transistor. You connect the + terminal of your 12 volt source to one end of the light, and connect the other wire from the light to the drain on the MOSFET. You then connect the source pin on the MOSFET to ground, and tie the ground of your Arduino to the 12 volt negative terminal.</p> <p>In this setup, the MOSFET acts as a switch. When you switch the output pin of your Arduino to HIGH, the MOSFET turns on, providing a very low resistance path to ground. Current flows from the +12 volt supply, through the light, through the MOSFET, and to ground.</p> <p>When the Arduino's output pin is low, the MOSFET acts as an open switch. There's no path to ground so the light is not lit.</p> <p>You can't use PWM to lower 12 volts to 6 volts without some additional circuitry. PWM rapidly pulses the output from all the way on to all the way off. If you feed a PWM pin into a transistor, it can be used to create a higher voltage and/or current pulsed signal. However, pulsed DC is not the same thing as a lower DC voltage. You'd need to feed the pulsed 12 volts through a reservoir capacitor, perhaps 2 capacitors (and possibly a choke) in order to average out the pulses into a lower DC voltage. That simple approach would work ok for powering a 6 volt incandescent light, but would not be good enough to power a solid state component because the output would not be even enough. It would have a fair amount of ripple and high frequency noise in it.</p>
4180
|arduino-ide|c|build|
How does Arduino IDE for mac deal with functions in other files
2014-09-13T18:27:47.800
<p>I'm a longtime C programmer. I've also done a little C++, a little Java, and a LOT of Objective-C, but am fairly new to the Arduino platform and it's IDE. </p> <p>So far all my sketches have had a single source file.</p> <p>I see how you copy libraries into the libraries sub-folder of your Arduino source folder, either from the Mac finder or from the IDE.</p> <p>I'm trying to understand somebody else's project (The "Camera Axe" device for high speed photography.) in that project there is a folder for the entire sketch, "cameraAxe". In that folder there's a file called "cameraAxe.ino", which follows the usual convention that the sketch's main source file needs to be inside a folder with the same name.</p> <p>However, for this project there are 17 other source ".ino" files. Looking at the main "cameraAxe.ino" file, it only #includes 2 files, "EEPROM.h" and "DogmCA.h", both using the convention of enclosing the filename in angle brackets so the compiler knows to look in it's libraries directory. That makes perfect sense to me, and works like any other C compiler I've ever seen.</p> <p>What I <strong>DON'T</strong> understand is how the compiler knows where to find the code for the many functions that are defined in other files in the same folder. There a function projectileMenu() which handles the menu for configuring a projectile sensor. That function is defined in the file menu01_projectile.ino, but it doesn't have a header, and there's no #include anywhere.</p> <p>Does the compiler treat all the ".ino" files in your sketch folder as part of your source and compile them all together and as if they are one large file? I see tabs in the IDE for each of the files, which suggests that it does. </p> <p>What if there are dependencies among the files? What defines the order in which they are compiled? Or is it a 2 pass compiler where the order of function definitions doesn't matter? </p> <p>::wanders off, muttering in confusion::</p>
<p>arduino has its own little .ino preprocessor that generates forward declarations (like in a header file) for all function in the project's .ino files. Most of the time this just makes things less confusing for new users.</p> <p>I'm not familiar with the entire process, but the effect is that any function in any .ino is known to all other .ino code. </p> <p>Anything with .h or .cpp in a library or in the project file is treated as normal c++ code and not subject to arduino's manipulations. It will need "#include"s. </p> <p>If you are interested, there is a hack to make arduino not mess with a function in a .ino file: add an empty "throw()" like this:</p> <pre><code>void foo() throw() { } </code></pre>
4183
|power|attiny|analogread|
Attiny84A and IR Sensor
2014-09-13T22:38:24.817
<p>I have a <a href="http://rads.stackoverflow.com/amzn/click/B00IMOSEJA" rel="nofollow noreferrer">GP2Y0A21YK0F Sharp IR Analog Distance Sensor 10-80cm + Cable, Arduino Compatible</a> and its is connected to my Arduino. All works well and I can read the analog data with the following code:</p> <pre><code>#include &lt;SoftwareSerial.h&gt; #define RX 2 // receive #define TX 3 // transmit #define SEN1 4 SoftwareSerial mySerial = SoftwareSerial(RX, TX); void setup() { mySerial.begin(4800); mySerial.println("Hello, world?"); } void loop() // run over and over { int reading = analogRead(SEN1); mySerial.println(reading); delay(500); } </code></pre> <p><img src="https://i.stack.imgur.com/NWzZQ.jpg" alt="GP2Y0A21YK0F"></p> <p>When the code runs on the Attiny with the <code>GP2Y0A21YK0F</code> IR Sensor connected, the Attiny84 resets over and over. The Attiny84 and <code>GP2Y0A21YK0F</code> are part of the same circuit e.g. Attiny and <code>GP2Y0A21YK0F</code> share the power and ground rail.</p> <p>When I disconnect the <code>GP2Y0A21YK0F</code>, the program runs and stops resetting. I was able to reproduce this on an Attiny85 and ATMega328.</p> <p>The strange thing is, it works fine on the Arduino. Any help is greatly appreciated.</p>
<p>It sounds like the microcontroller is browning out.</p> <p>IR sensors are notorious for taking a lot of power when they operate; often they will tax a small power supply and cause the voltage to droop low enough to reset/brownout the microcontroller.</p> <p>Try either putting a fairly beefy capacitor on the power bus, or getting a larger power supply.</p> <p>Hope this helps!</p> <p>(<strong>edit</strong>: I reverted another user's edit to this answer; "droop" is in fact the correct term for what is going on: <a href="http://en.wikipedia.org/wiki/Voltage_droop" rel="nofollow">http://en.wikipedia.org/wiki/Voltage_droop</a>)</p>
4188
|serial|arduino-galileo|
How to serial connect arduino galileo to alarm system
2014-09-14T22:01:20.343
<p>i'm a little new in this. I have an alarm system panel which has TX,RX wires with 12V output/input.</p> <p>how can i read the output with arduino and control it with serial communication?</p>
<p>First of all, you'll need to make sure this is UART and not another protocol. Don't worry, if it's not UART the worst thing that could happen is jumbled data.</p> <p>After that, you will need a 12v to 5v (or 3.3v) logic level shifter. When you have that you'll need to connect the Arduino to the system through the level shifter to pins 0/1.</p> <p>You won't know what you'll receive or can send without looking at the serial output and doing a little tinkering. You don't even know what the serial port does. It could just be for setting up the system. </p>
4196
|voltage-level|
Power supply voltage confusion
2014-09-15T15:18:12.963
<p>I just ran into this article: <a href="http://playground.arduino.cc/Learning/WhatAdapter">Arduino: What adapter?</a>.</p> <p>It says that the external power supply should be 9-12V. That really surprises me, since my Arduino Uno can also be powered via USB, which is 5V.</p> <p>Later he talks about a 9V pin. But I can only see a 5V and 3.3V pin on mine. Is he talking about a different version of Arduino?</p> <p>Judging from the picture, his Arduino looks slightly different from my Arduino Uno R3, but I can't tell which version is on the picture.</p>
<p>And the third part of your question: It is possible to bypass the voltage regulator and feed REGULATED 5 volts directly to the 5V pin. </p> <p>That's how the Arduino is powered using USB. The USB power is already regulated 5V, and is fed directly to the 5V pin.</p> <p>Beware of doing this yourself however. You better be certain the 5V you're feeding in is a clean, filtered and regulated 5V. If it's not you run the risk of destroying your Arduino (and possibly anything connected to it's 5V lines.)</p>
4200
|arduino-uno|xbee|c|
Receiver xbee receiving data even if the Transmitter is not sending?
2014-09-15T22:40:19.723
<p><img src="https://i.stack.imgur.com/qIFWb.png" alt="enter image description here"><img src="https://i.stack.imgur.com/bZxmF.png" alt="enter image description here"></p> <p>TX code:</p> <pre><code>#include &lt;SoftwareSerial.h&gt; const int MAX_LENGTH = 2; char buffer[MAX_LENGTH]; char lineFeed = 2; SoftwareSerial Xbee(10, 11); void setup() { Serial.begin(9600); Xbee.begin(9600); } void loop() { int length = Serial.readBytesUntil(lineFeed, buffer, MAX_LENGTH); int i = 0; while( i &lt; length ) { Serial.print(buffer[i]-48); Xbee.print(buffer[i]-48); i++; } } </code></pre> <p>RX code:</p> <pre><code>const int MAX_LENGTH = 2; char buffer[MAX_LENGTH]; char lineFeed = 2; void setup() { Serial.begin(9600); } void loop() { int length = Serial.readBytesUntil(lineFeed, buffer, MAX_LENGTH); int i = 0; while( i &lt; length ) { Serial.print(buffer[i]-48); i++; } } </code></pre> <p>NOTE : </p> <p>1- The Rx xbee is receiving data even if am not sending and even if the TX xbee is powered off</p> <p>2- When i send data from the TX xbee id didn't get revived by the RX xbee </p> <p>I need to solve both problems.</p> <p>*** What i need exactly is to send serial data from my pc to arduino and send it wireless through xbee and then receive to the other arduino connected to my circuit </p>
<p>The reason that it is printing characters with no input is that the readBytesUntil function has a timeout. If no new characters are received for a certain amount of time, "Serail.setTimeout()" seconds, it will just continue with the code. the default timeout is 1 second.</p> <p>The reason you are not receiving what you transmit (or at least a reason) is that the RX code does not read from an xbee, but reads from regular "serial".</p> <p>I recommend you try something simple first to test the xbee's configuration, like having TX run this:</p> <pre><code>void loop(){ xbee.println("Hello"); delay(1000); } </code></pre> <p>and RX run something to echo serial like this:</p> <pre><code> void loop(){ if(xbee.available()){ Serial.print((char)xbee.read()); } } </code></pre> <p>And make sure you set up an xbee object an the receiving side first.</p>
4204
|arduino-pro-micro|
What are the current limits on an Arduino Micro?
2014-09-16T04:32:42.277
<p>Just to make sure I don't set my board on fire, is there any information out there about the maximum current per pin/pin group on an Arduino Micro? </p> <p><a href="http://arduino.cc/en/pmwiki.php?n=Main/arduinoBoardMicro" rel="nofollow">This page</a> states I can get 40mA per pin, but are there limits on group of pins?</p> <p>As stated <a href="http://forum.arduino.cc/index.php/topic,148734.0.html" rel="nofollow">here</a>, there are pin groups which should not exceed 100mA. But could not find anything about that in the ATmega32u4 datasheet, or any other Arduino Micro related websites.</p>
<p>It's in the notes in section 29.2:</p> <blockquote> <ol start="3"> <li>Although each I/O port can sink more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:<br> ATmega16U4/ATmega32U4:<br> 1.)The sum of all IOL, for ports A0-A7, G2, C4-C7 should not exceed 100 mA.<br> 2.)The sum of all IOL, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA.<br> 3.)The sum of all IOL, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA.<br> 4.)The sum of all IOL, for ports F0-F7 should not exceed 100 mA.<br> If IOL exceeds the test condition, VOL may exceed the related specification. Pins are not guaranteed to sink current greater than the listed test condition.</li> <li>Although each I/O port can source more than the test conditions (20mA at VCC = 5V, 10mA at VCC = 3V) under steady state conditions (non-transient), the following must be observed:<br> ATmega16U4/ATmega32U4:<br> 1)The sum of all IOH, for ports A0-A7, G2, C4-C7 should not exceed 100 mA.<br> 2)The sum of all IOH, for ports C0-C3, G0-G1, D0-D7 should not exceed 100 mA.<br> 3)The sum of all IOH, for ports G3-G5, B0-B7, E0-E7 should not exceed 100 mA.<br> 4)The sum of all IOH, for ports F0-F7 should not exceed 100 mA.</li> </ol> </blockquote> <p>Note that the device will likely not <em>fail</em> if these are exceeded, but the rest of the numbers in the table may no longer apply.</p>
4218
|arduino-uno|programming|
4-digit 7 Segment LED displaying numbers in the wrong order
2014-09-17T02:19:33.640
<p>I am a novice Arduino programmer and am currently having trouble with a SH5461AS 4-digit/7-segment LED when using it with an Arduino Uno. I have struggled to find an accurate datasheet/tutorial of any kind for this particular model (It is the LED without the colons in between digits 2 and 3) but I believe I have it figured out.</p> <p>I currently have it going through a HC595 shift register but when I removed the register and connected the LED directly to the board the problem remained. My code below is with the shift register; I am displaying it this way because it is simpler to view and I thought it would make it easier to debug.</p> <p>I can display a single digit at a time correctly. However, when I try to display 2+ digits at one time, they are in the incorrect order. For example, I can count 1-9 on the first digit, then 1-9 on the 2nd digit, and so on and everything displays correctly (other digits are off). But as soon as I try to display multiple digits they are in the wrong order. So if I try to display 12__ with the last 2 digits off, 21__ is displayed with the last two digits off. If I try to display <em>23</em>, <em>32</em> is displayed. If I try to display 1234, 4123 is displayed.</p> <p>I am at a loss because the code seems like it should be simple.</p> <pre><code>const int DATA = 0; const int LATCH = 1; const int CLOCK = 2; const int DIGIT_ONE = 3; const int DIGIT_TWO = 4; const int DIGIT_THREE = 5; const int DIGIT_FOUR = 6; //digits[0-9] corresponds to the patterns for numbers 0 -&gt; 9. //Add 1 to the digits[X] to turn on the dot. byte digits[] = {B11111100, B00011000, B01101110, B00111110, B10011010, B10110110, B11110010, B00011100, B11111110, B10111110}; void setup() { pinMode(DATA, OUTPUT); pinMode(CLOCK, OUTPUT); pinMode(LATCH, OUTPUT); pinMode(DIGIT_ONE, OUTPUT); pinMode(DIGIT_TWO, OUTPUT); pinMode(DIGIT_THREE, OUTPUT); pinMode(DIGIT_FOUR, OUTPUT); digitalWrite(DIGIT_ONE, HIGH); digitalWrite(DIGIT_TWO, HIGH); digitalWrite(DIGIT_THREE, HIGH); digitalWrite(DIGIT_FOUR, HIGH); } void loop() { writeDigit(DIGIT_TWO, 2); writeDigit(DIGIT_THREE, 3); } /* * Write a digit to the 4-digit 7-segment LED * - digitPin corresponding to the pin on the LED to light up the correct digit. * - number 0-9 to display on the LED */ void writeDigit(int digitPin, int number) { digitalWrite(digitPin, LOW); digitalWrite(LATCH, LOW); shiftOut(DATA, CLOCK, LSBFIRST, digits[number]); digitalWrite(LATCH, HIGH); digitalWrite(digitPin, HIGH); } </code></pre> <p>So in this instance, I am expecting <em>23</em> but <em>32</em> is displaying instead.</p> <p>I am also having trouble with some bleeding (I don't know what the correct term is) where some segments are very faintly glowing even though I am not doing it intentionally. This is a much smaller issue, however, than digits randomly in the wrong order.</p> <p>If it would help, I can try to post the circuit diagram as well.</p>
<p>I don't have enough reputation to add a comment, but the datasheet link in @jfpoilpret is dead. <a href="https://www.play-zone.ch/en/fileuploader/download/download/?d=1&amp;file=custom%2Fupload%2FFile-1356269320.pdf" rel="nofollow">This link</a> has the datasheet from the same website.</p> <p>Thanks.</p>
4223
|accelerometer|
Enable free fall detection using Arduino
2014-09-17T05:33:51.933
<p>I'm trying to get an arduino board to detect simple free fall condtions. Currently, I have a 9DOF sensor (<a href="https://learn.sparkfun.com/tutorials/lsm9ds0-hookup-guide" rel="nofollow">https://learn.sparkfun.com/tutorials/lsm9ds0-hookup-guide</a>) and am able to get the raw data from the sensor.</p> <p>However I am unsure what to do from here onwards. From what I manage to gather, there is an alternative sensor ADXL345 accelerometer that has an inbuilt free fall component. I have tried modfying the code in such a way that it will work with the sensor I am using but to no avail.</p> <p>The free fall detection does not need to be extremely accurate/precise considering there are many fall/jerk patterns. It is just for a proof of concept for a project of mine. With that in mind, any suggestions on how to proceed will be greatly appreciated (or if I should just get the ADXL345 accelerometer).</p> <p>Thank you.</p>
<p>Take the root sum squared [sqrt(acc_x^2 + acc_y^2 + acc_z^2)] of your accelerometer readings. This is your total acceleration vector. Then write a function that triggers the free fall variable when that equation is less than or equal to a certain threshold near to zero (the value itself depends on your accelerometer).</p> <p>Your gyro and magnetometer will not help as they relate to the attitude (facing direction) and rotational speed of your thing, not the linear motion. Test and play with the threshold and you will get the most accurate result possible.</p>
4235
|arduino-yun|i2c|digital|
Arduino Yun - not enough i2c & interrupt pins?
2014-09-17T22:49:53.910
<p>I'm trying to build a small personal weather station. The rain sensor, and wind speed sensor use interrupts. The barometric sensor uses i2c SDA and SCL. </p> <p><a href="http://arduino.cc/en/pmwiki.php?n=Main/arduinoBoardYun" rel="nofollow">Reading the Arduino Yun manual</a>, it says there are 5 interrupt pins, but 2 of them are SCL/SDA (pins D2 and D3), and 2 of them are serial comms between Linio and the 32U4 (pins 0 and 1). </p> <p>This leaves me with 1 interrupt pin left (pin 7). </p> <p>Is there a work around to get my 2 digital sensors AND SDA SCL pins connected?</p> <p>If I do use pins 0 and 1 (Linux serial), what do I risk? I will need to use the Bridge to relay information to the internet. </p>
<p>Any of the port B pins on the ATmega32u4 can interrupt on pin change. Unlike the external interrupts however, these pin change interrupts share the same interrupt vector. So in the interrupt routine you have to work out which one fired.</p> <p>The port B pin change interrupt is not support by the Arduino core library so you have to download a third-party library. This one seems fairly recent:</p> <p><a href="https://code.google.com/p/arduino-pinchangeint/" rel="nofollow">https://code.google.com/p/arduino-pinchangeint/</a></p> <p>Then you connect your two interrupt lines to spare Port B pins and monitor for pin changes.</p>
4251
|arduino-yun|web-server|
Webserver with Arduino Yun without SD
2014-09-19T13:41:41.977
<p>I'm trying to set up a simple web-server with Arduino Yun without an SD card, i.e via REST, if I understood it right (I'm new to some of these stuff). I want to be able to "get" data (sent by Arduino) through a jQuery script and show the user a formatted HTML page.</p> <p>Here I provide you a simplified version of my Arduino sketch:</p> <pre><code>#include &lt;Bridge.h&gt; #include &lt;YunServer.h&gt; #include &lt;YunClient.h&gt; const byte internalLED = 13; YunServer server; void setup() { pinMode(internalLED, OUTPUT); digitalWrite(internalLED, HIGH); // Turn the led on to advise about bridge begin in progress Bridge.begin(); // Let's activate the Yun Bridge... ledBlink(150); // ...bridge activation done (user sees a blink) // server.listenOnLocalhost(); // Listen for incoming connection only from localhost (no one from the external network could connect) server.begin(); // Let's acrivate the Yun server... ledBlink(150); // ...server activation done (user sees a blink) } void loop() { YunClient client = server.accept(); // Get clients coming from server if (client) // Is there a new client? { client.print(77); // Send a "77" to client (e.g. browser) client.stop(); // Close connection and free resources. ledBlink(500); } delay(50); } void ledBlink(int delayTime) { digitalWrite(internalLED, HIGH); // Turn (or keep) the LED on delay(delayTime); digitalWrite(internalLED, LOW); // Turn (or keep) the LED off delay(delayTime); } </code></pre> <p>My Arduino Yun is connected via WiFi with static IP (192.168.1.98) to the same network of my laptop, and they can ping each other. Right now, if I insert into my browser the address </p> <pre><code>http://192.168.1.98/arduino/whatever </code></pre> <p>I correctly receive a simple «77» (no quotes or \r\n)</p> <p>But I cannot "get" it when opening the page get_test.html (which is on my harddisk, not in the SD):</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt; &lt;script&gt; $.get("http://192.168.1.98/arduino/whatever", {}, function(data,status){ alert("Data: " + data + "\nStatus: " + status); }); &lt;/script&gt; &lt;/head&gt; &lt;body&gt;&lt;/body&gt; &lt;/html&gt; </code></pre> <p>This is strange to me because this html code works if I change the address inside the "get" request with <a href="https://dl.dropboxusercontent.com/u/12389503/demo_test.txt" rel="nofollow">https://dl.dropboxusercontent.com/u/12389503/demo_test.txt</a> which consists only of a «21» (no \r\n). The problem is I don't even receive the alert when the address is the IP of Arduino, but the board is receiving the request since I can see the led blinking once, as expected. I'm running out of tests, any suggestion is welcome.</p>
<p>Whenever making ajax calls from/to different hosts (as your pc and the yun) you should use <a href="http://api.jquery.com/jquery.getjson/" rel="nofollow">JSONP</a>.</p>
4266
|uploading|bluetooth|
Resurrecting a fried Arduino (Bluno) USB port
2014-09-20T15:38:17.750
<p>Slightly distractedly, I went and connected 5V to the 3.3V pin on my <a href="http://www.dfrobot.com/index.php?route=product/product&amp;product_id=1044" rel="nofollow noreferrer">DFRobot Bluno</a> (the pins are right next to each other!)</p> <p>The magic smoke leaked out of the <a href="http://www.webtronico.com/documentos/AMS1117_33V.pdf" rel="nofollow noreferrer">AMS1117</a> 3.3V regulator in a neat little puff. The sketch that was loaded on the board still runs fine, but the Bluno is no longer recognised by my Macbook Pro when I plug it into USB (I have tried different ports and different cables; they're all fine—it's the USB on the Bluno that's fried.)</p> <p>In an attempt to repair it, I've <a href="https://www.sparkfun.com/tutorials/98" rel="nofollow noreferrer">replaced the AMS1117</a> (check the third paragraph of that tutorial—ha!) with an <a href="http://www.st.com/web/en/resource/technical/document/datasheet/CD00000546.pdf" rel="nofollow noreferrer">LF33ABV</a>; this went well and I'm now getting a stable 3.3V on the 3.3V pin. Check out my handiwork:</p> <p><img src="https://i.stack.imgur.com/m0vBK.jpg" alt="Bluno with original AMS1117 SMD 3.3V regulator replaced by a through-hole LF33ABV"></p> <p>However, the Bluno still isn't being recognised by the USB ports on my Mac.</p> <p>Is there another way to upload new sketches to the Bluno? Theoretically you can do so over BTLE, but you need another Bluno to act as the "peripheral" and I don't have one to hand. I have various other Arduinos laying about if that helps.</p>
<p>Upload via ICSP. See those six pins next to the regulator you so expertly tacked on? Those are the ICSP pins. You'll need a second controller or programmer to do it.</p> <p><a href="http://arduino.cc/en/Tutorial/ArduinoISP" rel="nofollow">http://arduino.cc/en/Tutorial/ArduinoISP</a></p>
4273
|motor|system-design|potentiometer|
Use potentiometer to control motor's speed
2014-09-21T10:10:09.530
<p>Following the arduino starter kit, one of the projects uses a push button to on/off a motor.</p> <p>In the end they suggest to try to use a potentiometer to control the speed of the motor. I already did it, but I am not sure how I should use the capacitors(I placed one with the pot).</p> <p>In one of the previous examples they used 2 100uF capacitors(one for the pot. and another for a servo motor) and I was wondering if this would be the same case.</p> <p>This is my circuit: <img src="https://i.stack.imgur.com/gDyCe.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/862vQ.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/cnFAy.jpg" alt="enter image description here"></p> <p>The code:</p> <pre><code>const int POT_PIN = A0; const int MOTOR_PIN = 9; int motorSpeed = 0; int potVal = 0; void setup() { pinMode(MOTOR_PIN, OUTPUT); } void loop() { potVal = analogRead(POT_PIN); motorSpeed = map(potVal, 0, 1023, 0, 255); analogWrite(MOTOR_PIN, motorSpeed); } </code></pre> <p><em>Previous example with capacitors:</em> <img src="https://i.stack.imgur.com/PiSwG.jpg" alt="enter image description here"> <img src="https://i.stack.imgur.com/EfjKa.jpg" alt="enter image description here"></p> <p>Code:</p> <pre><code>#include &lt;Servo.h&gt; Servo myServo; int const POT_PIN = A0; int potVal; int angle; int alpha = 0.8; int rawReading; void setup() { myServo.attach(9); Serial.begin(9600); } void loop() { rawReading = analogRead(POT_PIN); potVal = alpha*potVal + (1-alpha)*rawReading; Serial.print("potVal: "); Serial.print(potVal); angle = map(potVal, 0, 1023, 0, 179); Serial.print(", angle: "); Serial.println(angle); myServo.write(angle); delay(15); } </code></pre>
<p>Do you want to use a pushbutton to control the speed of the motor?</p> <p>Then one way to go would be to increment a variable by say 10 every time the switch is pressed.</p> <p>In pseudocode:</p> <pre><code>// In the setup section: speed =0 // In the main loop: Read pushbutton if different from previous state then speed = speed + 5 if speed &gt; 255 then speed = 0 // Go back to zero if over 255 analogWrite(pin x, speed) // This sets the PWM value </code></pre> <p>If you want to have a more fancy control then you could increment speed every second by 5 while the pushbutton remains pressed, and also go back to zero speed in small decrement instead of in a single step.</p>
4278
|motor|arduino-leonardo|arduino-motor-shield|
Over voltage on Arduino and Ardumoto
2014-09-19T02:04:07.963
<p>I am using Arduino Leonardo and <a href="https://www.sparkfun.com/products/9815" rel="nofollow noreferrer">Ardumoto</a> to drive 2 12v motors running at 1.3 amps each.</p> <p>I purchased a rechargeable battery of 12V with 5AH</p> <p>I first started by plugging in the battery to the Arduino via the barrel jack. Arduino then sparks and is fried.</p> <p>I read somewhere that I wasn't supposed to hook it up to the Arduino and to hook it up to the VIN ports in the Ardumoto. I purchased a new Arduino and plugged in the Positive and negative from the battery to the ports and now the Ardumoto board fried (copper lining on board burnt off).</p> <p>I'm reading online and from what I've gathered, the Ardumoto can handle a max of 18 volts and a maximum of 2 amps per each output. I'm obviously missing something and would not like to fry my boards next time.</p> <p>Please assist?</p> <p><img src="https://i.stack.imgur.com/M1ix9.png" alt="hook up of ardumoto"></p> <p><img src="https://i.stack.imgur.com/IKzUF.jpg" alt="enter image description here"></p>
<p>From your description, everything <em>should</em> be wired correctly. It should not have failed.</p> <p>Unfortunately, testing this sort of thing with a 5 amp-hour lead-acid battery is not a great way to get started, since a battery that large can source a <em>lot</em> of current, and doing anything wrong will likely produce immediate and spectacular failure.</p> <p>Really, the only think I can think of is that you have the polarity of the output lugs/pins on the battery backwards. Buy a $5 multimeter, and check them.</p>
4280
|led|
ULN2803 and common-anode RGB strip; how am I doing it wrong?
2014-09-21T20:42:16.330
<p>I'm not super-good with my electrical foo. But I've managed to get a <a href="https://www.sparkfun.com/datasheets/IC/uln2803a.pdf" rel="nofollow">ULN2803</a> wired up to give the +12v that my RGB LED strip needs. The strip has four connectors, RGB and common +12v.</p> <p>My concern is that (I think) the Arduino is shorting out- while the Arduino processes my loop, the USB connection dies and the RX/TX LEDs light up.</p> <p>Here's how I am wiring things. I'm currently powering the Arduino through USB, so when I say "power supply" I'm referring to the +12v supply I'm using.</p> <ul> <li>power supply ground to Arduino ground, ULN2803 pin 9.</li> <li>power supply +12v to 2803 pin 10, common +12v on LED strip.</li> <li>arduino output pin 11 to 2803 pin 1</li> <li>2803 pin 18 to green LED strip</li> </ul> <p>So, that's my circuit. It works- the strip lights up. But again, I think it's wrong. How do I correct it?</p>
<p>The COM pin on the ULN2803 is for protection when driving inductive loads, which means motors, solenoid. For an LED, nothing needs connect to COM.</p> <p>The chip you are using is a low side driver. That means it connects between the low side of the load (your LED) and ground. When you drive +5 to the input pin, the transistors will conduct, connecting the output pin to ground.</p> <p>So for your LED strip make the following connections:</p> <ul> <li>Arduino output pin -> driver input, 1B = pin 1 </li> <li>driver output, 1C = pin 18 -> LED strip R G or B </li> <li>+12 -> LED strip common power</li> <li>ground -> GND = pin 9</li> </ul> <p>Without the ground connection on the driver chip, no surprise that odd things happened. There are diodes designed to protect the input and output pins (<a href="http://www.ti.com/lit/ds/symlink/uln2803a.pdf" rel="nofollow">see chip data sheet</a>). Without the ground connection to the driver chip, the input protection diode might have been conducting back to the microcontroller output pin.</p>
4283
|sensors|
Sensing busy-ness of a restaurant?
2014-09-22T00:53:17.937
<p>I'm planning on an Arduino project for a restaurant I work at that would require determining how busy it is at any point in time, but I'm not sure how I would go about procuring this information.</p> <p>I don't have access to any of their IT systems or I would have simply pulled the data from their till systems.</p> <p>I was thinking perhaps measuring the ambient sound of the restaurant as it gets quite loud during peak time but that could be thrown off when the music volume is adjusted.</p>
<p>There are a few ways to go about it but my initial thoughts would be to detect people entering (and exciting) the front door and simply keep a running total.</p> <p>Motion detector <a href="http://www.adafruit.com/products/189" rel="nofollow">http://www.adafruit.com/products/189</a></p> <p>IR beam detectors <a href="http://arduino-info.wikispaces.com/InfraredBeamPair" rel="nofollow">http://arduino-info.wikispaces.com/InfraredBeamPair</a></p>
4284
|motor|pwm|
Use Arduino's PWM to control motor direction?
2014-09-22T05:10:39.913
<p>I'm looking for a way to allow Arduino to control a motor using PWM.</p> <p>So far what I have gathered is that using Arduino's PWM sets the digital value of 255 to 5v and 0 to 0v.</p> <p>However what I am looking to do is to set the motors to stop at 2.5v, move forward as it approaches 5v and move backwards as it approaches 0v.</p> <p>Any suggestion on how I would go about accomplishing this will be highly appreciated.</p>
<p>continuous rotation servo demonstrates a different approach of using PWM.</p> <p>A continuous rotation servo is a standard servo modified in 2 ways. First the "position feedback" in the servo is disconnected and set to always read as if the servo was in the center position. Second the "stop" which physically prevents the motor from turning 360 degrees is removed.</p> <p>Then if you set the servo to 0 degrees it rotates fast in one direction if you set it 180 degrees it move in the opposite direction.</p> <p>More information:</p> <ul> <li><a href="http://www.instructables.com/id/How-to-modify-a-servo-motor-for-continuous-rotatio/" rel="nofollow noreferrer">http://www.instructables.com/id/How-to-modify-a-servo-motor-for-continuous-rotatio/</a></li> <li><a href="https://learn.adafruit.com/modifying-servos-for-continuous-rotation" rel="nofollow noreferrer">https://learn.adafruit.com/modifying-servos-for-continuous-rotation</a></li> </ul>
4296
|power|arduino-pro-mini|mosfet|
Driving power MOSFET from 3.3v or lower Arduino Pro Mini
2014-09-22T20:47:28.297
<p>I want to control a low voltage (hobby class) motor with a 8Mhz/3.3v Arduino Pro Micro. I'd like to power both from 2 alkaline cells. The motor draws approximately 1 A @ 3V with new batteries. I would be doing PWM of a couple of channels at the normal Arduino rates.</p> <p>My thought is to connect the batteries to the Vcc pin (not Vraw) and run the Arduino unregulated at about 3V, but somewhat less when the motor is running. I'm willing to reprogram the fuses for a lower brownout voltage (or none) if needed.</p> <p>I'm feeling my way on the rest of this - I'll lay out my (perhaps naive) approach and get some feedback about whether I'm understanding it, and how to proceed.</p> <p>With such a low battery voltage, a TIP120 darlington seems to drop too much voltage and substantially reduce the motor speed/power. So I'm thinking that I need to use a power N channel MOSFET, and it appears that I need to be fairly selective to get one which can sufficiently turn on with a &lt;3V gate to source voltage.</p> <p>I'm considering something like the </p> <ul> <li>FQP30N06L <a href="http://www.mouser.com/ds/2/149/FQP30N06L-244344.pdf" rel="nofollow">http://www.mouser.com/ds/2/149/FQP30N06L-244344.pdf</a></li> </ul> <p>If I read the datasheet correctly, Vgs of 3V and a load Ids of 1A would result in less than 100mV drop Vds. But this transistor may be overkill, and the TO220 package is larger than I'd prefer.</p> <p>If I'm willing to deal with SOT-23-3 surface mount packaging, there are some options like:</p> <ul> <li>Toshiba SSM3K324RLF <a href="http://www.semicon.toshiba.co.jp/info/docget.jsp?type=datasheet&amp;lang=en&amp;pid=SSM3K324R" rel="nofollow">http://www.semicon.toshiba.co.jp/info/docget.jsp?type=datasheet&amp;lang=en&amp;pid=SSM3K324R</a></li> <li>Infineon BSS806NE <a href="http://www.mouser.com/ds/2/196/BSS806NE_Rev2%2001-359816.pdf" rel="nofollow">http://www.mouser.com/ds/2/196/BSS806NE_Rev2%2001-359816.pdf</a></li> </ul> <p>If I'm reading it right, with 2x1.5v (nominal) batteries directly powering an Arduino Pro Micro, I can sufficiently drive Vgs to handle 1A Ids at a small Vds and a low enough power dissipation, with any of these three. </p> <p>I would put a reverse diode and a cap across the motor. I've seen devices with a small electrolytic across the motor terminals, and I've seen a smaller value ceramic cap - what's the best practices?</p> <p>Is this a feasible and reasonable approach? What are the gotcha's that I need to take into consideration? Any advice about choosing among these (or other) transistors?</p> <p>My concerns are: not understanding MOSFETs enough, and the unregulated power supply being too noisy for the ATMega328p when it's also powering the motor. Can I handle the latter by adding another cap or two across the Arduino Pro Micro's Vcc/Ground?</p> <p>Backup option: run 3x1.5v alkalines and power the Arduino Pro Micro through its regulated Vraw input.</p>
<p>I don't think the mosfets will be an issue. Looking at the last one (BSS806NE); in figure 5 in the datasheet you see that for 1A and 1.4v (Vgs) you'd get a Vds of only .1v. </p> <p>I think a bigger problem might be the voltage of the batteries dropping under load. You'd have to measure that with a multimeter while the motor is running. A simple cap might help with a little noise, but not with the voltage dropping while the motor is running. Not sure how much the AVR would mind having its supply voltage dropping all of a sudden.</p> <p>Of the top of my head the minimal voltage of the Atmega328 @8mhz is 1.8v, while default fuse settings use 2.7v, so I'd probably change to fuses to make BOD at 1.8v. Other fuses don't need to change.</p> <p>Backup option sound good, though you might have to go with 4 x 1.5v depending on the voltage drop under load. Another alternative might be to have two sets of 1.5v batteries in parallel, halving the current load on each battery.</p>
4301
|sensors|
MMA7361 readings deviate a lot
2014-09-23T07:45:39.677
<p>This is what I get using a MMA7361 breakout board (just the IC, no resistors or capacitors). The IC is powered using arduino nano's 3v3 pin.</p> <p>The x, y, z values are read from analog pins A0, A1, A2. The readings are subtracted with 338.</p> <pre><code>x y z -4 -26 44 44 -27 -5 -57 -11 27 -29 -23 22 28 -21 9 -44 3 20 -26 -14 39 26 -32 -8 -17 -12 19 -30 -15 35 4 -26 14 24 -43 49 -58 -19 0 16 -29 24 9 -48 13 -58 -42 12 12 -47 14 -24 -31 9 -46 -31 10 16 -52 1 -43 -21 8 -31 -25 16 37 -18 11 -45 -10 20 -22 -36 16 27 -19 20 -5 -9 1 -59 -10 10 37 -18 30 -53 -18 16 -30 -8 10 54 -19 17 -27 -29 15 -40 -23 -14 -1 -18 19 34 -22 2 -35 -24 41 13 -17 7 -14 -17 21 -39 -14 35 -19 -31 6 62 -9 34 -63 -16 16 -12 -6 23 60 -33 36 -45 -2 34 -18 -15 9 </code></pre> <p>As you can see the x value, when the whole thing is not moving, can range from -59 to +44. This looks very unusual as other people's reading seems to have just +-3 deviations. What might be wrong with my setup?</p>
<blockquote> <p>(just the IC, no resistors or capacitors)</p> <p>What might be wrong with my setup?</p> </blockquote> <p>That's easy: You miss the capacitors ;-) Check figure 5 of the <a href="http://cache.freescale.com/files/sensors/doc/data_sheet/MMA7361LC.pdf" rel="nofollow">datasheet</a> and try again.</p>
4311
|arduino-uno|power|motor|
Why does the battery eliminator connected to the wall provide a better spin to my dc motors than my battery of the same voltage?
2014-09-24T05:41:55.423
<p>Using a H-bridge, I've connected my DC Motors to an Arduino. When I accept the external power source from a wall, using a 9V battery eliminator, the motors spin well and consistently. However, when I connect it to a 9V battery, the motors spin slower, and the speed deteriorates till the motors stop. This happens in approximately 5 minutes. I checked with multiple 9V batteries of the same type. I have tested the batteries to check if they're dead after the motors stop. They are not, and if I reconnect the motors to them, the same process occurs all over again. I have checked for short circuits, and there are none. Any possible ideas as to why this is happening?</p>
<p>The question is not about volts, but current.</p> <p>A 9V battery is notoriously bad at powering anything that requires high current, like running a motor. Due to to chemical nature of the battery, the 9V will struggle to keep supplying enough current and will fairly quickly drain.</p> <p>A regular alkaline 9V block can supply you with 565 mAh, which is not much if you power motors. You'll have more luck with LiPo (lithium polymer) batteries, which are capable of supplying 2200 mAh or more!</p> <p>To learn more about different types of batteries check out <a href="https://learn.sparkfun.com/tutorials/battery-technologies" rel="nofollow">https://learn.sparkfun.com/tutorials/battery-technologies</a></p> <p>Wall power can quite easily provide the required current your motors need.</p>
4339
|arduino-ide|code-optimization|
How to enable maximum Dead Code Removal?
2014-09-25T18:20:58.150
<p>I am running out of code and data memory space on ATMega328P. </p> <p>Code size is big as I used several libraries, but, I only use a few functions of those library. </p> <p>Apparently, the default IDE is only doing a partial job in <strong>dead code removal</strong> (remove unreferenced code and data). </p> <p>Some experiments shows:</p> <ol> <li><p>A normal program that uses several Arduino libraries is 22 kilo bytes in code size.</p></li> <li><p>Rename setup to o_setup. Rename loop to o_loop</p> <p>Add </p> <p><code>void setup(){};</code></p> <p><code>void loop(){};</code></p> <p>Code size is 8 kilo bytes while the program is 'empty' effectively.</p></li> <li><p><strong>Start</strong> a new program. </p> <p>Add </p> <p><code>void setup(){};</code></p> <p><code>void loop(){};</code></p> <p>Code size is 0.5 kilo bytes </p></li> </ol> <p>Apparently, the IDE (linker called by IDE) is doing a 'partial' dead code removal job, as reducing code from 22kB to 8kB (case 1 and 2), <strong>instead of 0.5kB</strong> (case 3). </p> <p>How can I <strong>enable maximum dead code removal</strong> function (reclaim code space occupied by unused library functions)?</p>
<p>Enable your IDE's verbose of the compile via the preferences. From there you can see exactly what and how it is being compiled.</p> <p>In short the IDE (and toolchain) will compile everything and anything it can find into an object. Where only the used code is compiled in the linking phase, as garbage collection is enabled with the "--gc-sections" command.</p> <p>Note that the optimization level is "-Os" or "Optimize for size". In IDE 1.0.+ this appears to be hardcoded. Where as in IDE 1.5.+ the compiler options are configurable, in "\arduino-1.5.6-r2\hardware\arduino\avr\platform.txt" can be customized to meet your needs.</p> <p>Where you can use the avr-objdump command as described in <a href="https://stackoverflow.com/questions/15291750/does-importing-libraries-load-everything-in-arduino/15296808#15296808">https://stackoverflow.com/questions/15291750/does-importing-libraries-load-everything-in-arduino/15296808#15296808</a>. </p> <p>I would recommend 1.5.6r2 and not 1.5.7 as the gcc commands won't run individually without some path manipulation.</p>
4340
|hardware|
Lego / Meccano style blocks for 'serious' projects
2014-09-25T19:53:42.290
<p>What can be used like Lego or other construction sets, but is more serious and 'professional'? E.g. what comes with gears and screws and things like that, but is geared to serious modelling or more permanent projects?</p>
<p>Here is what comes to mind (by no means exhaustive):</p> <p>billed as "the Industrial erector set", <a href="http://www.8020.net/Default.asp" rel="nofollow">8020</a> is legitimately used in industry for that kind of purpose, and if I remember correctly, pretty expensive. It is the most "professional" thing I can think of.</p> <p><a href="http://www.openbeamusa.com/" rel="nofollow">OpenBeam</a> styles itself as the the cheaper, "open sourced" 8020. I've frequently heard of it being used in 3d printers.</p> <p>These are not as serious or professional, but might be worth mentioning:</p> <p><a href="http://mindsirobotics.com/" rel="nofollow">MINDSi</a> is pretty close to the mindstorms, but tries to be more rigid/durable. It's aimed at robotics.</p> <p><a href="http://www.servocity.com/html/actobotics.html" rel="nofollow">Servo City's actobotics</a> is an aluminum modular building system. It is also sold on sparkfun.</p> <p>I have not used these enough to give good comparisons, but I hope one of these will be what you are looking for.</p>
4342
|arduino-ide|
Opening .h and .cpp files from folders other than the sketch folder
2014-09-25T20:45:37.100
<p>My team has a C++ program from another microcontroller that we are moving to Arduino, which is currently divided into two main folders, the sketch and libraries. We want to be able to open some of the library files in the Arduino IDE along with the sketch, something it will do automatically if they are in the same folder, but not allow otherwise. The files in question are referenced from the other libraries though, which means moving just a few of them results in compilation errors. We don't want to move them all to the sketch folder, since that defeats the purpose, but a few of my teammates are vehemently opposed to having to edit them using another IDE.</p> <p>So is there a way to have these files open in the Arduino IDE with the sketch? Or do I have to tell my teammates to suck it up and use a second editor if they want to make changes?</p> <p>Alternatively, a way to get the libraries able to reference files in the sketch folder would also work.</p>
<p>I don't recommend this</p> <p>A) Because the arduino editor is pretty bad for serious coding</p> <p>B) Because you will need to have a header guard on all library code that doesn't have one already (even in .cpp's)</p> <p>But, if you really have to, the only way I can think of is to make a symbolic link to the library file in the sketch directory. It works, but the file gets compiled twice, so you need those header guards on everything. </p>
4350
|arduino-ide|
Now at IDE 1.0.5, should I upgrade to 1.0.6 or 1.5.7 Beta for Pro mini and ATMega2560 use?
2014-09-26T15:35:06.667
<p>Do I need to <strong>re-install many libraries</strong> (or similar 'house keeping' works)? Is the upgrade straight forward?</p> <p>Apparently, from Arduino web, one need 1.5 BETA series for use with Due. For Pro Mini, UNO and ATMega2560, should one use <strong>1.5 BETA or 1.0.6</strong> (no beta, presumable stable)?</p> <p>I am running out of code space. Wonder if the upgrade will install a <strong>newer gcc</strong> compiler and smaller code size? </p>
<p>I have had trouble with 1.5.7 (Beta), so I would stick with 1.0.6. As for code space, you might want to look into <a href="http://www.atmel.com/tools/atmelstudio.aspx" rel="nofollow">Atmel Studio (Free)</a>, which uses a Visual Studio shell as the IDE. It blows the Arduino IDE out-of-water. Atmel is the maker of all the AT chips, so the Atmel Studio IDE is a great IDE for writing AVR code. Lots of tutorials online and there is a Arduino plug in called <a href="http://www.visualmicro.com/" rel="nofollow">Visual Micro (Free also)</a>.</p>
4354
|library|ide|visualstudio|
Can I switch from Arduino IDE to Atmel studio or Visual Micro but still use Arduino library?
2014-09-26T18:29:36.480
<p>If switch from <strong>Arduino IDE to Atmel studio or Visual Micro</strong>, how to <strong>use existing Arduino library</strong>? </p> <p>Library serves important function of 'packaging' real and complex hardware (like NRF24L01 radio board) into functions of 'relatively standard format', like radio.init, radio.write, radio.read, radio.on, etc. </p> <p>This allows user to easily use the hardware without reading the data sheet. </p> <p>How can the same be achieved under Atmel studio?</p>
<p><a href="http://www.visualmicro.com" rel="nofollow">Visual Micro</a> supports all Arduino libraries in the same way that the Arduino IDE supports these libraries. </p> <p>When using Visual Micro in Atmel Studio your sketch code remains identical to the Arduino IDE. You can switch between the two IDEs and see the same compiler results.</p> <p>If you can not see your user libraries on the "Atmel Studio>Projects>Add/Import Sketch Library" menu then this means you have configured the SketchBook folder path incorrectly. </p> <p>Arduino and Visual Micro use the SketchBook folder to find user libraries in a sub folder called 'Libraries'. </p> <p>I recommend leaving the sketchbook folder empty because Visual Micro will then auto discover the SketchBook folder that the Arduino IDE uses and remove the possibility of confusion.</p> <p>When the sketchbook folder is empty and has not been set in the Arduino IDE the default will be myDocuments\Arduino, therefore your user libraries will be expected to exist in myDocuments\Arduino\Libraries.</p> <p>@John, in response to your question below. It's a big topic and maybe best answered in our forum. </p> <p>A few examples are: </p> <ul> <li><p>Ability to re-define arduino core to use tools such as cygwin, we see the Arducopter example as a good one for this. They produce a window SITL program. </p></li> <li><p>Obviously we can all use the flexible Arduino 1.5 config structure to define our own hardware and build process but we also support the Teensy customization system which allows windows apps/tools to manage the build process and tool chains. Visual Micro supports both of these customizations combined in the same hardware def but also a number of other build properties. </p></li> <li><p>There is also the ability, in Visual Micro, to add compiler #defines for project or configuration and the ability to add programmers that use, for example, the atmel toolchain (if using atmel studio). </p></li> <li><p>Libraries can be referenced with a folder name (unlike arduino) which allows different projects to use similar libraries but of different versions. (Library paths are declared for the lib folder roots as well as individual libraries). </p></li> <li><p>If you consider the various different build properties build properties of Arduino, Teensy, Energia, ChipKIT and Intel then add a few on top this describes what you can do in any project regardless of hardware IDE.</p></li> </ul>
4356
|pins|digital|
Digital pins on Arduino function as both positive and negative terminals?
2014-09-26T22:37:30.170
<p>I'm learning the arduino platform and working on a circuit that connects the two pins of a piezo buzzer -- one to ground and the other to a digital pin of the arduino board. In this configuration, is the arduino's digital pin acting as the positive terminal of the circuit?</p> <p>The arduino docs seem to suggest it is:</p> <blockquote> <p>They (the digital pins) can provide a substantial amount of current to other >circuits. Atmega pins can source (provide positive current) or sink (provide >negative current) up to 40 mA (milliamps) of current to other devices/circuits.</p> </blockquote> <p>Can the digital pins act as both positive and negative terminals in circuits? Does this question even make sense? What resources are out there that can help me better understand the underlying electronics of the arduino and microcontrollers in general?</p>
<p>First of all, the Arduino doesn't supply negative voltage. It flows from positive to <em>ground</em>, the reference point that determines voltage.</p> <p>Anyway, I'm not quite sure of the exact details of the inner-workings of the ATmega chip, but I assume it goes something like this:</p> <ul> <li>A CPU cycle modifies a CPU register (or similar memory/latch somewhere)</li> <li>To the output of that "register," a circuit is connected that: <ul> <li>Shorts the pin to 5V if HIGH</li> <li>Shorts the pin to GND if LOW</li> </ul></li> </ul> <p>I suppose the latch could be directly connected to the pin, but I think that the current draw might be too high for the latch circuit, so an external transistor is used.</p> <p>That above isn't anything that's really technically correct (as these details aren't always released), but its intended purpose is to show you how it basically works from a logic point of view.</p> <p>You can then manipulate the pin's connection using either of these two pieces of code:</p> <pre><code>//HIGH (== 5V) pinMode(5, OUTPUT); digitalWrite(5, HIGH); </code></pre> <pre><code>//LOW (== GND; 0V) pinMode(4, OUTPUT); digitalWrite(4, LOW); </code></pre>
4364
|arduino-ide|
Can I change font Color and/or Type for IDE 1.5.6r2?
2014-09-27T13:03:35.180
<p>The program becomes harder to read (at least on my particular monitor) after upgrading. </p> <p>Any way to change font <strong>Color to darker</strong> color and/or <strong>Type to thicker stroke</strong> (like B in this question editor) for IDE 1.5.6r2?</p>
<p>Yes.</p> <p>Under the file menu select the preferences. From this you can find and than view/edit the preferences.txt file, which has the color settings.</p> <p>Example <a href="https://github.com/arduino/Arduino/blob/master/build/shared/lib/preferences.txt" rel="nofollow noreferrer">preferences.txt</a></p>
4368
|arduino-ide|
What is arduino_debug.exe for IDE 1.5.6r2?
2014-09-27T15:38:59.647
<p>After installing IDE 1.5.6r2, there are two .exe files, <strong>arduino_debug</strong>.exe and <strong>arduino</strong>.exe (which is same name as previously installed IDE 1.0.5). </p>
<p>Windows binaries can either be Window or Console applications. A Window application can NOT produce text output. Text output is the easiest way to gather error messages related to bugs.</p> <p>Hence, <code>arduino_debug.exe</code> should be used by Windows users that have found a bug in the Arduino IDE and wish to contribute submitting an <a href="https://github.com/arduino/Arduino/issues" rel="nofollow">issue on github</a>.</p>
4370
|arduino-mega|ethernet|
Arduino Ethernet Client crashes after obtaining values from string
2014-09-28T07:05:27.413
<p>My Ethernet server keeps crashing after pulling the RGB values from the string. It remains connected if I'm just toggling a pin, but whenever the string has the rgb values in it, the RGB values are pulled, the LED changes but then the server crashes and won't take any more requests. Do I need to restart the server after it plucks the RGB values for another read? If so, how would I go about doing this? </p> <p>Thanks, James :)</p> <p>Example HTTP request that causes the crash: /?LED=B233+G011+R133&amp;t=T HTTP/1.1</p> <pre><code> #include &lt;SPI.h&gt; #include &lt;Ethernet.h&gt; #include &lt;string.h&gt; byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte ip[] = {192, 168, 0, 102 }; byte gateway[] = {192, 168, 0, 1 }; byte subnet[] = {255, 255, 255, 0 }; EthernetServer server(84); ; char* redstring={0}; String blue1; String green1; String red1; String testString = "0123456789"; int blue; int green; int red; int been=0; int b=0; int g=0; int r=0; ////////////////////// void setup(){ pinMode(11, OUTPUT); pinMode(9, OUTPUT); pinMode(7, OUTPUT); pinMode(6, OUTPUT); //start Ethernet Ethernet.begin(mac, ip, gateway, subnet); server.begin(); //enable serial data print Serial.begin(9600); Serial.println("SERVER RUNNING HTTP / GET"); } void loop(){ //////////////////////////////////////// EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); //read char by char HTTP request if (sizeof(redstring) &lt; 100) { //store characters to string redstring += c; //Serial.print(c); } //if HTTP request has ended if (c == '\n') { /////////////////////////////////////////// Serial.println(redstring); client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("&lt;HTML&gt;"); client.println("&lt;link rel=\"shortcut icon\" href=\"data:image/x-icon;,\" type=\"image/x-icon\"&gt;"); client.println("&lt;HEAD&gt;"); client.println("&lt;TITLE&gt;Arduino GET&lt;/TITLE&gt;"); client.println("&lt;/HEAD&gt;"); client.println("&lt;BODY&gt;"); client.println("&lt;H1&gt;HTML GET&lt;/H1&gt;"); //change ip back if not local client.println("&lt;FORM ACTION=\"http://192.168.0.102:84\" method=get &gt;"); client.println("JQUERY: &lt;INPUT TYPE=TEXT NAME=\"LED\" VALUE=\"\" SIZE=\"25\" MAXLENGTH=\"50\"&gt;&lt;BR&gt;"); client.println("&lt;INPUT TYPE=SUBMIT NAME=\"t\" VALUE=\"T\"&gt;"); client.println("&lt;/FORM&gt;"); client.println("&lt;BR&gt;"); client.println("&lt;/BODY&gt;"); client.println("&lt;/HTML&gt;"); delay(1); //stopping client client.stop(); ///////////////////// //readString = Character.toUpperCase(readString); for (int i = 1; i &lt; sizeof(redstring); i++) { if (strchr(redstring, 'B') &amp;&amp; &amp;&amp; redstring[i+1] &gt; -1) { blue=redstring[i+1, i+4]; analogWrite(11, blue); delay(1000); } if (strchr(redstring, 'G') &amp;&amp; redstring[i+1] &gt; -1) { green=redstring[i+1, i+4]; analogWrite(9, green); delay(1000); } if (strchr(redstring, 'R')&amp;&amp; redstring[i+1] &gt; -1) { red=redstring[i+1, i+4]; analogWrite(7, red); delay(1000); } } //clearing string for next read redstring=""; (redstring, "0", sizeof(redstring)); } } } } } </code></pre>
<p>Using <code>String</code>, which uses dynamic allocation/deallocation on the heap is not advised in embedded platforms, as this can quickly lead to heap fragmentation, eventually leading to memory exhaustion, heap/stack collision...</p> <p>First off, you should try to replace all <code>String</code> usage, everywhere in your program, with C-tyle strings, i.e. <code>char*</code> or <code>char xxx[...]</code> along with dedicated C functions to deal with them: <code>strchr</code>, <code>strstr</code>, <code>strcpy</code>, <code>strcat</code>, <code>strtok</code>, <code>atoi</code>...</p> <p>Second, you can avoid using global variables and use the stack for many of them.</p> <pre><code>void loop() { ... if (client) { char readString[101]; const int READ_STRING_SIZE = sizeof(readString) - 1; int readIndex = 0; while (client.connected()) { if (client.available()) { char c = client.read(); if (readIndex &lt; READ_STRING_SIZE) { readString[readIndex++] = c; } if (c == '\n') { // Terminate the read string readString[readIndex] = 0; Serial.println(readString); // Prepare for next reeading readIndex = 0; client.println("HTTP/1.1 200 OK"); ... client.stop(); // convert readString to all uppercase for (i = 0; i &lt; strlen(readString); i++) readString[i] = toupper(readString[i]); bool b = false; bool r = false; bool g = false; int blue, red, green; // Look for 'B' value char* bb = strchr(readString, 'B'); if (bb != 0 &amp;&amp; isdigit(bb[1]) { blue = atoi(&amp;bb[1]); analogWrite(11, blue); delay(500); b = true; } // Same for 'G' and 'R' value ... if (b &amp;&amp; r &amp;&amp; g) { Serial.print("CHANGING RED TO: "); Serial.println(red); Serial.print("CHANGING GREEN TO: "); Serial.println(green); Serial.print("CHANGING BLUE TO: "); Serial.println(blue); } } if (strstr(readString, "PIN6") != 0) { digitalWrite(6, !digitalRead(6)); ... } } } } } </code></pre> <p>In this sample code, we have completely removed dynamic memory allocation.</p>
4374
|arduino-uno|c++|interrupt|rotary-encoder|
bitRead() gives wrong answer Arduino UNO R3
2014-09-28T21:09:24.170
<p>I am trying to read from a quadrature rotary encoder using an Arduino UNO R3. This is done by connecting the encoder's channel A pin to the Arduino interrupt 0 pin (digital IO pin 2). Inside the interrupt routine I then read the value of channel B (connected to digital IO pin 8) to determine the direction of rotation.</p> <p>I am able to read the correct value of channel B using the digitalRead() function, but when I use bitRead() it always gives me a 0. As far as I know digital IO pin 8 is mapped to PORTB bit 0, so I am using bitRead(PORTB, 0) to read the bit. I also tried to read all of the other pins, but all of them show 0, except the LED at pin 13, which shows 0s and 1s when it gets toggled (It is also the only pin defined to be an OUTPUT pin, whereas the encoder uses INPUT pins).</p> <p>Below is my code:</p> <pre><code>int channelA = 0; int channelB = 8; volatile int rotateNumber = 0; volatile boolean interrupted = false; void setup() { Serial.begin(115200); attachInterrupt(channelA, rotate, RISING); pinMode(channelB, INPUT); } void loop() { if(interrupted){ Serial.println(rotateNumber) interrupted = false; } } void rotate(){ if(bitRead(PORTB, 0) == 1) rotateNumber++; else rotateNumber--; interrupted = true; } </code></pre>
<p><code>PORTx</code> is the latched value last written there. The external value is found in <code>PINx</code>.</p>
4376
|arduino-uno|
How can I run two loops simultaneously on an Arduino Uno?
2014-09-28T21:54:06.227
<p>I'm new to Arduino and I have two devices that I'm trying to control:</p> <ol> <li>A RGB LED light strip that can change colors</li> <li>A light sensor that can detect the ambient light level</li> </ol> <p>What I'd like to do is have the LED strip continuously cycle through a rainbow of colors, and the light sensor will adjust the brightness of the LED strip based on the ambient light level. Here are the two pieces of code by themselves, which I've tested in isolation and confirmed that they work properly:</p> <p>LED strip:</p> <pre><code>j = (j + 1) % 256; // current iteration of the light cycle // set the strip color for(int i=0; i&lt; strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) &amp; 255)); } // display the new colors and wait 20ms before the next cycle strip.show(); delay(20); </code></pre> <p>Light sensor:</p> <pre><code>sensors_event_t event; tsl.getEvent(&amp;event); // get a light measurement strip.setBrightness(event.light); // set the brightness of the LED strip </code></pre> <p>The problem is that the light sensor takes anywhere from 100ms to 600ms to get a reading, and <code>tsl.getEvent(&amp;event)</code> is a blocking call, so the end result is that the LED strip updates way too slowly. I would need to run the two side by side so that the light sensor read does not block the LED strip update. Any idea how I can accomplish this?</p>
<p>1.Use two arduino's and have them talk to each other via serial or i2c. Probably the simplest option (but not the cheapest - though you can get clone arduinos from US$4 ).</p> <p>2.Find a light sensor that updates faster. Tried an ldr(light dependent resistor)/photocell ? Then could use analog read. </p> <p>Could also switch from using arduino to c, but thats a lot more work and you are still going to hit similar problems.</p>
4380
|interrupt|millis|isr|
Is `millis()` affected by long ISRs?
2014-09-29T02:49:44.190
<p>I have a project that uses timers and interrupts frequently. A lot of CPU time is spent handling ISRs over an extended period of time.</p> <p>Would this affect code inside the main loop that relies on the millis() function since a significant amount of time is spent processing the ISRs?</p>
<p>The timer interrupt can even disrupt measurement of pulses using micros() from an on change interrupt. The timer interrupt takes around 6.5us on Arduino Uno or mega. If a change interrupt takes place just after the timer interrupt, then the change interrupt will be delayed by up to 6.5us until the timer interrupt completes. In addition, the microsecond count is only updated once every 4us, introducing further uncertainty up to 4us.</p> <p>So the measurement may be up to 10.5us out. This should be considered when measuring pulse lengths.</p>
4395
|arduino-uno|avrdude|
Getting a long avrdude error while uploading a simple sketch to arduino uno
2014-09-30T05:13:12.207
<p>This is the error which shows up after the sketch is compiled and starts uploading.</p> <p>Is there some sort of fix to this problem?</p> <p>There are no shields connected to it, not even I/O pins are being used, just trying the simple Blink sketch.</p> <p>NOTE : It was working find before and then it started acting crazy</p> <pre><code> Binary sketch size: 1,084 bytes (of a 32,256 byte maximum) C:\Program Files (x86)\Arduino\hardware/tools/avr/bin/avrdude -CC:\Program Files (x86)\Arduino\hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P\\.\COM3 -b115200 -D -Uflash:w:G:\Temp\build5658632448223358877.tmp\Blink.cpp.hex:i 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:\Program Files (x86)\Arduino\hardware/tools/avr/etc/avrdude.conf" Using Port : \\.\COM3 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 "G:\Temp\build5658632448223358877.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.27s avrdude: 1084 bytes of flash written avrdude: verifying flash memory against G:\Temp\build5658632448223358877.tmp\Blink.cpp.hex: avrdude: load data flash data from input file G:\Temp\build5658632448223358877.tmp\Blink.cpp.hex: avrdude: input file G:\Temp\build5658632448223358877.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: . [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] 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: # [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] 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: . [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] 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: . [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] 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: . [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] 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: . [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] 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: . [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] 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: . [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] 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: . [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] avrdude: Recv: . [10] ### | 100% 0.20s avrdude: verifying ... avrdude: 1084 bytes of flash verified avrdude: Send: Q [51] [20] avrdude: Recv: . [14] avrdude: Recv: . [10] avrdude done. Thank you. </code></pre>
<p>This is not an error. AVRDude is running with the Verbose flag on. Verbose in English means: </p> <blockquote> <p>using or expressed in more words than are needed.</p> </blockquote> <p>In the Arduino IDE:</p> <p><img src="https://i.stack.imgur.com/7ZYID.png" alt="Running with the Verbose flag."></p>
4398
|button|
Turn Arduino on only by double tapping switch?
2014-09-30T09:16:50.000
<p>I don't have much experience with electronics. I was wondering if it is possible to create a push button switch, which will turn on the device only if it is tapped twice in quick succession?</p> <p>If it is tapped only once, then the device should behave as if nothing happened (i.e. tapping the switch again after a specified duration should have no effect).</p>
<p>You can use something like the ATtiny25/45/85 then have a button cell battery to power it, make it a sleeper that listens to the button, and when clicked it activates the Arduino.</p> <p>The Arduino is then turned on keeping a capacitor alive holding a transistor active, then add another button that drains the capacitor, thus closing the transistor and turning the Arduino off. Or you can program the ATtiny to drain the capacitor if the button is held down.</p> <p>A button cell on an ATtiny in sleepmode should last around a year or so.</p> <p>Just some information to get you going further:</p> <p><a href="http://playground.arduino.cc/Learning/arduinoSleepCode" rel="nofollow noreferrer">http://playground.arduino.cc/Learning/arduinoSleepCode</a> : The sleeper code, it is power saving using interrupts.</p> <p><a href="http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/" rel="nofollow noreferrer">http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/</a> : How to burn an ATtiny using Arduino. Fairly simple, did it myself a few times.</p>
4405
|arduino-uno|lcd|
How do I connect this display to an Arduino Uno
2014-09-30T22:03:46.430
<p>I am completely new to this, and a novice when it comes to electronics but I want to learn. Can someone pls tell me how I would connect the display in the photo here with an Arduino Uno (which I have ordered). The plan is to interface my car with this transparent display to produce a form of HUD. I have done some searching but to no avail so far, would appreciate being pointed in the right direction. many thanks<img src="https://i.stack.imgur.com/5KfTx.jpg" alt="transparent LCD clock"></p>
<p>You're in for a <em>lot</em> of work. Everything on the PCB is useless to you, so you'd have to interface the raw panel to the Arduino.</p> <p>The first matter is to remove the panel from the board. You will need to desolder all of the connections, and then solder either some sort of rigid connector or individual wires to the large ribbon connector. The only advice I can give you is "be prepared to fail".</p> <p>Once you've done that, you will need to read <a href="http://www.atmel.com/Images/doc8103.pdf" rel="nofollow">AVR340</a> in order to learn how to drive the panel. Note that the Uno itself does not have enough pins to drive the panel directly, so you will need to get an I/O expander or two for this.</p> <p>Did I mention that you're in for a lot of work? Well, I'm mentioning it again. Good luck though.</p>
4407
|arduino-mega|c++|
Advisability of Using Bit Fields in Structs
2014-10-01T00:19:12.370
<p>I have to track a large amount of data (for an Arduino) in a program while taking care of a fair amount of other business.</p> <p>I started with a struct like this:</p> <pre><code>struct MyStruct { // note: these names might as well be foo bar baz uint8_t color; boolean state; uint8_t area; uint8_t number; uint8_t len; }; </code></pre> <p>I have an array of 800 of these. At 5 bytes each, that's 4Kb, or half the ram on the Arduino Mega.</p> <p>I changed to a struct like this:</p> <pre><code>struct MyStruct { uint8_t color : 3; // max value 7 // uint8_t state : 1; *** moved, thanks Ignacio *** uint8_t area : 5; // m.v. 31 uint8_t number; uint8_t len : 5; // m.v. 31 uint8_t state : 1; // m.v. 1 }; </code></pre> <p>I understand this reduces the size of each instance to 3 bytes, for a total of 2.4Kb in my array.</p> <p>I have read that in some implementations / chipsets using bit fields in structs can lead to less efficient execution. Obviously this is a more efficient use of memory, but my question is:</p> <p>How does the Arduino handle bit fields? Will it be better, worse, or negligibly different in terms or speed when iterating through an array of bit field structs? Is there a good way to test this?</p>
<p>A discussion of bit-fields wouldn't be complete without mentioning that:</p> <blockquote> <p>Structures with bit-fields may be used as a portable way of attempting to reduce the storage required for a structure (with the probable cost of increasing the instruction space, and time, needed to access the fields), or as a non-portable way to describe a storage layout known at the bit level.</p> </blockquote> <p>[Kernighan &amp; Ritchie, <em>The C Programming Language, Second Edition</em>, Appendix A-8.3]</p> <p>Other posters, including yourself, have addressed the space/time tradeoff. But what is sometimes missed (possibly not relevant to your application - ?) is the complete <em>implementation-dependence of the storage layout</em>. This matters when applications share this data with another process: Reading or writing hardware, whose register bit-assignments are necessarily fixed; communicating the data to another system (via network or storage device doesn't matter); or to another application on the same system, that may have been compiled with a different compiler or version of the compiler.</p>
4427
|avr|programmer|atmel-studio|
Atmel STK500 and Atmel Studio
2014-10-02T16:03:08.193
<p>Is the <a href="http://store.atmel.com/PartDetail.aspx?q=p:10500070;c:100114#tc:description" rel="nofollow noreferrer">Atmel STK500</a> worth using as a AVR programmer and Dev board? I am starting to get to into AVR programming with Atmel studio. I plan on purchasing the <a href="http://store.atmel.com/PartDetail.aspx?q=p:10500053;c:100112#tc:description" rel="nofollow noreferrer">AVRDragon</a> and also looking into purchasing the Atmel STK500. This might be too broad of a question, but are their any benefits in using the Atmel STK500?</p> <p><strong>Atmel STK500</strong></p> <p><img src="https://i.stack.imgur.com/blQAZ.jpg" alt="Atmel STK500"></p>
<p>Benefits of STK500? Sure:<br> - It has push buttons<br> - It has LEDs<br> - It has easy accessible connectors to any controller pin<br> <br> Actually that's all. If you want/need to make use of this, buy both. Use the STK for "rapid prototyping" and the Dragon for debugging.<br> But if your budget allows it, have a look at the STK600 instead of 500. It's more expensive, but not so "old-fashioned", and it has much more features.</p>
4430
|arduino-uno|electricity|
Arduino output pin from 5V to 3.3V
2014-10-02T21:23:09.157
<p>I just have a question regarding Arduino output-pins and Voltage divider, because I am getting other results than what my calculations are giving me.</p> <p>I have measured the output-pin (from the Arduino) at 4.74V, according to my caulculations I will have and output voltage of 3.39V, with R1 = 4k ohm and R2 = 10k ohm, but when I use my multimeter to measure I read a voltage of 0.97V.</p> <p>I have tested with a 9V battery, measured to 8.72V. With the same resistors, the calculations gives me 6.23V as output, when I use my multimeter I can read a output of 6.21 which I consider as ok.</p> <p>So my question is, why is my output from the Arduino only 0.97V with the voltage divider?</p> <p>For information: I am using Arduino OSEPP Uno R3 Plus.</p> <p>Hope someone can give me helpfull information.</p> <p>***************************************update********************************************</p> <p>My code:</p> <pre><code>int echoPin = 7; int trigPin = 6; int SignalPin = 10; void setup(){ pinMode(echoPin, INPUT); pinMode(trigPin, OUTPUT); } void loop(){ float distanceCentimeters; int pulseLenMicroseconds; digitalWrite(trigPin, LOW); delayMicroseconds(20); digitalWrite(trigPin, HIGH); delayMicroseconds(100); digitalWrite(trigPin, LOW); pulseLenMicroseconds = pulseIn(echoPin, HIGH); distanceCentimeters = pulseLenMicroseconds / 29.387 / 2; if(distanceCentimeters &lt;= 35 &amp;&amp; distanceCentimeters &gt;= 10){ digitalWrite(SignalPin, HIGH); } else { digitalWrite(SignalPin, LOW); } delay(400); } </code></pre> <p>Image of the setup (not with Raspberry Pi).</p> <p><img src="https://i.stack.imgur.com/0HDVY.jpg" alt="enter image description here"></p>
<p>Your code does not configured SignalPin as an output, but only trigPin.</p> <p>As already explained in comments, your observed voltage is due not really to the voltage divider you constructed, but rather one formed by the "weak" internal pull-up resistance and your external resistors. From your measurement, it appears the value of the weak internal pull-up is about 35K, which is within the range of expectations. That and your 4K external form the top of the divider (39K) while your 10K forms the lower half, yielding about a fifth of the supply voltage.</p> <p>In <em>some</em> versions of the Arduino library, writing to an input pin enables and disables the internal pull-up resistor, so you could have observed your program seeming to control the pin - but at minimal drive strength.</p> <p>To get the desired behavior, you merely need to add</p> <pre><code>pinMode(SignalPin, OUTPUT); </code></pre>
4444
|bootloader|
Arduino mini requires uploading on every power up?
2014-10-04T00:02:06.760
<p>My Arduino mini is experiencing some really strange problem.</p> <p>I'm using the BlinkWithoutDelay example sketch for testing:</p> <pre><code>const int ledPin = 13; int ledState = LOW; // ledState used to set the LED long previousMillis = 0; // will store last time LED was updated long interval = 1000; // interval at which to blink (milliseconds) void setup() { pinMode(ledPin, OUTPUT); } void loop() { unsigned long currentMillis = millis(); if(currentMillis - previousMillis &gt; interval) { // save the last time you blinked the LED previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; // set the LED with the ledState of the variable: digitalWrite(ledPin, ledState); } } </code></pre> <p>The program basically turns pin 13 on and off every 1000ms.</p> <p>When I uploaded this sketch into the mini (via Arduino Uno board, sans Atmega chip), the scope reading of pin 13 shows nice square waves (1s pulsewidth, 2s period), as expected.</p> <p>I then unplug the USB cable powering the mini through the Uno board, wait for a few seconds for the scope traces to settle (I only have an old analog one at hand), and then plug it back in to turn on the board. However, the pin output is different - I now get a train of three pulses (60ms wide, 60ms between pulses) at sporadic intervals.</p> <p>Uploading the sketch then yields the desired square waves again.</p> <p>What is going on here? I'm fairly sure the mini has nonvolatile memory and it's intact (otherwise the bootloader through which I upload the sketch would not work).</p>
<p>There was a defective bootloader that shipped on some Arduino devices which caused the symptom you describe. See:</p> <p><a href="http://forum.arduino.cc/index.php?topic=51172.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=51172.0</a></p> <p><a href="http://forum.arduino.cc/index.php?topic=74090.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=74090.0</a></p> <p>If that's the case, your options are to re-write the bootloader yourself (if you have the capability) or return to the manufacturer.</p>
4447
|power|battery|
Can I have backup power for an Arduino device?
2014-10-04T03:53:10.493
<p>I have an arduino project that will work while plugged into a generic outlet. But I want to connect a battery in case the power goes out. I know there are various power sources (<a href="https://www.sparkfun.com/products/337" rel="noreferrer">coin cell</a>, <a href="https://www.sparkfun.com/products/8483" rel="noreferrer">polymer lithium</a>, <a href="https://www.sparkfun.com/products/10512" rel="noreferrer">9V</a>, etc.). But if I code my project to use the backup power if the main power goes down, would that mean the backup always has to be running? How would I go about this?</p> <p>Thanks for the help! Every time you help me you save a kitten!!</p>
<p>You can use <a href="https://www.regaldreamtech.com/micro-ups/" rel="nofollow noreferrer">https://www.regaldreamtech.com/micro-ups/</a> for the backup 5V power supply to Arduino in absence of main power. It has 5000mAh battery and 5V 2A output. It will handle the switching on its on between main and battery power.</p> <p>Disclosure: We manufacture this product.</p>
4449
|arduino-uno|c++|avr|compile|build|
Cannot compile C++11 code via Makefile
2014-10-04T07:04:05.480
<p>I am building my Arduino project with a makefile:</p> <pre><code>BOARD_TAG = uno ARDUINO_PORT = /dev/ttyACM0 USER_LIB_PATH = /home/prakhar/dev/alfred/arduino/libraries CPPFLAGS=-x c++ -std=c++11 -Wall -DUNIX_ENVIRONMENT -DHAVE_NAMESPACES -DHAVE_STD include /usr/share/arduino/Arduino.mk </code></pre> <p>I keep getting this error:</p> <pre><code>cc1plus: error: unrecognized command line option "-std=c++11" </code></pre> <p>I googled and <a href="https://stackoverflow.com/questions/14674597/cc1plus-error-unrecognized-command-line-option-std-c11-with-g">this</a> says that I need to update g++/gcc. I already have the newset versions:</p> <pre><code>prakhar@sim74stic ~ $ avr-g++ --version avr-g++ (GCC) 4.9.1 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. prakhar@sim74stic ~ $ avr-gcc --version avr-gcc (GCC) 4.9.1 Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. prakhar@sim74stic ~ $ g++ --version g++ (GCC) 4.9.1 20140903 (prerelease) Copyright (C) 2014 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </code></pre> <p>I installed <code>arduino</code> from the <code>AUR</code> (packages <code>aur/arduino 1:1.0.6-1</code> and <code>aur/arduino-mk 1.3.4-2</code>). Can anybody point out what I'm doing wrong?</p>
<p>As I turns out, the <code>avr-gcc (GCC) 4.9.1</code> goodies weren't being used at all! The arduino package was using a decrepit version of gcc,</p> <pre><code>prakhar@sim74stic ~ $ /usr/share/arduino/hardware/tools/avr/bin/avr-g++ --version avr-g++ (GCC) 4.3.2 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. prakhar@sim74stic ~ $ /usr/share/arduino/hardware/tools/avr/bin/avr-gcc --version avr-gcc (GCC) 4.3.2 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </code></pre> <p><strong>All I had to do was specify</strong>:</p> <pre><code>AVR_TOOLS_DIR = /usr </code></pre> <p>to exexute with <code>-std=c++11</code> flag (I also had to add an <code>-fpermissive</code> flag to compile <code>C</code> with <code>g++</code>).</p>
4450
|eeprom|
Setting data pin with NanodeUNIO
2014-10-04T14:38:04.250
<p>I'm using a sketch that helps to reset Da Vinci XYZPrinter cartridge EEPROMs, and it's based on the NanodeUNIO library. It uses digital pin 7 for data. I want to use my TFT Touch Shield to set the extruder temperature, but the shield also makes use for digital pin 7. Being that the sheild is wired to use pin 7, it can't be changed. But any pin that can be used as a digital pin should be useable with NanodeUNIO (at least, that is my assumption), but I can't find where in NanodeUNIO it sets the data pin. Where is that pin set, and how can it be changed?</p>
<p><code>xyz_dv_eprom.ino</code> uses low-level access rather than Arduino calls to manipulate PD7, most likely for speed reasons. Lines 96 through 104 (specifically 96, 97, 100, and 104) need to be modified in order to change both the port and the bit used.</p> <p><a href="http://arduino.cc/en/Hacking/PinMapping168" rel="nofollow">ATmegaXX8 pin mapping</a><br> <a href="http://arduino.cc/en/Hacking/PinMapping2560" rel="nofollow">ATmegaXXX0 pin mapping</a><br> <a href="http://arduino.cc/en/Hacking/PinMapping32u4" rel="nofollow">ATmegaXXU4 pin mapping</a></p>
4451
|interrupt|
Counting pulses with interrupt
2014-10-04T15:00:37.667
<p>I have been trying to count pulses from a 12,500&nbsp;Hz square wave to trigger an output. Here's the code I have so far. When the Arduino is reset it prints 315 to the serial over a 25&nbsp;ms sample. 315 x 40 = 12600. Which seems to me it's working perfectly.</p> <p>My only problem is it only returns this number once upon reset of the board. Now if I move that same code down into <code>void loop</code>, it counts consecutively giving me inconstant returns.</p> <p>I am not understanding what I need to put in the loop section so I can repeatedly and accurately count how many toggles of the input pin I am getting over a period of time so I can do something to the output based off the presence of the 12,500 Hz signal or not.</p> <pre class="lang-cpp prettyprint-override"><code>volatile int IRQcount; int pin = 2; int pin_irq = 0; //IRQ that matches to pin 2 void setup() { // Put your setup code here, to run once: Serial.begin (9600); attachInterrupt(pin_irq, IRQcounter, RISING); delay(25); detachInterrupt(pin); Serial.print(F("Counted = ")); Serial.println(IRQcount); } void IRQcounter() { IRQcount++; } void loop() { // Put your main code here, to run repeatedly: } </code></pre> <p>Using the above code, every time I press the reset button I get one line in the serial window.</p> <pre><code>Counted = 441 Counted = 442 Counted = 441 Counted = 441 Counted = 441 </code></pre> <p>Now I want to get the same result, but repeating over and over. That way if the signal drops out I can trigger an output to turn off (LOW). When the signal is present the output will go high.</p> <p>My attempt was to move the attach interrupt down into <code>void loop</code>, so it would repeat. Here's what it looks like.</p> <pre class="lang-cpp prettyprint-override"><code>volatile int IRQcount; int pin = 2; int pin_irq = 0; //IRQ that matches to pin 2 void setup() { // Put your setup code here, to run once: Serial.begin (9600); } void IRQcounter() { IRQcount++; } void loop() { // Put your main code here, to run repeatedly: attachInterrupt(pin_irq, IRQcounter, RISING); delay(25); detachInterrupt(pin); Serial.print(F("Counted = ")); Serial.println(IRQcount); } </code></pre> <p>The return I get is self-updating, but the "count" instead of starting from 0 each time starts from the previous count. So it gets larger and larger. I am looking to return a constant value that represents my 12500&nbsp;Hz signal so that, and only that, will trigger my output.</p> <pre><code>Counted = 442 Counted = 886 Counted = 1330 Counted = 177 Counted = 2221 Counted = 2667 Counted = 3112 Counted = 3557 Counted = 4002 Counted = 4448 Counted = 4893 Counted = 5338 Counted = 5784 Counted = 6229 Counted = 6674 Counted = 7120 Counted = 7565 Counted = 8010 Counted = 8456 Counted = 8901 Counted = 9347 Counted = 9792 Counted = 10237 Counted = 10683 Counted = 11130 Counted = 11576 Counted = 12022 Counted = 12469 Counted = 12915 Counted = 13361 Counted = 13808 Counted = 14254 Counted = 14700 Counted = 15147 Counted = 15593 Counted = 16040 Counted = 16486 Counted = 16932 Counted = 17378 Counted = 17825 Counted = 18271 Counted = 18717 Counted = 19164 Counted = 19610 Counted = 20056 Counted = 20503 Counted = 20949 Counted = 21395 Counted = 21842 Counted = 22288 Counted = 22735 Counted = 23169 Counted = 23616 Counted = 24062 Counted = 24508 Counted = 24955 Counted = 25401 Counted = 25730 Counted = 25756 Counted = 26200 Counted = 26646 Counted = 27093 Counted = 27539 Counted = 27985 Counted = 28432 Counted = 28878 Counted = 29324 Counted = 29770 Counted = 30217 Counted = 30663 Counted = 31110 Counted = 31556 Counted = 32002 Counted = 32449 Counted = -32641 Counted = -32195 Counted = -31748 Counted = -31302 Counted = -30855 Counted = -30408 Counted = -29962 Counted = -29515 Counted = -29069 Counted = -28622 </code></pre>
<p>You need to reset IRQCount back to <code>0</code> before attaching the interrupt again. Otherwise it will just continue counting from where it stopped last time.</p> <p>I would actually keep the interrupt attached and just reset the variable just before the delay. That way the overhead of attach/detachinterrupt doesn't get added to the 25ms delay.</p> <pre><code>volatile int IRQcount; int pin = 2; int pin_irq = 0; //IRQ that matches to pin 2 void setup() { // put your setup code here, to run once: Serial.begin (9600); attachInterrupt(pin_irq, IRQcounter, RISING); } void IRQcounter() { IRQcount++; } void loop() { // put your main code here, to run repeatedly: IRQcount = 0; delay(25); int result = IRQcount; Serial.print(F("Counted = ")); Serial.println(result); } </code></pre> <p>Since an int is 2 bytes an interrupt might occur in the middle of setting/reading those two bytes. This might result in an occasional wrong value. To prevent that you should disable interrupt while setting/reading the value</p> <pre><code>volatile int IRQcount; int pin = 2; int pin_irq = 0; //IRQ that matches to pin 2 void setup() { // put your setup code here, to run once: Serial.begin (9600); attachInterrupt(pin_irq, IRQcounter, RISING); } void IRQcounter() { IRQcount++; } void loop() { // put your main code here, to run repeatedly: cli();//disable interrupts IRQcount = 0; sei();//enable interrupts delay(25); cli();//disable interrupts int result = IRQcount; sei();//enable interrupts Serial.print(F("Counted = ")); Serial.println(result); } </code></pre>
4456
|shields|
Are all Arduino shields compatible with all Arduino boards?
2014-10-04T16:34:42.080
<p>Are all Arduino shields compatible with all Arduino boards? Like is the Wi-Fi one compatible with the Arduino Nano &amp; Micro as well as the Uno, etc., or do I need to be careful when buying shields that they'll be compatible with my board? Also, the shields just plug into the boards, don't they?</p>
<p>When you want to choose a shield for your board you should check:</p> <p>1- <strong>Pin-out</strong>, this one is the least concerning one , Most arduino boards are Shield pin-out compatible and you can verify it visually, for others, normally there are some converter boards (e.g for NANO), and in the worst case, building a converter board or wiring the shield to board is trivial in most situations.</p> <p>2- <strong>Shield operating voltage should match your board's</strong>, most shields operate at 5V, 3.3V or both. Normally AVR-based boards (e.g. UNO, Mega, ...) operate at 5V and ARM based ones (e.g. Due, ...) operate at 3.3V, So we should choose the shield accordingly <em>(just keep in mind that most shield are designed with Arduino UNO in mind so it's more likely that your shields operate at 5V)</em>.</p> <p>3- <strong>Library</strong>, Lots of Libraries for Arduino shields bypass Arduino library abstraction (mostly for performance reasons) and use hardware specific features (e.g directly write on specific ports), here is source of some incompatibilities between your board and the shield, for example there are handful of TFT LCD shields in the market which their library only supports UNO boards, in these cases you should either port it to your board's (based on micro-controller model and it's architecture, sometimes its as easy as changing some pin/port definitions and sometimes as hard as writing the library from scratch).</p>
4462
|arduino-mega|tinygps|gps|
uBlox LEA 6H and UNO no data
2014-10-04T23:19:54.073
<p>While using NEO 6M and getting close-to-perfect accuracy, connecting the 3dr uBlox LEA 6H shows incoming characters, but gibberish data (at 38400) like it is connecting to a wrong baud rate (although it isn't, i've checked it with u-center and works when connected to Ardupilot). So i guess it is some kind of configuration to show only certain parts of NMEA (if it is showing NMEA and not something else).</p>
<p>You can configure the ublox lea6H GPS to read either through NMEA protocol or the UBX protocol. You just need to send some configuration messages. For good data rate it is better to use UBX protocol as it gives data in binary format inducing less delay.In case you need to test your device you can use my GPS code for arduino mega - customized ardupilot gps code - UBX protocol.</p> <p><a href="https://github.com/ksskarthik/Team_Pushpak/blob/master/TP_GPS" rel="nofollow">https://github.com/ksskarthik/Team_Pushpak/blob/master/TP_GPS</a></p>
4475
|arduino-uno|programming|led|
Arduino function to fade from one RGB color to the next
2014-10-05T22:38:08.187
<p>For my Arduino project I have a <a href="https://learn.adafruit.com/downloads/pdf/adafruit-neopixel-uberguide.pdf" rel="nofollow">Neopixel RGB Strip</a> with 72 LED's.</p> <p>I can successfully change the colour of any of the LED's (at the moment I'm only setting the first one 0 for testing purposes) so I know my wiring isn't the problem here, it's my coding.</p> <p>What I would like to do is be able to select a color and then another color and have the first color fade to the next color and so forth (much like the LIFX bulbs behave when using the iPhone application).</p> <p>This is what I have at the moment:</p> <p>I am logging output of all the variables to give you an indication of what's going on. I'm not 100% sure on where I'm going wrong or whether there's a much easier way to do what I'm after (I'm open to suggestions).</p> <p>The function takes a parameter called <code>command</code>, which is a string separated by commas:</p> <p>e.g. <code>255, 0, 0</code> (RED) or <code>0, 255, 0</code> (GREEN).</p> <pre><code>/******************************************************************************* * Function Name : tinkerSetColour * Description : Sets the strip with the appropriate colour * Input : Pin and value * Output : None. * Return : 1 on success and a negative number on failure *******************************************************************************/ int Rstart = 0, Gstart = 0, Bstart = 0; int Rnew = 0, Gnew = 0, Bnew = 0; int tinkerSetColour(String command) { sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart); Spark.publish("rgb", rgbString); sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew); Spark.publish("rgb", rgbString); // Clear strip. strip.show(); int commaIndex = command.indexOf(','); int secondCommaIndex = command.indexOf(',', commaIndex+1); int lastCommaIndex = command.lastIndexOf(','); int red = command.substring(0, commaIndex).toInt(); int grn = command.substring(commaIndex+1, secondCommaIndex).toInt(); int blu = command.substring(lastCommaIndex+1).toInt(); int Rend = red, Gend = grn, Bend = blu; sprintf(rgbString, "Rend %i, Gend %i, Bend %i", Rend, Gend, Bend); Spark.publish("rgb", rgbString); // Larger values of 'n' will give a smoother/slower transition. int n = 200; for (int i = 0; i &lt; n; i++) { Rnew = Rstart + (Rend - Rstart) * i / n; Gnew = Gstart + (Gend - Gstart) * i / n; Bnew = Bstart + (Bend - Bstart) * i / n; // Set pixel color here. strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew)); } sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew); Spark.publish("rgb", rgbString); Rstart = red, Gstart = grn, Bstart = blu; sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart); Spark.publish("rgb", rgbString); return 1; } </code></pre> <p>The problem is the colors are not fading between themselves.</p> <p>Apologies if any of this is confusing. I can provide more information if necessary.</p> <p>Here's the <strong>output</strong> selecting <strong>RED</strong> to begin with:</p> <pre><code>Rstart 0, Gstart 0, Bstart 0 Rnew 0, Gnew 0, Bnew 0 Rend 255, Gend 0, Bend 0 Rnew 253, Gnew 0, Bnew 0 </code></pre> <p>Here's the <strong>output</strong> selecting <strong>GREEN</strong> directly afterwards:</p> <pre><code>Rstart 255, Gstart 0, Bstart 0 Rnew 253, Gnew 0, Bnew 0 Rend 0, Gend 255, Bend 0 Rnew 2, Gnew 253, Bnew 0 </code></pre> <p>And then the <strong>output</strong> selecting <strong>BLUE</strong> after that:</p> <pre><code>Rstart 0, Gstart 255, Bstart 0 Rnew 2, Gnew 253, Bnew 0 Rend 0, Gend 23, Bend 255 Rnew 0, Gnew 25, Bnew 253 </code></pre>
<p>There is no delay in there. It will fade very quickly, add a delay e.g. 5ms with <code>n</code> = 200 for a 1 second fade:</p> <pre><code>int n = 200; for (int i = 0; i &lt; n; i++) { Rnew = Rstart + (Rend - Rstart) * i / n; Gnew = Gstart + (Gend - Gstart) * i / n; Bnew = Bstart + (Bend - Bstart) * i / n; // Set pixel color here. strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew)); delay(5); } </code></pre> <p>The other thing is your last value of <code>n</code> in the loop is 199, not 200, and thus <code>Rnew</code> etc don't have the correct final value. Change the comparison to be <code>&lt;=</code> not <code>&lt;</code>:</p> <pre><code>for (int i = 0; i &lt;= n; i++) </code></pre>
4480
|arduino-nano|arduino-micro|
Are there any reasons to pick Nano over Micro?
2014-10-06T07:56:44.453
<p>Nano is from 2008, and micro from 2012. Micro seems better on every parameter, in particular in having a better (I think) microcontroller, ATMega32u4, over ATMega328P. </p> <p>However, all the shops I've checked out, both local and online, sell the Nano, and only some sell Micro. And Nano is always more expensive than Micro. E.g. at RS-Online 26GBP for Nano (<a href="http://uk.rs-online.com/web/p/processor-microcontroller-development-kits/6961667/" rel="noreferrer">link</a>) and 16GBP for Micro (<a href="http://uk.rs-online.com/web/p/processor-microcontroller-development-kits/7717667/" rel="noreferrer">link</a>).</p> <p>Why do many shops only sell the inferior product?</p> <p>Why is the older and less capable Nano more expensive? </p> <p>Why would anyone buy the Nano over the Micro? </p>
<p>I'd buy the NANO and STEER CLEAR of the micro with that 32u4 chip. The good ol' 328p chip also has a FTDI chip to handle USB to serial while the other chip handles it on its own. The problem is that the Micro's bootloader ONLY allows trying to program it with USB and requires a special driver. With Linux, only a few select versions have the needed driver. If your Linux version doesn't have the driver, you're out of luck. In that case, take it back or donate it to a hackerspace. You will NEVER make it work. </p> <p>I was at the arduino.cc site about this and tried everything only to get increasingly annoyed about that lemon of a card. You know it's time to give up when you get flamed. </p>
4482
|pins|
Arduino: How does digitalRead read a value? And what is this value?
2014-10-06T15:49:35.720
<p>I have a Arduino Uno with 14 digital pins. I believe they have an output of 5V. But they can also <em>input</em> values. I'm not sure of what exactly it reads when it does that (amperage, voltage ...). Also, <em>how</em> do they read it? How can such a tiny thing possibly know what it's receiving?</p> <p>Just to provide a little more context to the reading part of this question, here's an example circuit. I have a 5V battery connected to an LED and a 220 Ohm resistor. Next thing in the circuit is a wire, which exits the main circuit and connects to a digital pin on the Arduino Uno (here it reads the value). Then the main circuit closes by connecting to ground.</p> <p>Hope my question is clear enough :)</p>
<p>If somebody(like me) is looking for a explanation in terms of registers, the voltage at a pin when it's a digital input can be accessed with the <code>PINx</code> register, with a bit being used per a pin. Based on the value in the specific bit of the <code>DDRx</code> register, if it's <code>0</code> (an input), the voltage at the pin is represented by the bit in the <code>PINx</code>. When it's <code>1</code> (an output), the bit at the <code>PINx</code> register will be the value in the <code>PORTx</code> register for the specific bit(the value written). If the bit in the <code>DDRx</code> register for the pin is <code>0</code>(an input), the bit in the <code>PORTx</code> register represents whether the internal pull-up resistor should be connected to the pin. <code>x</code> is used to mark the port (<code>A</code>,<code>B</code>, for example).</p> <p>Edit: I've started working with the ATtiny10 for a specific, but most likely just-on-paper project. It has the separate <code>PUEx</code> register for the internal pull-ups. It has only 6 pins, with 4 or those being accessible as GPIOs. The pins have specific modes where every pin requires slightly different flag changes for changing the mode.</p>
4487
|c++|string|
Problems with substring loop
2014-10-06T18:59:57.557
<p>Hey folks … I was hoping some of you might cast your eye over my code.</p> <p>It splits up a string read from EEprom into an array of separate strings. Based on String length information stored in a separate array. (tempArray[])</p> <p>It reads fine … and also seems to process fine (ie. it does turn one long string into separate array items) for some reason it stops working no the 8th array item?</p> <p>The splitting code (problem) starts on line 80 and i have included the output above it in comments. </p> <p><a href="http://pastebin.com/Ax4R6t6J" rel="nofollow">http://pastebin.com/Ax4R6t6J</a> &lt;&lt; Full code also available here.</p> <pre><code>void reJigFromMemory(){ Serial.print("Eeprom read 1 :"); Serial.println(eepromReadOne); Serial.print("EEprom read 2 :"); Serial.println(eepromReadTwo); String tempArray[10]; int charLength=eepromReadOne.length()+1; char charBuff[charLength]; eepromReadOne.toCharArray(charBuff, charLength); //// GET MEMORY LOCATIONS /* converts long string of numbers: 13161717171717252533 into separate strings: 13 16 17 17 17 17 17 25 25 33 And stores them in an array. */ for (int i = 0; i &lt;10 ; i++){ tempArray[i]+=charBuff[i*2]; tempArray[i]+=charBuff[(i*2)+1]; Serial.print("I just translated :"); Serial.println(tempArray[i]); } /// GET THE STRINGS USING THE ABOVE ARRAYS /* converts long list of data ie: |0|Bingo#999#|1|Retest2#9222#|2|Retest3#92299#|3|Retest4#99339#|4|Retest5#95599#|5|Retest6#96699#|6|Retest7#99119#|7|User Defined eighth#0#|8|User Defined ninth #0#|9|User Defined tenth (last) .#0# into individual array strings: From Number = :0 To number : 13 Record 0 : |0|Bingo#999# From Number = :13 To number : 29 Record 1 : |1|Retest2#9222# From Number = :29 To number : 46 Record 2 : |2|Retest3#92299# From Number = :46 To number : 63 Record 3: |3|Retest4#99339# From Number = :63 To number : 80 Record 4: |4|Retest5#95599# From Number = :80 To number : 97 Record 5: |5|Retest6#96699# From Number = :97 To number : 114 Record 6 : |6|Retest7#99119# From Number = :114 To number : 139 Record 7 : &lt;&lt;&lt;&lt;&lt;&lt; THIS ONE IS MISSING ? WHY? From Number = :139 To number : 164 Record 8 : &lt;&lt;&lt;&lt;&lt;&lt; THIS ONE IS MISSING ? WHY? From Number = :164 To number : 197 Record 9 : &lt;&lt;&lt;&lt;&lt;&lt; THIS ONE IS MISSING ? WHY? */ String tempArray2[10]; int fromLocation = 0; int toLocation=0; for (int i = 0; i &lt;10 ; i++){ /////// LINE 80 toLocation += tempArray[i].toInt(); fromLocation += tempArray[i-1].toInt(); tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation); Serial.print("From Number = :"); Serial.println(fromLocation); Serial.print("To number : "); Serial.println(toLocation); Serial.print("I just translated :"); Serial.println(tempArray2[i]); } } </code></pre>
<p>Your 2nd for loop should look something like this:</p> <pre><code>int fromLocation = 0; int toLocation=0; for (int i = 0; i &lt;10 ; i++) { /////// LINE 80 toLocation += tempArray[i].toInt(); tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation); Serial.print("From Number = :"); Serial.println(fromLocation); Serial.print("To number : "); Serial.println(toLocation); Serial.print("I just translated :"); Serial.println(tempArray2[i]); fromLocation += tempArray[i].toInt(); } } </code></pre> <p>On the first pass through the loop, fromLocation is 0. toLocation starts at 0 and gets the value in tempArray2[0] added to it.</p> <p>After extracting a string, you add the current array value to fromLocation to advance the pointer to the beginning of the next string.</p> <p>Note that String objects are very inefficient way to save 2 digit numbers. It would be better use an array of ints, and write code that extracts 2 characters at a time into int values.</p> <p>With only 20 String objects it's not a huge deal, but bear in mind that String objects take a lot of memory overhead on a memory-starved platform like an Arduino. Better to learn how to use C strings.</p>
4491
|arduino-ide|bare-conductive|
Arduino Leonardo Upload issue with ubuntu 14.04
2014-09-29T19:12:51.873
<p>I got a bare conductive board ( which is based on arduino leonardo ) . I was trying to upload a blink sketch using arduion 1.5.7. But its always failing and here is the log. I never work a leonardo before. Any ideas what is happing with this ?</p> <pre><code>Build options changed, rebuilding all /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /tmp/build5447563659949358969.tmp/Blink.cpp -o /tmp/build5447563659949358969.tmp/Blink.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_analog.c -o /tmp/build5447563659949358969.tmp/wiring_analog.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_digital.c -o /tmp/build5447563659949358969.tmp/wiring_digital.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_shift.c -o /tmp/build5447563659949358969.tmp/wiring_shift.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WInterrupts.c -o /tmp/build5447563659949358969.tmp/WInterrupts.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/hooks.c -o /tmp/build5447563659949358969.tmp/hooks.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring_pulse.c -o /tmp/build5447563659949358969.tmp/wiring_pulse.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -c -g -Os -w -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/wiring.c -o /tmp/build5447563659949358969.tmp/wiring.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial3.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial3.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Tone.cpp -o /tmp/build5447563659949358969.tmp/Tone.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial1.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial1.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial2.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial2.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Print.cpp -o /tmp/build5447563659949358969.tmp/Print.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HID.cpp -o /tmp/build5447563659949358969.tmp/HID.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/USBCore.cpp -o /tmp/build5447563659949358969.tmp/USBCore.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/IPAddress.cpp -o /tmp/build5447563659949358969.tmp/IPAddress.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WMath.cpp -o /tmp/build5447563659949358969.tmp/WMath.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/WString.cpp -o /tmp/build5447563659949358969.tmp/WString.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/main.cpp -o /tmp/build5447563659949358969.tmp/main.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/HardwareSerial0.cpp -o /tmp/build5447563659949358969.tmp/HardwareSerial0.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/new.cpp -o /tmp/build5447563659949358969.tmp/new.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/Stream.cpp -o /tmp/build5447563659949358969.tmp/Stream.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -MMD -mmcu=atmega32u4 -DF_CPU=16000000L -DARDUINO=157 -DARDUINO_AVR_BARETOUCH -DARDUINO_ARCH_AVR -DUSB_VID=0x2A6E -DUSB_PID=0x8003 -DUSB_MANUFACTURER="Bare Conductive" -DUSB_PRODUCT="Touch Board" -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino -I/home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/variants/leonardo /home/achayan/Downloads/arduino-1.5.7/hardware/arduino/avr/cores/arduino/CDC.cpp -o /tmp/build5447563659949358969.tmp/CDC.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_analog.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_digital.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_shift.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WInterrupts.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/hooks.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring_pulse.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/wiring.c.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial3.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Tone.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial1.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial2.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Print.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HID.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/USBCore.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/IPAddress.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WMath.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/WString.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/main.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/HardwareSerial0.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/new.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/Stream.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-ar rcs /tmp/build5447563659949358969.tmp/core.a /tmp/build5447563659949358969.tmp/CDC.cpp.o /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-gcc -w -Os -Wl,--gc-sections -mmcu=atmega32u4 -o /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.o /tmp/build5447563659949358969.tmp/core.a -L/tmp/build5447563659949358969.tmp -lm /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-objcopy -O ihex -j .eeprom --set-section-flags=.eeprom=alloc,load --no-change-warnings --change-section-lma .eeprom=0 /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.eep /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avr-objcopy -O ihex -R .eeprom /tmp/build5447563659949358969.tmp/Blink.cpp.elf /tmp/build5447563659949358969.tmp/Blink.cpp.hex Sketch uses 4,798 bytes (16%) of program storage space. Maximum is 28,672 bytes. Global variables use 157 bytes (6%) of dynamic memory, leaving 2,403 bytes for local variables. Maximum is 2,560 bytes. Forcing reset using 1200bps open/close on port /dev/ttyACM0 PORTS {/dev/ttyACM0, } / {} =&gt; {} PORTS {} / {} =&gt; {} PORTS {} / {/dev/ttyACM0, } =&gt; {/dev/ttyACM0, } Found upload port: /dev/ttyACM0 /home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/bin/avrdude -C/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/etc/avrdude.conf -v -v -v -v -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -D -Uflash:w:/tmp/build5447563659949358969.tmp/Blink.cpp.hex:i avrdude: Version 6.0.1, compiled on Apr 3 2014 at 21:52:43 Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/ Copyright (c) 2007-2009 Joerg Wunsch System wide configuration file is "/home/achayan/Downloads/arduino-1.5.7/hardware/tools/avr/etc/avrdude.conf" User configuration file is "/root/.avrduderc" User configuration file does not exist or is not a regular file, skipping Using Port : /dev/ttyACM0 Using Programmer : avr109 Overriding Baud Rate : 57600 AVR Part : ATmega32U4 Chip Erase delay : 9000 us PAGEL : PD7 BS2 : PA0 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 9000 9000 0x00 0x00 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 0x00 0x00 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 9000 9000 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 9000 9000 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 9000 9000 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 9000 9000 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 : butterfly Description : Atmel AppNote AVR109 Boot Loader Connecting to programmer: .avrdude: Send: . [1b] avrdude: Send: S [53] avrdude: Recv: C [43] avrdude: ser_recv(): programmer is not responding avrdude: butterfly_recv(): programmer is not responding </code></pre> <p>And My dmesg output is</p> <pre><code>[ 3616.984079] usb 4-2: new full-speed USB device number 11 using uhci_hcd [ 3617.155216] usb 4-2: New USB device found, idVendor=2a6e, idProduct=8003 [ 3617.155224] usb 4-2: New USB device strings: Mfr=1, Product=2, SerialNumber=0 [ 3617.155229] usb 4-2: Product: Touch Board [ 3617.155234] usb 4-2: Manufacturer: Bare Conductive [ 3617.158323] cdc_acm 4-2:1.0: This device cannot do calls on its own. It is not a modem. [ 3617.158359] cdc_acm 4-2:1.0: ttyACM0: USB ACM device [ 3617.166427] input: Bare Conductive Touch Board as /devices/pci0000:00/0000:00:1a.1/usb4/4-2/4-2:1.2/input/input22 [ 3617.166675] hid-generic 0003:2A6E:8003.0007: input,hidraw1: USB HID v1.01 Mouse [Bare Conductive Touch Board] on usb-0000:00:1a.1-2/input2 </code></pre> <p>And My lsusb output</p> <pre><code>Bus 002 Device 002: ID 04f2:b179 Chicony Electronics Co., Ltd Bus 002 Device 004: ID 18d1:4ee2 Google Inc. Nexus 4 (debug) Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 008 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 007 Device 002: ID 03f0:171d Hewlett-Packard Bluetooth 2.0 Interface [Broadcom BCM2045] Bus 007 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 006 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 005 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 004 Device 011: ID 2a6e:8003 Bus 004 Device 002: ID 1d57:0008 Xenta Bus 004 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub Bus 003 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub </code></pre>
<p>Try the arduino.cc forums. Post your logs, and you MIGHT get an answer that'll work. The guys who developed the Leonardo got it to work with Ubuntu 10.04 without a special device driver. I use Ubuntu like you but not the magic 10.04 version and was forced to give up on the Leonardo despite heroic effort. </p> <p>The problem is that 32u4 chip the Leonardo (and Micro) use. Instead of having a separate FTDI chip like a good ol' UNO, it handles USB on its own. With a bootloader on a Leonardo that enables only USB to be used (besides ICSP) Windows needs a funny .inf file to make it work. But Linux? In this case, Windows of a given version is Windows is Windows. Linux boxes are more like people in that each has its own personality, given the zillion distributions and versions thereof. </p> <p>I'm convinced that the Leonardo developers merely got lucky with Ubuntu 10.04. </p>
4494
|motor|pwm|
PWM generation using Registers
2014-10-07T08:30:56.987
<p>I'm using the Registers of the Arduino micro to get a signal for Electronic Speed Controllers (ESC) for brushless motors. As far as I read, ESCs interpret everything they can, while just ignoring too fast update rates. If somebody knows better, this would be a great time to yell.</p> <p>The goal is to get a digital signal, where a timespan between 1 and 2 ms is HIGH and the rest low. Ideally I want this at 50-400Hz, since 488Hz is the fastest possible frequency, and 50 Hz the standard Servo frequency.</p> <p>I try to use Phase Correct Mode to count up and down continuously. As the value in the counter reaches my set OCRnx on the way up, it sets the output pin LOW, as it reaches the same value on the way down, after reaching TOP(value), it sets the output HIGH. In ATmega documentation terms, this is NON-inverted Phase-Correct-PWM.</p> <p>So I set the Registers DDR (to set the pin as output), TCCR1A and TCCR1B and ICR1 (TOPvalue = between 20000 and 2500).</p> <p>Now using OCR1A = 1000 should give me a pulse width of 1000ms. This is the expected or target behaviour.</p> <p>My testing code is:</p> <pre><code>// using a 16-bit timer to generate PWM signals for ESCs // Phase Correct Mode counts from Bottom to Top and back to Bottom // with a prescaler of 8 // motor signal (OCRnx) uses values of 1000 (idle) - 2000 (max) // which directly corresponds to microseconds HIGH-time // setting the range to (BOTTOM) 0 - TOPvalue sets the frequency // two important formulas are: // frequency(PWM) = F_CPU / (2*Prescalar*TOPvalue) // // PulseWidth [s] = High-tick-count / (F_CPU/Prescalar) // High-tick-count = 2 * OCR-value // n = number of timer (1,3) // x = A,B,C #include "Arduino.h" // #include &lt;Arduino.h&gt; // #define DEBUG // #include &lt;Moto.h&gt; #define PRESCALAR 8 #define PWM_FREQUENCY 50 #define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY) uint16_t dutytime = 1000; // this gives idle throttle signal void setup(void) { Serial.begin(115200); // moto.setup(); // TIMER 1 // TIMSK1 = 0; // disable Interrupts for timer1 DDRB |= (1&lt;&lt;DDB5); // D9 Output DDRC |= (1&lt;&lt;DDC6); // D5 Output // set 1000ms to start motors in idle mode OCR1A = 1000L; OCR3A = 1000L; // bits 7,5,3 PWM Output on pins A,B,C respectively // bits 1,0 WGM_1,0: phase correction mode // TCCR1A |= B10000010; // in hex: 0xAA for all 3 = B 1010 1010 TCCR1A |= (1&lt;&lt;COM1A1)|(1&lt;&lt;WGM11); // bit 4,3 WGM_3,2: phase correction mode // bits 2,1,0 Prescalar: 8 // TCCR1B |= B00010010; // in hex: 0x12; B 0001 0010 TCCR1B |= (1&lt;&lt;WGM13)|(1&lt;&lt;CS11); ICR1 = TOP_VALUE; // TIMER 3 // TIMSK3 = 0; // disable Interrupts for timer3 // bit 7 PWM Output on pin A // bits 1,0 WGM_1,0: phase correction mode TCCR3A |= B10000010; // in hex: 0x82; // B 1000 0010 // bit 4,3 WGM_3,2: phase correction mode // bits 2,1,0 Prescalar: 8 TCCR3B |= B00010010; // in hex: 0x12; B 0001 0010 ICR3 = TOP_VALUE; // TOPvalue = 2048 }//setup void loop(void) { // Serial.println(TOP_VALUE); // delay(500); while (dutytime &lt; 2000) { dutytime += 150; OCR1A = dutytime; OCR3A = dutytime; Serial.println(dutytime); delay(1500); } while (dutytime &gt; 1000) { dutytime -= 150; OCR1A = dutytime; OCR3A = dutytime; Serial.println(dutytime); delay(1500); } }//loop </code></pre> <p>I repeated the settings for timer3 to get something to compare to. Both do give the same: if i delete the loop and just write <code>loop{}</code> nothing happens. The pins are high and seem to stay so. With the while loops activated, my multimeter gives me 1Hz (which are the changes of course) and between 99.9% duty cycle and 96%. An led, which i connected to it blinks every second a very short time.</p> <p>What am I doing wrong?</p>
<p>What I did wrong was using <code>|=</code> instead of <code>=</code> . Apparently Arduino set some of these Bits on start, which didn't change. Now it works like a charm and I added a frequency choice, which works for at least 50,200,400,488 Hz. Everything in between should work aswell!</p> <p>Working testcode for timer1 with serial input of HIGH-time:</p> <pre><code>#define PRESCALAR 8 #define PWM_FREQUENCY 50 #define TOP_VALUE F_CPU/(2*PRESCALAR*PWM_FREQUENCY) uint16_t dutytime = 1000; // this gives idle throttle signal void setup(void) { Serial.begin(115200); // TIMER 1 DDRB |= (1&lt;&lt;DDB5); // D9 Output // set 1000ms to start motors in idle mode OCR1A = 1000L; // bits 7,5,3 PWM Output on pins A,B,C respectively (COMnx1) // bits 1,0 WGM1(1,0): phase correction mode TCCR1A = B10000010; // in hex: 0xAA for all 3 = B 1010 1010 // bit 4,3 WGM_3,2: phase correction mode // bits 2,1,0 Prescalar: 8 TCCR1B = B00010010; // in hex: 0x12; B 0001 0010 ICR1 = TOP_VALUE; }//setup void loop(void) { // Serial.println(TOP_VALUE); dutytime = serial_input(); if (dutytime) { OCR1A = dutytime; } delay(500); }//loop float serial_input() { double num = 0; while(Serial.available()) { delay(2); char ser = Serial.read(); if(isDigit(ser)) { num = (num*10)+(ser-48); }else{ break; } } if (num) {Serial.println(num);} return num; } </code></pre>
4500
|arduino-uno|sd-card|
Arduino can't create file in sd card
2014-10-07T19:44:31.993
<p>I need to write and read some data from SD card. I link SD card(LC STUDIO) to Arduino (UNO). I use <a href="http://www.instructables.com/id/Arduino-DIY-SD-Card-Logging-Shield/?ALLSTEPS" rel="nofollow">this link</a> for create my project. In first day I don't have any problem and data correctly save to file. But now my circuit isn't work nicely. When Arduino is running the sketch I don't saw any error message.But when I link the SD card to my laptop, I don't saw any file on card!! The code is here:</p> <pre><code>#include &lt;SPI.h&gt; #include &lt;SD.h&gt; const int chipSelect = 10; File file; void setup() { Serial.begin(9600); while (!Serial) { ; } Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println("Card failed, or not present"); } Serial.println("card initialized."); //creating file file = SD.open("test.txt",FILE_WRITE); file.close(); //write data to file file = SD.open("test.txt",FILE_WRITE); if(file){ file.println("OK!!"); file.println("1"); file.println("2"); file.println("3"); file.println("OK!!"); file.close(); } } void loop() { } </code></pre>
<p>Thank you all... I found solution for my problem. The circuit and the sketch isn't any problem. But I saw <a href="http://forum.arduino.cc/index.php?topic=122947.0" rel="nofollow">this</a> and I think problem is because of LC Studio's SD card. In previous circuit I connect 5v pin of SD card to 5v pin on arduino. But now I disconnect that and connect 3v3 pin on card to 3v3 on arduino. Now it's work very nice. And I don't know "why?" . Any idea? </p>
4505
|debugging|
Debugger for Code::Blocks + Arduino
2014-10-08T01:09:12.847
<p>I am not very experienced in this, but I was wondering if Code::Blocks has a way of getting a debugger that runs for Arduino chips, specifically. I understand there is Arduino IDE for but does it allow debugging specific to those microcontrollers (Amtel and such)?</p>
<p>If you are interested in on-board debugging or off-board debugging, you will need a programmer/debugger. I would recommend the Atmel <a href="http://www.atmel.com/tools/avrdragon.aspx" rel="nofollow noreferrer">AVR Dragon</a>. Atmel AVR Dragon uses the Atmel Studio 6.2, which is a great IDE.</p> <p><img src="https://i.stack.imgur.com/AXFgx.gif" alt="AVR Dragon"></p>