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
6690
|programming|c++|variables|progmem|avr-gcc|
What are the benfits of global variables over static class members?
2014-12-25T21:50:25.157
<p>On an embedded system we use global variables often to keep dynamic memory consumption on heap and stack low. But global variables are also considered bad programming practice if they aren't used in a global sense, i.e. they are used only inside one or two functions.</p> <p>So I really want to make use of the possibilites to protect my code from myself. Of course, the instantiation mechanism of c++ is to avoid on an embedded system with low resources, like an arduino. So I write classes with static members (and member functions) only. Many of the libraries shipped with arduino seem to work this way, too. </p> <p>I'm curious if there's a single drawback of moving static variables or even const arrays (designed for deposit in progmem) from global namespace to a class namespace and making them private? </p> <p>I'm primarily interested in drawbacks arising from the combination of OOP with the arduino platform (using an arduino uno) with avr-gcc. </p>
<p>I can see no specific drawback in using static class members instead of global variables on Arduino. They will be managed the same in the end program.</p> <p>The only difference I can see may arise based on how you design your classes (if design is correct, then no special problem shall arise):</p> <p>Let's suppose you decale a class A:</p> <pre><code>class A { public: void f(); void g(); ... static void z(); private: static int myStaticField; ... }; </code></pre> <p>if you need an instance of <code>A</code> for method <code>f()</code>, which does not need <code>myStaticField</code>, then that field exists anyway in your SRAM space.</p> <p>But this is a corner-case, as in good OOD, <code>myStaticField</code> should be needed as soon as you need to work with class A (whatever method youwant to use).</p>
6696
|arduino-uno|sensors|
Photoresistor is not working, is there something wrong in the code?
2014-12-26T11:18:28.207
<p>I am trying to make the photoresistor work in a simple project. </p> <p>The project is as follows: The LED light should light up brighter and brighter as the photoresistor reads less light in the room.</p> <p>The problem: The reading is fixed on 1023. Therefore the LED never lights up. I cannot understand why.. Sometimes if I cover the sensor the readings go down to 900- 950 but never less even though it is completely dark around the sensor. Is there something wrong in the code? What could have gone wrong? Please note that the resistor connected to the sensor is 10k Ohm as is the one connected to the LED.</p> <p>Here is the code</p> <pre><code>int photoPin = 0; int pReading; // analog readings int LED = 11; // red LED connected to pin 11 int LEDbrightness; // void setup() { //set up the serial connection Serial.begin(9600); } void loop() { pReading = analogRead(photoPin); Serial.print("Photocell reading = "); Serial.println(pReading); // Analog reading pReading = 1023 - pReading; //map 0-1023 to 0-255 LEDbrightness = map(pReading, 0, 1023, 0, 255); analogWrite(LED, LEDbrightness); delay(50); } </code></pre> <p>Here are the connections <img src="https://i.stack.imgur.com/cQpgX.jpg" alt="enter image description here"></p> <p>thank you!</p>
<p>The code looks OK. It looks like it's your circuit which is the problem.</p> <p>The main role of a photoresistor is to restrict the amount of <strong>current</strong> flowing through it when the light level is reduced. It won't directly affect voltage the way you're expecting (the analog pins respond to voltage).</p> <p>However, it's pretty easy to make it affect voltage with a slightly different circuit. Try creating a <strong>voltage divider</strong> circuit, such that the supply voltage (5V) goes through the photoresistor, then through another resistor, and then to ground. The Arduino's analog pin should be connected between the photoresistor and resistor. (See the image below, although the resistor on the output probably isn't necessary in this case.)</p> <p>This should cause the voltage on the analog pin to decrease when the light level decreases. You may need to experiment a little to find a suitable resistor value on the ground connection, although 2K Ohms is probably a good starting point. It basically affects the sensitivity of the circuit.</p> <p><img src="https://i.stack.imgur.com/GpQSC.jpg" alt="Photoresistor circuit diagram"> <sub>Image credit: Morteza Lahijanian (<a href="http://www.bu.edu/gk12/morteza/lesson3.html" rel="noreferrer">source</a>)</sub></p>
6697
|arduino-uno|arduino-yun|rfid|
Arduino Yun RFID-RC522 module not working
2014-12-26T11:34:31.170
<p>I have tried to use Arduino Uno with RFID-RC522 module. It is good work[1] and read rfid cards. But Arduino Yun doesn't work with RFID-RC522 module.</p> <p>What is diffrent Uno and Yun?</p> <p>1- <a href="http://www.grantgibson.co.uk/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/" rel="nofollow">http://www.grantgibson.co.uk/2012/04/how-to-get-started-with-the-mifare-mf522-an-and-arduino/</a></p>
<p>I had the same issues Thanks for help .However I made the following connections then above mentioned </p> <p>RC522 RFID borad Arduino YUN (as per the github example code dumpinfo) chip select (nss ) - Pin 10 Rst - Pin 9</p> <p>Link for Gihub RFID RC522 Hope it helps someone who is stuck</p>
6707
|arduino-uno|gsm|gps|
Arduino UNO GPS module
2014-12-26T17:53:50.320
<p>I am thinking about buying a gps module for Arduino UNO.</p> <p>I would like to install it on a self-build RC-car which is also controlled by Arduino. The problem is, I cannot install the gps module on the top of the car (on the surface), only the bottom and or/middle space is "free". My questions are:</p> <p>1)Is there a module which can overcome a small layer of steel (max 2cm thick) and some plastic and still get a good signal?</p> <p>2)It would be nice to be able to store the data into a memory card.</p> <p>3)It would be a great plus to be able to gather data real-time through some kind of connection. Sadly I do not know how to do here. Is there some place where I can look up any of this?</p> <p>Do you think that this <a href="http://www.adafruit.com/products/1272" rel="nofollow">http://www.adafruit.com/products/1272</a> is what I need?</p> <p>thank you</p>
<p>1) Just break out the headers on the GPS module to make for connections to the UNO.</p> <p>2) Add a SD expansion slot on top of the GPS Module and break out the pins for those as the required pins for those as well.</p> <p>3) I am not sure what you are asking exactly, but it seems to me that you want to analyze the data real-time. Get a network shield and make sure you can SSH into it through another computer.</p> <p>Note: When I say "break out the pins", I am simply saying either solder on some extra headers, or wires.</p>
6712
|serial|attiny|softwareserial|
Is SoftwareSerial left out for the ATTiny85/84?
2014-12-27T08:55:41.453
<p>I want to use SoftwareSerial with my ATTiny85 and when I google it several projects claim that they are using it... I downloaded the hardware from <a href="https://code.google.com/p/arduino-tiny/">https://code.google.com/p/arduino-tiny/</a>, but when I try to add SoftwareSerial and compile I get:</p> <pre><code>fatal error: SoftwareSerial.h: No such file or directory </code></pre> <p>Switching the board to UNO makes the problem go away, so did they leave it out? How can I fix this?</p>
<p>Below you can find the code for a minimal bit-bang send serial implementation ideally suited for debugging. Code size is about 60 bytes.</p> <p>It gives 38400 baud for 1 MHz or 230400 baud on 8 MHz Attiny clock.</p> <p>I wrote it for an Attiny 85.</p> <p><a href="https://github.com/ArminJo/AttinySendSerial_1Mhz_38400Bd" rel="nofollow noreferrer">ArminJo/AttinySendSerial_1Mhz_38400Bd</a></p>
6714
|serial|voltage-level|analogread|
5 Switches 1 AI pin
2014-12-27T12:11:19.427
<p>Im starting to get into Arduino a little. Ive got a Small project to start me off, To keep it simple its: 5 level Switches, 1 flow switch and 3 solenoid valves.</p> <p>This question is for the Level Switches.</p> <p>Now Im wanting to save Pins as I'm using a Arduino UNO. So would I be right to use the method ive seen around here a few times of Making a Resistance ladder.</p> <p>Question is. 1- Will the method of using the same value of resistors (2k2) work? I dont think so..</p> <p>As multiple "buttons" ie the flot switches will be pressed at once it will end up having no idea whats happening correct?, I need to be able to Identify each one (0%,25% etc etc)</p> <p>If I was to use different vales of resistance would that make a difference ?</p> <p>Cheers</p>
<p>Just look at <a href="https://electronics.stackexchange.com/a/99419">this answer</a>. When you press the LEFT switch, the SELECT button has no effect when pressed (i.e. it doesn't get detected, but also doesn't hinder detecting the LEFT button press). So in your case, you aren't really interested in the 0% button, when the 25% is pressed.</p> <p>I wouldn't use same value resistors, as the resulting voltages would be non-linear, making it difficult to differentiate between the button at the far end ladder. If you'd use 2k2 everywhere, the voltages would be</p> <ul> <li>100% 0.00v</li> <li>75% 2.50v</li> <li>50% 3.33v</li> <li>25% 3.75v</li> <li>0% 4.00v</li> <li>no value: 5v</li> </ul> <p>In the answer provided above, voltages would be: 0, 0.71, 1.61, 2.47, 3.62, 5v</p>
6715
|arduino-pro-mini|audio|
Audio Frequency White Noise generation using Arduino Mini Pro
2014-12-27T12:26:25.227
<p>For DIY, how to program Arduino Mini Pro to act as an <strong>Audio Frequency White Noise generator</strong>?</p> <p>Presumably, </p> <p>a) using one Digital Output pin </p> <p>b) feed to a simple passive RC low pass filter to reduce out of band signal </p> <p>c) feed to a simple class-D IC chip audio amplifier and speaker </p> <p>d) since it is DIY and noise, lo-fi (not hi-fi) is good enough. </p> <p>Specific questions,</p> <p>a) How to program? </p> <p>b) Wonder if it is better to use to chip act a Pulse Width Modulated 'digital to analogue converter'?</p> <p>c) How to calculate value for RC filter (assume amplifier has high input impedance)?</p> <p>Many years ago, I have programmed a hardware sound generator chip as part of a game machine. It has two registers for amplitude and 'frequency' control (band of 'white' noise). It worked very well. I once looked at the output using oscilloscope and it was square wave. I believe that it works, basically, using the above principles. Since I do not have the chip now, I cannot verify it. Now, I would like to duplicate its function using Arduino in software.</p>
<p>Mike's answer uses a Fibonacci Linear Feedback Shift Register configuration, but the compactness Galois Linear Feedback Shift Register Configuration could be faster:</p> <pre><code>#define speakerPin 8 unsigned long lastClick; void setup() { // put your setup code here, to run once: pinMode(speakerPin,OUTPUT); lastClick = micros(); } /* initialize with any 32 bit non-zero unsigned long value. */ #define LFSR_INIT 0xfeedfaceUL /* Choose bits 32, 30, 26, 24 from http://arduino.stackexchange.com/a/6725/6628 * or 32, 22, 2, 1 from * http://www.xilinx.com/support/documentation/application_notes/xapp052.pdf * or bits 32, 16, 3,2 or 0x80010006UL per http://users.ece.cmu.edu/~koopman/lfsr/index.html * and http://users.ece.cmu.edu/~koopman/lfsr/32.dat.gz * or generate a one with https://github.com/hayguen/mlpolygen */ #define LFSR_MASK ((unsigned long)( 1UL&lt;&lt;31 | 1UL &lt;&lt;15 | 1UL &lt;&lt;2 | 1UL &lt;&lt;1 )) unsigned int generateNoise(){ // See https://en.wikipedia.org/wiki/Linear_feedback_shift_register#Galois_LFSRs static unsigned long int lfsr = LFSR_INIT; /* 32 bit init, nonzero */ /* If the output bit is 1, apply toggle mask. * The value has 1 at bits corresponding * to taps, 0 elsewhere. */ if(lfsr &amp; 1) { lfsr = (lfsr &gt;&gt;1) ^ LFSR_MASK ; return(1);} else { lfsr &gt;&gt;= 1; return(0);} } void loop() { /* ... */ if ((micros() - lastClick) &gt; 50 ) { // Changing this value changes the frequency. lastClick = micros(); digitalWrite (speakerPin, generateNoise()); } } </code></pre> <p>For a 16 bit implementation (faster, but only a cycle of 2^16) try:</p> <pre><code>#define LFSR_MASK 0x8016 static uint16_t lfsr = LFSR_INIT; /* 16 bit init, nonzero */ </code></pre> <p>Written in a more compact form:</p> <pre><code>#define speakerPin 8 #define LFSR_INIT 0xfeed /* non-zero seed value for generateNoise() */ #define LFSR_MASK 0x8016 /* magic number from http://users.ece.cmu.edu/~koopman/lfsr/ */ unsigned long lastClick; void setup() { // put your setup code here, to run once: pinMode(speakerPin,OUTPUT); lastClick = micros(); } unsigned int generateNoise(){ // Return 1 bit of noise using a Galois Linear Feedback Shift Register // See https://en.wikipedia.org/wiki/Linear_feedback_shift_register#Galois_LFSRs static uint16_t lfsr = LFSR_INIT; if(lfsr &amp; 1) { lfsr = (lfsr &gt;&gt;1) ^ LFSR_MASK ; return(1);} else { lfsr &gt;&gt;= 1; return(0);} } void loop() { /* ... */ if ((micros() - lastClick) &gt; 50 ) { // Changing this value changes the frequency. lastClick = micros(); digitalWrite (speakerPin, generateNoise()); } } </code></pre> <p>For an 8 bit implementation (faster than 32 bit, slightly slower than 16, but only a cycle of 2^8) try:</p> <pre><code>#define LFSR_MASK 0x8e static byte lfsr = LFSR_INIT; /* 8 bit init, nonzero */ </code></pre> <p>Where the mask constants are from the 8.txt and 16.txt files at <a href="http://users.ece.cmu.edu/%7Ekoopman/lfsr/index.html" rel="nofollow noreferrer">http://users.ece.cmu.edu/~koopman/lfsr/index.html</a></p> <p>The <a href="https://github.com/hayguen/mlpolygen" rel="nofollow noreferrer">https://github.com/hayguen/mlpolygen</a> program can search for maximum length feedback polynomials of various bit sizes.</p>
6716
|serial|
too few arguments to function 'void setColor(int, int, int)'
2014-12-27T14:44:08.337
<p>When I put "c" inside <code>setColor(c);</code></p> <p>it tells me:</p> <pre><code>error: too few arguments to function 'void setColor(int, int, int)'. </code></pre> <p>I understand that I should put 3 arguments. What I don't understand is that the serial is correctly displaying the 3 arguments (255, 000, 000) so why it keeps telling me this error. What am I doing wrong ?</p> <pre><code>int rPin = 11; int gPin = 9; int bPin = 10; void setup() { Serial.begin(9600); pinMode(rPin, OUTPUT); pinMode(gPin, OUTPUT); pinMode(bPin, OUTPUT); } void loop() { if (Serial.available() &gt; 0) { delay(100); while (Serial.available() &gt; 0) { char c = Serial.read(); // serial will display an rgb code, for exemple: 255, 000, 000 (red color) setColor(c); } } } void setColor(int red, int green, int blue) { analogWrite(rPin, red); analogWrite(gPin, green); analogWrite(bPin, blue); } </code></pre>
<p>In the context of C/C++, the type <code>char</code> refers to a primitive type that can contain exactly one byte of information, or 8 bits if you like.</p> <blockquote> <p>the serial is correctly displaying the 3 arguments (255, 000, 000) </p> </blockquote> <p>In your question, you do not specify how you verify that this is indeed the information that returns from Serial.read. <a href="http://arduino.cc/en/Serial/read" rel="nofollow">Serial.read</a> returns one byte, which can be cast or parsed to an Integer but cannot be interpreted as the triplet (255,000,000) in no way. If you keep calling it repeatedly, however, as long as there is data (meaning that the result is greater than -1 or <code>Serial.available</code> returns a number greater than 0) - you can accumulate the characters to a meaningful string, which you can later split to three different <code>int</code> values. For example:</p> <pre><code>String incomingData = ""; void loop() { if (Serial.available() &gt; 0) { delay(100); while (Serial.available() &gt; 0) { char c = Serial.read(); incomingData.concat(c); } // now, the string incomingData will contain "255,000,000" which you can split into 3 different integers and send to setColor. // so, assuming the format "ddd,ddd,ddd": int color1 = incomingData.substring(0,3).toInt(); int color2 = incomingData.substring(4,7).toInt(); int color3 = incomingData.substring(8).toInt(); setColor(color1, color2, color3); } } </code></pre>
6728
|motor|current|
Discrete H-Bridge very low current output
2014-12-28T06:23:29.607
<p>I have built two parallel H-bridges from "Design 1" <a href="http://www.talkingelectronics.com/projects/H-Bridge/H-Bridge-1.html" rel="nofollow noreferrer">on this page</a> as you can see in the attached schematic.</p> <p>However when I apply the external power (VCC1 in the center of the diagram) the two motors do not spin.</p> <p>Using my multimeter, I can see that the entire circuit is working: the motor is getting a 'forward' and 'backward' current as the Arduino sets the pins high. The multimeter is reading +/- 5.54V with the motor replaced by the multimeter. (Across the motor this drops to 0.13V)</p> <p>So then I measure the current by putting my multimeter both in series with the motors and replacing the motors. There's only 40mA available! Looking around the web I found the suggestion to reduce the 220Ω resistors at R2, R3, R5 and R6. So I switched in (randomly) 27Ω resistors and the output current is still only 40mA.</p> <p>What else should I try to bring up the current enough to drive the motors?</p> <p><strong>Edit:</strong> So my uneducated guess is that it's likely that the limitation is coming from the transistors. The Ns are BC549 and the Ps are BC559. The datasheets list "low current" as a feature, but I figured that was the collector.</p> <p><strong>Edit 2:</strong> The motor is <a href="http://www.icstation.com/product_info.php?products_id=2535" rel="nofollow noreferrer">this one</a> which requires 70mA when running (and presumably more during startup)</p> <p><img src="https://i.stack.imgur.com/A3TDL.png" alt="Schematic of two H-bridges controlled by Arduino"></p> <p><strong>Edit 3:</strong> Code driving the Arduino: </p> <pre><code>// Pin setup int pinLeftMotorFwd = 5; int pinLeftMotorBck = 6; int pinRightMotorFwd = 10; int pinRightMotorBck = 11; // Directions for the {left, right} motors to achieve the four directions int FORWARD[] = { 1, 1 }; int BACKWARD[] = { -1, -1 }; int RIGHT[] = { -1, 1 }; int LEFT[] = { 1, -1 }; void setup() { Serial.begin(9600); pinMode(pinLeftMotorFwd, OUTPUT); pinMode(pinLeftMotorBck, OUTPUT); pinMode(pinRightMotorFwd, OUTPUT); pinMode(pinRightMotorBck, OUTPUT); } void loop() { go( FORWARD, 10 ); go( RIGHT, 3 ); go( FORWARD, 10 ); go( LEFT, 6 ); } // Move the bot in a particular direction from the array above for a given number of seconds void go ( int dir[], int dur ){ leftMotor( dir[0] ); rightMotor( dir[1] ); delay( dur * 1000 ); } // Sill both motors (OK, so stop both motors. But stop is a keyword in C) void still(){ leftMotor( 0 ); rightMotor( 0 ); } // Set the left motor to Backward (-1), Forward (1), or Stop (0) void leftMotor( int dir ){ // Pull both pins low digitalWrite(pinLeftMotorFwd, LOW ); Serial.println("pinLeftMotorFwd LOW"); digitalWrite(pinLeftMotorBck, LOW ); Serial.println("pinLeftMotorBck LOW"); // If we're going forward, pull the Fwd pin high if( dir == 1 ){ digitalWrite(pinLeftMotorFwd, HIGH); Serial.println("pinLeftMotorFwd HIGH"); } // otherwise, pull the Bck pin high else if( dir == -1 ) { digitalWrite(pinLeftMotorBck, HIGH); Serial.println("pinLeftMotorBck HIGH"); } } // Set the right motor to Backward (-1), Forward (1), or Stop (0) void rightMotor( int dir ){ // Pull both pins low digitalWrite(pinRightMotorFwd, LOW ); Serial.println("pinRightMotorFwd LOW"); digitalWrite(pinRightMotorBck, LOW ); Serial.println("pinRightMotorBck LOW"); // If we're going forward, pull the Fwd pin high if( dir == 1 ){ digitalWrite(pinRightMotorFwd, HIGH); Serial.println("pinRightMotorFwd HIGH"); } // otherwise, pull the Bck pin high else if( dir == -1 ) { digitalWrite(pinRightMotorBck, HIGH); Serial.println("pinRightMotorBck HIGH"); } } </code></pre>
<p>Design 1 wouldn't be my first thought on how to do this either! The transistors aren't a great choice, but are cheap &amp; common.</p> <p>The layout <a href="http://www.robotroom.com/BipolarHBridge.html" rel="nofollow">here</a> is more conventional, and you can physically link 1-2, &amp; 3-4 to connect to your arduino without the risk of short circuits.</p> <p>I suspect your code may be setting both lines high together - the only advantage I can see to the posted circuit is that this does not necessarily cause smoke (but may well do as you describe). This is why posting the code is recommended!</p>
6741
|library|wire-library|
Compilation error when trying to give pointer to a function to another function
2014-12-28T17:03:47.590
<p>I'm trying to write a library for Arduino using the Wire library. Here's my code:</p> <p>PiCom.h:</p> <pre><code>#ifndef PiCom_h #define PiCom_h #include "Arduino.h" #include &lt;Wire.h&gt; class PiCom { public: PiCom(int address, int* integers[], double* doubles[]); static void onReceiveCallback(int numbytes); static void onRequestCallback(); private: //Actually arrays of pointers to the data to be sent, has to be declared that way cause the size of the array isn't known at compile time int** _integers; double** _doubles; void onReceive(int numbytes); void onRequest(); static PiCom instance; }; #endif </code></pre> <p>PiCom.cpp:</p> <pre><code>#include "Arduino.h" #include "PiCom.h" static void onReceiveCallback(int numbytes) { } PiCom::PiCom(int address, int* integers[], double* doubles[]) { _integers = integers; _doubles = doubles; Wire.begin(address); void (*receiveFunction) (int); receiveFunction = &amp;PiCom::onReceiveCallback; Wire.onReceive(receiveFunction);//Here i get an error } </code></pre> <p>I want the constructor to be created when a new instance is created. A mehtod in this object should be called when data is requested or received. When trying to pass onRequest(int) directly to Wire.onRequest(void (*) (int)) an error is thrown. Same happend when saving it to receiveFunction.</p> <p>This problem was solved by using a static function (onReceiveCallback(int). I wanted this static function to call onRequest(int) in the object saved into PiCom::instance.</p> <p>But now i'm getting another error:</p> <pre><code>PiCom\PiCom.cpp.o: In function `PiCom': C:\Program Files\Arduino\libraries\PiCom/PiCom.cpp:26: undefined reference to `PiCom::onReceiveCallback(int)' C:\Program Files\Arduino\libraries\PiCom/PiCom.cpp:26: undefined reference to `PiCom::onReceiveCallback(int)' </code></pre>
<p>Pointer to a member function is <a href="http://sphaleron.blogspot.co.il/2012/01/evil-c-5-member-function-pointer.html" rel="nofollow">a painful corner of C++</a> until C++11. This is why when you try to pass an instance method pointer to <code>Wire.onReceive</code> (without the <code>static</code> keyword), you will get an error similar to:</p> <pre><code>error: ISO C++ forbids taking the address of a bound member function to form a pointer to member function. Say '&amp;PiCom::onReceiveCallback' </code></pre> <p>Well, you can't argue with the C++ ISO standard... changing the function to a static one (with external linkage, as they say) is indeed a workaround, as you have found out. For this workaround to compile properly you just need to omit the <code>static</code> keyword from your <strong>definition</strong> (where it is implemented), and leave your <strong>declaration</strong> (in the header file) as is:</p> <p>PiCom.h:</p> <pre><code>... static void onReceiveCallback(int numbytes); ... </code></pre> <p>PiCom.cpp:</p> <pre><code>void PiCom::onReceiveCallback(int numbytes) { ... } </code></pre> <p>By doing this you can pass it to Wire.onReceive without any problem, from the PiCom constructor, as follows:</p> <pre><code>PiCom::PiCom(int address, int* integers[], double* doubles[]) { ... Wire.onReceive(&amp;PiCom::onReceiveCallback); ... } </code></pre>
6750
|gps|
Data Report Which Technology
2014-12-29T10:20:10.033
<p>I want to create a small position reporter for cars. I found some good GPS Modules with which i could collect data. But i'm unsure with what technology i should send the data.</p> <p>A possibility would be to setup a service in the www which is feeded by the arduinos.</p> <p>I want to track the data live. so i think GPRS should be the right choice ? Or more better are there any shields which make this GPRS LOG and SEND as a package ? </p> <p>Which GPRS hardware would you use ? Would you use something else?</p> <p>Any hints are very welcome</p>
<p>You can actually find all the information for what you want to do on the formal Arduino.cc website. <a href="http://arduino.cc/en/Main/ArduinoGSMShield" rel="nofollow noreferrer">They suggest a GSM shield</a>:</p> <p><img src="https://i.stack.imgur.com/Fncge.jpg" alt="enter image description here"></p> <p>But of course you can find many other GSM shields for purchase. Most of them works the same. Arduino.cc also offer a <a href="http://arduino.cc/en/Reference/GSM" rel="nofollow noreferrer">nice GSM Library</a>, with which you <a href="http://arduino.cc/en/Tutorial/GSMExamplesWebClient" rel="nofollow noreferrer">can perform HTTP GET/POST</a> queries to a remote webserver (visible over the web).</p> <p>You can select whatever web server technology you prefer for receiving the data. Using NodeJS, PHP, MVC.NET or any other, you could expose a REST API to perform the update from the Arduino+GSM Shield side using HTTP. </p> <p>The web server then could analyze the incoming data and display it in any way you like.</p>
6752
|arduino-uno|motor|arduino-motor-shield|
Arduino motor shield will only work in one direction
2014-12-29T12:54:58.010
<p>I have this Arduino <a href="http://www.ebay.com/itm/161276647817" rel="nofollow noreferrer">motor shield</a> which is hooked up with two DC motors. The board is the same <a href="https://learn.sparkfun.com/tutorials/ardumoto-shield-hookup-guide" rel="nofollow noreferrer">as this one</a> from Sparkfun.</p> <p>A PWM output controls the speed of the motor, and a digital out controls the direction. The problem is that it only works in one direction, namely if the direction pin is high.</p> <p>With the direction pin HIGH and 255 is written to the PWM pin, Vout on the terminals is similar to Vin. If I reverse the direction by setting the direction pin LOW I would expect Vout to be -Vin, ie. the polarity reversed. But not so. I get a little more than zero volt across the terminals.</p> <p>It's the same for both channels.</p> <p><strong>Edit: The setup is powered from a 9V power adaptor through the barrel jack on Arduino.</strong></p> <p><img src="https://i.stack.imgur.com/EznN2.jpg" alt="Photo of the DC motor connected to the driver board"></p> <p>Is the board defective, or am I misunderstanding something?</p> <p>SOLUTION: Thanks to the edited post (especially #3) in the accepted answer, I not only looked at the schematic (again), I actually understood it. I had already noticed the jumper called V-LOGIC which on the picture from Sparkfun was set to 5V where it on my shield was not set. I really didn't know what it was used for, but I set it to 5V so it was the same. But by looking at the schematic and the inverters, I realized that the inverter was fed from V-LOGIC which was connected to 5V. And bingo: I had not connected the 5V pin on the shield, only vIN which I assumed would be sufficient. The thing is, I am awaiting a set of stackable headers instead of the ones supplied, so I only connected the minimum numbers of pins because I will need to desolder them when I get the new headers.</p>
<p>I think you may be having an issue with how you are powering the shield. Are you trying to do it with just your USB connection?</p> <p>In your photo, I do not see a connection to your Arduino's barrel jack or to the Vin connector of the shield itself. According to the <a href="https://learn.sparkfun.com/tutorials/ardumoto-shield-hookup-guide" rel="nofollow">SparkFun</a> site:</p> <blockquote> <p>The Ardumoto Shield should be powered through one of two power supply inputs. Pick one or the other:</p> <ol> <li>The <strong>barrel jack</strong> input on the Arduino.</li> <li>The <strong>Vin input</strong> on the shield</li> </ol> <p>If you don’t want to use the Arduino’s barrel jack input, you can use the <strong>Vin input on the shield</strong> instead. This voltage input will supply <strong>both the shield and the Arduino</strong>. Like the motor outputs, this connection is broken out to both a 3.5mm screw terminal and a 0.1"-pitch header.</p> <p>Do not supply power to both the Arduino barrel jack input and Vin on the shield!</p> </blockquote> <p>I hope this helps!</p> <p><strong>EDIT BASED ON COMMENTS</strong><br> Since you are properly powering the shield, I would recommend the following (see the <a href="https://www.sparkfun.com/datasheets/DevTools/Arduino/Ardumoto_v13.pdf?_ga=1.206814291.1113379437.1408059991" rel="nofollow">shield's schematic</a> for specifics):</p> <ol> <li>Maintaining the connection shown above (with the addition of the 9V power supply connected to the barrel jack) ensure that you are able to properly set the DIRA input. You can check this with a multimeter on pin 7 of the LN298 whenever you are trying to switch directions. </li> <li>If you are getting the expected results on pin 7 (pin goes HI when your code wants the motor to go one direction and pin goes LOW for the other) - check pin 9... the value here should always be the opposite of what you are setting for DIRA on pin 7. If that is all good, then you probably have an issue with the LN298. </li> <li>If you are not getting the expected results at pin 9, but pin 7 looks good, then you are having a problem with the 74HC1G04 IC (although I would doubt this since you are having problems with both the A and B motor outputs).</li> <li>If you are not getting the expected results at pin 7, then double check the code to make sure you have set and cleared the correct output pin. I would also check the solder joints of the connectors on the shield - you can set a multimeter to do a resistance check from the shield's connector (pin 12) to the direction input on the LN298 (pin 7). If the continuity is measuring close to 0 ohms then there is probably an issue with your code.</li> <li>If your code looks good, I have also had issues with bad outputs on the Arduino - you can check to see if you are properly toggling the direction pin (pin 12) on the Arduino without the shield connected. Then, if the pin is not toggling, there is probably an issue with your Arduino - try toggling a different (unused) pin and jumpering it.</li> </ol>
6753
|arduino-uno|led|sleep|
Choosing right Sleep state
2014-12-29T15:17:37.860
<p>I'm planning on building an LED clock, but I want it to be lit only when I press the POWER button on my remote control. Using an IR receiver, which Arduino sleep mode should I use to reduce the current consumption but still be able to receive this interrupt?</p>
<p>I recommend reading <a href="http://playground.arduino.cc/Learning/ArduinoSleepCode" rel="nofollow">ArduinoSleepCode</a>. Where it demonstrates placing the avr into a sleep state and using an interrupt to awake from the sleep state. In your case you can connect the output of your IR demodulator to the interrupt pin, to simular awake.</p> <p>Ken Shirriff's IR library allows you to use any pin as a receive input, so that you can use INT0 or 1 on D2 or D3. If you need to use a different pin, the Microtheron's github fork uses Pin Change interrupts. (I am not sure if stock sleep.h will awake from PCint, like int0 or 1 will, without tweek. Section 10.1 of data sheet says it will.) </p>
6756
|serial|interrupt|
Serial interrupts?
2014-12-29T16:19:41.143
<p>In a project, I’m using an EIA485 bus to send encrypted data packets. That works with Arduino’s buffered serial, but it is kind of awkward, and I’m using none of the more complex stuff in that class anyway.</p> <p>If I do not use <code>Serial</code> anywhere in my Arduino sketch, is it safe to create my own interrupt handlers for <code>USART_RXC</code> etc. and to directly manipulate the USART registers?</p>
<p>Absolutely. The only interrupt that Arduino takes for itself unilaterally is the timer 0 overflow interrupt, used for timing purposes (<code>delay()</code>, <code>milliseconds()</code>, et alia).</p>
6763
|bootloader|uploading|
Can the Sparkfun AVR pocket programmer bootload/program a 3.3 V ATmega328p
2014-12-30T10:39:02.060
<p>The product in question - <a href="https://www.sparkfun.com/products/9825" rel="nofollow">https://www.sparkfun.com/products/9825</a> - operating at 5 V (and can also supply it to the device being programmed).</p> <p>I need to program the bootloader onto a 3.3 V ATmega328p and don't have any level shifters immediately available. Thus the question. The "Hookup Guide" for the product (<a href="https://learn.sparkfun.com/tutorials/pocket-avr-programmer-hookup-guide" rel="nofollow">https://learn.sparkfun.com/tutorials/pocket-avr-programmer-hookup-guide</a>) seems to suggest that it will work fine as long as the 3.3 V device being programmed isn't powered by the programmer. I wouldn't have thought it's the best idea in the world, but maybe I'm wrong.</p> <p>So any practical experience?</p> <p>Are the over voltage tolerances for input lines on Atmel devices good enough to handle the extra voltage?</p> <p>I guess the output level from the device being programmed would be high enough to be buffered up to 5.0 V?</p>
<p>The Pocket AVR Programmer has a logic level shifting (74ACT125) on board, specifically for this situation. There is nothing wrong with powering the target with a separate power supply that the programmer. Why else would there be a "power target"/"No power" switch?</p> <p>I don't see why other people would suggest cutting traces, when all you need to do is toggle a switch.</p>
6769
|hardware|components|
Help with parts identification from arduino starter kit from aliexpress
2014-12-30T06:07:33.733
<p>Ordered an arduino starter kit from aliexpress <a href="http://www.aliexpress.com/item/UNO-KIT-Upgraded-version-of-the-For-Starter-Kit-the-RFID-learn-Suite-Stepper-Motor-ULN2003/1042001423.html" rel="noreferrer">Link</a></p> <p>The parts list they provide (as a jpg on the order page) is vague and not very descriptive, I've gone through most of the parts and am down to three they did not list.</p> <ol> <li>Capacitor? -- Looks to be a capacitor, labeled HDX and nothing else, rattles when I shake it. <img src="https://i.stack.imgur.com/4oTnn.jpg" alt="Unknown part #1 - HDX capacitor?"></li> <li>Black LED -- I think this is a flame sensor; if it is, what's the difference between this and an infrared receiver (like a 1838B) or photoresistor? <img src="https://i.stack.imgur.com/OA9f2.jpg" alt="Unknown part #2 - flame sensor LED?"></li> <li>They also list something as 'a digital control' near the bottom of the list, not sure what that is? Every other part from the list is matched up and I don't see anything different in the first picture (not parts list picture) from what I have received in the order.</li> </ol>
<p>The HDX is a "Tilt Switch" Turns on/off depending on the angle.</p>
6775
|programming|
Use website to communicate with Arduino WirelessProtoShield
2014-12-31T15:22:41.780
<p>I have a small office with wireless network, is it possible to make a wireless doorbell?<br> Practical example:<br> Arduino is connected to the main wireless network and has a static ip, i have a website that connects through arduino using ftp to activate the "open door" function.<br> note: "open door" activates a motor to press the button, or i will hack the current doorbell to connect wires :D</p>
<p>Arduino wifi web server: <a href="http://arduino.cc/en/Tutorial/WiFiWebServer" rel="nofollow">http://arduino.cc/en/Tutorial/WiFiWebServer</a> just modify the webserver to show a "open" button and to receive a post request and open the door.</p>
6777
|shields|lcd|sd-card|temperature-sensor|
DS1307 RTC conflicts with DS18B20
2014-12-31T16:53:35.957
<p>I'm working on a project to output the temperature from a DS18B20 to a 16x2 LCD while logging the temperature to a CSV file using the Adafruit Data Logging Shield. I keep getting this error when verifying the code:</p> <pre><code>RTClib-master/RTClib.cpp.o: In function `RTC_DS1307::now()': /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:252: undefined reference to 'Wire' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:252: undefined reference to 'Wire' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:252: undefined reference to 'TwoWire::beginTransmission(int)'RTClib-master/RTClib.cpp.o: In function 'TwoWire::write(int)': /Applications/Arduino.app/Contents/Resources/Java/libraries/Wire/Wire.h:72: undefined reference to 'TwoWire::write(unsigned char)' RTClib-master/RTClib.cpp.o: In function 'RTC_DS1307::now()': /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:254: undefined reference to 'TwoWire::endTransmission()' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:256: undefined reference to 'TwoWire::requestFrom(int, int)' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:257: undefined reference to 'TwoWire::read()' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:258: undefined reference to 'TwoWire::read()' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:259: undefined reference to 'TwoWire::read()' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:260: undefined reference to 'TwoWire::read()' /Users/g/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:261: undefined reference to 'TwoWire::read()' RTClib-master/RTClib.cpp.o:/Users/grafton/Documents/Arduino/libraries/RTClib-master/RTClib.cpp:262: more undefined references to 'TwoWire::read()' follow </code></pre> <p>When I comment <code>RTC_DS1307 RTC;</code> in the code (below) these errors go away, but of course I get errors related to an undefined RTC. I'm a newbie cobbling together code from various sources, so any help is greatly appreciated. Code follows:</p> <pre><code>#include &lt;LiquidCrystal.h&gt; #include &lt;OneWire.h&gt; #include &lt;DallasTemperature.h&gt; #define ONE_WIRE_BUS 2 #include &lt;SD.h&gt; #include "RTClib.h" OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&amp;oneWire); const int chipSelect = 10; File tempLog; RTC_DS1307 RTC; LiquidCrystal lcd(6, 7, 8, 9, 11, 12); void setup() { Serial.begin(9600); while (!Serial) { ; lcd.begin(16, 2); // ---------------- lcd.print("Current temp (F)"); sensors.begin(); } Serial.print("Initializing SD card..."); pinMode(SS, OUTPUT); if (!SD.begin(chipSelect)) { Serial.println("Initialization failed!"); while (1); } Serial.println("Initialization done."); tempLog = SD.open("templog.txt", FILE_WRITE); if (! tempLog) { Serial.println("Error opening templog.txt"); while(1); } char filename[] = "LOGGER00.CSV"; for (uint8_t i = 0; i &lt; 100; i++) { filename[6] = i/10 + '0'; filename[7] = i%10 + '0'; if (! SD.exists(filename)) { // only open a new file if it doesn't exist tempLog = SD.open(filename, FILE_WRITE); break; // leave the loop! } Serial.print("Writing to: "); Serial.println(filename); tempLog.println("Data Logging File"); tempLog.println("Date,Temp(F)"); } } void loop() { sensors.requestTemperatures(); float temperature = sensors.getTempFByIndex(0); lcd.setCursor(6, 1); lcd.print(temperature); Serial.println(temperature); //----------------------------------------------------------- String dataString = ""; //date time stuff------------------------------------------- DateTime now = RTC.now(); // log time // tempLog.print(now.unixtime()); // seconds since 1/1/1970 // tempLog.print(", "); tempLog.print('"'); tempLog.print(now.year(), DEC); tempLog.print("/"); tempLog.print(now.month(), DEC); tempLog.print("/"); tempLog.print(now.day(), DEC); tempLog.print(" "); tempLog.print(now.hour(), DEC); tempLog.print(":"); tempLog.print(now.minute(), DEC); tempLog.print(":"); tempLog.print(now.second(), DEC); tempLog.print('"'); tempLog.print(","); tempLog.print(temperature); tempLog.print(","); delay(500); tempLog.println(dataString); tempLog.flush(); } </code></pre>
<p>The RTC library requires the <code>Wire</code> library. Just put <code>#include &lt;Wire.h&gt;</code> in front of the line <code>#include "RTClib.h"</code></p>
6779
|arduino-uno|emulation|
Using an Arduino as an input device
2014-12-31T17:02:30.820
<p>I had an idea to create a control panel using an arduino and some buttons. How would I go about making the arduino emulate an input device so that when I press a button connected to the arduino, it would cause the same effect as when a keyboard key was pressed? (I'm using arduino UNO, if it helps.)</p> <p>Thanks in advance.</p>
<p>I have successfully reprogrammed the UNO's R3 8U2 to support keyboard emulation, as to just this. Making dedicated user inputs for kiosks to Computers. I recommend <a href="https://github.com/NicoHood/HID" rel="nofollow">NicoHood's GitHub</a> as it allows simultaneous Arduino Bootloader and Keyboard functionality, making it easy to reprogram the Arduino.</p> <p>This along with using <a href="https://www.sparkfun.com/products/9695" rel="nofollow">Capacitive Touch Sensor</a> connected to Copper tap under clear acrylic protecting printed graphics of buttons is very quick and easy to make. Very little machining.</p> <p>Example of such code is found at <a href="https://github.com/wreality/artemis-firmwares/tree/master/ConsoleFirmwares" rel="nofollow">artemis-firmwares</a> it was initially created with a different 8U2 method. Where next time we will use NicoHood's.</p> <p>Note the stock keyboard send key command for the Arduino is limited. Where the above methods allows the code to send complete virtual keys supporting full emulation. </p>
6791
|serial|arduino-nano|analogread|
Speeding up Girino gives strange readouts
2015-01-01T05:28:38.890
<p>I was reproducing the Girino (the <a href="http://www.instructables.com/id/Girino-Fast-Arduino-Oscilloscope/?ALLSTEPS" rel="nofollow noreferrer">Instructable</a> by Caffeinomane) bundled with the Girinoscope (the <a href="https://github.com/Chatanga/Girinoscope" rel="nofollow noreferrer">Java GUI</a> by Chatanga). The results worked well and I went on to see if the oscilloscope can go up to higher kS/s.</p> <p>In short, originally only upto prescaler 8 works. I removed PWM pin and it works upto 4 but prescaler 2 strangely behaves. Here are the details:</p> <p>I did a preliminary test on prescaler 32 (~38.5kHz). Settings as follows and the same in other tests.</p> <ul> <li>The signal (the same hereafter) is generated by a 555 timer astable multivibrator running at 4.5V (3 AA batteries).</li> <li>The circuitry was simply omitted. I just tied 3.3V of Arduino NANO / ATmega328 to digital pin 6 as the trigger level.</li> <li>There is no +2.5V offset done by the original Girino. (The scale should be 0~5V and the signal is 0~4V) <img src="https://i.stack.imgur.com/egXFy.png" alt="Prescaler 32 works"></li> </ul> <p>So then I wanted to try if it can speed up more. The code optimization quoted by Chatanga allowed prescaler 8 and 16 (76.9kHz and 151.8 kHz).</p> <p>In order to push it the poor Arduino to the limits, I disabled PWM pin in the original Girino which sets the trigger level with duty cycles (PWM from pin ~3 being fed into pin 6). It's because I simply used a fixed 3.3V trigger level.</p> <p>Prescaler 4 is unlocked. <img src="https://i.stack.imgur.com/uRUCs.png" alt="Prescaler 4 works with code optimization and disabled PWM"></p> <p>Ambitious I go on to test prescaler 2. The GUI did not provide this option so I simply set it in the Arduino code. <img src="https://i.stack.imgur.com/RDuTS.png" alt="Prescaler 2 strangely behaves (all full scale deflection)"></p> <p>I thought it did not work. I noticed if the prescaler is exceeding the Arduino's capability, TXRX simply does not blink. But this time the TXRX is just blinking! To verify this, I shifted the wait duration. <img src="https://i.stack.imgur.com/hHCqG.png" alt="Prescaler 2 strangely behaves (all full scale deflection)"></p> <p>In previous screenshots, the leftmost green line is dashed (probably because it's below fullscale deflection). But in the last two, be it offset or not, the line is solid.</p> <p>The debug output is like this: (8bits 0~255 given by ADC)</p> <ul> <li>many 0 then suddenly 255 thereafter. (matches the GUI output)</li> </ul> <p>I suspect it's due to slow TXRX? How to solve this? Or anything I overlooked?</p> <p>Hope that this overdetailed question does not sicken you.</p>
<p>From the ATmega328P datasheet, section 29.8, "ADC Characteristics":</p> <blockquote> <p>Clock Frequency — Min.: 50kHz, Max: 1000kHz</p> </blockquote> <p>With a 16MHz system clock this means that a /16 prescaler is the most the ADC is considered reliable under for a reasonable 10 bit result (for a <em>full</em> 10 bit result the maximum frequency is 200kHz, which corresponds to a prescaler of /80). </p> <p>As the frequency increases the sample-and-hold circuitry of the ADC gets less time to do the "sample" part before conversion begins. As such any correctness goes out the window, certainly at the lower bits. The fact that you got any sort of result that you did at /4 is luck.</p> <p><strong>TL;DR:</strong> The ADC is too slow.</p>
6801
|arduino-uno|
How to convert this prototype to finished product?
2015-01-01T21:48:51.583
<p>My prototype contains below components:</p> <ul> <li>Arduino Uno R3</li> <li>Bluetooth LE nRF8001 Break-out (<a href="https://www.adafruit.com/products/1697" rel="nofollow">https://www.adafruit.com/products/1697</a>)</li> <li>MicroSD Break-out (<a href="https://www.adafruit.com/products/254" rel="nofollow">https://www.adafruit.com/products/254</a>)</li> <li>ADXL335 triple-axis Accelerometer</li> </ul> <p>I think It's OK on paper (and presumably on a breadboard too). I'm trying to wrap my head around on how to convert it to a finished product that sits inside a plastic box.</p> <p><strong>What are my options?</strong></p> <p>For instance, can I create a single PCB that contains all the components? If not, how can I connect these multiple break-out boards together? Is soldering some wires on both boards to connect them is a viable option?</p> <p><strong>Edit:</strong></p> <p>My ultimate goal is to create a product that is for sale. So I mean something that can be mass-produced and can meet regulatory requirements.</p> <p>This is why I was thinking about a single PCB. Arduino (or should I say ATMegaXXX?) is fairly simple to place on a custom PCB. So I was thinking perhaps I could "re-create" my break-outs (see above) on this PCB thus creating a single piece including all components and the microcontroller. For some reason this makes sense to me but I don't know how hard it is or if it is even possible.</p>
<p><strong>step1: Make the hardware</strong></p> <ul> <li><p>Refer the schematics of arduino you are using and make your own pcb</p></li> <li><p>Approach any PCB manufactures and deliver them your GERBER files with correct Bill of Materials.</p></li> <li>You can easily make a single PCB. consider PCB with components on both sides, and multi stackable PCB only if the dimension of required PCB matters.</li> <li>Try not to place nRF antenna and crystal for the micro controller close to each other.</li> </ul> <p><strong>Step2: Firmware</strong> </p> <p>This step is about getting .hex file from arduino code and givin this to the same pcb manufacturer, with proper fuse values </p> <ul> <li>Go to file->preferences in arduino</li> <li>Check show verbos </li> <li>open the temp file (type %temp% on RUN) </li> <li>Compile your arduino code. this will generate a build folder inside temp folder Search for yourArduinoProjectName.hex inside that folder. </li> </ul> <p><em>This is the code you need to get fuse bits</em></p> <pre><code>#include &lt;avr/boot.h&gt;; void setup() { Serial.begin(57600); cli(); uint8_t lowBits = boot_lock_fuse_bits_get(GET_LOW_FUSE_BITS); uint8_t highBits = boot_lock_fuse_bits_get(GET_HIGH_FUSE_BITS); uint8_t extendedBits = boot_lock_fuse_bits_get(GET_EXTENDED_FUSE_BITS); uint8_t lockBits = boot_lock_fuse_bits_get(GET_LOCK_BITS); sei(); Serial.print("Low: 0x"); Serial.println(lowBits, HEX); Serial.print("High: 0x"); Serial.println(highBits, HEX); Serial.print("Ext: 0x"); Serial.println(extendedBits, HEX); Serial.print("Lock: 0x"); Serial.println(lockBits, HEX); } void loop() { } </code></pre> <p>Or check the file</p> <blockquote> <p>C:\Program Files (x86)\Arduino\hardware\arduino\avr\boards.txt</p> </blockquote> <p>to find the fuses.</p>
6804
|atmega328|
Arduino vs Old Computers
2015-01-02T01:00:22.307
<p>How does an arduino microprocessor compare to some of the older computers in RAM, and computational speed? Like how does it compare to the Intel 400 or the original IBM PC. I'm interested in both the Atmega328 and the 2560. Just how much better/worse is the arduino compared to an old computer?</p>
<p>The Arduino chip (usually Atmega328p-pu) is an AVR (Advanced Virtual RISC*)!!! It doesn't processor but a &quot;full functional nano computer&quot; a Microcontroller! The characteristics of Atmega328P-PU is an 8bit CPU with 2Kb RAM**, 1Kb ROM*** and 32Kb Flash. The CPU's max speed is 20 MIPS @ 20 ΜHz, double of Motorola 68020 (1988) and the half of ARM7 (1994) more fast than Intel i486DX (1991). ***electrically erasable Programmable ROM **synchronous RAM or SRAM yes! is a type of RAM *RISC=Reduced instruction set computer <a href="https://www.microchip.com/wwwproducts/en/ATmega328P" rel="nofollow noreferrer">https://www.microchip.com/wwwproducts/en/ATmega328P</a> <a href="https://en.wikipedia.org/wiki/Instructions_per_second" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Instructions_per_second</a></p>
6806
|arduino-uno|interrupt|timers|avr-gcc|
TIMER1 CTC Interrupts not working with avr-gcc
2015-01-02T04:49:33.167
<p>I am attempting to program my arduino in plain C, and I've come across some very strange behavior. If I load the following code from the Arduino IDE, it works as expected and toggles Pin 6 every 100ms. However, if I compile it with avr-gcc and then load it with avrdude, no interrupts are run. Here is the C code:</p> <pre><code>#include &lt;avr/io.h&gt; #include &lt;avr/interrupt.h&gt; int main(); void timer1_init(); int main() { // connect led to pin PD6 DDRD |= (1 &lt;&lt; 6); PORTD |= (1 &lt;&lt; 6); // initialize timer timer1_init(); // loop forever while(1) { // do nothing // whenever a match occurs, ISR is fired // toggle the led in the ISR itself // no need to keep track of any flag bits here // done! } } // initialize timer, interrupt and variable void timer1_init() { /*cli();*/ /*TCCR1A = 0;*/ /*TCCR1B = 0;*/ /*TCNT1 = 0;*/ OCR1A = 24999; TCCR1B |= _BV(WGM12) | _BV(CS11) | _BV(CS10); TIMSK1 |= _BV(OCIE1A); sei(); } ISR (TIMER1_COMPA_vect) { // toggle led here PORTD ^= (1 &lt;&lt; 6); } </code></pre> <p>And here is the Makefile I'm using to load it onto the arduino:</p> <pre><code>CC = avr-gcc CFLAGS = -g -O0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 SOURCE = test all: load $(SOURCE): $(SOURCE).o $(CC) $(SOURCE).o -o $(SOURCE) hex: $(SOURCE) avr-objcopy -O ihex -R .eeprom $(SOURCE) $(SOURCE).hex load: hex avrdude -F -V -c arduino -p ATMEGA328P -P /dev/tty.usbmodem1411 -b 115200 -U flash:w:$(SOURCE).hex clean: rm -f *.o *.hex rm -f `find . -perm 755 | perl -pe 's/\.\n//g' | perl -pe 's/\.\/(\w+)\n/\1 /g'` </code></pre> <p>Is there something that the arduino ide automatically adds to it that makes it work? What am I missing?</p> <p>Edit: Here is the make output:</p> <pre><code>avr-gcc -g -O0 -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -MMD -DUSB_VID=null -DUSB_PID=null -DARDUINO=106 -c -o test.o test.c avr-gcc test.o -o test avr-objcopy -O ihex -R .eeprom test test.hex avrdude -F -V -c arduino -p ATMEGA328P -P /dev/tty.usbmodem1411 -b 115200 -U flash:w:test.hex avrdude: AVR device initialized and ready to accept instructions Reading | ################################################## | 100% 0.01s avrdude: Device signature = 0x1e950f avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed To disable this feature, specify the -D option. avrdude: erasing chip avrdude: reading input file "test.hex" avrdude: input file test.hex auto detected as Intel Hex avrdude: writing flash (196 bytes): Writing | ################################################## | 100% 0.04s avrdude: 196 bytes of flash written avrdude: safemode: Fuses OK (E:00, H:00, L:00) avrdude done. Thank you. </code></pre>
<p>I just tried using arduino-mk <a href="https://github.com/sudar/Arduino-Makefile" rel="nofollow">https://github.com/sudar/Arduino-Makefile</a>, and it worked, so I guess I'm just going to stick with that.</p>
6810
|serial|
Serial Connection to Phone Line
2015-01-02T14:55:22.673
<p>I was hoping to create a cheap security system by connecting an Arduino to the phone line output of a base station. </p> <p>Since the base station should call a phone number if the alarm is tripped I wouldn't have to do much hardware hacking so long as I can read/parse the output from the base station. </p> <p>My question is can I read serial output from a phone line like this?</p>
<p>Phone lines run off of the RS-232 telecommunications protocol which can run off -25v to 25v, which would completely destroy your Arduino. Luckily there is an IC made to help you with that. You can use the MAX3232 IC to convert RS-232 to TTL 5v or 3.3v (Same chip can do either). Look at providers like Digikey for just the chip or you can get a breakout from providers like SparkFun.</p> <p>TL;DR Yes, but you need a special IC to not fry your Arduino.</p>
6813
|sensors|
VCNL4000 Proximity/Light sensor
2015-01-02T18:12:09.757
<p>I want to use the VCNL4000 Proximity/Light sensor s. <a href="http://www.adafruit.com/products/466?&amp;main_page=product_info&amp;products_id=466" rel="nofollow noreferrer">http://www.adafruit.com/products/466?&amp;main_page=product_info&amp;products_id=466</a></p> <p>In the package i've this 6 pin connector but the VCNL has 5 pins (i now i can connect it by myself with male jumper) but what am i missing here? <img src="https://i.stack.imgur.com/pidtP.png" alt="enter image description here"> I assume that it is not an "accident" that the thing has one more pin then the sensor ; )</p>
<p>You can just cut off the extra pin. Adafruit probably just had a bunch of 6 pin headers in their stock. </p>
6821
|led|
Light LED when 2 others are disconnected
2015-01-01T20:00:32.827
<p>I need to make circuit in which orange LED will light only when yellow and red are disconnected. When one of buttons is pushed orange LED should turn off.</p> <p>See my attempt at it below.</p> <p>I am new to electronics so your help is very appreciated.</p> <p><img src="https://i.stack.imgur.com/N75Z5.png" alt="Fritzing diagram"></p> <p><strong>EDIT:</strong></p> <p>After many atemps I managed to build this circuit as on left side of schematic (tested on live breadboard)</p> <p><img src="https://i.stack.imgur.com/A31Fw.png" alt="schematics"></p> <p>but my primary goal is to make this work with RGB LED. I took Common Anode RGB LED for this and build circuit on right side of schematic. I do not have such RGB LED to test it live so I ask you to review if that schematic will work as it has few changes to one with 3 LED's. Thank you</p> <p><strong>SOLUTION:</strong></p> <p>Thanks to Bruce's help my circuit now works. </p> <p>3 separate LEDs emulate common anode RGB LED (as I do not have one to test circuit)<br> Q2 is BC 560B transistor with CBE type pinout</p> <p><img src="https://i.stack.imgur.com/Ig8uq.png" alt=""></p> <p><img src="https://i.stack.imgur.com/8BtrL.png" alt=""></p> <p>CODE:</p> <pre><code>void setup() { pinMode(2,INPUT); pinMode(4,INPUT); Serial.begin(9600); digitalWrite(2,HIGH); digitalWrite(4,HIGH); } void loop() { Serial.println(digitalRead(2)); Serial.println(digitalRead(4)); } </code></pre>
<p>You want the green LED to be on <em>only</em> when the red and blue LEDs are both off. In other words, you want the voltage on the green LED to be LOW only when the voltages on the red and blue LEDs are both HIGH. That is a logical NAND function.</p> <p>Your right-hand circuit with the RGB LED won't work because the transistor's collector is connected to the wrong place - it's shorting out the battery! Another problem is that the Arduino can only switch to Ground or +5V, so it can't replace a 'floating' switch. </p> <p>You need a configuration that produces a logical NAND function. Your left-hand circuit is doing it, but won't work with a common anode RGB LED. So swap the transistor to a PNP type, and add a couple of resistors to switch it on when either input goes low, like this:-</p> <p><img src="https://i.stack.imgur.com/xK7ud.png" alt="enter image description here"></p>
6823
|networking|
WiFi UDP.endPacket() continuously fails
2015-01-03T01:39:16.483
<p>I am attempting to send data from my Arduino to my computer using the WiFi shield. However, my code is erroring out on UDP.endPacket(), and I do not understand why. Here is my code:</p> <pre><code>#include &lt;WiFi.h&gt; #include &lt;WiFiUDP.h&gt; int status = WL_IDLE_STATUS; char ssid[] = "NETGEAR31"; // your network SSID (name) char pass[] = "oddearth926"; // your network password (use for WPA, or use as key for WEP) char ReplyBuffer[] = "acknowledged"; // a string to send back WiFiUDP Udp; void setup() { //Initialize serial and wait for port to open: Serial.begin(9600); // check for the presence of the shield: if (WiFi.status() == WL_NO_SHIELD) { Serial.println("WiFi shield not present"); // don't continue: while (true); } // attempt to connect to Wifi network: while ( status != WL_CONNECTED) { Serial.print("Attempting to connect to SSID: "); Serial.println(ssid); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: } Serial.println("Connected to wifi"); printWifiStatus(); Serial.println("\nStarting connection to server..."); if(!Udp.begin(8765)) { Serial.println(F("failed")); } // if you get a connection, report back via serial: } void loop() { IPAddress ip(10,0,0,5); int port = 8766; // send a reply, to the IP address and port that sent us the packet we received if(!Udp.beginPacket(ip, port)) { Serial.println(F("Failed beginning packet")); } Udp.print(ReplyBuffer); if(!Udp.endPacket()) { Serial.println(F("Failed ending packet")); } } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your WiFi shield's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); } </code></pre> <p>And here is the log:</p> <pre><code>Attempting to connect to SSID: NETGEAR31 Connected to wifi SSID: NETGEAR31 IP Address: 10.0.0.34 signal strength (RSSI):-63 dBm Starting connection to server... Failed ending packet Failed ending packet Failed ending packet Failed ending packet Failed ending packet Failed ending packet </code></pre> <p>It will continue to spit out "Failed ending packet" until I stop it. Any ideas?</p>
<p>Fixed by updating firmware on Wifi Shield.</p>
6831
|arduino-uno|interrupt|
Problem with while loops while detecting frequency of a signal
2015-01-03T13:28:00.080
<p>I just started to use the unusual part of Arduino language (avr) like interrupts, accessing registers, etc in Arduino IDE. I wrote a program to calculate the frequency of a digital signal using external interrupts.</p> <p>The following code is to calculate timeperiod of a digital signal, the output of the color sensor (TCS3200) which depends on the color filter choosen via S2 and S3 pins, as in the code. That is, color sensor produces 50% duty cycle square pulses of frequency dependent on the power of the light incident on it. So when sensor faces red color, output signal's frequency in red color mode (by setting S2, S3 pins) is more than the frequency in blue and green modes. Thus we can detect the likeliness of the color which it faces w.r.t R,G,B.</p> <p>When this code is uploaded in the Arduino, it failed to print the values as expected in the serial monitor i.e. its stuck in while loops. But when <code>Serial.print(e)</code> statement in the while loops are uncommented, it is able to print the required time periods. I am unable to figure out the problem here, which is making Arduino to be inside the while loop when no statements are in it.</p> <pre><code>// INT0 interupt is used i.e. digital pin 2 int ti=0,tim=0,e=0,S2=4,S3=5; void Interruptinit() //initializing interrupt INT0 { cli(); EICRA = 0x02; //Control register EIMSK = 0x01; //Mask register sei(); } void setup() { pinMode(2,INPUT); digitalWrite(2,HIGH); //enabling pull up register pinMode(S2,OUTPUT); pinMode(S3,OUTPUT); Interruptinit(); Serial.begin(9600); } ISR(INT0_vect) { tim=micros()-ti; ti=micros(); e++; } void loop() { digitalWrite(S2,0); digitalWrite(S3,0); //switching over red filtered photodiodes e=0; while(e&lt;2) //Serial.print(e) //waiting till interrupt is addressed 2 times ; Serial.print("red:"); Serial.print(tim); digitalWrite(S2,0); digitalWrite(S3,1); //switching over blue filtered photodiodes e=0; while(e&lt;2) //Serial.print(e) ; Serial.print(" blue:"); Serial.print(tim); digitalWrite(S2,1); digitalWrite(S3,1); //switching over green filtered photodiodes e=0; while(e&lt;2) //Serial.print(e) ; Serial.print(" green:"); Serial.println(tim); } </code></pre>
<p>Whenever you modify non-local variables in an ISR, it's important that they are declared as <code>volatile</code>. This tells the compiler that the contents may change unexpectedly, ensuring it doesn't use out-of-date cached copies somewhere else. If you don't do this, the code can behave in unpredictable ways, such as outputting the wrong value under some circumstances.</p> <p>Since the variables are bigger than 1 byte, it's also necessary to disable interrupts around non-ISR code which uses them (e.g. in <code>loop()</code>). This is because interrupts could be triggered at any time, potentially half way through an operation which reads/writes them.</p> <p>You can use <code>noInterrupts()</code> and <code>interrupts()</code> to disable/enable interrupt handling.</p>
6832
|flash|
Cheap 2-5mb memory to use with arduino
2015-01-03T14:14:02.763
<p>I'm looking for a storage solution for small files that would be moved into a small sensor running arduino-like processor.</p> <p>Ideally the single memory unit would be cheap (in 1-10 cents range), but the memory can be very limited (several megabytes).</p> <p>The closest I've got so far is small SD Memory card, but the smallest 4GB ones cost several dollars (at least bought in quantities &lt; 100). Anything else I should be looking at?</p>
<p>I assume that, if this is a cost sensitive item, you need a reliable supply of multiples (so looking for small SD cards on e-bay isn't a viable solution).</p> <p>Does it need to be non-volatile storage? If it does't you may be able to find small 8-bit wide RAM chips at a pretty good price. If it needs to be non-volatile, you might look at individual flash chips. I found <a href="http://uk.rs-online.com/web/p/flash-memory-chips/8228473P/" rel="nofollow">this one</a>, an 8-bit by 512 KB Serial-SPI flash chip for £0.19 (about $0.28 US) in single units and £0.176 if you can by 100 at a time. I would expect DRAM chips and chips with a simpler interface to be less expensive (but you might end up spending more on interfacing the chips so it might end up as a wash).</p> <p>If you're able to consider a variety of processor chips it might be worth looking for something that has adequate storage on chip. That might be the most cost effective way to get the space.</p>
6834
|programming|arduino-ide|c|python|
Can I program Arduino with Python?
2015-01-03T18:04:55.177
<p>I know that I can program Arduino with python but is it possible to make every project, which can be completed by normal IDE?</p>
<p>The direct answer is almost certainly not. </p> <p>There are some auspicious developments so that you might be able to adapt a specific open source Python package, but the resulting software would require a special Arduino board with an MCU chip with much more SRAM and a higher clock speed than we usually see on Arduino boards.</p> <p><strong>Discussion</strong></p> <p>I have looked several times and have never found anything.</p> <p>I did find a "stripped down" implementation of a Python 3.3 interpreter called <a href="http://micropython.org" rel="nofollow">Micro Python</a>. The software was developed hand in hand with MicroPy, an ARM-based single board computer (also described at the MicroPython website). MicroPy is closer to a Raspberry Pi or Beaglebone than an Arduino. However, the software environment is less complex because the MicroPy doesn't require a Linux-based or other operating system. </p> <p>The base Micro Python package software package seems to require about 110KB of SRAM to boot up and expects a 1 MB SD chip with a boot record and MicroPython on it. </p> <p>The Micro Python software was released under the MIT open source license so, in theory, a clever person could adapt it for the Arduino if they built a board with a really powerful chip SD socket. </p> <p>Although the Micro Python/MicroPy package is very appealing, I don't think I would head down the path. I would rather be programming for hardware that is available from more than one source.</p> <p>Another potential issue is that the Micro Python implementation uses a mark and sweep garbage collector which might tie up the processor for 4 msec at time. Depending on your application a 4 msec busy period might not be acceptable.</p>
6839
|system-design|electronics|
Washing machine controlled by Arduino for homebrewing
2015-01-04T03:04:04.010
<p>So, this question might sound a bit silly at first glance (no, I know, it sounds flat out insane), but not all that silly at second.</p> <p>I have heard once about a guy who transformed some (presumably old-ish) washing machine into his own personal home-brewing apparatus. It is quite some idea if you think about it. Washing machine can easily solve most issues people have with homebrewing. It can carefully control and adjust temperature throughout the long and complicated process of brewing, it can stir, it can pump in fresh water.</p> <p>Main question is, how to control washing machine to do what I want it to do. Most automatic washing machines already have some controllers, but I don't see much chance in trying to simply reprogram them (Am I wrong?). <strong>Arduino seems like best choice for its simplicity and expandability. However I am still fairly new to Arduino and have trouble imagining how would connecting everything from washing machine (motor, pump, maybe water and temperature sensors) to Arduino actually look like.</strong></p> <p><em>So is it even possible? Are there any projects to "bounce of"?</em> (I couldn't find any, but maybe I looked for wrong projects) <em>Should I expect any major problems?</em></p>
<p>There is <a href="http://blog.atmel.com/2013/10/17/let-arduino-control-your-dishwasher-or-washing-machine/" rel="nofollow">an article by Atmel</a>, talking exactly about this (not for homebrewing, though). They provide a <a href="http://grietinfo.in/projects/MAIN/EEE2013/cd-3-projectdocumentationpdf.pdf" rel="nofollow">link to a PDF file</a> that describe in detail a project involving Arduino and a re-created washing machine.</p> <p>Note that it seems to be some kind of Bachelor graduation project, and that the students seem to build an entire washing machine. They control the rotor using an Arduino, and even provide the code (and a brief history about washing machines..).</p> <p>Apart from building the entire machine, there are two main directions here as I see it:</p> <ol> <li><p>Manipulate the existing washing machine's control board using Arduino. The bad news are the it would require some reverse engineering of the existing controller, because, per my understanding (and I'm not an expert on the subject) there is no one standard and any manufacturer seems to use it's own propriety control board (similar to Microwaves or Dishwashers). The good news are that an expert could probably do it, either by dumping the controller memory and examining the hex code or by using JTag. </p></li> <li><p>Another way to go here is interfacing the electrical hardware itself; <a href="http://www.instructables.com/id/Washing-machine-countdown-timer-Arduino/" rel="nofollow">see this instructable</a> where the guy connected the Arduino in parallel to the start button, by thus allowing an alternative way to start. </p></li> </ol> <p>As for a beginner, it would make more sense to go for the latter; in-parallel connection with an existing hardware button should be a fairly comprehensible task. Consider the hazards of working with a high voltage/power device such as washing machines. I must say that on first glance such a project doesn't seem fit a novice, but I would be the last one to hold an enthusiast's back. And if you know any, I would suggest asking supervision from someone with a strong EE background.</p>
6840
|time|datalogging|rtc|
Reading atomic radio clock
2015-01-04T09:54:25.217
<p>i have some data logging to do. And i want some what accurate time meaning accuracy has to be +/- 1 minute.</p> <p>I have considered a RTC, but then i thought. When i was 10 i got a watch that kept time from this radio clock. And if it is possible 20 years ago to make a clock that updates automatically in such as small form factor, then i should be able to do it with my arduino today.</p> <p>Does anyone know of a guide/solution with components where i can read this atomic radio clock?</p>
<p>So, the first consideration goes to the radio propagation aspect. Every country does things a little different with their radio clocks. And you might only have good signal a few times a day. For a nice overview, check out a solution for the <a href="http://blog.blinkenlight.net/experiments/dcf77/the-clock/" rel="noreferrer">German DCF77</a>. If you're totally set on using a radio clock, time-nuts has discussed in the past ripping open a $10ish clock to get at the fun parts of a <a href="http://comments.gmane.org/gmane.comp.time.nuts/38831" rel="noreferrer">WWVB receiver</a>, so that's one overview of the pool you're diving into.</p> <p>For myself I've skipped past the terrestrial time keeping and went straight to GPS. Find a receiver that provides a pulse-per-second and attach that to an interrupt and process it alongside the timestamp; you can see how I've gone about that in both <a href="https://github.com/ptudor/jemma-clock" rel="noreferrer">code</a> and <a href="https://www.tindie.com/products/ptudor/jemma-clock/" rel="noreferrer">final product</a>.</p> <p>I think GPS is both easier and more precise than the alternatives, assuming you're above ground and can pick up satellites. I think of RTCs as something to tell me the day and the year, while GPS can tell me the second. But you could consider ripping the antenna out of a cheap bedside radio-controlled clock and using that to set an RTC, careful to consider whether you want a cheap RTC (DS1307) that drifts a minute per day or a slightly more expensive RTC (DS3231 or ISL1220) that drifts a minute per month. (Rough numbers of course.)</p>
6857
|sensors|accelerometer|
How to protect sensors used on atheletes?
2015-01-05T03:17:37.373
<p>I'm working on a project were we are trying to attach accelerometers to soccer players and capture various aspects of movement data. Breadboarded circuits are coming along nicely and I'm now looking for how to best protect sensors we can mount on players. (All wire at the moment unfortunately - BT next.)</p> <p>Although I can find ways to protect the sensor for sensor damaging impact (we are essentially interested in player impacts with the ball or ground) there are other aspects of protection I'm not sure about. Any recommendations on how to protect from moisture without increasing bulk too much, minimizing cushioning which could affect the data and of course avoid adding anything that could injure the player? I have come across other examples of movement studies, but they have been by musicians or other situations that do not include outdoor weather and sweaty bodies.</p>
<p>The only way this is ever done is with some kind of product casing. You can buy pre-fab cases for electronic projects, but to get something really slick and appropriate for your purpose, you're gonna have to make something yourself. You might look into 3D printing.</p> <p>Something like this might work: <a href="https://www.sparkfun.com/products/8601" rel="nofollow">https://www.sparkfun.com/products/8601</a></p> <p>For protection from salt-water, this product is worth a look: <a href="http://www.corrosionx.com/" rel="nofollow">http://www.corrosionx.com/</a></p> <p>There's some different products there, but I've seen a demo of that product, where we ran an entire RC airplane system, servos, motors, and receiver, UNDER WATER.</p>
6858
|arduino-uno|
Arduino RBBB - Device not accepting address
2015-01-05T03:55:16.390
<p>I recently purchases and make a Arduino RBBB with a BUB II from Modern Device. I ordered the package found <a href="http://moderndevice.com/product/rbbb-bundle/" rel="nofollow noreferrer">HERE</a>. I built everything according to the instructions, but when I connect it to my laptop (running Ubuntu 14.10), I get the following in dmesg</p> <pre><code>[63415.213391] usb 3-1: new full-speed USB device number 63 using xhci_hcd [63415.381403] usb 3-1: device descriptor read/64, error -71 [63415.485225] xhci_hcd 0000:00:14.0: Setup ERROR: setup context command for slot 26. [63415.485240] usb 3-1: hub failed to enable device, error -22 [63415.597236] usb 3-1: new full-speed USB device number 64 using xhci_hcd [63415.709154] usb 3-1: device descriptor read/64, error -71 [63415.813102] xhci_hcd 0000:00:14.0: Setup ERROR: setup context command for slot 27. [63415.813116] usb 3-1: hub failed to enable device, error -22 [63415.925108] usb 3-1: new full-speed USB device number 65 using xhci_hcd [63415.925270] usb 3-1: Device not responding to setup address. [63416.129120] usb 3-1: Device not responding to setup address. [63416.332902] usb 3-1: device not accepting address 65, error -71 [63416.444973] usb 3-1: new full-speed USB device number 66 using xhci_hcd [63416.445174] usb 3-1: Device not responding to setup address. [63416.649008] usb 3-1: Device not responding to setup address. [63416.852734] usb 3-1: device not accepting address 66, error -71 [63416.852813] usb usb3-port1: unable to enumerate USB device </code></pre> <p>It is repeatable every time I insert. lsusb does not register it. I have read that I should switch out the cable, but it is brand new (and I don't have another to test with. I was wondering if there is something evidently wrong with my circuitry. I posted pictures</p> <p><img src="https://i.stack.imgur.com/z1911.jpg" alt="Top Down"> <img src="https://i.stack.imgur.com/fVuSE.jpg" alt="Side"> <img src="https://i.stack.imgur.com/XI3Iq.jpg" alt="Bottom"> <img src="https://i.stack.imgur.com/RNRVh.jpg" alt="Side"></p>
<p>I fixed it. Here is how I did it.</p> <p>First, I tried connecting just the BUB II to via the USB. Same error, thus I ruled out the Arduino RBBB as the source. I then decided that perhaps it was the voltage jumpers (black things on the pins sticking out in the first picture). After removing them, it works under dmesg, yielding the below.</p> <pre><code>[ 214.044563] ftdi_sio 3-1:1.0: FTDI USB Serial Device converter detected [ 214.044687] usb 3-1: Detected FT232RL [ 214.044696] usb 3-1: Number of endpoints 2 [ 214.044704] usb 3-1: Endpoint 1 MaxPacketSize 64 [ 214.044712] usb 3-1: Endpoint 2 MaxPacketSize 64 [ 214.044718] usb 3-1: Setting MaxPacketSize 64 [ 214.045209] usb 3-1: FTDI USB Serial Device converter now attached to ttyUSB0 </code></pre> <p>Thus I wanted to put them back on so I wouldn't lose them. I proceeded to try various combinations till it worked. Ultimately, I ended with 5V for VOUT and VL for LGLV. If that is a bad idea, someone please comment, but it works.</p> <p>May this help someone else.</p>
6860
|programming|c++|library|
Error: Function not declared in the scope
2015-01-05T08:31:17.850
<p>I want to make a timer library. The cpp file I have written is:</p> <pre><code>#include "avr/interrupt.h" #include "Arduino.h" #include "AllTimer.h" AllTimer::AllTimer() {} void AllTimer::dofun(void) { TIFR1 |= _BV(OCF1A); TCCR1B = 0X00; digitalWrite(13,!digitalRead(13)); } void AllTimer::setTimer(void) { TCNT1 = 0x0BDC; TCCR1A = 0x00; TCCR1B = 0x00; TCCR1B |= (1&lt;&lt;CS12) &amp;&amp; (1&lt;&lt;CS10); TIMSK1 |= (1&lt;&lt;TOIE1); sei(); } ISR (TIMER1_OVF_vect) { dofun(); } </code></pre> <p>And the header file:</p> <pre><code>#ifndef AllTimer_h #define AllTimer_h class AllTimer{ public: AllTimer(); void setTimer(void); private: void dofun(void); }; #endif </code></pre> <p>While compiling the file i am getting the following error:</p> <pre><code>sketch_jan05a.cpp: In function ‘void __vector_13()’: sketch_jan05a.cpp:34:9: error: ‘dofun’ was not declared in this scope </code></pre>
<p>Answering here because I do not have enough rep to comment. At each iteration, the value in the timer counter must be reloaded. Either the ISR or dofun are responsible to reload TCNT1.</p>
6866
|serial|usb|linux|ubuntu|
communicating with arduino over serial via terminal
2015-01-05T16:12:01.117
<p>I'm attempting to write data over a serial line to the arduino, however I don't want to use the arduino IDE but rather use the command line. </p> <p>In order to do this I have the following commands: </p> <pre><code>$stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts $echo s123 &gt; /dev/ttyACM0 </code></pre> <p>The code on the receiving end checks whatever or not the input is s123 and if it is starts blinking. I have tested this using the arduino IDE and it worked, however this did not work.</p> <p>The sketch looks like this:</p> <pre><code> void loop(){ if(Serial.available()==4){ byte b1,b2,b3,b4; b1=Serial.read(); b2=Serial.read(); b3=Serial.read(); b4=Serial.read(); if(b1=='s'){ digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) Serial.println("the cow has landed"); } } void setup(){ //////////////SETUP//////////////////////// Serial.begin(9600); } </code></pre> <p>the output of </p> <pre><code>stty -F /dev/ttyACM0 -a </code></pre> <p>was :</p> <pre><code>speed 9600 baud; rows 0; columns 0; line = 0; intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = &lt;undef&gt;; eol2 = &lt;undef&gt;; swtch = &lt;undef&gt;; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; flush = ^O; min = 0; time = 0; -parenb -parodd cs8 -hupcl -cstopb cread clocal -crtscts ignbrk -brkint -ignpar -parmrk inpck -istrip -inlcr -igncr -icrnl -ixon -ixoff -iuclc -ixany -imaxbel -iutf8 -opost -olcuc -ocrnl -onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0 -isig -icanon -iexten -echo -echoe -echok -echonl noflsh -xcase -tostop -echoprt -echoctl -echoke </code></pre> <p>Thank you</p>
<p>This was fixed this morning after a reboot and upgrade command, still don't know which one of these fixed it but it seems to work now.</p> <p>Ah figured it out we were using the 0 and 1 rx gates to communicate over serial rather then usb and as the used power supply turned out to be only 5V rather then 9-12V it didn't quite work as intended.</p>
6874
|arduino-uno|
Wiring Issues with Sparkfun Oled
2015-01-06T04:15:05.403
<p>I'm attempting to hook up an arduino uno with a Sparkfun Oled. I downloaded the example program and made these changes:</p> <pre><code>#define PIN_RESET 3 // Connect RST to pin 3 #define PIN_DC 4 // Connect DC to pin 4 #define PIN_CS 10 // Connect CS to pin 10 #define DC_JUMPER 0 </code></pre> <p>I connected everything according to Sparfun's walkthrough. I also wired accordingly. However, I cannot seem to get the Oled to do, well, much of anything. I have tried switching the MOSI and MISO to see if that makes a difference, but it doesn't seem to have any effect.</p> <p>I'm using: pin 13 - clock (in the picture I was trying pin 8 for the clock but I have tried both)</p> <p>pin 12 - MISO</p> <p>pin 11 - MOSI</p> <p>pin 10 - CS</p> <p>pin 4 - DC</p> <p>pin 3 - RESET</p> <p>Can anyone tell me what's going wrong? I've tried to figure it out for a good long while now and I can't make the display do anything productive.</p> <p>Thanks</p> <p><img src="https://i.stack.imgur.com/fPHgg.jpg" alt="enter image description here"></p>
<p>Have you connected the <code>GND</code> pin from the <code>UNO</code> to the breadboard? I can't hardly tell. But it looks like you are also using 5V to power it?</p> <p>How are you powering the <code>UNO</code>? Is it just 3.3V? I'm powering mine with a 5V but have level converters connected. </p> <p>Mine:</p> <p><img src="https://i.stack.imgur.com/K8Lth.jpg" alt="UNO with OLED"></p>
6875
|arduino-uno|
How to use 503 Thermistors for temperature?
2015-01-06T04:23:25.653
<p>I have a black Thermistor with the number 503 on it.</p> <p>I know that I would need a 50k resistor as a voltage divider. </p> <p>I don't get to convert the number I am getting. I get the number 340 when my house is at 64*F. I bought a kit on Amazon and it came with it and there is no documentation.A test with multimeter has shown at 17*C I get 30k ohms.</p> <p>This is how it is wired:</p> <pre><code>[Ground] -- [50k-resistor] -- | -- [(503)thermistor] --[Vcc (5v)] | Analog Pin 0 </code></pre>
<p>I found some code for a 10k thermistor and modified it for a 50k and cut out the code to display Celcius. I found this on the Arduino playground posted by: Milan Malesevic and Zoran Stupic.</p> <p>Origional code is found here: <a href="http://playground.arduino.cc/ComponentLib/Thermistor2" rel="nofollow">http://playground.arduino.cc/ComponentLib/Thermistor2</a></p> <p>This is what I came up with and it returned the proper temp in F for a 503 Thermistor.</p> <pre><code>#include &lt;math.h&gt; // enumerating 3 major temperature scales enum { T_KELVIN=0, T_CELSIUS, T_FAHRENHEIT }; #define EPISCO_K164_10k 4300.0f,298.15f,50000.0f // B,T0,R0 float Temperature(int AnalogInputNumber,int OutputUnit,float B,float T0,float R0,float R_Balance) { float R,T; // R=1024.0f*R_Balance/float(analogRead(AnalogInputNumber)))-R_Balance; R=R_Balance*(1024.0f/float(analogRead(AnalogInputNumber))-1); T=1.0f/(1.0f/T0+(1.0f/B)*log(R/R0)); switch(OutputUnit) { case T_CELSIUS : T-=273.15f; break; case T_FAHRENHEIT : T=9.0f*(T-273.15f)/5.0f+32.0f; break; default: break; }; return T; } //example of use #2 // using numbers instead of episco k164 definition // this time reading from analog input 2 // getting result in fahrenheit void setup() { Serial.begin(9600); } void loop() { Serial.println("********"); Serial.println("Temp"); Serial.println(Temperature(2,T_FAHRENHEIT,4300.0f,298.15f,50000.0f,10000.0f)); Serial.println("********"); Serial.println(" "); delay(500); } </code></pre> <p>Good luck!!!!</p>
6883
|serial|
When I open a COM port some pins on Arduino Uno goes low for about 2 seconds
2015-01-06T17:15:25.757
<p>I have no idea why this is happening, but after I open COM port to talk with my Arduino (I click "Open" in RealTerm), the state of some pins goes from high to low for about 2 seconds and then goes back to high. Here's my code:</p> <pre><code>void setup() { pinMode(5, OUTPUT); digitalWrite(5, HIGH); Serial.begin(9600); } void loop() { } </code></pre> <p>In this case pin 5 will behave this way. I've checked it also for pin 6 and pin 8 and they behave in the same manner. I suppose more pins act like that. Why is this happening?</p>
<p>The arduino is reseting because of the serial port initializing. If you want to avoid it, you can put a 120 ohm resistor between 5v and reset.</p> <p><a href="http://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection" rel="nofollow">Source</a></p>
7893
|arduino-mega|
Self answering a Intercom and playing louldy for person to response
2015-01-07T09:58:53.043
<p>We have two labs - one in 1st floor and other at 2nd floor. We are connected by intercom - both the labs has one device each. The issue is that the person who sits near the intercom is busy through out day answering the intercom and reaching out to the person for whom the call is made for.</p> <p>This is very tiresome and hence I wish to automate this. I have an Arduino Mega 2560 board. My plan is to make Arduino receive the call ask for the person whom the caller is reaching out and play the name loudly over speaker in all rooms of labs (to attended the phone). If the user does not turns up even after 3 repeated times of calling - disconnect the call. If the user answers the phone by picking up the receiver then turn the conversation speaker mode off until call has not ended.</p> <p>I have Arduino Mega 2560 board which has 4 serial ports but I am not user what would be the circuit to make this functionality workable? What are the extra h/w required and concept of its implementation.</p>
<p>Let's try to break it down to several components:</p> <ul> <li><strong>Interfacing with POTS</strong> (Plain Old Telephony System): There is <a href="http://ww.joes.com/intercom/index.html" rel="nofollow noreferrer">a nice article</a> by Joe Doll describing how to interface an Arduino and POTS. POTS involves high voltage during both idle and ringing time (48 V DC, superimposed 90 V AC) and the circuit itself is <a href="http://www.joes.com/intercom/circuit.html" rel="nofollow noreferrer">mostly analog</a>. You can find the required parts and their values in his article, which goes down into the nasty details in a spectacular fashion. Here is the analog circuit, involving the Arduino, from his post:</li> </ul> <p><img src="https://i.stack.imgur.com/iEReN.jpg" alt="Arduino interfacing POTS from Joe Doll&#39;s website"></p> <p>Consider that there are other projects performing similar task in a different manner, like <a href="http://brohogan.blogspot.co.il/2009/12/telephone-interface.html" rel="nofollow noreferrer">this one</a>, and <a href="http://blog.andrewstella.com/2013/12/new-project-arduino-rotary-phone.html" rel="nofollow noreferrer">this one</a> which specifically explains how to record sound from an old rotary phone.</p> <ul> <li><p><strong>Play/Record sound from Arduino Mega 2650:</strong> There are many projects that describe how to <a href="http://www.instructables.com/id/Arduino-playing-wav-files/" rel="nofollow noreferrer">Play</a> or <a href="http://www.instructables.com/id/Arduino-Mega-Audio-File-logging/" rel="nofollow noreferrer">Record</a> sound using Arduino. Most involve a SD card to store the wav files. There is also the option of an MP3 shield, that comes with a pre-built SD card slot, such as <a href="https://www.sparkfun.com/products/10628" rel="nofollow noreferrer">this one</a>. They are fully documented and are easy to interface with. </p></li> <li><p><strong>Code that encapsulates the Logic</strong>: Here you could decide how many times the Arduino should play the recorded name, and what happens if the user won't answer. The disconnection will be done utilizing the POTS interface you created in bullet #1. In addition, you should handle the logic of what happens when the user does answer. It is not clear what you mean by 'receiver', but if you plan to have a remote extension or similar, some extra work will be required.</p></li> </ul> <p>As a side note, it might be easier to create/re-use a walkie-talkie kind of wireless communicator, accompanied by an Arduino, to signal or broadcast the names of the people called. This might not include reuse or interfacing with the current intercom device, but by thus I believe it will make development easier and faster.</p>
7905
|programming|
Programming Arduino
2015-01-08T12:55:09.053
<p>I'm new to electronics. Professionally I'm a software developer. I want to know whether it is possible to program Atmel AVR 8-bit and 32-bit Microcontrollers using Arduino IDE. If yes could any one guide me on the process or direct me to any site where I can learn about it.</p>
<p>Just to complement the other responses. You can program some AVR chips using the Arduino IDE, but for it to work out-of-the-box just by using a USB cable it needs to be an Arduino or "Arduino compatible" board, mostly because these come with the <a href="http://arduino.cc/en/Hacking/Bootloader?from=Tutorial.Bootloader" rel="nofollow">Arduino Bootloader</a>.</p> <p>The bootloader is a small piece of software that runs at power-up and is responsible to load your program into the chip (as well as other configuration stuff, for more info read the previous link). If the AVR chip does not have the bootloader already flashed, then you will have to use a programmer (connected to its ISP pins) to burn it first.</p> <p>So, it's not like you can just buy random AVR chips or development boards online and start using them. But taking in consideration the wide selection of official boards and "Arduino compatible" ones, you should be able to find something to fit your needs.</p>
7908
|led|
SMlib State Machine Library not working as expected
2015-01-08T15:13:04.563
<p>I have the following setup and sketch.</p> <p>The problem is that when I click the button it works sometimes, but other times it executes On Off straight after On as if it's executing twice.</p> <p>This is after pressing the button only 7 times:</p> <pre><code>Off On Off On Off On Off On Off </code></pre> <p>I thought that was the whole point of a state machine? That it continues to execute the next state (not multiple times at random).</p> <p>Very very confused with this one.</p> <p><img src="https://i.stack.imgur.com/xcvLw.png" alt="enter image description here"></p> <pre><code>//http://www.arduino.cc/playground/uploads/Code/FSM.zip #include &lt;FiniteStateMachine.h&gt; //http://www.arduino.cc/playground/uploads/Code/Button.zip #include &lt;Button.h&gt; //http://www.arduino.cc/playground/uploads/Code/LED.zip #include &lt;LED.h&gt; const byte NUMBER_OF_STATES = 2; //how many states are we cycling through? //initialize states State On = State(ledOn); State Off = State(ledOff); FSM ledStateMachine = FSM(On); //initialize state machine, start in state: On Button button = Button(2, INPUT_PULLUP); //initialize the button (wire between pin 12 and ground) LED led = LED(13); //initialize the LED byte buttonPresses = 0; //counter variable, hols number of button presses void setup(){ Serial.begin(9600); } //poor example, but then again; it's just an example void loop(){ if (button.uniquePress()){ //increment buttonPresses and constrain it to [ 0, 1 ] buttonPresses = ++buttonPresses % NUMBER_OF_STATES; switch (buttonPresses){ case 0: ledStateMachine.transitionTo(On); Serial.println("On"); break; case 1: ledStateMachine.transitionTo(Off); Serial.println("Off"); break; } } ledStateMachine.update(); } //utility functions void ledOn(){ led.on(); } void ledOff(){ led.off(); } //end utility functions </code></pre>
<p>It doesn't look like the state machine is a problem here. More likely it's a problem of the button bouncing, as you don't have any code or circuitry to guard against it.</p> <p>A button is typically a very simple component which doesn't necessarily make/break connections cleanly. Sometimes it will have a brief intermittent connection, making it look like it's been pressed/released multiple times. This is referred to as bouncing.</p> <p>There's lots of material online about debouncing, whether in hardware or software. The top answer here may help:</p> <ul> <li><a href="https://arduino.stackexchange.com/questions/408/why-does-my-sketch-report-too-many-button-presses/411#411">Why does my sketch report too many button presses?</a></li> </ul>
7912
|atmega328|hardware|
Can I use an ATmega328 alone without anything and what is the max voltage I can power the atmega328 with
2015-01-08T16:15:23.107
<p>Okay 2 questions. If I am to replace the Arduino with an ATmega328 programmed with a standard blink on pin 13, is this configuration correct, do I still need oscillators and whatnot?</p> <p><img src="https://i.stack.imgur.com/uaFJc.jpg" alt="Simple breadboard circuit with LED on pin 13 of ATmega328"></p> <p>Second question is, what is the max voltage I can power the ATmega328 with without frying it? I have seen conflicting answers of this on the net. Some have said 5V while some say 6V can someone clarify?</p>
<p>I have a page describing <a href="http://www.gammon.com.au/breadboard" rel="nofollow noreferrer">How to make an Arduino-compatible minimal board</a>. The minimal setup would be:</p> <p><a href="https://i.stack.imgur.com/4NRfB.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4NRfB.jpg" alt="enter image description here"></a></p> <p>That excludes the circuitry for uploading your code.</p> <p>By the way, in the image in the question you have an LED with no resistor. That will damage both the LED and the Atmega328. You need a <strong>current-limiting resistor</strong>.</p> <hr> <blockquote> <p>do I still need oscillators</p> </blockquote> <p>Not if you program the fuse to use the internal oscillator.</p> <blockquote> <p>Some have said 5v while some say 6v can someone clarify?</p> </blockquote> <p>The datasheet says 1.8 to 5.5 V operating range with an <strong>absolute maximum rating</strong> of 6 V.</p> <p>This is what the datasheet says about absolute maximum ratings:</p> <blockquote> <p>This is a stress rating only and functional operation of the device at these or other conditions beyond those indicated in the operational sections of this specification is not implied. Exposure to absolute maximum rating conditions for extended periods may affect device reliability.</p> </blockquote> <p>Page 2 of the datasheet says:</p> <blockquote> <ul> <li>Operating Voltage:</li> <li>1.8 - 5.5V</li> </ul> </blockquote>
7917
|lcd|frequency|
How to change input pin of FreqCounter Arduino Uno/Dumilanove library?
2015-01-08T22:23:11.357
<p>The following link to the library defines arduino pin 5 for input pin for signal.<br> <a href="https://www.pjrc.com/teensy/td_libs_FreqCount.html" rel="nofollow noreferrer">https://www.pjrc.com/teensy/td_libs_FreqCount.html</a></p> <p>But the problem is I'm using an 16x2 LCD display with the arduino pin 5. The display needs pin 5 to work. So the question can solved in two ways,to both of which I don't know the answer.<br> 1. Change LCD pin number to other pin. (Tried it was a failure. I've probably done it wrong)<br> 2. Change the input pin for the freqcount library.</p> <p>Any idea how to get past this bottleneck?</p>
<p>The library makes use of the hardware peripheral Timer 1 which has its input on pin 5 of the Uno.</p> <p>It can't be changed. You have no choice in that.</p> <p>You will have to move the LCD to another pin instead.</p>
7920
|button|string|
Simple Text input using 5 buttons
2015-01-09T10:35:35.703
<p>So I have to get this function done but I'm not so bright and got confused. (excuse me! I'm total noob)</p> <p>The function is basically inputing text using five buttons, directional buttons and an ok button. The up and down buttons will be used to cycle through letters (a-z), and the left and right buttons will be used to control which array to cycle letters.</p> <p>The control will be:</p> <ul> <li>up button (up): ASCII-1 (z, y, x...)</li> <li>down button (dw): ASCII+1 (a, b, c...)</li> <li>right button (ri): array[i] ~> i+1 (go to next character/array)</li> <li>left button (le): array[i] ~> i-1 (go to previous character/array)</li> <li>ok button (ok): confirm text and changes the limit to stop function looping</li> </ul> <p>I can't get it work with this code I write. </p> <pre class="lang-cpp prettyprint-override"><code>void intext() { int lim=16; lcd.setCursor(0,1); lcd.print(input); for(i=0; i&lt;lim ; ) { if(digitalRead(dw)==HIGH) { if(input[i]&lt;'a') input[i]='z'; if(input[i]&gt;'z') input[i]='a'; input[i]=input[i]+1; delay(1000); } if(digitalRead(up)==HIGH) { if(input[i]&lt;'a') input[i]='z'; if(input[i]&gt;'z') input[i]='a'; input[i]=input[i]-1; delay(1000); } if(digitalRead(ri)==HIGH) { delay(1000); i=i+1; } if(digitalRead(le)==HIGH) { delay(1000); i=i+1; } if(digitalRead(ok)==HIGH) { lim=i+1; delay(1000); } } } void loop() { lcd.begin(16,2); lcd.setCursor(0,0); lcd.print("Type your text:"); intext(); lcd.setCursor(0,0); lcd.print("Success!!"); lcd.setCursor(0,1); lcd.print(input); } </code></pre> <p>The result I wanted it to be is like this: first you got the "type your text:" on the first row and blank in the second row. our cursor is in the first column of the second row, so we can cycle through the alphabet letters. if you press right you can edit the next column of second row. you can get to the previous column in second row by pressing left. you can input up to 15 characters. after done typing pressing ok will stop the typing and you will see "Success!!" in the first row and typed text in the second row.</p> <p>Please help. I'm stumped. Thank you.</p>
<p>Several issues in the code you posted:</p> <ul> <li><p>Every change to the text you do inside the <code>for</code> loop, will not be reflected to the LCD until the for loop will end (when <code>i&lt;limit</code> will no longer be a true statement). You might want to add an additional code, inside the <code>for</code> loop and outside any of its conditional statements, that will repeatedly set the cursor and print <code>input</code> to the LCD. Something similar to the code you have prior to the <code>for</code> loop:</p> <pre><code>void intext() { ... // rest of the code until the for loop for (int i; i&lt;limit; ) { ... // all the conditions for up/down/left/right/ok lcd.setCursor(0,1); lcd.print(input); } } </code></pre></li> <li><p>Another problem is that when the user clicks <em>left</em>, the counter should be decremented, not incremented, and you should check for left boundary:</p> <pre><code>if(digitalRead(le)==HIGH &amp;&amp; i&gt;0) // left boundary check added { delay(1000); i=i-1; // and not i=i+1; } </code></pre></li> <li><p>After clicking <em>Ok</em>, and since the <code>for</code> loop does not increment <code>i</code>, the condition in the <code>for</code> loop (<code>i&lt;limit</code>) will stay true, and the loop will not end until the user will click <em>Right</em> once more. To mitigate this, change the following</p> <pre><code>if(digitalRead(ok)==HIGH) { lim=i; // and not: lim=i+1; delay(1000); } </code></pre></li> </ul> <p>Otherwise, the user will have to click <em>Right</em> for completion, to increment <code>i</code> once more. </p> <ul> <li><strong>jfpoilpret</strong> comment about pull up/down is very important. Make sure you use pull up/pull down resistors in order to prevent <a href="http://arduino.cc/en/Tutorial/Debounce" rel="nofollow">input debounce</a> (more details inside this link).</li> </ul>
7926
|sensors|
What is the best vehicle platform to begin with (e.g. tracked, four-wheel drive)
2015-01-09T16:25:06.973
<p>Despite many articles on the topic of vehicle platforms, none of them seem to recommend the best one to start with. Later on I am sure I will seek an exact kind of chassis for autonomous vehicle construction, but now I am looking to learn the basics of this area of the Arduino world. If you could give me a simple recommendation for the general category of vehicle platform to use it would be much appreciated. I will be using an ultrasonic distance sensor coupled with a servo motor to detect obstacles, so it is a very simple project. Thank you so much.</p>
<p>SparkFun's <a href="https://www.sparkfun.com/products/12866" rel="nofollow noreferrer">Magician Chassis</a> is a very simple, very flexible chassis for starting out. Also comes as part of the <a href="https://www.sparkfun.com/products/12697" rel="nofollow noreferrer">RedBot Kit</a>.</p> <p><img src="https://i.stack.imgur.com/GUDrQ.jpg" alt="enter image description here"></p>
7928
|programming|c++|coding-standards|
coding standards for bigger projects
2015-01-09T16:46:38.533
<p>I'm starting a decently sized project around arduino/ATMELavr, and I came to wonder if there are any commonly accepted C/C++ coding standards or style guidelines specifically aimed at embedded C++/arduino.</p> <p>I've worked mostly with python recently, and came to love the PEP8 guidelines, and the associated pep tool (which checks syntax consistency with the style guide). Similarly, I've used jslint and similar tools for javascript, as I find they help keeping your code base homogeneous, and avoid wasting time and commits on silly typos, and arguing over where the braces should go.</p> <p>Any similar tools for C++ or more specifically arduino C++?</p>
<p>In my experience (15 years in industry, 30 total), <strong>this does not matter</strong>. What matters is having good developers who understand code written in ANY valid style. I currently work at a large bank, and there's 2 different bracket styles being used in our code, and nobody cares. Good developers don't care about this. We care a lot more about the code being valid, error-free, and efficient. If you do that, I don't care where your brackets are.</p> <p>Yes, there are style guides for C++ but you don't need to use them. This is a good one though...</p> <p><a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.html" rel="nofollow">http://google-styleguide.googlecode.com/svn/trunk/cppguide.html</a></p> <p>I am not aware of any style tools that integrate into Arduino IDE. There are some style tools that integrate into Eclipse though - and if this is important to you and your team, I strongly suggest using Eclipse for development. The Arduino IDE isn't really for large projects.</p> <p><a href="http://astyleclipse.sourceforge.net/" rel="nofollow">http://astyleclipse.sourceforge.net/</a> - but Eclipse doesn't really need this, it has a pretty good built-in formatter.</p>
7936
|ftdi|
5V FTDI cable for Arduimu V3
2015-01-10T17:34:07.307
<p>I just recently bought an Arduimu v3. Rather annoyingly they did not supply an FTDI cable. I'm going for an FTDI cable where the I/O pins are configured to operate at 5v. I assume this is the right but I don't want to fry this board. Is this cable OK?</p>
<p>A 5V cable would be fine, or for about the same price, I would recommend an <a href="http://www.adafruit.com/product/284" rel="nofollow">Adafruit FTDI Friend</a> which is configurable between 5V and 3.3V.</p>
7953
|led|
How to make arduino show cpu usage with 10 leds?
2015-01-11T13:13:35.077
<p>So i want to make arduino show my computer cpu usage with leds, for example if 10% then 1 led will light, if 50% then 5 leds, if 80% then 8 leds...</p>
<p>There's three basic steps you need to cover:</p> <ol> <li>Get the CPU usage of your computer</li> <li>Communicate that to the Arduino</li> <li>Have the Arduino respond to the data</li> </ol> <p>We can't really help you with step 1. That's outside our remit. You should head over to <a href="https://stackoverflow.com/">StackOverflow</a> for that. How you would do it depends on your host OS since each one has its own way of reporting it.</p> <p>For step 2 you would need to write software for your computer, incorporating what you have learned from step 1. Once you have the correct data you need to send it over to the Arduino through its serial connection. You'd need to come up with a good way of doing that, but probably just sending the usage percentage as plain ASCII text separated by new-lines is probably simplest.</p> <p>Step 3 would entail reading in the data you sent in step 2, deciding what the numbers you have got mean, and then turning on the relevant LEDs.</p> <p>Another option, which might simplify things a little, might be to use something like <a href="http://arduino.cc/en/reference/firmata" rel="nofollow noreferrer">Firmata</a>, where your PC sends the instructions to turn the LEDs on and off, and the Arduino just becomes a kind of dumb interface that doesn't do much on its own.</p>
7958
|arduino-uno|sd-card|
Arduino Uno with SD, Cardinfo sketch how to list only visible files
2015-01-11T18:42:57.077
<p>There are two files (that can be seen on my computer) on my sd card, <code>6.bmp</code> and <code>example.txt</code> (the latter written from my arduino). I have them connected to my arduino via LCSTUDIO breakout board (which surprisingly caused me no trouble at all).</p> <p>When I run the example "cardinfo" sketch, the files it lists includes those two files along with tons of others, which I assume are just invisible from a personal computer.</p> <p>How would I list only the files that can be seen from my computer (i.e. aren't inside any directory, but are just plain in the SD card)?</p> <p>Using arduino UNO</p>
<p>Simple Answer: Don't think you can</p> <p>Long Answer: Dont think you can, because, unlike an OS like windows, mac, linux, etc. The arduino just tales all the files. You could save those two files and format it as FAT16 though, then add the 2 files back on the sd and there you go.</p>
7959
|serial|arduino-leonardo|communication|
Arduino Leonardo on Win 8.1 COM port disappeared
2015-01-11T16:47:54.417
<p>I've been using an Arduino Leonardo on my Windows machine for a few days now without too much trouble but today the COM port disappeared. I've been able to successfully send sketches to the arduino and execute them so everything was working until recently. When I look in Device manager on the control panel there is no com port listed for the arduino. If I reset the device then a com port shows up briefly with "Arduino Leonardo BootLoader" but after a few seconds that disappears. I've tried USB2.0 and USB 3.0 ports on my PC and a different cable but to no avail. I don't have anything listed under "Other Devices" and I'm out of ideas for what could be the trouble. I'm trying to get it recognised now as just the leonardo with nothing connected to any pin. Any ideas of what to try?</p>
<p>Strange, it's resolved itself/I resolved it. I don't know whether what I did was actually responsible for solving this but I'm back in business: * I reset the board so that the bootloader appeared as a com port * I set the arduino IDE to use the port that appeared for the bootloader * I uploaded a simple sketch and pressed reset during the "upload phase" so that the port appeared during the upload * the upload completed successfully and the arduino was back in the com port list</p> <p>I'd still be interested to understand what I did that caused the problem in the first place but I suppose something was corrupted on the board?</p>
7963
|led|
RGB fade program
2015-01-12T01:59:54.837
<p>I'm working on a function to fade RGB LEDs smoothly from one color to the next, so I thought I'd use a for loop to increment each RGB value according with the set value. I've made the for loop as following:</p> <pre><code>for (redFadeCurrent, greenFadeCurrent, blueFadeCurrent; ((redFadeCurrent != redFadeTarget)&amp;&amp; (greenFadeCurrent != greenFadeTarget)&amp;&amp; (blueFadeCurrent != blueFadeTarget)); redFadeCurrent = redFadeCurrent + redStep, greenFadeCurrent = greenFadeCurrent + greenStep, blueFadeCurrent = blueFadeCurrent + blueStep) { analogWrite(ledRedPin, redFadeCurrent); analogWrite(ledGreenPin, greenFadeCurrent); analogWrite(ledBluePin, blueFadeCurrent); Serial.print("Red: "); Serial.print(redFadeCurrent); Serial.print(" Green: "); Serial.print(greenFadeCurrent); Serial.print(" Blue: "); Serial.println(blueFadeCurrent); delay(3000); if (redFadeCurrent&gt;redFadeTarget) { redStep = -1; } else if (redFadeCurrent&lt;redFadeTarget) { redStep = +1; } else { redStep = 0; } if (greenFadeCurrent&gt;greenFadeTarget) { greenStep = -1; } else if (greenFadeCurrent&lt;greenFadeTarget) { greenStep = +1; } else { greenStep = 0; } if (blueFadeCurrent&gt;blueFadeTarget) { blueStep = -1; } else if (blueFadeCurrent&lt;blueFadeTarget) { blueStep = +1; } else { blueStep = 0; } </code></pre> <p>Problem is, when one of the values hit the target the code leaves the for loop. I'm guessing the condition <code>((redFadeCurrent != redFadeTarget)&amp;&amp;(greenFadeCurrent != greenFadeTarget)&amp;&amp;(blueFadeCurrent != blueFadeTarget))</code> does not work. </p> <p>Is there any way to work around this? </p> <p>Thanks is advance.</p>
<p>You are correct, the problem is the condition inside the <code>for</code> statement.</p> <p>Let's examine what happens when the <em>red</em> LED hits its fading target, which is, say, 100 (for the sake of the example, I will fabricate the other values):</p> <pre><code>for (...; (100 != 100) &amp;&amp; (90 != 100) &amp;&amp; (80 != 100) ; ... ) </code></pre> <ul> <li>(100 != 100) -> <strong>FALSE</strong> </li> <li>(90 != 100) -> <strong>TRUE</strong></li> <li>(80 != 100) -> <strong>TRUE</strong></li> </ul> <p><strong>FALSE</strong> &amp;&amp; <strong>TRUE</strong> &amp;&amp; <strong>TRUE</strong> -> <strong>FALSE</strong></p> <p>The condition inside the <code>for</code> evaluates to <code>FALSE</code>, therefor the loop will exit. </p> <p>If you want the loop to continue as long as there is at least one LED which hasn't hit the fading target, you should change the <code>AND</code> to <code>OR</code>:</p> <pre><code>((redFadeCurrent != redFadeTarget) || (greenFadeCurrent != greenFadeTarget) || (blueFadeCurrent != blueFadeTarget)) </code></pre> <p>Let's examine what happens now with the same values:</p> <pre><code>for (...; (100!=100) || (90 != 100) || (80 != 100) ; ...) </code></pre> <ul> <li>(100 != 100) -> FALSE</li> <li>(90 != 100) -> TRUE</li> <li>(80 != 100) -> TRUE</li> </ul> <p><strong>FALSE</strong> || <strong>TRUE</strong> || <strong>TRUE</strong> -> <strong>TRUE</strong> ==> The loop will continue. </p> <p>And what will happen when all the colors hit the fading targets?</p> <pre><code>for (...; (100!=100) || (100 != 100) || (100 != 100) ; ...) </code></pre> <ul> <li>(100 != 100) -> FALSE </li> <li>(100 != 100) -> FALSE </li> <li>(100 != 100) -> FALSE </li> </ul> <p><strong>FALSE</strong> || <strong>FALSE</strong> || <strong>FALSE</strong> -> <strong>FALSE</strong> ==> The loop will stop since the condition will not evaluate to <code>TRUE</code>.</p>
7966
|led|
Why are LED 0 and 1 on as well?
2015-01-12T08:55:38.213
<p>I was just playing around a bit and ran into a strange problem. LED 3, 5, 6, 9 and 10 are on, as intended. For some reason LED 0 and 1 are on as well. Can someone explain why this is happening?</p> <pre><code>int ledPins[] = {3, 5, 6, 9, 10}; int pinCount = sizeof(ledPins); void setup(){ for (int i = 0; i &lt; pinCount; i++){ pinMode(ledPins[i], OUTPUT); } } void loop(){ for (int i = 0; i &lt; pinCount; i++){ digitalWrite(ledPins[i], 1); } } </code></pre>
<p>The behaviour of your program is undefined because you're reading past the end of your array.</p> <p>In C/C++, the <code>sizeof</code> operator always gives you the size of something in <strong>bytes</strong>. It doesn't directly tell you the number of items in an array. Since <code>int</code> is usually 2 bytes for Arduino programming, the <code>pinCount</code> variable is actually being initialised to <strong>10</strong> (5 items x 2 bytes each).</p> <p>The result is that each <code>for</code> loop is actually doing 10 iterations. The first 5 iterations are OK, reading correctly from the <code>ledPins</code> array. However, the rest of the iterations are reading whatever data happens to be in memory after that. This means it could be trying to initialise and switch on any pin, potentially including 0 and 1.</p> <p>I can't guarantee that this is the source of the problem, but it's certainly very important to fix.</p> <p>The solution is quite easy though. Divide the total size of the array by the size of a single element:</p> <pre><code>int pinCount = sizeof(ledPins) / sizeof(int); </code></pre>
7976
|serial|arduino-mega|
Decoding a RS232 message in Arduino
2015-01-12T11:14:01.863
<p>I have an Arduino Mega with an MaxBotix (MB7066) sonar attached, the sonar has the ability to send serial data with it's reading. It uses a asynchronous RS232 format, except the voltages are 0-Vcc. The output should be a capital "R" (ASCII), followed by four digits(ASCII) and a carriage return (ASCII 13). The baud rate is 9600, 8 bits, no parity with one stop bit. What I get from the device is as follows: (sonarSerial.read() while sonarSerial.available())</p> <pre><code>43 192 6 6 179 89 30 0 </code></pre> <p>What do I have to get to the information? Or is my sensor just retuning garbage? Please see the code below:</p> <pre><code>#include &lt;SoftwareSerial.h&gt; #define pin1 3 #define pin2 5 //pwm #define pin3 6 //analog #define pin4 10 //RX for sonar, TX for arduino #define pin5 11 //TX for sonar, RX for arduino SoftwareSerial sonarPort(pin5,pin4); void setup(){ Serial.begin (9600); pinMode(pin1, OUTPUT); pinMode(pin4, OUTPUT); pinMode(pin5, INPUT); sonarPort.begin(9600); } void loop(){ digitalWrite(pin1, HIGH); digitalWrite(pin4, LOW); digitalWrite(pin4, HIGH); delayMicroseconds(20); digitalWrite(pin4, LOW); long pulse = pulseIn(pin2, HIGH)/58; Serial.print("PM Result: "); Serial.println(pulse); String buffer = ""; sonarPort.listen(); while(sonarPort.available() &gt; 0){ int inByte = sonarPort.read(); buffer += inByte; buffer += " "; if(!sonarPort.available()){ Serial.print("Serial result: "); Serial.println(buffer); } } delay(500); } </code></pre>
<p>I contacted MaxBotix with the problem and for my surprise their technical support is really great:</p> <blockquote> <p>The Arduino is set up to natively read TTL serial data.The MB7066 outputs its serial data in the RS232 format. Do not worry; this problem can easily be fixed. You can use an inverter such as the MAX232. You can also follow the following tutorial to make your own <a href="https://github.com/simonmonk/raspirobotboard/wiki/Rangefinder-Adapter" rel="nofollow">https://github.com/simonmonk/raspirobotboard/wiki/Rangefinder-Adapter</a>.</p> <p>Another option would be to test using this code section SoftwareSerial sonarSerial(rxPin, txPin, true); //define serial port for recieving data, output from maxSonar is inverted requiring true to be set.</p> </blockquote>
7977
|arduino-yun|ethernet|
Unable to connect to Linux Environment (Linino AR9331 Interface) in Arduino Yun
2015-01-12T12:08:48.483
<p>I was trying to reset my Arduino Yun (WLAN button pressed for more than 30 seconds), but it just kept on blinking for about 10 minutes. Then I finally got impatient and restarted the Yun. After the restart, there was no WLAN (blue) or USB (white) LED blinking or glowing anymore. I am unable to connect through the Wifi network, the Yun does not create it's own Wifi network and unfortunately when connected via Ethernet, I can still not navigate to arduino.local or 192.168.240.1. </p> <p>So I have a feeling that somehow only the AVR is still functioning (because I can still upload sketches) and nothing else.</p> <p>I have updated the firmware to the latest version (OpenWrt-Yun 1.5.3). Is there a way to connect or reset, if the Ethernet does not work? Can I upload a sketch to check in the console if the Linino interface still functions.</p> <p>Thanks in advance!</p>
<p>Try uploading YunSerialTerminal example, opening the serial monitor and pressing the YUN RST button. You should see the linux side starting.</p> <p>If it starts but it looks somehow bricked, you could try following the <a href="http://arduino.cc/en/Tutorial/YunUBootReflash" rel="nofollow">http://arduino.cc/en/Tutorial/YunUBootReflash</a> tutorial.</p>
7979
|power|interrupt|atmega328|sleep|
Power consumption issue. I made project using atmel-328p
2015-01-12T14:57:07.483
<p>I made project using atmel-328p. I want to run it over a year. I am using power_down mode &amp; 5500 mAh li-ion battery still battery discharges in 1 day. I am using standard code as explain on arduino site. code is:</p> <pre><code>String uniqueid; char value; volatile int NbTopsFan; //measuring the rising edges of the signal uint32_t Calc; int hallsensor = 2; //The pin location of the sensor int power = 4; // ph sensor define SensorPin 0 //pH meter Analog output to Arduino Analog Input 0 define Offset 0.00 //deviation compensate unsigned long int avgValue; //Store the average value of the sensor feedback // temp sensor OneWire ds(8); byte i; byte present = 0; byte data[12]; byte addr[8]; int HighByte, LowByte, SignBit, Whole, Fract, TReading, Tc_100, FWhole; int wakePin = 3; // pin used for waking up int sleepStatus = 0; // variable to store a request for sleep int countsleep = 0; // counter void wakeUpNow() // here the interrupt is handled after wakeup {// execute code here after wake-up before returning to the loop() function } void rpm () //This is the function that the interupt calls { NbTopsFan++; //This function measures the rising and falling edge of the //hall effect sensors signal } void setup() { pinMode(hallsensor, INPUT); //initializes digital pin 2 as an input Serial.begin(9600); //This is the setup function where the serial port is pinMode(power, OUTPUT); //initialised, attachInterrupt(0, rpm, RISING); //and the interrupt is attached //initialised, //and the interrupt is attached // temp sensor pin 8 if ( !ds.search(addr)) { // Serial.println("temp sensor is not connected"); delay(1000); ds.reset_search(); return; } if ( OneWire::crc8( addr, 7) != addr[7]) { // Serial.println("CRC not valid!"); delay(1000); return; } pinMode(wakePin, INPUT); attachInterrupt(1, wakeUpNow, LOW); // use interrupt 1 (pin 3) and run function } void sleepNow() // here we put the arduino to sleep { countsleep = 0; ADCSRA = 0; set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here sleep_enable(); // enables the sleep bit in the mcucr register // so sleep is possible. just a safety pin // turn off brown-out enable in software MCUCR = bit (BODS) | bit (BODSE); // turn on brown-out enable select MCUCR = bit (BODS); // this must be done within 4 clock cycles of above sleep_cpu (); attachInterrupt(1,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function // wakeUpNow when pin 2 gets LOW sleep_mode(); // here the device is actually put to sleep!! // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP sleep_disable(); // first thing after waking from sleep: // disable sleep... detachInterrupt(1); // disables interrupt 0 on pin 2 so the // wakeUpNow code will not be executed } void loop() { countsleep++; delay(1000); // waits for a second // compute the serial input if (Serial.available()) { String content = ""; char character; // to read serial data coming while(Serial.available()&gt;0) { character = Serial.read(); content.concat(character); } String uniqueidread = content.substring(0,16); String parameter = content.substring(16,17); String checkuuid = content.substring(0,3); String putinsleep = content.substring(0,5); if (uniqueidread == uniqueid &amp;&amp; parameter == "5") { // Serial.flush(); digitalWrite(power,HIGH); NbTopsFan = 0; //Set NbTops to 0 ready for calculations sei(); //Enables interrupts delay (1000); //Wait 1 second cli(); //Disable interrupts Calc = (NbTopsFan * 60 / 7.5); //(Pulse frequency x 60) / 7.5Q, = flow rate digitalWrite(power,LOW); getTemp(); delay(1000); getTemp(); // printTemp(); Serial.print("Temp is: "); if (SignBit) { Serial.print(" - "); } if( Whole == 0) { Serial.print("temp sensor is not connected"); } else { Serial.print(Whole); Serial.print(" C / "); Serial.print(FWhole); Serial.print(" F"); } Serial.print(", Current Reading = "); Serial.print (Calc, DEC); //Prints the number calculated above Serial.print(" L/hour"); phvalue(); Serial.println("S=m"); delay(100); sleepNow(); } if ( content == "sleep") { Serial.println("S=m"); delay(100); // this delay is needed, the sleep sleepNow(); // sleep function called here } } if (countsleep &gt;= 10) { Serial.println("T=m"); delay(100); // this delay is needed, the sleep //function will provoke a Serial error otherwise!! sleepNow(); // sleep function called here } } void getTemp() { int foo, bar; ds.reset(); ds.select(addr); ds.write(0x44,1); present = ds.reset(); ds.select(addr); ds.write(0xBE); for ( i = 0; i &lt; 9; i++) { data[i] = ds.read(); } LowByte = data[0]; HighByte = data[1]; TReading = (HighByte &lt;&lt; 8) + LowByte; SignBit = TReading &amp; 0x8000; // test most sig bit if (SignBit) { TReading = -TReading; } Tc_100 = (6 * TReading) + TReading / 4; // multiply by (100 * 0.0625) or 6.25 Whole = Tc_100 / 100; // separate off the whole and fractional portions Fract = Tc_100 % 100; if (Fract &gt; 49) { if (SignBit) { --Whole; } else { ++Whole; } } if (SignBit) { bar = -1; } else { bar = 1; } foo = ((Whole * bar) * 18); // celsius to fahrenheit conversion section FWhole = (((Whole * bar) * 18) / 10) + 32; if ((foo % 10) &gt; 4) { // round up if needed ++FWhole; } } void printTemp(void) { Serial.println(""); Serial.print("Temp is: "); if (SignBit) { Serial.print(" - "); } Serial.print(Whole); Serial.print(" C / "); Serial.print(FWhole); Serial.print(" F"); } void phvalue() { int buf[10]; //buffer for read analog for(int i=0;i&lt;10;i++) //Get 10 sample value from the sensor for smooth the value { buf[i]=analogRead(SensorPin); delay(10); } for(int i=0;i&lt;9;i++) //sort the analog from small to large { for(int j=i+1;j&lt;10;j++) { if(buf[i]&gt;buf[j]) { int temp=buf[i]; buf[i]=buf[j]; buf[j]=temp; } } } avgValue=0; for(int i=2;i&lt;8;i++) //take the average value of 6 center sample avgValue+=buf[i]; float phValue=(float)avgValue*5.0/1024/6; //convert the analog into millivolt phValue=3.5*phValue+Offset; //convert the millivolt into pH value Serial.print(" pH:"); Serial.print(phValue,2); Serial.print(" "); } </code></pre> <p><img src="https://i.stack.imgur.com/Hrn0t.jpg" alt="enter image description here"></p>
<p>You need to first check the individual current consumption of all elements: </p> <ul> <li>pH sensor, </li> <li>temp sensor, </li> <li>water flow sensor</li> <li>xbee. </li> </ul> <p>Since many of these just have an output pin in addition to +V &amp; GND, this means those have a permanent current consumption that, overall, may possibly drain your battery.</p> <p>You should then check the datasheets for all these components and see the minimum current consumption (and conditions for this consumption to be achieved).</p> <p>If the total minimum current for these components is too high for your system, then you can possibly:</p> <ul> <li>use an available ATmel digital output pin to power them (and unpower them just before switching the ATmel to low power mode); that's possible only if you stay within current limitations of the MCU (there are current limitation per pin, 20mA IIRC, and total current for the whole MCU)</li> <li>if current consumption is above ATmel limits then you can still use the method above but add a MOSFET in-between so that you limit ATmel current consumption</li> </ul> <p>I strongly advise you <a href="http://www.gammon.com.au/power" rel="nofollow">this link from Nick Gammon</a>, which is comprehensive and complete.</p>
7991
|bluetooth|android|
Android <-> HC-05 <-> Arduino communication issue
2015-01-12T22:04:41.743
<p>My project involves Android (Samsung Galaxy 2) to Arduino (Uno) communication via HC-05.</p> <p>HC-05 is connected to Arduino on pins 10,11 using SoftwareSerial lib.</p> <p>I got this setup running for a while and was satisfied by the outcome - my bi-directional communication worked fine.</p> <p><strong>Issue:</strong></p> <p>I made a change to the communication protocol and now messages sent from Android to Arduino get corrupted. It happens under particular circumstances - when Arduino writes (streams) packets of data to Android and, at the same time, monitors the input from Android for a particular message which signals the end of communication. This message, when read from SoftwareSerial buffer, gets corrupted. This corruption is not consistent - it corrupts the packet in (seemingly) random way.</p> <p>I've already run many tests and am pretty sure that this message is not corrupted on the Android side.</p> <p><strong>Questions:</strong></p> <ol> <li>Is there anything about HC-05 or SoftwareSerial lib which prevents simultaneous bi-directional communication? </li> <li>Can it be that input/output buffers interfere in some way?</li> <li>How can I achieve reliable communication using the aforementioned HW and comm scheme? </li> </ol> <p>P.S. I got pretty much code and am not sure what parts of it might be relevant to this issue. Will provide relevant parts per your request.</p> <p>Thx</p>
<p>Hey thought I'd pitch in. I was having quite a few issues in trying to control an led using hc 05 from an android phone. I was using SoftwareSerial. It didn't work. The board is an arduino mega 2560. Finally, I got it. SoftwareSerial turns digital pins to tx and rx com pins. Make sure to use digital pins on the board to communicate when your using SoftwareSerial. Hope it helps...</p>
8015
|arduino-uno|servo|
Cannot control servo with button.
2015-01-14T02:03:17.680
<p>I am unable to get a button on my arduino board to control a servo. I'd like the servo to rotate 90 degrees on button push, but it is unresponsive.</p> <p>Is there a flaw in my code or is it wiring?</p> <pre><code>#include &lt;Servo.h&gt; // servo library const int button1Pin = 2; // pushbutton 1 pin Servo servo1; // servo control object void setup() { pinMode(button1Pin, INPUT); servo1.attach(9); // Set servo 1 to output? } void loop() { int button1State; int position; button1State = digitalRead(button1Pin); if (button1State == LOW); { servo1.write(90); // move servo } } </code></pre>
<p>The problem is that <code>servo1.write(90)</code> does not do what you think it does.</p> <p><code>servo.write(angle)</code> tells the servo to go to that position, not to move by that many degrees. What you need is to set one angle when the button is not pressed, and a different angle when the button is pressed.</p> <p>Normal hobby servos can move about 180 degrees. Where 0 is depends on how the servo horn is positioned. Which direction of rotation is positive depends on the manufacturer. </p> <p>try something like this to set one position when the button is pressed and a different one when it is not:</p> <pre><code>if (button1State == LOW);{ servo1.write(45); // move servo } else { servo1.write(135); } </code></pre>
8025
|sensors|
Get the distance to non perpendicular surface
2015-01-14T16:56:23.807
<p>So I'm using the HC-SR04 modules to get the distance to objects, the problem is that if it's not a perpendicular surface I dont get any reading, and I assume that the reason is that the ultrasounds get reflected in another direction, so they don't come back to the sensor. What's the way to get over this issue?</p> <p>Thanks in advance</p>
<p>Use a <a href="https://www.sparkfun.com/products/242" rel="nofollow noreferrer">Infrared Proximity Sensor</a> <img src="https://i.stack.imgur.com/VWQT3.jpg" alt="enter image description here"></p> <p>or</p> <p>Something like a <a href="https://www.sparkfun.com/products/13167" rel="nofollow noreferrer">LidarLite</a> <img src="https://i.stack.imgur.com/YKvmE.jpg" alt="enter image description here"></p> <p>They measures distance by measuring the offset (<a href="https://en.wikipedia.org/wiki/Parallax" rel="nofollow noreferrer">parallax</a>) from a projected point of light. This will not suffer from echo restrictions, like Ultrasonic Sensors do.</p>
8026
|arduino-uno|sensors|
Freeze with VCNL 4000 Proximity Sensor
2015-01-14T17:31:07.940
<p>I've the VCNL 4000 Proximity Sensor I use some sample code and at the very beginning</p> <p>the following code hangs (never finishes)</p> <pre><code> readVCNLByte(0x81); is called </code></pre> <p>Can this problem be caused because the contact of the pin isn't very good.</p> <p>I only but the part with pins in the sensor without to solder it.</p> <p>Is it likely that this may be the problem ? I have not many experince with solder and the sensor is really small so i'd like to avoid it for first tests ;)</p> <p>Here the code. The last output in the Serial window is &quot;pre product&quot;</p> <pre><code> Serial.println(&quot;VCNL&quot;); Wire.begin(); Serial.println(&quot;pre product&quot;); uint8_t rev = read8(VCNL4000_PRODUCTID); Serial.println(&quot;post product&quot;); if ((rev &amp; 0xF0) != 0x10) { Serial.println(&quot;Sensor not found :(&quot;); while (1); } </code></pre> <p><img src="https://i.stack.imgur.com/jcIwU.jpg" alt="Before" /></p> <p><img src="https://i.stack.imgur.com/2MBZ0.jpg" alt="After" /></p> <p><img src="https://i.stack.imgur.com/prnZ1.jpg" alt="enter image description here" /></p>
<p>Sorry .. my answer comes late .. I had the same issue, this has nothing to do with bad connexion between wires (not only at least). But by playing with some parameter (current value &gt; 60mA) I noticed that the module begin to freeze more often. To fix that : You need to add a small delay within your readbyte function after a i2c.stop()</p> <p>I found that an issue had been written about that : <a href="https://github.com/adafruit/VCNL4000/issues/1" rel="nofollow noreferrer">https://github.com/adafruit/VCNL4000/issues/1</a> They recommand a 170us delay</p> <p>I'm testing myself at full current and max speed (an since 30min it didn't freeze)... Before it could freeze in a second.</p> <p>Hope it helps ;)</p> <hr /> <p>EDIT : In order to better understand where the freeze comes from, I re-write a simple I2C library. I could get rid of the freeze by simple add a small delay in the i2c_start function (that send the start condition along with the slave address)</p> <pre><code>uint8_t i2c_start(uint8_t i2c_slave_address){ //reset TWI control register TWCR = 0; //transmit start condition TWCR = (1&lt;&lt;TWINT) | (1&lt;&lt;TWSTA) | (1&lt;&lt;TWEN); //wait for end of transmission while((TWCR &amp; (1&lt;&lt;TWINT))==0){ _delay_us(75); // &lt;-- here is the trick } if( (TWSR &amp; 0xF8)!= TW_START ){ return -1; } // load slave address into data register TWDR = i2c_slave_address; //start address transmission TWCR = (1&lt;&lt;TWINT) | (1&lt;&lt;TWEN); //wait for transmission while ( (TWCR &amp; (1&lt;&lt;TWINT))==0 ); //check if the slave did acknoledge the Read/Write mode uint8_t twst = TW_STATUS &amp; 0xF8; if ( (twst != TW_MT_SLA_ACK) &amp;&amp; (twst != TW_MR_SLA_ACK) ){ return -1; } return 0; } </code></pre> <p>you will need to add these libraries : util/twi.h (for the macro TW_STATUS .. TTW_MT_SLA_ACK and so on)</p> <p>util/delay.h</p> <p>stdlib.h (for the uint8_t way of typing variable ..not actually 100% sure)</p> <p>I'm still not fully satisfy by this solution, but it is still more effective that the one that adafruit propose.</p> <p>I suggest you write you own i2c library (5 functions : init / start / read / write / stop) you now have the start already .. so 4 left ;)</p> <p>If you're still to much afraid : in twi.c ( .\arduino\avr\libraries\Wire\utility\twi.c) and twi_readFrom(...) function. On line 155 and 159 you will see that arduino send the start condition, but do not wait / take care that the transmission as been done... you can add a while function as previously describe to ensure it.</p> <hr /> <p>MASTER EDIT :</p> <p>My previous solution didn't solve the issue neither... Actually reading the application note (Designing VCNL4000 into an Application : google that) gives the solution (page 7) <a href="https://i.stack.imgur.com/4vcQ0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4vcQ0.png" alt="enter image description here" /></a></p> <p>after you send the command to perform a single measurement, you need to wait. I put a delay of 500ms and have none anywhere else. This works like a charm.</p> <p>But for energy efficiency I recommend to put the uC in sleep mode for that period of time.</p>
8029
|arduino-uno|
Emergency! INO file disappeared on computer. Still on Arduino!
2015-01-14T21:29:43.517
<p>For some reason, my Arduino program has disappeared from my computer, and it was a really long, complex program. It is currently still on my arduino, and I HAVE to get it back. Please, someone help me. Arduino UNO, Macbook Pro.</p> <p>Edit: Perhaps I wasn't clear. I need the INO file back FROM MY ARDUINO.</p>
<p>Your INO file is not (ever) on your Arduino.</p> <p>When you "upload your sketch" to the Arduino, it is first compiled. Your Arduino cannot interpret a sketch directly, and there are various processes which convert your sketch into machine code. This process is not practically reversible.</p>
8052
|lcd|string|
Simple word translator, return error: invalid array assignment
2015-01-16T04:24:57.693
<p>I know this is not a good question. But I am clueless with this error : invalid array assignment (at function convert). For extra information, I involved a lot of copying/pasting programs I haven't exactly understand from internet in the convert function (the strncpy ones) so.. yeah. </p> <p>This is the program I've done (the menu/mn button currently not used):</p> <pre><code>#include &lt;LiquidCrystal.h&gt; #define WORD 11 #define LETTER 15 LiquidCrystal lcd(7,6,5,4,3,2); int i=0; char input[] = "a"; char output[15]; const int dw = 8; const int ri = 9; const int le = 10; const int up = 11; const int ok = 12; const int mn = 13; int checker = 0; int bounceCk = 0; int bdw=0, bri=0, ble=0, beu=0, beo=0, bem=0; void setup() { pinMode(dw, INPUT); pinMode(ri, INPUT); pinMode(le, INPUT); pinMode(up, INPUT); pinMode(ok, INPUT); pinMode(mn, INPUT); } void intext() { int lim=16; lcd.setCursor(0,1); lcd.print(input); for(i=0; i&lt;lim ; ) { lcd.setCursor(0,1); lcd.print(input); if(digitalRead(dw)==HIGH) { checker=digitalRead(dw); delay(100); bounceCk=digitalRead(dw); if(checker==bounceCk) { if(input[i]&gt;'z') input[i]='a'; input[i]=input[i]+1; } } if(digitalRead(up)==HIGH) { checker=digitalRead(up); delay(100); bounceCk=digitalRead(up); if(checker==bounceCk) { if(input[i]&lt;'a') input[i]='z'; input[i]=input[i]-1; } } if(digitalRead(ri)==HIGH &amp;&amp; i&lt;16) { checker=digitalRead(ri); delay(100); bounceCk=digitalRead(ri); if(checker==bounceCk) { i=i+1; } } if(digitalRead(le)==HIGH &amp;&amp; i&gt;0) { checker=digitalRead(le); delay(100); bounceCk=digitalRead(le); if(checker==bounceCk) { i=i-1; } } if(digitalRead(ok)==HIGH) { checker=digitalRead(ok); delay(100); bounceCk=digitalRead(ok); if(checker==bounceCk) { lim=i; } } } } void convert() { char sumber[WORD][LETTER] = {{0}}; /* declare a progmem unsigned static array of kata x huruf */ char dasar[WORD][LETTER] = {{0}}; /* declare a progmem unsigned static array of kata x huruf */ /* copy various strings to statically declared storage SUMBER */ strncpy (sumber[0],"memakan", strlen("memakan")+1); strncpy (sumber[1],"makanan", strlen("makanan")+1); strncpy (sumber[2],"menyuci", strlen("menyuci")+1); strncpy (sumber[3],"perubahan", strlen("perubahan")+1); strncpy (sumber[4],"penulisan", strlen("penulisan")+1); strncpy (sumber[5],"tercampurkan", strlen("tercampurkan")+1); strncpy (sumber[6],"pengelompokan", strlen("pengelompokan")+1); strncpy (sumber[7],"pengembangan", strlen("pengembangan")+1); strncpy (sumber[8],"kehebatan", strlen("kehebatan")+1); strncpy (sumber[9],"memotret", strlen("memotret")+1); strncpy (sumber[10],"melakukan", strlen("melakukan")+1); /* copy various strings to statically declared storage DASAR*/ strncpy (dasar[0],"makan", strlen("makan")+1); strncpy (dasar[1],"makan", strlen("makan")+1); strncpy (dasar[2],"cuci", strlen("cuci")+1); strncpy (dasar[3],"ubah", strlen("ubah")+1); strncpy (dasar[4],"tulis", strlen("tulis")+1); strncpy (dasar[5],"campur", strlen("campur")+1); strncpy (dasar[6],"kelompok", strlen("kelompok")+1); strncpy (dasar[7],"kembang", strlen("kembang")+1); strncpy (dasar[8],"hebat", strlen("hebat")+1); strncpy (dasar[9],"potret", strlen("potret")+1); strncpy (dasar[10],"laku", strlen("laku")+1); /* mencari input pada sumber */ int k=0, search=0, sel=9; while(search==0) { sel=strcmp(input, sumber[k]); if(sel==0) { output[]=dasar[k]; //!!!!THE ERROR IS HERE!!! happen to either this or output=dasar[k] lcd.clear(); lcd.setCursor(0,0); lcd.print("Base Word:"); lcd.setCursor(0,1); lcd.print(output); search=1; } else { k=k+1; if(k&gt;=11) { lcd.clear(); lcd.setCursor(0,0); lcd.print("Error:NF"); lcd.setCursor(0,1); lcd.print("word n found"); search=1; } } } /* //print the values while (*sumber[i]) printf (" %s\n", sumber[i++]); */ } void loop() { lcd.begin(16,2); lcd.setCursor(0,0); lcd.print("Type your word:"); intext(); convert(); delay(15000); } </code></pre> <p>I found more errors before, I've fixed those, but can't fix this one. I think this problem is caused by the wrong instruction or wrong format. But can't found solution...yet.</p> <p>The program is converting words to its basic word in Bahasa, you can compare it to English like this. You type "eaten" and it will return "eat". You type "understood" it will return "understand". When you type "stunk" it will return "stink". Or something like that. </p> <p>Example in bahasa : </p> <p>"memakan" (eating) -> "makan" (eat)</p> <p>"makanan" (food) -> "makan" (eat)</p> <p>"pengembangan" (development) -> "kembang" (becoming bigger/better)</p> <p>etc</p> <p>I hope someone will give me a clear hint or two (I'm not too bright, but I still need to learn how not just copying things around), Thank you very much!</p>
<p>It looks like you're trying to copy the contents of a particular sub-array in <code>dasar</code> across to the <code>output</code> array. However, this isn't valid in C/C++:</p> <pre><code>output[]=dasar[k]; </code></pre> <p>To copy data from one array to another, you either need to copy each element one-by-one (e.g. in a loop), or use a block memory operation like <code>memcpy</code>.</p> <p>Here's how I would do it:</p> <pre><code>memcpy(output, dasar[k], sizeof(output)); </code></pre> <p>This should work because arrays are basically just pointers in C/C++. It uses the start of <code>output</code> as the destination of the copy, and uses the start of <code>dasar[k]</code> as the source. The number of bytes it copies is taken from the total size of the <code>output</code> array.</p>
8057
|audio|
Reading the audio signal from a smartphone
2015-01-16T15:26:55.133
<p>i want to read the audio signal from my smartphone. Can i just cut a headphonewire and connect it to the analog in? (Arduino uno) I sadly dont know much about electronics.</p> <p>greetings</p>
<p>No. It partly depends on the phone, but most put out a low voltage AC signal. This would drive the Arduino inputs negative. You can do this by biassing the input at the mid point (+2.5V) and feeding audio in via a capacitor. There are many projects which use similar to record audio.</p> <p>PS I would not recommend cutting a headphone cord. The wires are very fine, and almost impossible to solder. If you want to do this make a custom cable.</p>
8063
|programming|
Question about viability of building a Bill Counter machine
2015-01-17T02:38:14.447
<p>I have a need for a bill counter at my current job, but besides counting bills we also could use a machine to count admission cards.</p> <p>The idea is to either buy a bill counter machine (like those that the Banks have), or make one from scratch by buying the parts. Besides the bill counting feature i wanted to make it so that it also counts the certain number of cards, and check if they are either stamped or not.</p> <p>My question is:</p> <p>Is this possible?</p> <p>If so, is it easier to just buy a arduino and use it with other parts (sensors, moving gears etc etc), or to buy a bill counter and just "crack" the OS?</p> <p>Any insight would be appreciated!</p> <p>PS: I am a 1st year Computer Science student, but i have 0 experience in programming in Arduino</p>
<p>There are many more things to consider than just put some parts together if you try to build a counter from scratch. Automated currency handling has come a long way to today's bill counters or any vending machines. You may perfectly handle the computing part of task with an embedded system like the arduino, but paper handling is an art of itself. </p> <p>If you think of this task as a challenge to acquire and hone engineering skills, go ahead. It may be one of the best training tasks one can think of. But while you may learn a lot from this conundrum, you will propably end up without an usabale device. :)</p> <p>You have to consider, there are subtasks in</p> <ul> <li>mechanics</li> <li>electronics</li> <li>programming</li> </ul> <p>which may include</p> <ul> <li>paper handling (separation, traction, alignment)</li> <li>pattern recognition</li> <li>motor control</li> <li>high speed sensors</li> <li>signal detection and processing</li> <li>error and fault processing and handling</li> <li>motor and gear connection</li> <li>bearings and mechanical substructure</li> <li>user interface</li> </ul> <p>and many more.</p> <p>To modify an existing device solves a lot of mechanical problems in advance. But it may still be difficult to change the firmware of a bill counter to your needs. </p> <p>You will have to</p> <ul> <li>break into the system (may be impossible)</li> <li>reverse engineer the firmware</li> <li>understand the mechanical constraints</li> <li>find a way to adapt the system to your needs.</li> </ul> <p>A third way, which in my eyes is rather intriguing, is to take an existing bill counter, rip out the controller and try to plug in your own controller, e.g. an arduino. This gives you a real chance to reach your goal while still having the opportunity to learn a lot. </p>
8071
|serial|sd-card|string|
Serial.write and Serial.println return different values? Cannot use correct ones
2015-01-18T03:49:02.973
<p>I have a text file on an SD card, and I am trying to print the lines to the serial monitor.</p> <p>This Code Works:</p> <pre><code>#include &lt;SPI.h&gt; #include &lt;SD.h&gt; File myFile; void setup() { Serial.begin(9600); Serial.print("Initializing SD card..."); pinMode(10, OUTPUT); if (!SD.begin(4)) { Serial.println("initialization failed!"); return; } Serial.println("initialization done."); myFile = SD.open("c.txt"); if (myFile) { Serial.println("c.txt:"); while (myFile.available()) { Serial.write(myFile.read()); //THIS LINE RIGHT HERE } myFile.close(); } else { // if the file didn't open, print an error: Serial.println("error opening c.txt"); } } void loop() { } </code></pre> <p>However, if I replace the line <code>Serial.write(myFile.read());</code> with <code>Serial.println(myFile.read());</code>, then the code doesn't return the correct lines.</p> <p>It should return numbers similar to this (albeit 3000 of them):</p> <pre><code>564 564 564 564 564 564 564 464 564 664 564 </code></pre> <p>If I use <code>Serial.println</code> it returns numbers like this (and it doesn't stop at 3000 lines):</p> <pre><code>13 10 54 54 52 13 10 53 54 52 </code></pre> <p>And if I try to do <code>int(myFile.read())</code> then the integer becomes the wrong numbers (returned by <code>println</code>), not the right ones (returned by <code>write</code>).\</p> <p>How do I get a number returned by <code>Serial.write(myFile.read());</code> to be an integer?</p>
<p>The text file contains the sequential ascii values that spell out the data, not binary data. <code>println</code> in printing the numerical value of each byte. For example, the 10's <code>println</code> prints are '\n' characters. <code>write</code> is printing the ascii character associated with the binary value (the new line). You need to parse the ascii characters into numbers.</p> <p>Luckily for you the SD library inherits from the <code>Stream</code> class, so it will have the same <code>parseInt</code> function most often used to parse ints from the serial monitor. </p> <p>You probably want to set <code>myFile.setTimeout(0)</code> first because the file isn't slowly getting characters from the serial bus, so the timeout would just slow you down.</p> <p>Then you should be able to parse and print out the ascii integers with something like this:</p> <pre><code>int val = myFile.parseInt(); Serial.println(val); </code></pre>
8073
|pins|ethernet|
Where can I find a better pinout diagram for "Arduino Ethernet" board?
2015-01-18T15:06:21.840
<p>I'm looking for a complete pinout of the <a href="http://arduino.cc/en/Main/arduinoBoardEthernet" rel="nofollow noreferrer">Arduino Ethernet R3</a>. I've found one <a href="http://f1mvp.perso.sfr.fr/Robotic/arduino.htm" rel="nofollow noreferrer">here</a> which is low quality, and seems not complete (where are the digital I/O pins?).</p> <p><img src="https://i.stack.imgur.com/9mk4A.jpg" alt="enter image description here"></p> <p>BTW, it was not a good idea for Arduino to name this board "Arduino Ethernet", as this is pretty useless for searching online :-(</p>
<p>That's a better one from :</p> <p><a href="https://pinoutguide.com/images/arduino/ethernet.png" rel="nofollow noreferrer">https://pinoutguide.com/images/arduino/ethernet.png</a></p> <p>This one also presents the Arduino Ethernet R3 board and has the extra I2C pins (SCK=A5,SDA=A4) next to the AREF pin.</p> <p><a href="https://i.stack.imgur.com/QLJqj.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QLJqj.png" alt="enter image description here"></a></p>
8076
|arduino-uno|ethernet|
data type error on sensor data to ethernet client
2015-01-18T16:36:44.863
<p>I'm having a hard time debugging this piece of code, and i'm hoping someone can point out where i am making the mistake.<br> <br> My serial output is:</p> <pre><code>connected GetData() got data... next stage... </code></pre> <p><br> I've tested with a simple network client that loops sending a hello world, and it works fine. Every time this code halts after attempting to send a value to the <code>client</code>. I know that <code>getData()</code> is causing the issue, but i cannot work out why, or how to best resolve it. (apologies for the code dump, i want to be thorough)</p> <pre><code>#include &lt;LiquidCrystal.h&gt; #include &lt;dht11.h&gt; #include &lt;SPI.h&gt; #include &lt;Ethernet.h&gt; dht11 DHT11; #define DHT11PIN 8 byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; IPAddress server(192,168,1,100); IPAddress ip(192,168,1,50); EthernetClient client; LiquidCrystal lcd(12, 11, 5, 4, 3, 2); const int trigPin = 6; const int echoPinOne = 7; const int echoPinTwo = 8; const int echoPinThree = 9; const int echoPinFour = 10; void setup() { lcd.begin(16, 2); Serial.begin(9600); delay(1000); //Network if (Ethernet.begin(mac) == 0) { Serial.println("DHCP FAIL"); Ethernet.begin(mac, ip); } delay(1000); Serial.println("connecting..."); lcd.setCursor(0, 0); lcd.print("connecting"); connect(); } void connect(){ if (client.connect(server, 8080)) { Serial.println("connected"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("connected"); client.println("hello server"); client.println(); delay(500); lcd.clear(); } else { Serial.println("connection failed"); lcd.clear(); lcd.setCursor(0, 0); lcd.print("Connection Failure"); } delay(500); } void loop() { //network if(!client.available()){ Serial.println("lost connection!-restart"); lcd.println("Disconnection"); client.stop(); connect(); } else { int inp[5]; getData(inp); Serial.println("next stage..."); char *output = (char *) &amp;inp[0]; client.println(output); client.println("first"); Serial.println("sent first..."); //here repeats the same process for the other sensors - omitted for clear reading } //end network delay(500); } void getData(){ Serial.println("GetData()"); long durationThree, inchesThree, cmThree = 0; long durationOne, inchesOne, cmOne = 0; long durationTwo, inchesTwo, cmTwo = 0; long durationFour, inchesFour, cmFour = 0; //SENSOR ONE pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); pinMode(echoPinOne, INPUT); durationOne = pulseIn(echoPinOne, HIGH); delay(100); //SENSOR TWO pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); pinMode(echoPinTwo, INPUT); durationTwo = pulseIn(echoPinTwo, HIGH); delay(100); //SENSOR THREE pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); pinMode(echoPinThree, INPUT); durationThree = pulseIn(echoPinThree, HIGH); delay(100); //SENSOR FOUR pinMode(trigPin, OUTPUT); digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); delayMicroseconds(10); digitalWrite(trigPin, LOW); pinMode(echoPinFour, INPUT); durationFour = pulseIn(echoPinFour, HIGH); //DISTANCE CALCULATION cmOne = microsecondsToCentimeters(durationOne); cmTwo = microsecondsToCentimeters(durationTwo); cmThree = microsecondsToCentimeters(durationThree); cmFour = microsecondsToCentimeters(durationFour); //Serial.println("sending..."); //char *out = (char *) &amp;cmOne; //Serial.println(out); //client.println(out); //Serial.println("sent!"); used this to test - same issue Serial.println("got data..."); inputBuf[0] = cmOne; inputBuf[1] = cmTwo; inputBuf[2] = cmThree; inputBuf[3] = cmFour; } long microsecondsToCentimeters(long microseconds) { return microseconds / 29 / 2; } </code></pre>
<p>The code you posted is performing incompatible casts and by thus is sending garbage to <code>client.println</code>. </p> <p>There is no automatic conversion in C/C++ from an array of integers (<code>int inp[]</code>) or longs, to a C style string <code>char *</code>. A C Style string should end with null terminator <code>\0</code>, and the one in your code doesn't. For example, in this line:</p> <pre><code>char *output = (char *) &amp;inp[0]; </code></pre> <p>The <code>inp[0]</code> contains the first integer. The expression <code>&amp;inp[0]</code> contains the address of that integer in memory. </p> <p>Thus the cast to <code>(char *)</code> will yield a malformed C style string, since it will not end with a null terminator, and more important, will not contain the data you expect it would (this cast is saying - "hey, compiler, note that the <em>address</em> of that <code>int</code> is actually the address of a C style string").</p> <p>You can, however, utilize the <code>String</code> type constructor that receives int/long, and send the duration in order, something similar to:</p> <pre><code> void getData() { ... // rest of the code here client.println(String(cmOne)); client.println(String(cmTwo)); ... // etc. } </code></pre>
8079
|uploading|
Multiple upload/ Synchronization problem
2015-01-18T20:16:21.100
<p>I am trying to do an experiment with Arduino Uno r3 board plus a 2-channel relay shield. What I need to do is to alternatively turn on and off the relay shields. So, it requires multiple compile and upload of the program to assign values to corresponding pins. What I have seen by now is that uploading the program to Arduino is a kind of painful process and it requires nothing to be connected to pins 0 and 1 to prevent synchronization errors. So, I was wondering how I can do my experiment without having to mount/unmount relay shield each time I want to upload a new program into it.</p> <p>Thanks in advance </p>
<p>Well, you can write a program that takes numbers out of Serial input.</p> <pre><code>int pin1 = Serial.parseInt(); int pin2 = Serial.parseInt(); // etc., etc. </code></pre> <p>Simple.</p>
8096
|motor|shields|arduino-motor-shield|
H-Bridge vs Motor shield for the arduino
2015-01-19T09:28:42.277
<p>Assuming we wish to control a small toy car with an arduino - meaning spinning the right and left wheels forward and backward and being able to break and control the speed, where each wheel has it's own engine (but of course two engines on the same side will run on the same speed and direction).</p> <p>We saw we have two main options - Buying and wiring up a H-Bridge or buying a motor shield (which is based on one).</p> <p>Are there any advantages for using a motor shield?</p> <p>Thanks in advance.</p>
<p>If I were a beginner, I'd go with the Motor shield.</p> <p>I'm even personaly using the one from DfRobot, which as @Gerben said, is just plug and play.</p> <p>It also allows you to select the input power for the motors, which can be either from the 5V Arduino pin or from an external battery. This is pretty convenient if you need more than 5V to power up your motors. It can also support 2A of current draw, which is more than enough for small arduino toy cards.</p> <p>Here is the shield: <a href="https://www.dfrobot.com/index.php?route=product/product&amp;product_id=1180&amp;search=2A&amp;description=true" rel="noreferrer">https://www.dfrobot.com/index.php?route=product/product&amp;product_id=1180&amp;search=2A&amp;description=true</a></p>
8098
|serial|power|
where to syphon off voltage from a 25 pin serial?
2015-01-19T14:55:48.330
<p>I have a mircocontroller that's looking to be powered by a 5v source.</p> <p>I am trying to 'cypher off' some of this power from a 25 pin serial port, which is being powered by a constant power source.</p> <p>Are there any pins that could give me that sort of voltage, or enough to power the board?</p> <p><img src="https://i.stack.imgur.com/T8GlS.png" alt="enter image description here"></p> <p>Please note, I'm <strong>not an electrical person</strong> at all, and so hope this is actually possible (otherwise my 3 months + program's work doesn't really add to anything).</p> <p>I've tried a 9v battery, but it didn't seem to hold its charge? </p> <p>I'm reading these labels going "what the ..." so you can probably tell coding the board wasn't the easiest, either.</p> <p><strong>Edit History</strong></p> <ul> <li><em>I would like to clarify this is an <strong>existing serial lead</em></strong></li> <li><em>I understand this may be deemed verging off topic,</em> <em>but due to the need to 'power' a</em> <em>microcontroller, I thought this could be answered here</em></li> <li><em>If this isn't possible, (as an alternative, possibly) would a 9V/battery be able to power this board reliably for around 2-3 weeks?</em></li> </ul>
<p>In a lot of further research, I have discovered that 'It doesn't really matter' what the serial port diagram says, since in 25 pin serials (and 9 pin D-subs), it all depends on the circuit at the other end, showing which wires are actually '<em>connected</em>', or '<em>used</em>'.</p> <hr> <p>I managed to get <em>some</em> current from +pin 6 -pin 5 in which allowed me to draw <em>some</em> current, but have chosen to go with a (PP3?) 9v battery instead due to its reliability.</p> <hr> <p>So, in conclusion to this question, there isn't a specific answer, since it all depends on how the serial at the other end is wired.</p> <p>It seems to me that in my case, there were minimal wires actually connected, so I was forced to look for other means of connecting to a 'reliable' power source.</p>
8100
|arduino-uno|audio|
Arduino Uno synthesizer - Line Level (audio) output to mixer/amplifier
2015-01-19T15:27:12.643
<p>Is using PWM tones from Arduino amplified by a HiFi amplifier safe? Can I damage the amplifier or speakers because the PWM signal is not a &quot;real&quot; audio signal? Taken in consideration that I do not clip the signal and using a RC Low Pass Filter to filter out inaudible frequencies and using a LM386 amplifier chip to amplify and control the volume?</p> <p>I am developing a synth/sampler project based on the Arduino Uno r3. This is my first electronics project ever and because of that reason I have some questions which I can't find a definite answer for on internet.</p> <p>The synth has two function. It has a tone generator using the ToneAC library. With code I have mimicked LFO and VCO functions, using potentiometers I can adjust the frequency and LFO speed realtime. The other function is that I can trigger samples stored on a SD card using the TMRpcm library. The lowest frequency which can be played is 100hz and the highest 3100hz.</p> <p>The device will be used in nightclubs on high end sound-systems and PA. I am afraid I will damage the equipment with my device because I do not send a pure audio (AC?) signal.</p> <p>Currently the flow is like this:</p> <p>PWM output (pin 9, 10) -&gt; voltage divider to 2.5v -&gt; RC Low Pass Filter 15Khz -&gt; LM386 amp with volume control -&gt; mono jack output -&gt; mixing desk -&gt; amplifier -&gt; speakers</p> <p><em>(the TMRpcm and ToneAC library share the same pin (9), I have fixed this by disabling the TMRpcm when the ToneAC is playing and vice versa. The mono jack is wired as follow. pin 9 goes to plus side of mono jack output, pin 10 to negative side. The TMRpcm pin 9 also needs to go to plus side of mono jack output, and mono jack negative needs to go to ground. Because I disable the ToneAC at that time I consider port 10 grounded because it not generating any sound so there is no signal/voltage running out of it, aka the IO pin is set to LOW)</em></p> <p>I am hoping that using the voltage divider I am within range of the Audio Line levels of a default mixers Line-IN (like Pioneer, Behringer, etc). The RC Low Pass Filter is used to filter of inaudible frequencies and clean up the sound a bit, the LM386 audio amp is used to amplify the signal and (hopefully) make it a real audio signal.</p> <p>Because I lack a lot of knowledge in this field and because I do not own a oscilloscope I can't say for sure if my output signal is harmful for the equipment and was hoping to get some guidance on my project on this forum.</p>
<p>In theory, the peak signal accepted from your amplifier should be 0.894V p2p if you want to rescpect the common -10dB signal strength/level. I don't know why you would want to have a 5V to 2.5V "voltage divider" in the first place, but in any case if you use that you already limit the current probably enough, it all depends on the resistor values used.</p> <p>Using the LM386 amplifier is also simply not required at all, since the Arduino is already providing more than enough power. If you want to tune the volume at that stage, simply combine all functions (volume, low pass and current limit) by connecting the 5V PWM output thru a resistor (eg. 4k7) to a POT (eg. 1k) in parallel with the capacitor (eg.2n2) would give you approximately what you want. Then to remove de DC component, add a series capacitor (eg. 1uF) and you're all set. You may still hear a "click" when you connect it to the amplifier though, so keep the faders low when connecting.</p> <p>Of course you can adapt the values quite liberally, but these values are both safe and should be close to what is needed (cutoff 15kHz, Vpp 0.88V max).</p>
8117
|arduino-uno|variables|temperature-sensor|
Can't store temperature in variable ( for further processing)
2015-01-20T14:45:43.223
<p>I am trying to store temperature data in a variable, so that I can use it for making a JSON object, but the problem is, that when I try to store the temperature in a variable, it prints out the wrong value. I'm using a DHT11 temperature/humidity sensor and a library for calculating the temperature.</p> <pre><code>Serial.print("Temperature (°C): "); Serial.println((float)DHT11.temperature, DEC); int temp1 = ((float)DHT11.temperature, DEC); Serial.println(temp1); </code></pre> <p>These 4 lines is printing out this:</p> <pre><code>Temperature (°C): 23.0000000000 10 </code></pre> <p>The first one is correct, but the second line should also be saying "23". I have tried only loading the data in once with the library, as in outcommenting one line, but that does not work. It's like I have some syntax wrong, but I can't figure out what.</p>
<p>This line:</p> <blockquote> <pre><code>int temp1 = ((float)DHT11.temperature, DEC); </code></pre> </blockquote> <p>casts <code>DHT11.temperature</code> to an <code>float</code>, throws away the value, then assigns <code>DEC</code> to <code>temp1</code>. That is not what you want.</p> <blockquote> <pre><code>int temp1 = DHT11.temperature; </code></pre> </blockquote>
8128
|arduino-uno|nrf24l01+|teensy|
Throughput and BER test with nRF24L01+ radio and Teensy microcontroller
2015-01-21T00:09:45.697
<p>I am trying to modify the example given in the <a href="http://shanes.net/another-nrf24l01-sketch-string-sendreceive/" rel="nofollow">this page</a> to a basic throughput and BER test with two nRF24L01+ and Teensy 3.0 modules. </p> <p>I want to modify the nrf24l01_send_string example in a way that I can remove the powerUp powerDown and delay and transmit the next packet purely based on the ACK received from the receiver. The problem is <a href="http://maniacbug.github.io/RF24/classRF24.html" rel="nofollow">RF24 class</a> does not seem to have a method to transmit ACK (not ACK+Payload) and the datasheet does give any information on the structure of the ACK message. The example works when powerUp and powerDown are removed, but I need to modify it to measure throughput by removing the delay. </p>
<p>@Gerben remarked: </p> <blockquote> <p>You can't send the ACK manually. The module itself sends the ACK automatically (if enabled that is), once it receives the package. This way the sending module only need to be listening for the ACK for the shortest amount of time, reducing power usage. To attach data to the ACK package you need the writeAckPayload function. But you have to prepare this before any package is received</p> </blockquote>
8130
|servo|
Arduino cannot communicate with PC after running servo
2015-01-21T00:50:00.560
<p>I was messing around with my arduino uno r3 and servo today. The book I got said to run the servo through the arduino. Everything was fine. I started changing the code, and then things started to get bad. I noticed that if I did not put a delay in between the servo movements, the board would freeze, and I would have to get lucky. Well now I just can't communicate with the board. I plug the board in to my pc, windows 7 makes the connection sound, the board turns on the ON light, the L light flashes, then goes steady. In the arduino software, the COM3 port, which is where I'm plugging it in, is not coming up. Only COM1 is there. I'm not sure what to do. The board is still functioning, the servo moves. I tried to plug it in with a different port and with the servo disconnected but it still doesn't want to communicate with my pc. The code I'm using is below</p> <pre><code>#include &lt;Servo.h&gt; Servo servo1; void setup() { servo1.attach(9); } void loop() { servo1.write(50); delay(500); servo1.write(90); delay(500); servo1.write(140); delay(1000); for(int i = 50;i&lt;140;i+=10){ servo1.write(i); delay(10); } } </code></pre> <p>I would also like to add that I understand that you shouldn't run the servos through an arduino. I was following the book, and began researching when things went down hill.</p>
<p>I've had some problems in the past reprogramming my Arduino Uno if it writes to the serial port - I don't know if the problem is the same, but here's how I got around it:</p> <p>Option 1: Hold down the reset switch, then plug your Arduino into the USB port. Select the right COM port (if needed), compile your code (something ultra simple, e.g. blink led), and then, JUST BEFORE IT STARTS UPLOADING, release the reset switch. Wash, rinse, repeat, until you get it to work, through blind luck.</p> <p>Option 2: Get hold of a ICSP (such as the one I got, USBASP made by FreeTronics <a href="http://www.freetronics.com.au/products/usbasp-icsp-programmer-for-avr-arduino#.VL8Vv3WjlIc" rel="nofollow">http://www.freetronics.com.au/products/usbasp-icsp-programmer-for-avr-arduino#.VL8Vv3WjlIc</a> which I am v. happy with), plug it into the serial port, plug the other end onto your Arduino UNO ICSP header (6 pins, opposite end of the board from USB), then select Tools -> Burn Bootloader. Overwrites any program, works 100% of the time. Now you can unplug your USBASP, and plug your Uno back in and program it normally. This is also a great tool if you end up using AtMega (or AtTiny) chips directly (AtMega is the chip used to do all the work on the Arduino).</p> <p>To avoid this, I have gotten into the habit of putting a 5 second delay as the first thing in the startup code.</p> <p>FOR FUTURE GENERATIONS: I got mine here in New Zealand, so that will probably not help most people. FreeTronics makes them, and I am very happy I got their one (they have a "slow clock" jumper that is very convenient when programming Atmel chips not on an Arduino board), I expect that any USBASP would do the trick too - in response to the question, Amazon has a couple under $4, and I expect that the price will not go up.</p> <p>Search for "USBASP". Make sure you get a ribbon cable. For Arduino Uno, you need a 6-pin ribbon cable. It is also possible to use these cables to communicated directly with a running Arduino over these same pins.</p>
8140
|attiny|map|
Does the map() function works on an ATtiny85?
2015-01-21T12:47:46.503
<p>I have a working project on Arduino Uno.Now I want to shrink my project using an ATtiny85. Before purchasing an waiting for the shipment to arrive, I want to make sure that my whole code will run on ATtiny85.</p> <p>specialy, will the map() function which is working on an Arduino Uno ( ATMEGA328P-PU ), work with a ATtiny85 Microcontroller?</p>
<p>The <code>map</code> function uses integer arithmetic, and since the ATmega series and the ATtiny series use the same 8-bit AVR instruction set, there should be no difference when using it, and you are good to go from that aspect.</p> <p>Consider that there are many other differences regarding I/O pins, storage etc. - that you might want to consider. <a href="https://goddess-gate.com/projects/en/arduino/attiny85vsatmega328" rel="nofollow">Here is a good source</a> for a basic comparison between the ATmega based Arduino to ATtiny85.</p>
8148
|ide|
Arduino screws up trivial program involving enum
2015-01-21T16:33:39.377
<p>Behold this insanity:</p> <pre><code>enum WhatArduinoIs { Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed }; void TellMe(WhatArduinoIs pls) { } void setup() { } void loop() { } </code></pre> <p>I'm pretty good at C++, so I'm fairly sure that should compile. However I get this error:</p> <pre><code>sketch_jan21b.ino:3:13: error: variable or field 'TellMe' declared void sketch_jan21b.ino:3:13: error: 'WhatArduinoIs' was not declared in this scope Error compiling. </code></pre> <p>I've encountered the Arduino "IDE"'s propensity for insane and totally unrobust modification of programs before. Specifically when you <code>#include</code> libraries Arduino only magically adds the relevant C++ files if the <code>#include</code> is in your main sketch. <code>#include &lt;LiquidCrystal.h&gt;</code> in another C++ file? Link errors.</p> <p>I suspect in this case it is Arduino magically trying to add function declarations to the start of the file so their order doesn't matter. I.e. it turns the file into this:</p> <pre><code>void TellMe(WhatArduinoIs pls); enum WhatArduinoIs { Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed }; void TellMe(WhatArduinoIs pls) { } void setup() { } void loop() { } </code></pre> <p>That obviously doesn't work. How can I tell Arduino to leave my damn program alone?</p>
<p><strong>All</strong> you need is a function prototype. I have a detailed explanation at <a href="https://arduino.stackexchange.com/questions/13178/classes-and-objects-how-many-and-which-file-types-i-actually-need-to-use-them">Classes and objects: how many and which file types I actually need to use them?</a></p> <p>So, this compiles:</p> <pre><code>enum WhatArduinoIs { Easy, But, Insane, Obsolete, And, Far, Worse, Than, mBed }; void TellMe(WhatArduinoIs pls); // prototype void TellMe(WhatArduinoIs pls) { } void setup() { } void loop() { } </code></pre> <p>Off-site reference: <a href="http://www.gammon.com.au/forum/?id=12625" rel="nofollow noreferrer">How to avoid the quirks of the IDE sketch file pre-preprocessing</a></p>
8153
|hardware|
Replacing the Voltage regulator of a fried Arduino
2015-01-21T18:39:58.143
<p>I accidentally fried my Arduino. I found <a href="http://www.instructables.com/id/Fix-a-fried-Arduino-Mega/?ALLSTEPS" rel="nofollow">this</a> Instructable. The symptoms are the same. The board not powering on connecting USB source and the over current protector was heating up. So I removed the voltage regulator as mentioned in the Instructable. But the problem is the pins 1 and 2 of where the regulator used to be are still shorted out. That is even after removing the regulator, the pins seem to be somehow internally shorted. I tried checking the continuity on another working Arduino and found it to be not shorted. What seems to be the problem?</p>
<p>I know it's an old thread, but others are likely to have this problem. If you check <a href="https://www.arduino.cc/en/uploads/Main/Arduino_Uno_Rev3-schematic.pdf" rel="nofollow">the open source schematics</a>, there are a couple of nearby capacitors that connect pin 1 (GND) to pin 2 (+5V) of the regulator.</p> <p>I would check C2 and PC2 (top right of the diagram) as well as C1 (top left of schematic diagram), and any other components you can find that bridge the rails between +5V and ground. Capacitors are more likely to fail shorted than many other components. You will have to remove at least one pin of each capacitor to test it since you don't know where the short is, or you can simply remove capacitors until the short goes away.</p>
8160
|avr|
How are Arduino's OSH if Atmel AVR is proprietary?
2015-01-21T21:32:29.590
<p>I keep reading how Arduinos are "open source", but my understanding of OSH is that all its components must be open source.</p> <p>Arduino uses an <a href="http://en.wikipedia.org/wiki/Atmel_AVR" rel="nofollow">Atmel AVR</a> CPU - but Googling this shows the Atmel is proprietary!?</p> <p>So I ask: <strong>how can Arduino be truly OSH if it's chief component - its Atmel CPU - is proprietary?!?</strong></p>
<p>Open-source hardware is fundamentally different from open-source software in that you cannot make a copy of OSH for free. If you want to build an Arduino, you will need all the components it's made of, and even the simplest components like diodes are proprietary, just like the AVR chip. Neither can be home-made and both are proprietary designs.</p> <p>The important thing about OSH is not that it's made of free components, but the fact that <strong>information about how it's made is freely available</strong>. The abundance of Arduino shields and addons is not due to availability of free AVR cores, but to the fact that anyone has access to the information needed to make their board Arduino-compatible. BTW, that's how personal computers gained the dominant position on the market: IBM has published detailed specifications <a href="https://en.wikipedia.org/wiki/IBM_Personal_Computer#Third-party_products" rel="nofollow noreferrer">including schematics</a> of their IBM PC (albeit not under a free license), enabling other companies to make compatible hardware, and later on, PC clones.</p> <p>Last but not least, the open-source aspect of Arduino is by no means limited to the hardware. The core library was written in portable way, which made it possible to run it on a <a href="https://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems" rel="nofollow noreferrer">wide range</a> of hardware cores. There are even FPGA boards featuring Arduino connectors (<a href="https://www.eevblog.com/forum/microcontrollers/cyclone-v-gx-starter-kit-the-ultimate-arduino/" rel="nofollow noreferrer">1</a>, <a href="http://www.aloriumtech.com/xlr8/" rel="nofollow noreferrer">2</a>, <a href="http://papilio.cc/" rel="nofollow noreferrer">3</a>), which can run Arduino software on soft-cores such as <a href="http://www.nxlab.fer.hr/fpgarduino/" rel="nofollow noreferrer">F32C</a> or <a href="https://github.com/dimag0g/nios_duino" rel="nofollow noreferrer">NIOS</a>.</p>
8166
|power|
Where Can I Find a 12v Solder-less Breadboard Power Supply?
2015-01-22T01:02:39.453
<p>I am trying to find a 12 V input and 12 V output breadboard power supply but I can't find one. I am making an Arduino-controlled lock but the Arduino cannot power the lock strike by itself so I need to use a separate power supply. The link to make things clearer: <a href="http://www.instructables.com/id/Arduino-RFID-Door-Lock/#step0" rel="nofollow noreferrer">http://www.instructables.com/id/Arduino-RFID-Door-Lock/#step0</a></p>
<p>There is nothing special about a "breadboard power adapter" that isn't served by a normal regulated supply. Simply use wires or a barrel jack or some other connector to connect any regulated supply to the breadboard as desired.</p>
8167
|atmega328|hardware|avr|
Can Arduino's open design be "scaled" to 64-bit CPUs?
2015-01-22T01:52:28.707
<p>If Arduino is OSH that simply uses 8-bit Atmel AVR MCU as a design component, then can Arduino somehow be tweaked to work with a 64-bit CPU/MCU? If so, what might this entail?</p>
<p>It has already been ported to a 32-bit Arm - the Arduino Due - 84mhz, Cortex M3.</p> <p>To port it to a 64-bit CPU, someone would need to create a design for the PCB, and set up an appropriate build/compile system for it.</p> <p>Having said that, a 32-bit CPU is an awful lot of power for this sort of thing - I suspect that if a 32-bit Arm isn't enough, then what you're really looking for is a full-blown PC. A Cortex M3 can handle 4GB of memory, and can run a version of Linux (uCLinux, since the M3 does not have a memory management unit, MMU, and the standard Linux kernel needs this). The Due would be unable to run even uCLinux, due to limited memory.</p> <p>In fact, the Raspberry Pi is also a (700mhz Cortex A8) 32-bit CPU; I imagine that a little bit of tweaking could make the Arduino IDE compile &amp; upload for the Raspberry Pi. This would fall into the category of "Because I can".</p> <p>Note: The Raspberry Pi is not opensource, I know. Neither is the Arm in the Arduino Due, nor the AtMega that is at the heart of the Arduino Uno. </p>
8176
|arduino-uno|usb|
connection issues with 3 arduinos any suggestions?
2015-01-22T14:07:27.970
<p>I have 3 arduinos that I want to program on, all of them with their own cable and I have tried to connect them to my laptop on several different usb ports, my usb ports work with mouses so that's unlikely to be the problem. However I just cannot connect to them they just don't appear under /dev/ttyACM* and the arduino IDE cannot find them either. I'm running ubuntu 14.04 any suggestions for finding out what is likely to be wrong with my system or the arduinos? </p> <p>For some odd reason they now all appear to be seen as /dev/ttyACM* but they now all give me a </p> <pre><code>avrdude: stk500_recv(): programmer is not responding avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00 </code></pre> <p>error</p> <p>Anybody have any idea how to fix? The arduino's do not have any wires in them except usb (nothing in reset or any other pin), I'm on ubuntu so the drivers shouldn't be an issue? And pin 13 flashes when I reset the arduino. </p>
<p>it's been a while but a long time later I found that the cable I was using was broken. A different cable worked.</p>
8185
|arduino-uno|nrf24l01+|
Increasing payload size above 32 bytes using nRF24L01+
2015-01-22T21:26:17.667
<p>I tried to modify the example in the following page, by replacing the given string with a 56 bytes one after making all the suitable changes to read(), write() and max_payload_size(increased to 64 bytes), payload_size() parameters/methods in the RF24 library. </p> <p><a href="http://shanes.net/another-nrf24l01-sketch-string-sendreceive/" rel="noreferrer">http://shanes.net/another-nrf24l01-sketch-string-sendreceive/</a></p> <p>The problem is the receiver truncates the string to 32 characters. Is 32 bytes a hard limitation for payload with the nrf24l01+ radio? If so how to I modify the receiver in above example problem to receive the entire string?</p>
<p>If you look at the <a href="https://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01P" rel="noreferrer">specification or datasheet</a> for the nRF24l01+, you will see that the 32 byte payload is the maximum that the device can handle.</p> <p>For example:</p> <p><img src="https://i.stack.imgur.com/QvWcG.png" alt="spec" /></p> <p>If you need to transmit anything larger than 32 bytes, you will need to develop a protocol that splits up your data into chunks of 32 bytes or less and sends the data in several packets.</p> <p>The actual protocol you design is up to you, but a simple technique might be using the first packet to send a count of the number of data packets to expect and then simply send those packets, each with a part of your data and reassemble it at the receiving end.</p> <p>You may need to design something more robust so you don't get confused by lost packets or bad data. The larger your payload, the more chance of transmission errors, so it might be an idea to experiemnt with the payload size to get the best throughput for your particular application.</p>
8193
|sensors|temperature-sensor|
Connecting multiple DHT 11 sensors
2015-01-23T13:43:31.097
<p>I want to collect data (both Humidity &amp; Temperature) from 80 sensors. let's say I have 80 "DHT 11 Humidity &amp; Temperature" sensors (for ex. in a warehouse) and one Arduino Uno R3 pack. It's clear that arduino has no so many pins to connect. I'm sorry that I don't know if it's possible. If so, what can I use to achieve this? Thank you all for your suggestions.</p>
<p>Analog multiplexers are one way, but they tend to have a significant resistance when on, and this could cause the protocol not to work.<br> For 80 channels you need 7 bits addressing. Say you have an 8-input multiplexer, then a 3-bit address indicates which of the 8 inputs is selected. Use 10 of these, all with the three address lines connected, and you have 10 outputs from 80 inputs. Next, use a 16-input multiplexer to select which of the 10 inputs you want to use. For this multiplexer you need 4 address lines. Together with the other 3 address lines you have 7 address lines, enough to select 1 of up to 128 sensors. But I repeat, this approach may not work if the multiplexer's resistance is too high.</p> <p>A more robust (albeit more expensive) is to use analog switches to connect/disconnect each sensor. Analog switches (Analog Devices has a lot of them) have on-resistances down to &lt; 1 ohm, so the sure should be OK for the application.<br> To control the long series of switches you could use a daisy chain of 74HC595 shift registers, which only requires a couple of I/Os on your controller, but gives you virtually unlimited outputs.</p>
8196
|power|battery|
Arduino on battery getting unstable if temperature falls
2015-01-23T19:20:22.717
<p>i am building an outdoor sensor with a combination of a custom Arduino board and a battery (+solar charging). I experience strange behavior when the temperature falls below a certain value (i can reproduce it by putting it in the freezer), regardless which type of battery i am using. The custom Arduino runs without power-regulation, straight from the 3.7volts the battery can provide. How can i prevent this to happen? I guess a little heating would be not really a solution as i am trying to consume as less energy as possible. Would a (step up) regulator possibly help? Any other ideas?</p> <p>---Update--- Thanks to your comments here i figured out, that the AVR 328p should not be operated below a voltage of 3.7v if run at 16Mhz. As i am running with a 3.7v LiPo Battery that could easily explain my problem i guess. My first try to decrease the processor speed to 8Mhz with a Prescaler worked, but the GSM Fona does not seem to like it. So i would like to try something in between like 10Mhz or 12Mhz. As the prescaler does not support this, my question is: can i just use another crystal or would i have to modify something in the code/bootloader as well?</p>
<p>To answer your modified question:</p> <p>Running the ATmega328p at 16Mhz with 3.7v is out of spec - see <a href="https://electronics.stackexchange.com/questions/58818/programming-3-3v-atmega328-running-at-16mhz">this EESE answer</a> for reference or the ATmega datasheet - so the obvious solution would be to lower its speed to 8Mhz.</p> <p>But since you also mentioned that there is an additional GSM breakout board involved (Adafruit Fona), which expects UART (in auto-baud mode) Rx/Tx connection, it might not be that trivial. Further exploration of the Fona library's source code reveals that it has several hard-coded delays (see <code>Adafruit_FONA.cpp::begin</code>, for example), but its core seems to be implemented inside the <code>Adafruit_FONA::readline</code> method, which uses an underlying <code>Stream</code>, which in turns comes from a Software/Hardware serial object, as shown in the <code>FONAtest.ino</code> example that comes with the library. </p> <p>From my experience, Software/Hardware serial should work fine on 8Mhz, except maybe when <a href="http://forum.arduino.cc/index.php?topic=212962.0" rel="nofollow noreferrer">using high baud rates</a>, which is solvable. The hard-coded delays doesn't look like they should cause actual damage except for delay, but you could cut them in half just to see if you can make the library work.</p> <p>Additional aspect that you should consider is the comment from Adafruit's Fona product page, regarding pin <strong>Vio</strong>:</p> <blockquote> <p>This is the pin that you MUST drive with an external voltage from 3V-5V to set the logic level converter</p> </blockquote> <p>So, despite that from the datasheet, the Fona seems to have a voltage regulator, you might still want to consider adding a decoupling capacitor between Vcc and Gnd of your battery, to mitigate transient current draws from any component in your circuit. </p>
8206
|arduino-uno|serial|arduino-mega|ethernet|
How can I speed up reading of an SD card?
2015-01-24T00:23:21.647
<p>I am working on a project using an Arduino as a web server.</p> <p>Code:</p> <pre><code>webFile = SD.open("index.htm"); if (webFile) { while(webFile.available()) { client.write(webFile.read()); } webFile.close(); </code></pre> <p>This sends data line by line, leading to a long time to load the webpage. Is there a faster way to load this page?</p>
<p>maybe you should use SdFat library; a library which is almost the same as the standard SD library, but also it can support Long Filenames.</p> <p>I did some tests with read and write; it is most of the times > 60% faster!! <a href="https://github.com/greiman/SdFat" rel="nofollow noreferrer">https://github.com/greiman/SdFat</a></p>
8244
|arduino-uno|wifi|lcd|display|
Arduino Uno + Wifi Shield + PS2 Keyboard + LCD Display
2015-01-26T15:15:54.333
<p>I'm new in the Arduino Community and I'm facing a problem when I try to use a PS2 Keyboard and an LCD Display (16x2) on an Arduino Uno with a Wifi shield.</p> <p>I would like to write something with the keyboard and display it in the LCD before sending it to a webservice.</p> <p>Here is my problem:</p> <ul> <li>When I use the keyboard and the display on my Arduino WITHOUT the wifi shield --> All is OK. I can write on the display the key that has been pressed.</li> <li>When I use the keyboard and the display on my Arduino WITH the wifi shield --> All is OK until I write something on the display. As soon as I write on the display with the function lcd.print(), the keyboard does not work anymore (it detect the character '2' every time I press a key).</li> </ul> <p>It's very surprisingly because if I dont use lcd.print(), the keybord works without any problem.</p> <p>Here is a part of my code:</p> <pre><code>#include &lt;LiquidCrystal.h&gt; #include &lt;PS2Keyboard.h&gt; LiquidCrystal lcd(12, 11, 2, 5, 6, 8); PS2Keyboard keyboard; const int DataPin = 9; const int IRQpin = 3; void setup(){ keyboard.begin(DataPin, IRQpin); lcd.begin(16, 2); } void loop(){ checkKeyboard(); } void checkKeyboard(){ if (keyboard.available()) { char c = keyboard.read(); // check for some of the special keys if (c == PS2_ENTER) { Serial.println(); } else if (c == PS2_TAB) { Serial.print("[Tab]"); } else if (c == PS2_ESC) { Serial.print("[ESC]"); } else if (c == PS2_PAGEDOWN) { Serial.print("[PgDn]"); } else if (c == PS2_PAGEUP) { Serial.print("[PgUp]"); } else if (c == PS2_LEFTARROW) { Serial.print("[Left]"); } else if (c == PS2_RIGHTARROW) { Serial.print("[Right]"); } else if (c == PS2_UPARROW) { Serial.print("[Up]"); } else if (c == PS2_DOWNARROW) { Serial.print("[Down]"); } else if (c == PS2_DELETE) { Serial.print("[Del]"); } else { Serial.print(c); displayText(c); } } } void displayText(char c){ lcd.clear(); lcd.setCursor(0,0); lcd.print("Pressed key:"); lcd.setCursor(0,1); lcd.print(c); } </code></pre> <p>Does somebody know how to solve this problem?</p> <p>Thank you very much in advance :)</p> <p>Edit: Here are the pins that I use on the board :</p> <ul> <li>Arduino pin 2 -> LCD pin 11</li> <li>Arduino pin 5 -> LCD pin 12</li> <li>Arduino pin 6 -> LCD pin 13</li> <li>Arduino pin 8 -> LCD pin 14</li> <li>Arduino pin 11 -> LCD pin 6</li> <li>Arduino pin 12 -> LCD pin 4</li> <li>Arduino pin 3 -> Keyboard IRQ</li> <li>Arduino pin 9 -> Keyboard Data</li> </ul>
<p>Sorry I do not have enough reputation to place a comment. </p> <p>@Valentin from the link, you provided, to the wifi shield it states that it uses pins 11 ,12 and 13 on the UNO which will give you a conflict on pins 11 and 12 with the LCD. Not sure why that manifests as an apparent keyboard error though: </p> <p>From the linked page:</p> <blockquote> <p>Arduino communicates with both the Wifi shield's processor and SD card using the SPI bus (through the ICSP header). This is on digital pins 11, 12, and 13 on the Uno and pins 50, >51, and 52 on the Mega. On both boards, pin 10 is used to select the HDG204 and pin 4 for >the SD card. These pins cannot be used for general I/O. On the Mega, the hardware SS pin, >53, is not used to select either the HDG204 or the SD card, but it must be kept as an output or the SPI interface won't work.</p> </blockquote> <p>Again sorry this is not a full answer but thought it may help.</p>
8256
|arduino-leonardo|uploading|
Arduino board not recognized by Linux (dmesg, lsusb, etc.)
2015-01-27T00:50:31.387
<p>I just received my first <a href="http://www.elecfreaks.com/wiki/index.php?title=NFC_Bridge" rel="nofollow noreferrer">Arduino board</a> which is essentially a Leonardo (ATmega32U4) customized to include a NFC reader (PN532).</p> <p>When I plug it in, the PWR LED comes on steady, the D13 LED flashes a few times, and then the STA LED blinks once and only the PWR LED is left on. I can upload a basic sketch to the correct Serial Port, but the Serial Monitor is always empty.</p> <p>I have noticed that, when uploading the sketch, the RX/TX LEDs stay off (which I thought was a sign of uploading/downloading data). I figured this was the root of my issue so I tried to look into it further. Running <code>lsusb</code> does not find the device and <code>dmesg</code> does not show any information when (un)plugging the device.</p> <p>I also tried on a Windows install, but couldn't install the Leonardo drivers since Device Manager wouldn't register any unknown USB/Arduino devices.</p> <p>Do you think my board is dead on arrival or am I doing something wrong?</p> <hr> <p><strong>Update:</strong></p> <p>I just uploaded the Blink tutorial sketch and it uploaded "successfully" but I noticed no differences. Please note that I don't have an external LED attached, but am looking at the board's LED on pin 13. This pin already flashes a few times (as mentioned above) on a reset, so I modified the delay times and still noticed no change.</p> <p><img src="https://i.stack.imgur.com/bbb6n.png" alt="uploaded sketch"></p> <p>I am uploading using board Leonardo, as recommended for my hardware, and the serial port /dev/ttyS0. I thought this was the right port because I remember not seeing it at first, but on second thought I had a permission issue at first (which is now resolved) causing me to not see the port.</p> <p><em>So it looks like my board is</em> <strong><em>not</em></strong> <em>detected by my computer and I'm successfully uploading sketches to a meaningless port.</em> Any troubleshooting options for me? I've tried different USB ports and am, as of recently, plugging my board into external power (9V). The only thing I can think of that on my end is that I'm using a Y-cable for my USB connection (I have a normal Mini-USB coming tomorrow via Amazon) since it is all I had. I can also confirm that this USB connection <strong><em>does</em></strong> power the board when plugged in.</p>
<p>So, to summarise the comments trail; the blinking lights at power-up are the normal boot sequence for the Leonardo, indicating the processor is good, and that power is reaching the board; the device seen should be /dev/ttyACM0 or some other number; dmesg wasn't recording a plug-in event as the cable was not good.</p> <p>We still don't quite know why the IDE thought it had sent a program to /dev/ttyS0, but presumably the level of interaction is much less (ie, none) via RS232 serial? Which explains why it said it had uploaded a test program when, in fact, it hadn't!</p> <p>And replacing the USB cable has solved the problem - excellent news!</p>
8257
|avr|c++|
How can I make pinMode calls faster?
2015-01-26T21:35:43.947
<p>I'm trying to use 3 pins as capacitive pins along side the <a href="http://sensorium.github.io/Mozzi/" rel="nofollow">Mozzi</a>.</p> <p>I had several attempts and so far the closest I had was using code from the <a href="http://playground.arduino.cc/Code/ADCTouch" rel="nofollow">ADCTouch library</a> straight into the main code, but with the current implementation (removing averaging and taking less samples to speed things up) it's only fast enough to process 1 pin and I'd like to use 3.</p> <p>Here is my implementation so far:</p> <pre><code>/* Based on the Gain Example changing the gain of a sinewave, using Mozzi sonification library. Demonstrates the use of a control variable to influence an audio signal. Circuit: Audio output on digital pin 9 on a Uno or similar, or DAC/A14 on Teensy 3.0/3.1, or check the README or http://sensorium.github.com/Mozzi/ Mozzi help/discussion/announcements: https://groups.google.com/forum/#!forum/mozzi-users Tim Barrass 2012, CC by-nc-sa. */ #include &lt;MozziGuts.h&gt; #include &lt;Oscil.h&gt; // oscillator template #include &lt;tables/sin2048_int8.h&gt; // sine table for oscillator // use: Oscil &lt;table_size, update_rate&gt; oscilName (wavetable), look in .h file of table #included above Oscil &lt;SIN2048_NUM_CELLS, AUDIO_RATE&gt; aSin(SIN2048_DATA); // control variable, use the smallest data size you can for anything used in audio byte gain = 255; //ADC Touch setup int sampleCount[3] = {0}; int values[3] = {0}; void setup(){ startMozzi(); // start with default control rate of 64 aSin.setFreq(4200); // set the frequency } void updateControl(){ if(gain &gt; 3){ gain = gain - 3 ; }else{ gain = 0; } //begin ADCTouch pinMode(A4, INPUT_PULLUP); ADMUX |= 0b11111; ADCSRA |= (1&lt;&lt;ADSC); //start conversion ADCSRA |= (1&lt;&lt;ADIF); //reset the flag pinMode(A4, INPUT); values[0] = mozziAnalogRead(A4); sampleCount[0]++; //end ADCTouch if(sampleCount[0] == 64){//wait for 64 samples if(values[0] &gt; 500) {//did we get a touch with all these samples ? gain = 255;//amp it up } sampleCount[0] = 0;//reset count } } int updateAudio(){ return (aSin.next()* gain)&gt;&gt;8; // shift back to STANDARD audio range, like /256 but faster } void loop(){ audioHook(); // required here } </code></pre> <p>The issue is as soon as do the pinMode calls for the second pin I'd like to use (A5) so I'm guessing pinMode needs to work faster. To use <code>pinMode(INPUT_PULLUP)</code> and <code>pinMode(INPUT)</code> calls for pins A4,A5 and digital 10, now can I write this using direct port manipulation ?</p> <p>(I'm new to avr/arduino internals and slowly getting the grips with this).</p>
<p>First, <a href="https://www.google.com/search?q=arduino+pin+mapping">figure out which port and pin you're using</a>. Then, manipulate them.</p> <pre><code>DDRC &amp;= ~_BV(PC5); PORTC |= _BV(PC5); </code></pre> <p>...</p> <pre><code>DDRF &amp;= ~_BV(PF5); PORTF |= _BV(PF5); </code></pre> <p>...</p> <pre><code>DDRF &amp;= ~_BV(PF0); PORTF |= _BV(PF0); </code></pre>
8276
|arduino-uno|analogread|digital|
Is it wise to use analog input pins to read digital buttons?
2015-01-27T21:46:29.153
<p>I am thinking about building a circuit that is literally going to take 11 of the 14 digital pins of an <code>UNO</code> to communicate with an SD card and an external EEPROM chip (EEPROM programmer).</p> <p>Using 4 shift registers and the SD card, I will have 1 digital pin left. Well, I'm also reserving pins 0/1 for serial communication.</p> <p>Anyway, I need to read some external buttons and I have the 6 analog pins that I haven't touched. </p> <p>I will only need about 4-5 push buttons in my design so they should fit nicely on A0+.</p> <p>So, my question is, will I run into any issues doing this? Or, are the analog inputs better left for true analog reading?</p> <p>Thanks.</p>
<p>The Analog pins are essentially identical in functionality to digital pins when used as digital I/O.</p> <p>If desired you could "be clever" and use an analog input in analog mode to read multiple keys using one pin. eg using 10k, 22k, 39k, 82k, 150k in series with 5 buttons from V+ to pin and a say 4k7 to ground would result in 5 voltages which were easily distinguished using an analog read. This is a very very old technique indeed and allows far more than 5 keys on one input pin. THere are limitations which can be discussed if required. </p> <p>R1 ... R5 correspond to buttons 1...5</p> <p>Vout = V+ x Rb / (Rb + Rbutton)</p> <p>Example only </p> <p>Rb = 39k<br> R1 = 10k<br> R2 = 22k<br> R3 = 39k<br> R4 = 82k<br> R5 = 150k</p> <p>Gives </p> <ul> <li><p>The % of V+ in column 2 when a button is pressed. </p></li> <li><p>The voltage in column 3 with V+ = 5V </p></li> </ul> <p>Delta-V is the difference between that key and the one below - very ample clearance. </p> <p><img src="https://i.stack.imgur.com/F9KCN.jpg" alt="enter image description here"></p> <p><img src="https://i.stack.imgur.com/Cq9kc.jpg" alt="enter image description here"></p>
8285
|arduino-ide|c|avr|
Is Arduino IDE enough to program with C or C++?
2015-01-28T10:17:01.563
<p>I am using Arduino IDE to program my ATmegas with bootloaders. I can directly manipulate ports, use timers, interrupts, PWM pins and timers, etc. Everything is working.</p> <p>But this question arises: Does the Arduino IDE differ from AVR Studio in terms of using C or C++ on an ATmega chip?</p> <p>I know AVR Studio has some features or something. My question is not about that. My question is that I am coding everything, not using extra libraries, features etc.</p>
<p>It is unclear exactly what you are asking. The Arduino is different to most computers - it has NO OS (if you exclude the bootloader).</p> <p>You can use a c/c++ compiler which translates your code to machine code. If you include libraries this may include machine code which someone else has compiled into a library.</p> <p>You could write 100% of your code in assembler and produce exactly the same result. Even in the good (bad?) old days of the 1970s before we had compilers on microprocessors it was common to have prewritten code (libraries) for common functions.</p> <p>You haven't lived until you have written your own assembler (hand coded).</p>
8288
|arduino-uno|avr|atmel-studio|
Can I program AVR Microcontrollers using Arduino Development board with AVR Studio?
2015-01-28T12:58:26.580
<p>I know and I can program any AVR microcontroller with Arduino IDE and Arduino Uno board. Can I use Arduino board with AVR Studio? Or I have to buy an AVR Development board?</p>
<p>There is an <a href="http://www.visualmicro.com/" rel="nofollow">Arduino plugin</a> available for AVR Studio, which allows you to upload sketches to an Arduino, just like you would with the Arduino IDE. I think this also enables you to upload plain C/C++ files created with the standard AVR tools.</p> <p>Alternatively, if you have an AVR ISP programmer, you can use this to upload compiled C/C++ to the Arduino from AVR studio without needing the Arduino plugin.</p>
8302
|programming|attiny|system-design|
Programming an Array of ATTiny
2015-01-29T10:41:56.350
<p>I am designing a board for my electronics project and i am using a number of ATTiny85 for it. The ATTiny's will be SMD so i will not be able to remove them for programming. </p> <p>Moreover all of the pins of my uCs will be used for connections (apart from reset). </p> <p>Is it possible in this case to achieve that, any ideas and suggestions are welcome</p> <p>EDIT: Well, Vcc and Ground will be common, i will be using an external oscillator for all of them, the reset pin will be free, the other three pins will be used for gpio communication between the attinys. I am connecting about 10 attiny in a daisy chain kind of thing</p>
<p>As long as whatever you're connecting the MISO, MOSI, and SCK pins to doesn't mind being driven externally, you can still program the ATTiny in-circuit - just break out those pins with reset to a standard 6 pin header and program them that way.</p> <p>If one or more of those pins can't be driven externally (eg, because they're connected to another device that drives them and has no output disable), you'll need to add a tristate buffer IC between the MCU and the other device, or some jumpers you can remove when you want to program them.</p>
8305
|c|
Chain of, or one big if sentence
2015-01-29T13:58:11.160
<p>(This might be more of a common C question)</p> <p>I want to test several conditions in an IF-sentence</p> <pre><code>if(variable) { // fastest check if(register) { // a bit slower if(read_peripheral) { // very slow check // [do something] } } } </code></pre> <p>It seems obvious that I want to start with the fastest check, and move on to the slower ones afterwards, potentially avoiding to check them if the above was false. </p> <p>Now since I need to check quite a few conditions, I'd like to know if the following is the same, or if all conditions will be evaluated prior to making a decision?</p> <pre><code>if(variable &amp;&amp; register &amp;&amp; read_peripheral) { // [do something] } </code></pre>
<p>Putting them all in a single condition like that is absolutely fine. C/C++ uses "short circuit evaluation" which means it will stop as soon as it's determined the outcome. If everything is combined using logical AND operators (&amp;&amp;) then that means it will stop as soon as one of them evaluates to false.</p> <p>For example:</p> <pre><code> if (blah() &amp;&amp; foo()) { ... } </code></pre> <p>If <code>blah()</code> returns false, it will never call <code>foo()</code> at all because it already knows the overall outcome is false.</p> <p>The reverse happens with the logical OR operator (||):</p> <pre><code> if (blah() || foo()) { ... } </code></pre> <p>If <code>blah()</code> returns <em>true</em> in this case, it won't call <code>foo()</code>. That's because it already knows the overall outcome is true.</p>
8307
|arduino-uno|serial|programming|bluetooth|
Can't program Arduino via Bluetooth (HC-06) with a Mac
2015-01-29T18:16:45.627
<p>I bought a HC-06 Module for my Arduino Uno the other day, yesterday it arrived and I'm having trouble using it with the Arduino IDE.</p> <p>I set it up, connecting 5V, GND and RX/TX crossed. After a bit of searching, it shows up on the bluetooth settings on the macbook. When I click "connect", it fails, after I click "Options", then set the Pin to 1234 it says "Connected". The LED on the HC-06 is still blinking (which is OK I guess, since I'm not yet communicating).</p> <p>I have a Sketch running on the Uno that prints out some text. When I open the serial monitor (after connecting like above) it works, displaying the values I expect. However, after closing the serial monitor the HC-06 changes to "not connected" on the mac.</p> <p>Also, if I try to upload code via the Arduino IDE it states: <code>avrdude: ser_open(): can't open device "/dev/tty.HC-06-DevB": Resource busy ioctl("TIOCMGET"): Inappropriate ioctl for device</code> or throws a <code>processing.app.SerialException: Fehler beim Öffnen des seriellen Ports "/dev/tty.HC-06-DevB".</code> (German for "Error while opening Serial Port "/dev...." ").</p> <p>Do I have to configure the HC-06 or the Arduino IDE in any way to make this work, and, if so, how can I do that?</p> <p><strong>Edit:</strong> I've also connected TX and RX uncrossed, though that alone doesn't solve the problem.</p> <p>Thanks in advance for your Support!</p>
<p>After dealing with the problem for several hours I unexpectedly solve the problem.</p> <p>The HC-06's LED keep blinking after I entered the "1234" code. In my case (I'm using Windows 10), the HC-06 status changed to "connected" for few seconds and then changed to "Paired". Once I opened the correct COM port to receive data from the HC-06 to my PC computer, the LED changed to solid ON. Then I was able to catch data from my Arduino UNO. As soon as I closed the COM port in my PC (I used CoolTerm), the LED changed to blinking back again. The COM port I used to receive the data was the one indicated with direction "Outgoing" in the PC's Bluetooth settings. So, I was expecting the HC-06 to behave as my Bluetooth speakers or my Bluetooth headphones: Always connected. I was wrong and it cost me several hours of testing.</p> <p>In my firsts tests I focused opening the COM port with direction "Incoming". Nothing happened here and I lost a lot of time. I tested my wiring between the arduino and the HT-06 module by changing the device name from "HC-06" to "ArduinoBT01" and it worked.</p> <p>This is the sketch I used to receive data form the Arduino via Bluetooth:</p> <p><a href="https://i.stack.imgur.com/HKL3M.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/HKL3M.jpg" alt="enter image description here"></a></p> <p>This is the CoolTerm's window capture:</p> <p><a href="https://i.stack.imgur.com/XOD8q.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XOD8q.jpg" alt="enter image description here"></a></p> <p>Mysteriously, the CoolTerm speed setting is 14400bps but the speed in the device manager for COM34 is 9600bps. After triying opening many times the COM34 port with 9600bps I got this error in CoolTerm:</p> <p>"An error occurred while attempting to open the port". "1168: Error 1168"</p> <p>So, it only works with 14400 bps. Crazy!!</p> <p>I hope this helps.</p> <p>Sorry for bugs in my English.</p>
8317
|c++|
I am looking for the source and/or proper definition for the int() function
2015-01-30T03:40:40.320
<p>I am looking for the source and/or proper definition for the int() function. I have searched through the source in Arduino.app, without much success.</p> <p>The reference gives a terse explanation </p> <pre><code>int(x) x: a value of any type Converts a value to the int data type </code></pre> <p>Passing 1, '1' or 49 returns the int 1. I haven't tested other types.</p> <p>This seems to be an Arduino specific function - it doesn't seem to be in any c/c++ library.</p>
<p><code>int(x)</code> is not a function but <strong>another way to perform an explicit cast</strong> of <code>x</code> to an <code>int</code>. It is part of the C++ language itself, that is why you could not find it in a library.</p> <p>This is not Arduino-specific.</p> <p>In C and C++ you can cast a value to an int by doing this:</p> <pre><code>int y = (int) x; </code></pre> <p><strong>C++</strong> has extended this notation by allowing to do it this way, which is equivalent:</p> <pre><code>int y = int(x); </code></pre> <p>You can find this <a href="http://en.cppreference.com/w/cpp/language/explicit_cast" rel="nofollow">in more details</a> in C++ language reference.</p>
8320
|power|ethernet|
What is Vin for the EthernetPOE board?
2015-01-30T05:47:43.173
<p>I am working on a project that needs to drive a relay board. I'm looking at the ETHERNET board with PoE and according to the documentation here (<a href="http://arduino.cc/en/Main/ArduinoBoardEthernet" rel="nofollow">http://arduino.cc/en/Main/ArduinoBoardEthernet</a>) the output of the PoE module is 9V. </p> <p>Is that the voltage to expect out of the Vin pin? </p> <p>The Relay board that I want to use (<a href="http://numato.com/downloads/dl/file/id/29/product/47/user_manual.pdf" rel="nofollow">http://numato.com/downloads/dl/file/id/29/product/47/user_manual.pdf</a>) specifies that it wants a 7-12V power supply. </p> <p>I want to confirm that this is the case so I can use the voltage out of the PoE and I don't need to add a separate DC power supply to this system.</p>
<p>Your question is a little confusing, so let me give you a couple pieces of information.</p> <p>First things first - the VIn pin on the Arduino is strictly for power going to the Arduino board, you shouldn't be drawing power from this pin. The documentation in the link you sent is a little misleading on this - it's basically saying 9v is coming OUT of the PoE module, and going IN to the VIn on the Arduino itself. If you wanted to tap into this 9v power, you should connect to the PoE module VOut instead.</p> <p>PoE by default can deliver 37-57 volts or 42-57 volts, depending on what type of PoE you're using (which 802.3 specification). <a href="http://en.wikipedia.org/wiki/Power_over_Ethernet#Standard_implementation" rel="nofollow">Wikipedia</a> has a good overview of this information.</p> <p>That being said, the Arduino Ethernet board you're using can't handle this voltage by itself - unless these boards have changed, they require an additional <a href="http://store.arduino.cc/product/X000002" rel="nofollow">PoE module</a>, which is basically just a DC-to-DC buck converter that will convert the high PoE voltage down to 9v or 12v. At this point, the Arduino's built-in converter can consume that 9 or 12v and distribute it at 5v across the board.</p> <p>Now, to your problem - you want to power a relay that requires 7-12v. You could theoretically connect the relay to the VOut of the PoE module, giving you 12v. However, if the relay draws too much power for too long, you will either get brownouts (and your Arduino will restart) or potentially damage the Arduino board. Unless the relay draws a lot of current or is being powered for extended periods, you should be fine. If you want to be more thorough, you could put a large capacitor between your PoE module and the relay.</p> <p>You should NOT try to connect the relay directly to the PoE VOut, as the voltage will be far too high. </p>
8321
|pwm|analogwrite|
Issue with PWM output pin
2015-01-30T07:52:19.773
<p>I'm just starting off with using the Arduino and was learning about PWM<br> (<a href="http://arduino.cc/en/Tutorial/PWM" rel="nofollow noreferrer">http://arduino.cc/en/Tutorial/PWM</a>).<br> Below is what my circuit looks like.</p> <p><img src="https://i.stack.imgur.com/MDY9x.jpg" alt="enter image description here"></p> <p>Below is the very simple code.</p> <pre><code>const int pinNine = 9; // LED connected to digital pin 9 void setup() { // initialize serial communications at 9600 bps: Serial.begin(9600); // set the digital pins as outputs pinMode(pinNine,OUTPUT); } void loop() { analogWrite(pinNine, 0); } </code></pre> <p>I was expecting my LED to not be lighted as its a 0% duty cycle. I even change the pinNine outputValue to (64, 127, etc) but for some reason the LED is always lighted. Any ideas?</p> <hr>
<p>Ok, it seems my understanding of the PWM was wrong. I tried the circuit and code from here (<a href="http://arduino.cc/en/Tutorial/Fade" rel="nofollow">http://arduino.cc/en/Tutorial/Fade</a>) and it worked as expected (fade in and out).</p> <p>Actually when i wrote my original code i was expecting the LED to blink. So, as i got closer to 255 i was expecting it to spend more time being 'lit', as compared to 0 where it should spend less time being 'lit'.</p> <blockquote> <p>I even change the pinNine outputValue to (64, 127, etc) but for some reason the LED is always lighted.</p> </blockquote> <p>It being lighted makes sense. What i missed out was it being dimmer when the value was lower.</p> <p>Thanks for all your help..</p>
8326
|arduino-uno|
Tile NeoPixel NeoMatrix 8x8
2015-01-30T10:29:20.837
<p>As a programmer I am new and lack some knowledge in electronic and I will appreciate the help.</p> <p>I wish to connect 3 Adafruit NeoPixel NeoMatrix 8x8 - 64 RGB LED Pixel Matrix (<a href="https://www.adafruit.com/products/1487" rel="nofollow">https://www.adafruit.com/products/1487</a>) can some one please provide me a scheme how to connect/tile 3 these NeoMatrix 8x8 to one Arduino Uno.</p> <p>Thanks a lot</p>
<p>I found the <a href="http://fastled.io/" rel="nofollow">http://fastled.io/</a> libary to be a useful and well documented (<a href="https://github.com/FastLED/FastLED/wiki/Overview" rel="nofollow">https://github.com/FastLED/FastLED/wiki/Overview</a>) alternative to Adafruit's NeoPixel library.</p> <p>FastLED has some clever compression of palettes, and many other nice features that might save you valuable memory when using many neopixels.</p>
8337
|arduino-ide|build|
Good way to get automatically generated code into a sketch
2015-01-30T21:32:23.823
<p>Situation:</p> <p>Mac OS, Arduino IDE 1.5.6r2</p> <p>I've got a sketch with several files, all classic .cpp and .h source and header files except the main sketch file. As the project goes more complex I started to generate code automatically by another program. Now I have hard times integrating the generated code it into my sketch. The arduino IDE seems to load the code on opening the sketch. After that, the source files aren't beeing checked for external changes by the IDE (as I would expect it from a real editor like <em>vim</em>). On top of that, when I verify my code the IDE seems to save the files from RAM into a temporary build directory ignoring the contents of the sketch directory further. So if I let my code generator change a source file while the sketch is opened in the IDE, the changes won't reach the build. I had to close the IDE and reopen it. The next thing I tried is to include my autogenerated file from an existing and opened code file inside the IDE. But the IDE ignores files, which aren't opened completely. Hence, the file is missing in the build directory. </p> <p>Is there a trick to let the IDE take the code unknown to itself along into the build directory? Or how else can I deal with this situation? I don't want to close and open the IDE a hundred times a day.</p>
<p>According to the release notes starting with V1.5.2 of the IDE you can verify and upload from the command line.</p> <p>You could use your favorite editor and then use the command line to do the arduino build/upload instead of the IDE.</p> <p>See: <a href="https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc" rel="nofollow">https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc</a></p> <p>I have not used it so I can't say if it work well or not.</p>
8339
|arduino-uno|
RTClib library dependency on Wire library
2015-01-31T00:49:07.557
<p>I downloaded the RTClib library from <a href="https://github.com/adafruit/RTClib">https://github.com/adafruit/RTClib</a>. In every provided example, <code>#include &lt;Wire.h&gt;</code> is written immediately above <code>#include "RTClib.h"</code> at the top of the sketch. </p> <p>Why is this necessary? I know the RTClib library requires the functionality of the Wire library but, if this is the case, why can't I just <code>#include &lt;Wire.h&gt;</code> at the top of RTClib.h? I have tried the latter, even using just the following sketch, but my sketch failed to compile.</p> <p>RTClib.h:</p> <pre><code>// Code by JeeLabs http://news.jeelabs.org/code/ // Released to the public domain! Enjoy! #ifndef _RTCLIB_H_ #define _RTCLIB_H_ #include &lt;Wire.h&gt; ... #endif // _RTCLIB_H_ </code></pre> <p>Sketch:</p> <pre><code>#include "RTClib.h" void setup() {} void loop() {} </code></pre>
<p>Not getting too formal here, The arduino IDE looks at which libraries are included in the top level sketch when deciding what libraries to include in the compilation.</p> <p>It would make sense for only RTClib.h to include Wire.h yes, but the IDE does not get the information to add Wire to the compilation list that way. It is a quirk of the IDE that makes implementing libraries that use other libraries a bit more painful.</p>