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
1823
|attiny|accelerometer|
MMA7660 accelerometer with ATTiny85
2014-06-03T16:24:18.880
<p>I'm trying to make the ATTiny85 work with the MMA7660 accelerometer, so far, without any success. Google search for "ATTiny85 MMA7660" gives poor results, and I'm not sure it has been done at all, at least publicly, so I thought I'll try my luck here.</p> <p>What I've tried is using the <a href="https://github.com/adafruit/TinyWireM" rel="nofollow noreferrer">TinyWireM</a> library, in different combinations. The last one is based on the MMA7660 Arduino library, specially adjusted to the TinyWireM, and taken from <a href="http://forum.arduino.cc/index.php?topic=103180.0" rel="nofollow noreferrer">this post</a> in Arduino forums (<a href="http://forum.arduino.cc/index.php?PHPSESSID=6uhahs306gip7a2d4hp2gjcbf3&amp;action=dlattach;topic=103180.0;attach=17551" rel="nofollow noreferrer">direct link to download</a>).</p> <p>The SCL is connected to PB0 and SDA to PB2, with 5k ohm pull-ups (I know that the recommended is 4.7k but this is what I have available, and I assumed it shouldn't make much difference).</p> <p>I am using the Arduino IDE v1.5.6, which works successfully with other non-I2C attiny projects I have.</p> <p>As for the final code I am using the .pde example that comes with the MMA7660, altered to use SoftwareSerial:</p> <pre><code>#include &lt;TinyWireM.h&gt; #include &lt;MMA7660.h&gt; #include &lt;SoftwareSerial.h&gt; SoftwareSerial mySerial(-1,4); void setup() { mySerial.begin(9600); MMA7660.init(); } void loop() { int x,y,z; delay(100); // There will be new values every 100ms MMA7660.getValues(&amp;x,&amp;y,&amp;z); mySerial.print("x: "); mySerial.print(x); mySerial.print(" y: "); mySerial.print(y); mySerial.print(" z: "); mySerial.println(z); } </code></pre> <p>The current problem with the above code is that the pointers just dump some memory without making any sense. If I try to see what TinyWireM.receive() command returns, values are 216 for all three variables. This is true even when I disconnect the MMA7660 from the prototyping board...! so I assume the problem is with the I2C itself, not working properly. The actual I2C address for the MMA (0x4C) and other relevant code is in MMA7660.cpp.</p> <p>Any ideas?... Unfortunately I don't currently have another I2C device to examine the health of this protocol with my ATTiny85, so any experience you might have with this sort of configuration will be blessed. </p> <p><strong>EDIT: I marked dvlabsllc's answer as accepted answer since it gave me the right direction to pinpoint the issue further down the library path. I have opened a new question regarding TinyWireM library <a href="https://arduino.stackexchange.com/questions/1829/ic-with-attiny85-at-8mhz-using-tinywirem-library">here</a>.</strong></p>
<p>I have run into similar frustrations using standard libraries and I2C. I would have to look into the code and try it out on my own before confirming anything about this particular code; however, in the meantime you might want to try a tool such as <a href="http://playground.arduino.cc/Main/I2cScanner" rel="nofollow">I2cScanner</a> that simply scans the I2C bus for all possible addresses and reports addresses that are "alive". This (or something similar as I am not sure if you are using Arduino API) might be a good start to just see if the I2C is working and that you have the correct address.</p>
1830
|arduino-uno|programming|serial|
Reducing lag between the arduino and a processing sketch on my computer
2014-06-04T12:27:35.490
<p>I'm currently on project #14 of the Arduino project book.</p> <p>I'm trying to control a processing sketch on my laptop using my Arduino. This is accomplished by using a potentiometer to control the background of an image.</p> <p>Arduino code:</p> <pre><code>void setup(){  Serial.begin(9600); } void loop(){  Serial.write(analogRead(A0)/4); } </code></pre> <p>Processing:</p> <pre><code>//imports serial library import processing.serial.*; //setups the serial object Serial myPort; //creates an object for the image PImage logo; //variable to store background color int bgcolor = 0; void setup(){  colorMode(HSB,255);  logo = loadImage("http://arduino.cc/logo.png");  size(logo.width,logo.height);  println("Available serial ports");  println(Serial.list());  myPort = new Serial(this,Serial.list()[0],9600); } //equivalent of arduino's loop function void draw(){  if(myPort.available() &gt; 0)  {    bgcolor = myPort.read();    println(bgcolor);  }  background(bgcolor,255,255);  image(logo,0,0); } </code></pre> <p>Now, while the code works, and the background color changes as i turn the potentiometer, there is a <strong>huge</strong> lag between turning the potentiometer and seeing the background change color, and the values from the Arduino/potentiometer change on the processing's serial monitor.</p> <p>What I've tried:</p> <ul> <li>Changing the speed of Serial communication</li> </ul> <p>I've noticed that when I decrease the speed of Serial communication, e.g. around 100, the delay between turning the potentiometer and seeing it change on my laptop decreases to about 1 second. However, when I decrease the speed of Serial communication even further, e.g. a value of 1, the delay increases again.</p> <p>On the flip side, at the standard speed of 9600, the delay is huge, roughly 5sec ++ before the changes in the potentiometer show up on the laptop/processing.</p> <p>Why does decreasing the communication speed (up to a certain point) decrease the time lag, and increasing it increase the time lag? Also, is there anyway I can make it near instantaneous?</p>
<p>Two simple solutions that are guaranteed to work for anyone who is still looking:-</p> <ol> <li><p>Increase the delay to 50 to 100 milliseconds.</p></li> <li><p>Add this after the <code>Serial.begin(9600)</code> in <code>setup()</code>;</p> <pre><code>Serial.setTimeout(50); </code></pre></li> </ol> <p>Step two is the most important. It worked for me only after I added the above code. This is not mentioned very often in many other forums that I have looked when I had the exact same problem.</p>
1832
|arduino-uno|electricity|
How to measure voltage with Arduino analog input
2014-06-04T16:21:25.653
<p>I'm totally new to Arduino and to electrodynamics in general.</p> <p>I'm wondering what happens if I connect my digital pin to an analog input on Arduino, and make digitalWrite and analogRead on the according pins. Here are the options I can think about:</p> <ul> <li>Just connect them directly - <em>it is not a short circuit, is it?</em></li> <li>Connect a resistor in between - <em>the voltage should still be 5v, right? Whatever resistor I use?</em></li> <li>Make a circuit: digital output -> resistor -> ground, and connect the analog input in parallel (in between the resistor and ground) - <em>Does it make sense? What is the difference with the previous option?</em></li> </ul> <p>As you see, I'm really confused now. I would highly appreciate if someone could explain in detail what is happening in all the cases, with corresponding values for the <em>current</em>, <em>voltage</em> and <em>resistance</em>.</p>
<p>If you have a 250 ohm resistor from the digital pin to Gnd, and connect the digital pin to an analog input pin, then 20mA will flow thru the resistor to Gnd (5V/250 ohm = 20mA), while almost nothing flows into the analog input, as the max input current is 1uA per the datasheet, implying the input acts like a large resistor to Gnd: High input of 5V/.000001A = 5Meg-ohm.</p> <p>I say acts because the input pin is the gate of a MOSFET, and a diode protection clamp to +5 and another to Gnd to limit the input voltage to -0.5 and Vcc+0.5V (so 5.5V with Vcc = 5V). </p> <p>The diode clamps are only good for ~1mA (not shown in the data sheet, but discussed in an application note on detecting AC zero crossing), exceed that and you risk blowing the diode and/or the input pin and/or the chip (which will then feel warm or hot to the touch when it is powered up).</p> <p>That's why you don't apply signals to unpowered chips - to prevent damaging the diode clamp circuits.</p>
1834
|arduino-uno|temperature-sensor|
Problems with Dallas temperature sensor code
2014-06-04T17:36:04.037
<p>I have connected up my temperature sensor and I am trying to run the one wire address finder to find the address of the sensor.</p> <p>The problem is that when I run the code it gives me the error: 'OneWire' does not have a type.</p> <p>I have imported by the temperature and the onewire libraries but it still does not work.</p> <pre><code>#include &lt;OneWire.h&gt; OneWire ds(6); // This is where the error is </code></pre>
<p>I presume the exact error you get is</p> <blockquote> <p>error: 'OneWire' does not name a type</p> </blockquote> <p>This error is typical when the OneWire library (or any other library for that matter) is not located under the <strong>libraries</strong> folder, which should be at the root of the Arduino installation folder.</p> <p>Also, make sure that the OneWire.h and OneWire.cpp files are 1 folder down the hierarchy, as follows:</p> <p>[Arduino Installation Folder]\libraries\OneWire\OneWire.h</p> <p>If they are nested deeper inside the folder hierarchy, the Arduino IDE will not find these files in its initial scan, and you will get the same error.</p> <p>Make sure to close all Arduino IDE windows and re-open it after fixing the folder path.</p>
1836
|arduino-due|analogread|
AnalogRead always 1023 on Arduino Due?
2014-06-04T19:06:07.057
<p>Just using the Basic Example <code>AnalogReadSerial</code>.</p> <pre><code>// the setup routine runs once when you press reset: void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue = analogRead(A0); // print out the value you read: Serial.println(sensorValue); delay(1); // delay in between reads for stability } </code></pre> <p>I have a basic voltage divider set up between two 10K resistors from 5V to GND. I have verified with a DMM that the DC voltage at pin A0 is 2.5V. Grounding the A0 pin has no effect.</p> <p>It also seems that enabling either ADC channel 7 (Arduino pin AD0) or enabling every channel, putting the ADC in free-running mode, and deliberately setting it to <em>not</em> sleep has no effect:</p> <pre><code>ADC-&gt;ADC_CHDR = 0; ADC-&gt;ADC_CHER |= 0xFF; ADC-&gt;ADC_MR |= 0b10000000; ADC-&gt;ADC_MR &amp;= 0b11011111; </code></pre> <p>Also, by running the sketch <code>DigitalInputPullup</code>, I can get the LED on pin 13 to toggle and serial communication to work as I tie the pin to ground, demonstrating that the board is being programmed properly.</p> <p>I guess I'm just stumped. Should be the simplest thing in the world and it's just not working.</p> <p>EDIT: This is my attempt at manually controlling the ADC:</p> <pre><code>volatile unsigned long value; void setup() { //ADC setup ADC-&gt;ADC_WPMR &amp;= 0xFFFE; //disable write protect ADC-&gt;ADC_CHER = 0b100; //Enable AD2 | ADC-&gt;ADC_MR &amp;= 0b11111111000000001111111100000000; ADC-&gt;ADC_MR |= 0b00000000000100100000000000000000; //software trigger, hi res, no sleep, not free running ADC-&gt;ADC_IER = 0b100; //enable interrupt ADC-&gt;ADC_IMR = 0b100; //enable interrupt in mask ADC-&gt;ADC_CR |= 0b10; //start first conversion Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { ADC-&gt;ADC_CR |= 0b10; //start conversion while (!(ADC-&gt;ADC_ISR &amp; 0b100)); //wait for conversion to end for (int i = 0; i &lt;= 15; i++) { value = ADC-&gt;ADC_CDR[i]; //read conversion data for all channels Serial.println(value); } Serial.println(); Serial.println(); Serial.println(); delay(3000); } </code></pre> <p>Just doesn't seem to be doing anything. <code>ADC_CHSR</code> (the ADC channel status register) shows channel 2 and only channel 2 enabled and conversions are starting and completing, yet now the conversion data is always 2048. Here's the serial output of all 15 channels, now in 12 bit mode:</p> <pre><code>0 0 4095 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4095 0 0 0 0 0 0 0 0 0 0 0 0 0 </code></pre>
<p>Answer to a 6 years old thread. Hope this will help others :)</p> <p>Looks like you have been using an external power source and only connected the positive core to the pin. If you had an external power source, did you connect the external power source GND to Arduino GND?</p>
1838
|arduino-yun|web-server|
Arduino Yun and REST call security
2014-06-04T22:34:15.163
<p>I'm not expert about web development but very excited of doing some rest call using the yun as server (with a minimal python or node.js server inside the openwrt machine in the yun) and expose sensors and actuators to the cloud.</p> <p>I'm also worried about security. I don't want the super-shellproof system but just don't want that accidental visitors reads my home temperature or make my garden light switch on when I'm out.</p> <p>For instance I have a central unit yun with some logic inside it and few arduino yun that makes reads from sensors and runs actuators around my home. The communication between the central yun and the slaves is happening via REST calls. I'm using <code>curl</code> for testing it, for instance. Here two questions:</p> <ol> <li><p>Arduino Yun provide a simple user/password account when <code>arduinoname.local/arduino</code> is called. How is it implemented?</p></li> <li><p>Let's say I'm using node.js to make a super simple web-server, what is the best way to protect the communication central-yun and slave-yun? and to protect central-gun and internet communication? </p></li> </ol> <p>Best way in term of computation (the yun machine is not very powerful and I'm going to use battery in some cases) and in term of "easy to implement".</p>
<p>Password protection of the REST API is done with <a href="http://en.wikipedia.org/wiki/Basic_access_authentication" rel="nofollow">Basic Authentication</a>. This, coupled with <a href="http://en.wikipedia.org/wiki/HTTP_Secure" rel="nofollow">HTTPS</a>, makes API calls more secure. Since the SSL certificate is self-generated, you'll need to run <code>curl</code> with <code>-k</code> parameter.</p> <p>As Annonomus Penguin suggested, before going into securing the Yuns, you should secure the network they are using (e.g.: home WiFi should use a strong password).</p>
1844
|arduino-uno|potentiometer|
How to emulate an analog potentiometer with PWM
2014-06-05T12:34:34.223
<p>I have a piece of electronic that controls a motor. It takes power from AC power.</p> <p>Now there is a 10KOhm Potentiometer. The data sheet of this controller says that the control signal is 10Vcc.</p> <p>Here's the <a href="http://we.tl/Kk89gm2PRL" rel="nofollow noreferrer">connections diagram</a> (in Italian):</p> <p><img src="https://i.stack.imgur.com/gieFs.png" alt="enter image description here"></p> <p>I'd like to emulate the Potentiometer with Arduino. I'm not sure if PWM will do the job. </p> <p>Any hints?</p>
<p>my solution is simple get a servo (pwm input) and connect the shaft of the servo to the pot with a coupler then just use a simple servo control program</p>
1846
|arduino-uno|programming|serial|
Reading text/strings via processing
2014-06-05T17:37:55.640
<p>I'm trying to control an led attached to my arduino via key presses on my laptop.When i hold down a key, the led should light up, and when i release the key, the led should turn off.</p> <p>While my code works ATM, i am wondering why my code will not work if i replace the numbers in my code with text/strings.</p> <p>Processing code(Working)</p> <pre><code>import processing.serial.*; Serial myPort; void setup(){ println("The available ports are: "); println(Serial.list()); myPort = new Serial(this,Serial.list()[0],9600); myPort.buffer(8); size(500, 500); } void draw(){ if(keyPressed){ if(key == 'r' || key == 'R'){ myPort.write(1); println("red"); } } } void keyReleased(){ myPort.write(2);println("released"); } </code></pre> <p>Arduino Code(Working)</p> <pre><code>int red = 7; void setup(){ Serial.begin(9600); pinMode(red,OUTPUT); } void loop(){ } void serialEvent(){ int input = Serial.read(); if(input == 1){ digitalWrite(red,HIGH); }else if(input == 2){ digitalWrite(red,LOW); } } </code></pre> <p>Processing Code (Not working)</p> <pre><code>import processing.serial.*; Serial myPort; void setup(){ println("The available ports are: "); println(Serial.list()); myPort = new Serial(this,Serial.list()[0],9600); myPort.buffer(8); size(500, 500); } void draw(){ if(keyPressed){ if(key == 'r' || key == 'R'){ myPort.write("red"); println("red"); } } } void keyReleased(){ myPort.write("released"); println("released"); } </code></pre> <p>Arduino Code(Not working)</p> <pre><code>int red = 7; void setup(){ Serial.begin(9600); pinMode(red,OUTPUT); } void loop(){ } void serialEvent(){ int input = Serial.read(); if(input == "red"){ digitalWrite(red,HIGH); }else if(input == "released"){ digitalWrite(red,LOW); } } </code></pre> <p>From the above example, i get the error ISO C++ forbids comparisons between pointers and integers.After googling the error, it was suggested that i replace the double quotes with single quotes, after which the arduino code is able to compile, but the processing code gives an error "badly formed character constant(expecting quote,got e)".</p> <p>I then tried changing using double quotes for processing and single quotes for the arduino quote, but predictably, it did not work.</p> <p>Why does my code work when i pass numbers to the arduino via serial communication, and my code fails when i use text strings?</p>
<p>The problem is that you're mixing different variable types. It's kinda an oil/water scenario.</p> <p>Basically, the <code>serial.read();</code> command returns an integer, <code>-1</code> if there's nothing in the buffer. If there is something, it will return the character code (i.e. 93 = <code>a</code>). Because of that, <em>it's an integer.</em> When you put something in single quotes, it compiles as the equivalent ISO character code.</p> <p>So, when you do <code>input == 2</code>, it is <code>integer [compared to] integer</code>. When you do <code>input == "string"</code>, you're doing <code>integer [compared to] string</code>, thus you get errors. BTW: a string is a type of pointer.</p> <p>So, what you have to do is this:</p> <pre><code>string input = ""; if(serial.avaliable()) { delay(100); //Wait for all data to be received while(serial.avaliable()) { string = string + char(serial.read()); } } if(input == "yay_it_works!) { //Done! } </code></pre>
1849
|uploading|arduino-leonardo|
Uploading Sketches from Windows Command Line
2014-06-05T19:48:56.400
<p>The resources I've found regarding the Command Line interface seem to be out of date so I was hoping to find someone with experience using it. I'm currently running Arduino 1.5.6-r2 BETA on Windows 8.1 looking to upload code to an Arduino Leonardo. </p> <p>I'm trying to create a script(Powershell) file that I can just use to upload code without user intervention. The actual upload part using Arduino CLI is just straight not working for me. If my understanding is correct I should have it already due to my version of the Arduino IDE but none of the functionality works so I'm doubting myself.</p> <p>Source: <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>This is the command I'm attempting to run from Windows Command Prompt:</p> <pre><code>C:\Program Files (x86)\Arduino\arduino.exe --board arduino:avr:leonardo --port COM3 --upload C:\Users\Dev\Documents\Arduino\myProject\myProject.ino </code></pre> <p>Any insight into what I'm missing would be very much appreciated!</p> <p><strong>EDIT:</strong> Additionally, if anyone could provide information regarding the build/upload process which could lead me to a solution from within C# that would be even more amazing. </p>
<p>I recommend you to look into cross-platform tool named <a href="http://platformio.ikravets.com" rel="nofollow">PlatformIO</a>. It has support for <em>Windows OS</em> and doesn't require <em>Arduino IDE</em> or any tools.</p> <p>From <a href="http://platformio.ikravets.com/#!/get-started" rel="nofollow">Get Started</a> let's install platform and setup environment for your Arduino Leonardo:</p> <p><strong>Install new development platform</strong></p> <pre><code>&gt; platformio platforms install atmelavr </code></pre> <p><strong>Initialize new PlatformIO based project</strong></p> <pre><code>&gt; cd path\to\empty\directory &gt; platformio init # Project has been initialized! # Please put your source code to `src` directory, external libraries to `lib` # and setup environments in `platformio.ini` file. # Then process project with `platformio run` command. </code></pre> <p><strong>Setup environments in the <em>Project Configuration File</em> <code>platformio.ini</code></strong></p> <pre><code>[env:my_leonardo_board] platform = atmelavr framework = arduino board = leonardo </code></pre> <p><strong>Process the project’s environments</strong></p> <pre><code>&gt; platformio run --target upload </code></pre> <p>P.S: What is interesting, this tool allows you to manage libraries via CLI and then you can build Arduino-based source code with single line </p> <pre><code>#include &lt;%HEADER_FILE_OF_INSTALLED_LIB&gt; </code></pre>
1857
|programming|
How do I convert code between Arduino platforms?
2014-06-06T01:25:21.727
<p>What documentation is available regarding the differences between the different Arduino platforms?</p> <p>For example, I have some code written for an Arduino Teensy that I would like to run on an Arduino Mega.</p> <p>Is there documentation on the capabilities and equivalencies between each of the platforms? e.g. memory, number of PWM outputs, etc?</p>
<p>The most detailed one seems to be <a href="http://www.baldengineer.com/projects/arduino-comparison-chart/" rel="nofollow">Baldengineer's</a>, but <a href="http://arduino.cc/en/Products.Compare" rel="nofollow">Arduino</a>, <a href="https://www.sparkfun.com/arduino_guide" rel="nofollow">SparkFun</a>, and <a href="https://learn.adafruit.com/adafruit-arduino-selection-guide/arduino-comparison-chart" rel="nofollow">Adafruit</a> have their own as well, although more limited.</p> <p>As always, the best source for information about them is the datasheets for both the MCU(s) used as well as for the boards themselves.</p> <p>And note that different macros are predefined for each MCU and feature (e.g. <code>__AVR_ATmega328__</code> and <code>__AVR_HAVE_MUL__</code>); it is possible to test for their existence in order to customize behavior.</p>
1866
|android|
Input audio from jack to Arduino, and output by
2014-06-06T17:29:39.103
<p>I've never used Arduino but I know a few of its utilities.</p> <p>I want to input audio from a Jack cable (analog) and be able to send it via Bluetooth, or Wi-Fi, or USB to an Android Phone and being able to print the values (from 0 to 1).</p> <p>I'm looking for tutorials but I just find the way to make the input but not the output.</p> <p>Which one would you recommend me of Bluetooth, Wi-Fi and USB?</p> <p>Thanks.</p>
<p>The simplest solution: <em>it really depends.</em> There are a couple of things to consider:</p> <ul> <li><p><strong>Bluetooth</strong> would probably be the least professional to impliment. The easiest way to do this is <a href="https://play.google.com/store/apps/details?id=com.primavera.arduino.listener" rel="nofollow">with an app</a>. You can impliment it into <em>your</em> application with this:</p> <blockquote> <p>Let your own Android application receive data from Arduino by listening to the "primavera.arduino.intent.action.DATA_RECEIVED" intent. This intent will contain the "primavera.arduino.intent.extra.DATA" byte array with the received data. Call getByteArrayExtra("primavera.arduino.intent.extra.DATA") to retrieve the data. Send data to Arduino from your application by broadcasting an intent with action "primavera.arduino.intent.action.SEND_DATA". Add the data to be sent as byte array extra "primavera.arduino.intent.extra.DATA".</p> </blockquote> <p>Still, that's pretty unprofessional IMHO. There are probably other ways to do this, but <em>Arduino Uno Communicator</em> is the easiest by far that I've seen. The main advantage of Bluetooth is it works without a router and it's very cheap (as far as wireless). I can't remember if it's the HC4 or HC5 chip that is commonly available, but [one of those] can be picked up for around $6. Just connect via serial and issue AT commands.</p></li> <li><strong>WiFi</strong> would be the most professional. First of all, people hear <em>Wifi</em> and they think <em>Ohh! Shiny! I'm going to buy it!</em> That's just what I've observed in the past, but it may not always be true. WiFi can be done with the TL-WR703N router. <a href="http://www.martinmelchior.be/2013/07/use-tp-link-tl-wr703n-to-send-arduino.html?m=1" rel="nofollow">This blog post</a> outlines how you can even connect it <em>directly</em> to the Arduino. You can also use an ethernet shield (or equivalence, I've seen breakout ethernet boards built for ~$5). Either way, it's a great way to add 5V WiFi to your Arduino. The only disadvantage is cost and it only works if you're near a WiFi router. If those aren't disadvantages, go ahead with WiFi; it's a great product.</li> <li><p><strong>USB</strong> is only useful if you want:</p> <ul> <li>Speed</li> <li>Stability</li> <li>Portability (i.e. no WiFi Router)</li> </ul> <p>Speed can be eliminated as a need if you only send data every 300 ms or so, depending on what you're doing. For WiFi, it might be best to only go to a webpage when an even occurs (i.e. button pushed on Arduino). Bluetooth and WiFi are stable enough if you're over short distances (and you couldn't go a long way with wires, anyway), and there's not too much interference (don't try at a football game with 50K cell phones... granted, they will be on different bands if using cell service, but Bluetooth may be on).</p> <p>As far as portability, for the price of an OTG cable for your phone, you'd be better off buying a Bluetooth module for a dollar extra.</p></li> </ul> <p>Suggestion: go with WiFi unless you need the portability. Consider figuring out WPS so your users can connect to WiFi with a push of a button. I don't know if the TL-WR703N has support for WPS, via serial or not.</p> <p>Forgot to mention: I don't know everything about your app, but WiFi might have too much latency/overhead for near-instant response. As far as wireless, Bluetooth would have much lower latency AFAIK. (As you can tell, there's no perfect solution here :-))</p>
1872
|arduino-uno|programming|serial|
Unable to light up all the LEDS connected to Arduino using processing
2014-06-08T08:21:06.747
<p>I have 3 LEDs connected to my arduino which are controlled via laptop key presses with processing.</p> <p>While the LEDs are able to light up when the respective buttons are pressed, i am unable to light up all 3 LEDs simultaneously when i press all 3 keys at the same time. I am however able to light up 2 LEDs by pressing 2 buttons simultaneously.</p> <p>All the LEDs light up when their respective buttons are pressed, so i know that it is not a defective LED and/or faulty connections/wiring at play but something else that is causing the issue.</p> <p>My processing code:</p> <pre><code>import processing.serial.*; Serial myPort; void setup(){ println("The available ports are: "); println(Serial.list()); myPort = new Serial(this,Serial.list()[0],9600); myPort.buffer(64); size(500, 500); } void draw(){ if(keyPressed){ if(key == 'r' || key == 'R'){ myPort.write(1); println("red"); } else if(key == 'y' || key == 'Y'){ myPort.write(2); println("yellow"); } else if(key == 'g' || key == 'G'){ myPort.write(3); println("green"); } } } void keyReleased(){ if(key == 'r' || key == 'R'){ myPort.write(4); println("red released"); } else if(key == 'y' || key == 'Y'){ myPort.write(5); println("yellow released"); } else if(key == 'g' || key == 'G'){ myPort.write(6); println("green released"); } println("released"); } </code></pre> <p>My Arduino code:</p> <pre><code>int red = 7; int yellow = 6; int green = 5; void setup(){ Serial.begin(9600); pinMode(red,OUTPUT); pinMode(yellow,OUTPUT); pinMode(green,OUTPUT); } void loop(){ } void serialEvent(){ int input = Serial.read(); if(input == 1){ digitalWrite(red,HIGH); } else if(input == 2){ digitalWrite(yellow,HIGH); } else if(input == 3){ digitalWrite(green,HIGH); } else if(input == 4){ digitalWrite(red,LOW); } else if(input == 5){ digitalWrite(yellow,LOW); } else if(input == 6){ digitalWrite(green,LOW); } } </code></pre> <p>Things i've tried.</p> <ol> <li>I've tried increasing the buffer size from 10(initially) to 64(in the code above)</li> <li>I've tried increasing the baud rate from 9600 to 12000, just in case it was the serial information not being read fast enough.</li> </ol> <p>None of the things i've tried, listed above, was above to solve my problem, and i dont see what could be causing the problem.</p> <p>Any advice would be much appreciated.</p>
<p>I'm guessing it is a hardware issue as I discussed in the comments above. </p> <p>I have just set up a breadboard and copied your code verbatim into the Arduino IDE and Processing (I edited the port index to use). It works as desired. Pressing R, G, or Y will turn on the respective LED and releasing it will turn it off. </p> <p>I can press these three keys in any combination of none on, one only, any two, or all three, and the LED gives the expected result. </p> <p>Keyboards were not initially designed to have multiple "main" keys pressed down at any one time, the exceptions to these being the modifier keys (Windows/Command, Option/Alt, Control and possibly some others (I'm thinking the older keyboards here that had "other" keys—Scroll Lock, Print Scr, etc—I'm really unsure). </p> <p>It appears now, that some hardware and software may have overcome this. As I've said, your project works fine for me. Also, you could try three different keys, it could be a result of how the keys are scanned and you may stumble across three that don't interfere with each other. </p> <p>As I've suggested in the comments to your question, modify the code to utilise the modifier keys instead, or use the keyboard keys as toggles (ie press once for on, press again to turn it off). </p>
2875
|arduino-uno|sensors|pulsein|
What is the work of pulseIn?
2014-06-08T18:01:43.597
<p>I have code for an ultrasonic sensor which I found from a site. Here is the code:</p> <pre><code>#define trigPin 12 #define echoPin 13 void setup() { Serial.begin (9600); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); } void loop() { int duration, distance; digitalWrite(trigPin, HIGH); delayMicroseconds(1000); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); distance = (duration/2) / 29.1; if (distance &gt;= 200 || distance &lt;= 0){ Serial.println("Out of range"); } else { Serial.print(distance); Serial.println(" cm"); } delay(500); } </code></pre> <p>However, I don't understand the work of <code>pulseIn()</code> function. I mean, I want to know when the time count starts and when it ends. For example, in this code, does the time start at <code>digitalWrite(trigPin, HIGH);</code> or does the time start at the <code>pulseIn()</code> function?</p> <p>If it's the second one, when it stops, then how does the time give us the distance of an obstacle when I am already delaying 1000 microseconds after I send a ping in air?</p>
<p>Don't get confused, as the ultrasonic module has a particular way of working. First you set a pulse in the trigpin. When it ends, the module sends 8 bursts of 40 kHz pulses (and thats actually what is used to measure distance, not your pulse in the trigpin, which goes nowhere). At exactly the moment the first burst is sent, the echo pin sets itself in HIGH. When this is happening, the program is in the line of pulseIn, and since echopin is in HIGH it starts timing (because pulseIN(echopin,HIGH) waits for echopin to be HIGH for start timing). When the first pulse of the 40 kHz bounces in the object and gets back to the receiver, the echopin sets itself in LOW. Then the pulseIn function stops the time and returns it. Then the program continues running. This module is a little bit tricky in order to learn the way of working of pulseIn.</p>
2878
|arduino-uno|atmega328|firmware|sketch-size|
Feasability of flashing Arduino UNO r3 with teensy firmware for HID (keyboard) emulation purposes
2014-06-08T22:42:14.087
<p>I've been working on a DIY keyboard project I have all the hardware designed and now its time for the code. For the microcontroller, I'm sort of locked into an Arduino UNO r3 as I already have it lying around. I know it doesn't have HID capabilities baked in, but I can flash different firmware to it. At first I was going to go with a generic HID firmware. This approach was problematic because it would require me to first write/send my Arduino sketch, then touch I wire to various portions of my UNO (it isn't SMD). After this, I would flash the HID firmware and hope that there were no bugs in my sketch as fixing bugs would have required flashing Arduino firmware and repeating the aforementioned steps. I then had the idea to use Teensy firmware (<a href="https://www.pjrc.com/teensy/" rel="nofollow noreferrer">https://www.pjrc.com/teensy/</a>). This approach seems better, but I have questions regarding its feasibility. </p> <ol> <li><p>Can I upload Teensy programs/sketches to the Arduino after I've updated its firmware (if I had a real Teensy I could do this via the teensyduino plugin)?</p></li> <li><p>Similarly, I'd like to write some software that allows me to remap the keyboard. Would the Teensy firmware allow this?</p></li> <li><p>Does the Arduino have enough memory to support #2?</p></li> <li>Is it possible to reflash BOTH the 8u2 and the 16u2 on my UNO (for details see #2 in update one below)</li> <li>If 4 is possible is it possible to write code that would read/write the flash on the 8u2 as a filesystem? (for details see #2 in update one below)</li> </ol> <p><strong>Would the teensy firmware be a good option given these constraints?</strong> I know I've focused mainly on the Teensy, but if you have a more straightforward approach I'd love to hear it. <strong>Also, I know Arduino has a keyboard library(<a href="http://arduino.cc/en/Reference/MouseKeyboard" rel="nofollow noreferrer">http://arduino.cc/en/Reference/MouseKeyboard</a>) but, it seems rather basic, seems to block other keyboard signals while in use, and isn't easily remappable(see #2). I haven't completely written this off, so if you think this would be the best option please let me know.</strong> Thanks for any and all help.</p> <p><strong>Update</strong> Thanks to one of the questions linked by @Ignacio Vazquez-Abrams(<a href="https://arduino.stackexchange.com/questions/991/can-the-2nd-mcu-on-the-uno-r3-be-used-for-keyboard-emulation">Can the 2nd MCU on the UNO R3 be used for keyboard emulation?</a>) on the original question(weirdly it didn't show up here) I have learned the following things(not necessarily from the question itself but by links provided in it):</p> <ol> <li>the Atmel 8u2 of the UNO has 8kb of flash while the 16u2 has 16kb (should've known) I still don't know if either of these sizes are enough to hold my Teensy code AND 1+ map files generated by the mapping software I would make. (see #2 above)</li> <li>the 8u2 seems like the chip that tinkers are generally advised to reprogram as it wouldn't hold the Arduino sketch. If I'm uploading teensy firmware I shouldn't need Arduino sketch capability (Teensy has that built in) So What I might do is use the 16u2 as a place to hold the firmware my code and use the 8u2 as a filesystem to hold any maps I'd like to store. This leads to more questions see the newly added 4 and 5 </li> </ol>
<p>Its is possible and very easy to do. See the HID Project and the Hoodloader: <a href="https://github.com/NicoHood/HID" rel="nofollow">https://github.com/NicoHood/HID</a> <a href="https://github.com/NicoHood/Hoodloader" rel="nofollow">https://github.com/NicoHood/Hoodloader</a></p>
2879
|softwareserial|tinygps|arduino-duemilanove|
tinygps abnormal behaviour with EM408 gps
2014-06-08T23:56:12.657
<p>I have an Arduino Duemilanove and em408.</p> <p>My code is this: </p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;TinyGPS.h&gt; #include &lt;SoftwareSerial.h&gt; #define GPS_RX_PIN 2 #define GPS_TX_PIN 3 TinyGPS gps; SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN); void setup() { Serial.begin(9600); ss.begin(4800); } void loop() { while (ss.available()) { char c = byte(ss.read()); // Here i tried Serial.write(c); and i succesully saw the NMEA data in my serial monitor if (gps.encode(c)) { long lat, lon; unsigned long fix_age; gps.get_position(&amp;lat, &amp;lon, &amp;fix_age); if (fix_age == TinyGPS::GPS_INVALID_AGE ) Serial.println("No fix ever detected!"); else if (fix_age &gt; 2000) Serial.println("Data is getting STALE!"); else Serial.println("Latitude and longitude valid!"); Serial.print("Lat: "); Serial.print(lat); Serial.print(" Lon: "); Serial.println(lon); } else Serial.println("No data!"); } } </code></pre> <p>My output is this:</p> <pre class="lang-cpp prettyprint-override"><code>No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! No data! Latitude and longitude valid! Lat: 32758239 Lon: 15637489 No data! No data! No data! No data! No data! No data! No data! </code></pre> <p>And then i continue getting No data! forever...</p> <p>So...</p> <ol> <li><p>Why does gps.encode() only manage to return true only 1 time? I have gotten the raw data from the gps (the commented code on my code snippet) and it's ok. Why it returns true only one time? </p></li> <li><p>Why the longitude/latidude data is like this? As far as i know, this isnt valid, correct?</p></li> </ol> <p>EDIT: Also tried with TinyGPS++.. but no luck in encoding too...</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;TinyGPS++.h&gt; #include &lt;SoftwareSerial.h&gt; #define GPS_RX_PIN 2 #define GPS_TX_PIN 3 TinyGPSPlus gps; SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN); void setup() { Serial.begin(9600); ss.begin(4800); } void loop() { while (ss.available()&gt;0) { char c = byte(ss.read()); // Here i tried Serial.write(c); and i succesully saw the NMEA data in my serial monitor if (gps.encode(c)) //i previously used if(gps.encode(ss.read())); but no luck then { Serial.print(F("Location: ")); if (gps.location.isValid()) { Serial.print(gps.location.lat(), 6); Serial.print(F(",")); Serial.print(gps.location.lng(), 6); } else { Serial.print(F("INVALID")); } Serial.print(F(" Date/Time: ")); if (gps.date.isValid()) { Serial.print(gps.date.month()); Serial.print(F("/")); Serial.print(gps.date.day()); Serial.print(F("/")); Serial.print(gps.date.year()); } else { Serial.print(F("INVALID")); } Serial.print(F(" ")); if (gps.time.isValid()) { if (gps.time.hour() &lt; 10) Serial.print(F("0")); Serial.print(gps.time.hour()); Serial.print(F(":")); if (gps.time.minute() &lt; 10) Serial.print(F("0")); Serial.print(gps.time.minute()); Serial.print(F(":")); if (gps.time.second() &lt; 10) Serial.print(F("0")); Serial.print(gps.time.second()); Serial.print(F(".")); if (gps.time.centisecond() &lt; 10) Serial.print(F("0")); Serial.print(gps.time.centisecond()); } else { Serial.print(F("INVALID")); } Serial.println(); } else Serial.println("No data!"); } } </code></pre> <p>New code:</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;TinyGPS++.h&gt; #include &lt;SoftwareSerial.h&gt; #define GPS_RX_PIN 2 #define GPS_TX_PIN 3 TinyGPSPlus gps; SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN); void setup() { Serial.begin(9600); ss.begin(4800); } char clat[11]; char clng[11]; void loop() { //if (buttons || tilt) { //if (buttons &amp; BUTTON_SELECT) { bool isGpsLocationValid = false; do { while (ss.available()&gt;0) { char c = byte(ss.read()); if (gps.encode(c)) //i previously used if(gps.encode(ss.read())); but no luck then { if (gps.location.isValid()) { dtostrf(gps.location.lat(), 11, 6, clat); dtostrf(gps.location.lng(), 11, 6, clng); //send-print //delay (just in case multiple bumps) isGpsLocationValid = true; } } } } while (isGpsLocationValid == false); Serial.write(clat); Serial.println(); Serial.write(clng); //} //} } </code></pre> <p>EDIT: The newest code i have posted works 100%! So if you have similar problems with that aweful gps, use this!</p> <p>Apparently, TinyGPS and TinyGPS++ don't work well with this gps. To be precice, there is a problem with the gps.encode(c) function.</p> <p>So using <code>if (gps.encode(c))</code> most of the times returns false, except some rare occasions which returns true and then you can do some processing...</p> <p>My last code takes care of that problem by checking continuously, using a do...while loop. If <code>if (gps.location.isValid())</code> returns true, which means i have valid data, then i do the processing i want and end the do...while loop.</p>
<p>Thaks very much!!! You have already given me the solution for my problem, I`ve been trying to get this data for 3 days!! When I was using just the GPS module, it was fine, I could get the data, but when I tried to use GSM module + GPS, I could not get the data from GPS!! U gave me the solution </p> <pre class="lang-c prettyprint-override"><code>bool isGpsLocationValid = false; do { while (ss.available()&gt;0) { char c = byte(ss.read()); if (gps.encode(c)) //i previously used if(gps.encode(ss.read())); but no luck then { if (gps.location.isValid()) { dtostrf(gps.location.lat(), 11, 6, clat); dtostrf(gps.location.lng(), 11, 6, clng); isGpsLocationValid = true; } } } } while (isGpsLocationValid == false); Serial.write(clat); Serial.println(); Serial.write(clng); </code></pre> <p>Congratulations!! Brazilian Hugs for you ; )</p>
2880
|arduino-ide|linux|
Arduino IDE has no shortcut in openSUSE
2014-06-09T01:19:33.493
<p>I just installed the Arduino IDE in openSUSE 13.1. I am able to open the application using the run dialogue, so I know it has installed. However, there is no way to open the IDE from any application launcher. I have tried both the Kickoff and Lancelot applciation managers. I have also tried to uninstall and re-install the IDE, both through the 1-click on the Arduino website as well as through the command line.</p> <p>Does anyone know why I am unable to launch the application from the launcher? Thanks in advanced for any help!</p>
<p>I had the same problem and this seems to work. If you right click on the Kickoff Application launcher and open 'edit applications' with KDE Menu Editor, you can 'add new item' where you want and give it a name (ArduinoIDE) and then just put arduino (small case) in the 'command' box, and shut down KDE Menu Editor, it should appear in the menu where ever you placed it. At least it did for me.</p>
2881
|lcd|wires|
Arduino LCD shows only black boxes
2014-06-08T23:52:20.927
<p>I've hooked up my Arduino on <a href="http://arduino.cc/documents/datasheets/LCD-WH1602B-TMI.pdf" rel="nofollow noreferrer">this</a> LCD, and after running the following code, all I see is a row with black boxes and another one empty.</p> <pre><code>//LiquidCrystal d(RS, E, D4, D5, D6, D7); LiquidCrystal lcd(0, 1, 2, 3, 4, 5); void setup() { lcd.begin(16, 2); lcd.print("hello, world!"); } void loop() { lcd.print("hello, world!"); } </code></pre> <p>Wiring: <img src="https://i.stack.imgur.com/nZumv.jpg" alt="table showing wiring between arduino and lcd"></p> <p>(The UTP cable is used just for the data lines :-)</p> <p>Actual wiring photos: (sorry for the total klutz in the wiring, I had limited solid-core wires so I had to use these scrap ones)</p> <p><img src="https://dl.dropboxusercontent.com/s/t7u0e8jt2640zep/Photo%2008-06-14%2008%2031%2013%20PM.jpg" alt="wiring"> <img src="https://dl.dropboxusercontent.com/s/o9hg6i5drzva1x8/Photo%2008-06-14%2008%2031%2020%20PM.jpg" alt="wiring"> <img src="https://dl.dropboxusercontent.com/s/3ugmxr0ddjcpz4x/Photo%2008-06-14%2008%2031%2031%20PM.jpg" alt="wiring"></p>
<p>The problem was that the R/W pin on the LCD was left floating, after I connected it to GND, I started working :)</p>
2885
|pins|wires|prototype|
Prototyping method
2014-06-09T13:25:37.037
<p>I'm currently using a normal breadbord 'n' solid-core-wires for prototyping, but it gets messy when I need to connect a large number of pins on the arduino, as when using an LCD display + another sensor. What are my other options for prototyping? </p>
<p>One of the Arduino's greatest strengths are shields, and shields upon shields. (Another is it's ease of programming via USB amongst a whole host of others).</p> <p>They are perfect for prototyping. There's nothing wrong with breadboarding it as well, but it's pretty much one or the other (excluding making your own circuit board). </p> <p>I am working on a garage controller and it has three shields on top of the arduino itself.</p> <ol> <li><p>XBee/wireless coms</p></li> <li><p>a relay shield, and</p></li> <li><p>a prototying shield where I have created custom circuitry (buttons, connectors, optocouplers etc). </p></li> </ol> <p>Especially with the top shield, I have made several changes to get it to perform as I'd like. If I'd committed to making a custom board, then I would have had to change it (and re-change it). What I've done would be virtually impossible on a breadboard. </p> <p>The idea is, you use the shields to get your idea up and running, as a proof of concept. Then, you could/can leave it as is, or you could take the next step, break it down to the required components and make a custom PCB for your project. If it wasn't for shields and stacking shields, you would either breadboard it (which as you've indicated can get ugly, cumbersome and problematic), or make a PCB which (depending on the project) might not be a small task. So shield it up, test it out, then build your own based on what you've put together. </p> <p>That's not to say, you have to make your own PCB in the end, many projects can remain a shield on an arduino. So if you can find a shield to do specifically what you're after, then why wouldn't you use it? </p>
2895
|variables|
Assigning formatted value to variable
2014-06-10T01:25:39.407
<p>Look at this snippet of code (from TinyGPS++ library):</p> <pre><code>Serial.print(gps.location.lat(), 6); </code></pre> <p>It prints the latitude location with 6 decimal points. I want, instead of printing that value, to have it assigned to a variable.</p> <p>But i want it assigned just like above, with six decimal points. Is there a way to do this?</p>
<p>I had the same problem and I found answer</p> <pre><code>char latitude[20]; char longitude[20]; dtostrf(gps.location.lat(),8,6,latitude); dtostrf(gps.location.lng(),8,6,longitude); </code></pre>
2896
|arduino-nano|
2 Arduino controller boards - 1 shared input
2014-06-10T08:48:39.097
<p>I'm beginning with electronics and don't have all the good reflexes yet. So here is my question:</p> <p>Can I do what I did here?</p> <p><a href="http://www.movod-design.com/forum_img/canIDoThis.jpg" rel="noreferrer">can i do this http://www.movod-design.com/forum_img/canIDoThis.jpg</a></p> <p>Do I have to add diodes between the Nano +5V and the junction point?</p> <p>My goal is to have one button's state read by 2 Arduino Nano.</p>
<p>I have done something like this to be able to have a redundant system. Is this what you were doing: Two computers receiving the trigger, if one computer failed you have the other running?</p> <p>If that is your case, then there is a problem on this setup:</p> <ul> <li>If one computer shuts down the Arduino on that computer will be powered by the second one and there will be not enough power for both.</li> </ul> <p>I fixed it with a couple of diodes.</p> <p>I still had some problems with false triggering from time to time, with tests on a Mac running OSX. The same tests with a Linux machine give no problem for now.</p> <p>I wanted to make this really stable (next I'll try to use opto-isolators) I'm not a Programer nor a Engineer. Please tell me if I'm saying something stupid or if there is any other easy fix.</p> <p>I was using two Arduino Pro micro Chinese copies and passing the data to midi to the computers - I did not test with real Arduinos to see if it was a board problem.</p>
2899
|led|gsm|
Receiving SMS by Arduino GSM Shield and control the LED with the content of this SMS?
2014-06-10T10:01:39.933
<p>I am using Arduino GSM Shield receiving SMS from an Android app. And the content of this SMS will control a LED. If the content of this SMS is not "off", the LED will be on and the content will be printed in the serial monitor. But if it is "off", the LED will be off immediately. Besides, the LED will keep being on until the "off" message coming. For now, I used the code from the example of the software. But I cannot use the content of this SMS to control the status of LED. With the code below, the LED could not be turned on and the content could not be displayed on the monitor. I think it was because the sketch failed to get the whole content of this SMS. Could anybody tell me how to solve this problem? Thanks.</p> <pre><code>#include &lt;GSM.h&gt; GSM gsmAccess; GSM_SMS sms; char senderNumber[20]; int led=13; void setup() { Serial.begin(9600); pinMode(led,OUTPUT); digitalWrite(led,LOW); while (!Serial) { ; } Serial.println("SMS Messages Receiver"); boolean notConnected = true; while(notConnected) { if(gsmAccess.begin("6442")==GSM_READY) notConnected = false; else { Serial.println("Not connected"); delay(1000); } } Serial.println("GSM initialized"); Serial.println("Waiting for messages"); } void loop() { char c; int val=0; val=digitalRead(led); if (val==HIGH){ digitalWrite(led,HIGH); } if (sms.available()){ Serial.println("Message received from:"); sms.remoteNumber(senderNumber, 20); Serial.println(senderNumber); if(sms.peek()=='#') { Serial.println("Discarded SMS"); sms.flush(); } while(c=sms.read()) if(c='off'){ digitalWrite(led,LOW); }else{ digitalWrite(led,HIGH); Serial.print(c); } Serial.println("\nEND OF MESSAGE"); sms.flush(); Serial.println("MESSAGE DELETED"); } delay(1000); } </code></pre>
<p><code>sms.read()</code> function returns only a single byte of the SMS string. You can store the whole data in a character array and process it later like following:</p> <pre><code>char c, message[140]; int i=0; while (c = sms.read()) { message[i++] = c; } if (strstr (message, "off")) { //If SMS contains off anywhere digitalWrite(led,LOW); } else { digitalWrite(led,HIGH); Serial.print(message); } </code></pre> <p>And I believe the following portion in your code is not required as it is doing nothing:</p> <pre><code>val=digitalRead(led); if (val==HIGH){ digitalWrite(led,HIGH); } </code></pre>
2915
|arduino-uno|serial|arduino-due|arduino-nano|softwareserial|
Wired serial connection between two Arduinos - do they need a common Ground (GND)?
2014-06-11T23:09:18.197
<p>I would like to connect two Arduinos by a serial connection. Is it sufficient to connect TX1&lt;-->RX2 and RX1&lt;-->TX2 or do I also need to connect the GND of the two Arduinos?</p>
<p>Short answer: Yes.</p> <p>Rx/Tx is referenced with a logic ground. Without ground being common, there is no way to determine what is high or low.</p> <p>(Sorry I don't have a more technical explanation)</p> <p>Edit: I thought I would add, if you are using the same power source, then they probably have a common ground. In this case, a common power source doesn't mean the wall side of a wall adapter, but the SAME wall adapter. </p>
2921
|arduino-uno|sensors|interrupt|
Reading the rpm of multiple fans
2014-06-12T17:22:40.060
<p>I am trying to build a fan controller for my pc, the problem is that the example code(<a href="http://playground.arduino.cc/Main/ReadingRPM" rel="nofollow">http://playground.arduino.cc/Main/ReadingRPM</a>) im using utilizes interrupts. On my uno I can then only read the rpm of one fan. I want to also control the rpm (via pwm) and monitor temperatures (via thermistors) Anyone know how I coud do it differently? I. E. Without interrupts. I would also like it to be as close to real time as possible</p>
<p>If you only want 2 fans, the uno has 2 external interrupts, so you can use the same strategy as your example, just make another interrupt function for fan 2 and attach it on interrupt 1 instead of 0. the fan should be plugged in to pin 3 in this case. On a leonardo, you could have 5 fans on interrupts, and a mega has 6 external interrupts. See <a href="http://arduino.cc/en/Reference/attachInterrupt" rel="nofollow">http://arduino.cc/en/Reference/attachInterrupt</a></p> <p>If you need more than what your hardware can support, I would look into using a timed interrupt to check all the fans. If you find the minimum amount of time in-between reads to read your fans at max RPM and then use a timer interrupt to check some pins at that interval, you can probably read as many as you need, provided the interrupt routine stays fast enough. the function </p> <pre><code>attachInterrupt(function, period); </code></pre> <p>from the libraries on this page : <a href="http://playground.arduino.cc/Code/Timer1" rel="nofollow">http://playground.arduino.cc/Code/Timer1</a> should help you out with this.</p>
2922
|serial|arduino-pro-mini|reset|
Watchdog timer stuck in restart loop? (green led flashing)
2014-06-12T19:55:13.287
<p>I am trying to set up a way to reboot arduino on command. The code below should do that but it seems like my arduino just get's stuck in some sort of a loop where I cant upload or get any serial output. The green led (pin 13) flashes very fast. The only way to stop this is to cut power to the device, even reset button does not work. This happens only when "R" is received via serial or if wdt_reset() function is commented out.</p> <pre><code>#include &lt;avr/io.h&gt; #include &lt;avr/wdt.h&gt; int ledPin = 3; void setup() { MCUSR=0; wdt_disable(); Serial.begin(57600); Serial.println("BOOT!"); pinMode(ledPin, OUTPUT); digitalWrite(ledPin, LOW); delay(500); } void loop(){ if (Serial.available() &gt; 0){ char cmd = Serial.read(); if (cmd == 'R'){ Serial.println("R received!"); wdt_enable(WDTO_1S); delay(2000); Serial.println("1 SEC."); } } wdt_reset(); digitalWrite(ledPin, HIGH); } </code></pre> <p>What am I doing wrong?</p>
<p>Remove watchdogs flag at init is one solution. I am using optiboot 8.0 and it works perfect.</p> <pre><code>// Function Pototype void wdt_init(void) __attribute__ ((naked, used, section(".init3"))); // Function Implementation void wdt_init(void) { MCUSR = 0; wdt_disable(); return; } </code></pre>
2931
|arduino-uno|atmega328|bootloader|
How does RXD/TXD request signal look betwen 16u2 and 328p on oscilloscope?
2014-06-13T22:24:39.383
<p>I have a broken Arduino Uno. The man tells that he connected power supply and USB at the same time. </p> <p>I got the new 16u2 (empty) chip. then asked my friend to re-solder it. He was using an air soldering station, but that did not work out. Then I try do that by myself. After 6 or 8 time I was successful. I think.</p> <p>With stk500v2 programmer thru ICSP I burned in the hardware called:</p> <pre><code>Arduino-COMBINED-dfu-usbserial-atmega16u2-Uno-Rev3.hex </code></pre> <p>which I found in Arduino "hardware" folder.</p> <p>I then burned bootloader to 328p controller:</p> <pre><code>optiboot_atmega328.hex </code></pre> <p>That hardware also from Arduino folder.</p> <p>The problem is that I can upload sketch</p> <pre><code>error: avrdude: stk500_getsync(): not in sync: resp=0x00 </code></pre> <p>meaning that device not recognizing.</p> <p>My PC founds Arduino in device manager. 328p with ICSP programmable and working. (checked with blinking.hex 13 pin)</p> <p>When pressing reset button the 13 led turns of then blinks fast several times that means the boot loader installed property.</p> <p>Right after pressing upload the Rx blinks 3 times after that I am getting error.</p> <p>Strange isn't it? </p> <p>So what I what to know:</p> <ul> <li><p>I suppose the first must start blinking Tx led?</p></li> <li><p>Can anyone show me how must look like rxd txd interrupts?</p></li> <li><p>So about my assumption that I overheated 16u2 and it does strange things. What are you thinking about that?</p></li> </ul>
<p>See screenshot below. The Rx on the Uno (incoming data) should flash first. </p> <p><a href="https://i.stack.imgur.com/7tqmH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7tqmH.png" alt="Uno boot sequence"></a></p> <p>The programmer sends <code>STK_GET_SYNC</code> and the board replies <code>STK_INSYNC</code>:</p> <pre><code>Sent: STK_GET_SYNC / CRC_EOP (30/20) Got: STK_INSYNC / STK_OK (14/10) </code></pre> <p>Afterwards you see the bigger blocks on the lower line as the programmer sends the hex code to the board. Then about half-way through the bigger blocks are on the top as the board sends back the verification data (by reading the flash back).</p> <p>The little blips would be the other side acknowledging a packet of data.</p> <hr> <p>For more details see <a href="https://arduino.stackexchange.com/questions/15936/what-happens-when-code-is-uploaded-using-the-bootloader">What happens when code is uploaded using the bootloader?</a></p>
2932
|xbee|voltage-level|attiny|
Operating / pin voltages ATTiny chips
2014-06-14T10:32:30.563
<p>I would like to set up a project with an ATtiny chip, such as the ATtiny84 or ATtiny85, in which I interface the microcontroller directly with an XBee for both wireless serial communication, as well as monitoring a digital signal from the Xbee (digital input to the ATtiny). As the Xbee chips can handle only 3.3V and will be damaged at higher voltages (such as 5V), I was wondering whether I can simply power the entire project at 3.3V so that all digital inputs and outputs will be at that voltage?</p>
<p>Yes. As given in the <a href="http://www.atmel.com/devices/ATTINY85.aspx" rel="nofollow">datasheets</a>, normal ATtinyX4/X5 chips can run with a supply between 2.7 and 5.5V inclusive, whereas the low-power versions can run between 1.8V and 5.5V. Mind the speed restrictions when running at lower voltages though; see the "Electrical Characteristics" section of each datasheet to determine the maximum characterized speed for a given voltage.</p>
2939
|arduino-uno|led|pwm|
Arduino PWM fading led
2014-06-15T10:38:36.537
<p>I am trying to blink an LED with PWM on Arduino. </p> <p>I don't know what is wrong but my LED is not fading as expected. What is wrong? </p> <p>I think that I have bad registers settings, but I am not sure.</p> <p>LED is connected to Arduino pin 9.</p> <p>Here is my code:</p> <pre><code>#include &lt;avr/io.h&gt; #include &lt;util/delay.h&gt; const int delay=1000; void initialize_PWM() { TCCR0A|=(1&lt;&lt;WGM00)|(1&lt;&lt;WGM01)|(1&lt;&lt;COM0A1); TCCR0B=1; DDRB|=(1&lt;&lt;PB1); } void set_pwm(uint8_t data) { OCR0A=data; } int main (void) { initialize_PWM(); uint8_t brightness=200; while(1) { for(brightness=0;brightness&lt;255;brightness++) { set_pwm(brightness); _delay_ms(1); } for(brightness=255;brightness&gt;0;brightness--) { set_pwm(brightness); _delay_ms(1); } } return 0; } </code></pre>
<p>The easiest way is to use the timer1 library written for arduino. You can download it <a href="http://code.google.com/p/arduino-timerone/downloads/list" rel="nofollow">here</a>. </p> <p>To install, simply unzip and put the files in Arduino/hardware/libraries/Timer1/</p> <hr> <p>Prescaler set for 16Mhz</p> <pre><code>Prescale Time per counter tick Max Period 1 0.0625 uS 8.192 mS 8 0.5 uS 65.536 mS 64 4 uS 524.288 mS 256 16 uS 2097.152 mS 1024 64uS 8388.608mS </code></pre> <p>In general:</p> <p>Max Period = (Prescale)<em>(1/Frequency)</em>(2^17) Time per Tick = (Prescale)*(1/Frequency)</p> <hr> <p>Instructions available using this library are:</p> <p>initialize(period) You must call this method first to use any of the other methods. You can optionally specify the timer's period here (in microseconds), by default it is set at 1 second. Note that this breaks analogWrite() for digital pins 9 and 10 on Arduino.</p> <p>setPeriod(period) Sets the period in microseconds. The minimum period or highest frequency this library supports is 1 microsecond or 1 MHz. The maximum period is 8388480 microseconds or about 8.3 seconds. Note that setting the period will change the attached interrupt and both pwm outputs' frequencies and duty cycles simultaneously.</p> <p>pwm(pin, duty, period) Generates a PWM waveform on the specified pin. Output pins for Timer1 are PORTB pins 1 and 2, so you have to choose between these two, anything else is ignored. On Arduino, these are digital pins 9 and 10, so those aliases also work. Output pins for Timer3 are from PORTE and correspond to 2,3 &amp; 5 on the Arduino Mega. The duty cycle is specified as a 10 bit value, so anything between 0 and 1023. Note that you can optionally set the period with this function if you include a value in microseconds as the last parameter when you call it.</p> <p>attachInterrupt(function, period) Calls a function at the specified interval in microseconds. Be careful about trying to execute too complicated of an interrupt at too high of a frequency, or the CPU may never enter the main loop and your program will 'lock up'. Note that you can optionally set the period with this function if you include a value in microseconds as the last parameter when you call it.</p> <p>setPwmDuty(pin, duty) A fast shortcut for setting the pwm duty for a given pin if you have already set it up by calling pwm() earlier. This avoids the overhead of enabling pwm mode for the pin, setting the data direction register, checking for optional period adjustments etc. that are mandatory when you call pwm().</p> <p>detachInterrupt() Disables the attached interrupt.</p> <p>disablePwm(pin) Turns PWM off for the specified pin so you can use that pin for something else.</p> <p>read() Reads the time since last rollover in microseconds.</p> <hr> <p>Example - Sets up PWM output on pin 9 with a 50% duty cycle, and attaches an interrupt that toggles digital pin 10 every half second.</p> <pre><code>/* * Timer1 library example * June 2008 | jesse dot tane at gmail dot com */ #include "TimerOne.h" void setup() { pinMode(10, OUTPUT); Timer1.initialize(500000); // initialize timer1, and set a 1/2 second period Timer1.pwm(9, 512); // setup pwm on pin 9, 50% duty cycle Timer1.attachInterrupt(callback); // attaches callback() as a timer overflow interrupt } void callback() { digitalWrite(10, digitalRead(10) ^ 1); } void loop() { // your program here... } </code></pre> <p>Source: <a href="http://playground.arduino.cc/Code/Timer1" rel="nofollow">http://playground.arduino.cc/Code/Timer1</a></p>
2940
|arduino-uno|serial|
Is it possible to press a button from Arduino and my computer will get a key event?
2014-06-15T11:23:22.690
<p>My idea seems easy: </p> <p>I connect a button with arduino, then write some code and upload it to arduino. Then I open the notepad(or any other editor) on my computer. When I press the button, there will be a character "A" displayed in the notepad.</p> <p>I have tried with my Arduino uno, and use <code>Serial.write/print</code> function to send an <code>A</code> to serial port <code>9600</code>, but it seems the character <code>A</code> only shows in the serial monitor GUI.</p> <p>My question is:</p> <ol> <li>Is "Arduino uno" is OK to implement this?</li> <li>If not, what other board should I use?</li> <li>Is <code>Serial.write/print</code> the correct function?</li> <li>Or shall I use the <code>Keyboard.???</code> function?</li> <li>Do I have to write an application which runs on the computer and listens the serial port, and emit a real key event? (that's sad)</li> </ol>
<p>Check this video, <a href="https://www.youtube.com/watch?v=RoG_-9lAnSI" rel="nofollow">Arduino UNO as a USB keyboard (HID device) [Anything Arduino] (ep 6)</a>, as I think this is what you are looking for.</p> <p>From the youtube video you can get links to the library site and schematics.</p> <p>You do need to build a small interface to connect your Arduino to a PC. I got it for Uno and Micro, but other Arduinos with latest firmware would be OK.</p>
2946
|arduino-uno|nrf24l01+|
nRF24L01 pipe question
2014-06-15T18:25:51.253
<p>I am looking through the example code found <a href="https://github.com/maniacbug/RF24/blob/master/examples/GettingStarted/GettingStarted.pde" rel="nofollow noreferrer">here</a>. I know there are 6 pipes that the nRF24L01 module can use but I've been searching the internet for the address designations and have been able to find nothing. More specifically on line 37, is there a reference for where the author is getting 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL?</p> <p>Thanks.</p>
<p>There's something that everyone forgets to tell you:</p> <p>Pipes at <strong>receiver</strong> should be shortened after the first one</p> <pre><code>const uint64_t pipe01 = 0xE8E8F0F0A1LL; const uint64_t pipe02 = 0xA2LL; const uint64_t pipe03 = 0xA3LL; const uint64_t pipe04 = 0xA4LL; const uint64_t pipe05 = 0xA5LL; const uint64_t pipe06 = 0xA6LL; radio.openReadingPipe(1, pipe01); radio.openReadingPipe(2, pipe02); radio.openReadingPipe(3, pipe03); radio.openReadingPipe(4, pipe04); radio.openReadingPipe(5, pipe05); </code></pre> <p>Pipes at <strong>transmitter</strong> should be</p> <pre><code>const uint64_t pipe01 = 0xE8E8F0F0A1LL; const uint64_t pipe02 = 0xE8E8F0F0A2LL; const uint64_t pipe03 = 0xE8E8F0F0A3LL; const uint64_t pipe04 = 0xE8E8F0F0A4LL; const uint64_t pipe05 = 0xE8E8F0F0A5LL; const uint64_t pipe06 = 0xE8E8F0F0A6LL; uint64_t setPipeToSend = pipe01; // or pipe02 or pipe03 or pipe04 or pipe05 radio.openWritingPipe(setPipeToSend ); </code></pre> <p>If you want to know which pipe's message has come, use </p> <pre><code> uint8_t someVariable; if (radio.available(&amp;someVariable)) { Serial.print("pipe number "); Serial.printLn(someVariable); } </code></pre> <p>Also <strong>pipe number 6</strong> is used for receiving <strong>acknowledge</strong> messages. </p> <p>In addition, the initialization code must have <code>radio.enableDynamicPayloads();</code> This one works well for me:</p> <pre><code> radio.begin(); //radio.setChannel(0x57); //if set should be the same at the both sides radio.setPALevel(RF24_PA_LOW); // "LOW" is more stable mode radio.enableAckPayload(); //for autoanswers radio.openWritingPipe(pipe01); //for sending //link pipe numbers to the pipe addresses //radio.openReadingPipe(1, pipe01); // I use pipe01 for sending radio.openReadingPipe(2, pipe02); radio.openReadingPipe(3, pipe03); radio.openReadingPipe(4, pipe04); radio.openReadingPipe(5, pipe05); radio.enableDynamicPayloads(); //must have for multi pipe receiving radio.startListening(); //start listening </code></pre> <p>Good luck...</p>
2963
|serial|arduino-due|
SerialEvent handling when using multiple serial ports
2014-06-16T21:16:06.667
<p>I would like to use multiple (three) serial ports on an Arduino Due. Instead of polling the ports continuously, I would like to use a Serial.Event function for each of the ports. These handler functions will read out the incoming string from the port and parse the string (i.e. check for a pre-defined command and call a corresponding sub-routine). </p> <p>I was wondering what is going to happen when serial data arrives at the same time at two different ports? For example, if the program is in the process of handling/parsing the first serial message, will it interrupt/abandon this process as soon as another SerialEvent on another port is triggered? Or will it complete the first SerialEvent routine before going to the second one?</p>
<p>That should be fairly simple to implement.</p> <p>Each serial port has TX and RX interrupts. You just need to tie into the various interrupts.</p> <p><a href="http://mbed.org/cookbook/Serial-Interrupts" rel="nofollow">Here is an example</a> for a mbed, but it should be similar (both use ARM NVIC interrupt controllers).</p> <p>To be clear, this wouldn't involve touching the <code>serialEvent()</code> function stuff at all, but rather implementing what it does using your own code.</p> <hr> <p>If you set up your own interrupt handlers, you also get the benefit of being able to control interrupt priority yourself. The ATSAM3X has 16 interrupt priority levels, and a interrupt of a higher priority can pre-empt a lower-level interrupt.</p> <p>I Strongly suggest you read the <a href="http://www.atmel.com/Images/doc11057.pdf" rel="nofollow">ATSAM3X datasheet</a>. It describes the interrupt controller, as well as the rest of the processor peripherals.</p>
2969
|spi|
Can the SPI pins of an Arduino be separated from SPI?
2014-06-17T09:26:21.223
<p>Are the SPI pins on the ICSP header of an Arduino Uno "separable" from the correspondent I/O pins - when one chooses to the use the ICSP header can the corresponding I/O pins be used for something else?</p>
<p>Actually, it can. You just can not use them at the same time. One needs to be careful to wire it in ways not to comprise the shared functions. Where MISO can be used as GPIO-INPUT and MOSI/SCK can be used as GPIO-OUTPUT, avoiding any pull up/downs, etc... As such electrical items may interfere with the ICSP.</p> <p>For example I use the ICSP programming, along with the MISO, MOSI and SCLK pins as hard SPI and use them as Bit Bang one-wire, all on the same board and same wires. I simply ensure the SPI is properly configured each at each use.</p> <p>One additionally needs to ensure that any peripherals on the shared SPI/ICSP lines are guaranteed to be in reset. Such as a pull down on such devices reset pins. Or a Pull Up on their ChipSelects. Noting that ATmega's GPIO pins are Hi-Z out of reset and during the ICSP. </p>
2972
|arduino-uno|sensors|
SRF04 Ultrasonic sensor - inaccurate readings
2014-06-17T16:26:03.833
<p>I have an Arduino Uno linked up to an SRF04 ultrasonic sensor. I'm using the library from here: <a href="https://code.google.com/p/srf04-library/" rel="nofollow">https://code.google.com/p/srf04-library/</a></p> <p>I'm then using the basic script "Centimeter" that comes in the examples. This gives me a reading, but it seems to be ~20-25% inaccurate. When it reads 100cm, the distance is actually nearer 80cm. </p> <p>I've replaced the SRF04 with another, and the same issue occurs. Additionally, it seems when it reads out of range (or even on surfaces that give an uneven "bounce"), I get very random figures (e.g. -5cm). </p> <p>Has anyone experienced something similar? </p>
<p>This saved my project:</p> <p><a href="https://create.arduino.cc/projecthub/panagorko/next-level-ultrasonic-sensor-a67478?f" rel="nofollow noreferrer">https://create.arduino.cc/projecthub/panagorko/next-level-ultrasonic-sensor-a67478?f</a></p> <p>Please spread the word, I almost gave up. This gem seems widely unknown, I spent two full days in vain trying to improve my ultrasonic sensor's accuracy.</p>
2980
|analogwrite|
Direct 5V current based on analog signal
2014-06-18T00:42:13.930
<p>I would like to manage many LEDs from my Arduino - 12 or so - but I do not have the available digital pins to do this. Only one LED needs to be on at one time. Instead, I was hoping to control these with an analog pin. I was wondering if there is some sort of switch out there which can take an analog signal and, based on the value, direct a 5V current to a certain LED.</p> <p>I realize that I could use a second Arduino for this, but I am trying to avoid that.</p> <p>Thanks in advance for any help!</p>
<p>You can use some of the analog pins to clock a shift register by defining them as a digital output. Also two of the analog pins are also defined as I2C depending on your code. You could use 2 PCF8574s or an PCF8575 expansion board and control it that way. They can be used as inputs and outputs any order you want. There are a lot of other chips you can use to do this. The reason I am suggesting this approach is later you will probably want to expand into other peripherals such as LCDs etc.</p>
2984
|arduino-uno|wires|
splitable jumper wires question
2014-06-18T04:37:16.840
<p>I just received my starter kit from oddwires.com today and it came with a split-able ribbon cable for prototyping. I was curious if it is possible to split each wire off and use only what I need to for the tutorials or is that a bad idea? I am very excited to start playing around and learning this as it has been a interest of mine for many years.</p>
<p>Each wire in the Dupont ribbon cable is is independent, and does not hold onto its neighbors with any real force. You can split them or join multiple wires together using larger connectors as desired.</p>
2991
|programming|serial|
No usb serial on Mac
2014-06-18T20:03:39.383
<p>I've been using my Arduino UNO without a hith for a few days now, but suddenly I can't program it anymore.</p> <p>When I try to programm my Arduino on Mac, I get the following Error:</p> <pre><code>avrdude: stk500_recv(): programmer is not responding </code></pre> <p>The USB option under serial port has disappeard (It was there before). Has anyone an idea on how to fix this?</p> <p>The last thing I did is use the serial port for some communication. A reboot hasn't improved anything.</p> <p>I tried programming Linux, but it resulted in the exact same result.</p>
<p>It seemed to be a hardware problem on the board. Thanks for the effort.</p>
2994
|arduino-uno|pins|wires|display|electronics|
7 Segment Display SET UP
2014-06-18T20:47:02.200
<p>I am new to Arduino. I have been trying to connect a 7 segment display (3 digits) to my Arduino and I was successful, but I am not doing any connection to ground. I do not find the data sheet so I am not sure if this connection is well done. My doubt is: Is the connection to ground necessary? Or how do Arduino pins work? I am using 12 pins of the Uno to do the set up.</p> <p>Thanks</p> <p>My set up is the following: <img src="https://i.stack.imgur.com/ADNED.jpg" alt="enter image description here"></p>
<p>I don't know exactly how your display is wired exactly, but it is certain that some sort of multiplexing is going on, since A: there is no wired ground, and B, you are controlling more LED's than you have pins going to the display. </p> <p>Multiplexing manages this by using some trickery and persistence of vision. The pins for each part of the segment are all wired together. For example, the top segment on each of the three segments are all connected to one arduino pin. The common anode/cathode (depending on your specific display) for each of your three displays are wired separately however. Turning only one of the common pins on will cause only one display to function when the other pins set which segments are on. The micro controller then changes which common is active and what segments are on to illuminate the next character very quickly. It pulses between segments so quickly you cannot tell they are only on one third of the time each. </p> <p>The wiring inside the display will likely look similar to this: <a href="http://www.modd3d.com/articles/wp-content/uploads/normal-multiplexing-s.gif" rel="nofollow">http://www.modd3d.com/articles/wp-content/uploads/normal-multiplexing-s.gif</a></p>
3008
|led|
Confusion around LEDs on a breadboard
2014-06-20T00:57:02.117
<p>I am just starting out with an Arduino Diecimila and am playing around with LEDs, and am confused by why some circuits result in an LED not lighting up. </p> <p>Successful Scenarios:</p> <ol> <li><p>Yellow LED from pin13 to 16B on the breadboard, Green LED from 16A to GND. This works both LEDS light up.</p></li> <li><p>Yellow LED from pin13 to 16A on the breadboard. Wire from 16E to 14E. Green LED from 14A to GND. This works and both LEDs light up.</p></li> </ol> <p>Failed Scenarios: </p> <ol> <li><p>Yellow LED from pin13 to 16A. Green LED from 16E to 14E. Yellow LED from 14A to GND. No LEDs light up. I would assume that all the LEDS are in series, and all 3 should light up, I assumed this would be exactly the same as my second successful scenario where the LED is acting the same as the wire.</p></li> <li><p>Yellow LED from pin13 to 16A. Wire from 16E to 14E. Yellow LED from 15A to GND. Green LED from 16B to 14B. Here I have both Yellow LEDS lit, but the Green LED is not lit. I was expecting that the Green LED would have been in parallel and should have lit up.</p></li> </ol> <p>In both failed scenarios I have swapped around the LEDs and proved that all the LEDs function.</p> <p>There must be some basic concept that I am not understanding with the circuits, any ideas?</p>
<p>Scenario 1 fails because yellow and green LEDs have forward voltages of about 2V each, so when putting 3 in series, you need a forward voltage to light them that exceeds the 5V available.</p> <p>Scenario 2 fails because the wire you have in parallel with the LED provides a path with a very low voltage drop (close to 0V), so the path through the LED with a ~2V voltage drop is not taken (and if you remove the wire, the same reasoning as in scenario 1 applies, so nothing would work).</p> <p>BTW, you should never run LEDs without a series resistor, as your experiments will surely demonstrate to you soon ;-)</p>
3010
|serial|terminal|
Serial.write() prints a variable twice
2014-06-20T11:56:01.807
<p>I have this code:</p> <pre><code>#include &lt;TinyGPS++.h&gt; #include &lt;SoftwareSerial.h&gt; #define GPS_RX_PIN 2 #define GPS_TX_PIN 3 TinyGPSPlus gps; SoftwareSerial ss(GPS_RX_PIN, GPS_TX_PIN); void setup() { Serial.begin(9600); ss.begin(4800); } char clat[11]; char clng[11]; void loop() { bool isGpsLocationValid = false; do { while (ss.available()&gt;0) { char c = byte(ss.read()); if (gps.encode(c)) { if (gps.location.isValid()) { dtostrf(gps.location.lat(), 11, 6, clat); dtostrf(gps.location.lng(), 11, 6, clng); isGpsLocationValid = true; } } } } while (isGpsLocationValid == false); Serial.write(clat); Serial.println(); Serial.write(clng); } </code></pre> <p>Now when all is done, the clng value is printed twice in the serial monitor. The value i get is in this format:</p> <pre><code>27.275869 15.151013 15.151013 </code></pre> <p>As you can see, clng is printed twice. Any ideas why is that?</p>
<p>The width parameter to <code>dtostrf()</code> is the width of the resulting string NOT including the null terminator. So you are overflowing the array.</p> <p>Change:</p> <pre><code>char clat[11]; char clng[11]; </code></pre> <p>to</p> <pre><code>char clat[12]; char clng[12]; </code></pre> <p>and it should work.</p>
3016
|ethernet|
Arduino Ethernet Shield: May I connect it to a PC connected to the internet via wifi?
2014-06-21T02:16:48.240
<p>I have an Arduino Ethernet shield. </p> <p>May I <strong>connect it to a machine that´s connected wirelessly to the internet</strong> in order to get the arduino into the internet? </p> <p>Or do I need to connect it <strong>only</strong> to a router?</p>
<p>Assuming an Ethernet port on the PC, the Ethernet shield can be connected to it using an <a href="http://en.wikipedia.org/wiki/Ethernet_crossover_cable" rel="nofollow noreferrer">Ethernet <strong>crossover</strong> cable</a>:</p> <p><img src="https://i.stack.imgur.com/xbJ3g.png" alt="enter image description here"> (<em>source: <a href="http://en.wikipedia.org/wiki/File:Ethernet_MDI_crossover.svg" rel="nofollow noreferrer">Wikipedia</a></em>)</p> <p>Many recent PC network interfaces have automatic cross-over (<a href="http://en.wikipedia.org/wiki/Medium_Dependent_Interface#Auto_MDI-X" rel="nofollow noreferrer">Auto MDI-X</a>), with which even a regular (straight) Ethernet patch cable will work. </p> <p>This merely addresses the <strong>physical Ethernet connectivity</strong>. </p> <p>For <strong>actually routing IP packets</strong> between the Arduino and the rest of the Internet, some software router or software bridge is required to run on the PC. Several open source routing products exist, especially for Linux and FreeBSD, but that is outside the scope of this StackExchange.</p> <p>Finally, the Ethernet shield does not need a router, it an as well be hooked up to an Ethernet <strong>switch</strong> or <strong>hub</strong>. </p>
3020
|arduino-uno|relay|
Arduino Uno rev 3 toggling a 230 V submersible pump on intervals
2014-06-21T13:10:52.310
<p>I am software programmer and hobby farmer. While I was working on a <a href="http://en.wikipedia.org/wiki/Hydroponics" rel="nofollow noreferrer">hydroponic</a> farming stuff, I had to use submersible pumps with timers. I don't want to buy timers that are actually a tedious scheduling process. so I am making one myself.</p> <p>I want to toggle 230&nbsp;V for turning a submersible pump(150-230&nbsp;V and 18&nbsp;W) ON/OFF. I read that Arduino may not able to supply enough input current that the relay requires. I am not sure about what transistor to use to amplify the input current. I came across a circuit diagram and a relay board. Do I still need to use a transistor and diode if I use this relay with an Arduino?</p> <p>This is the <a href="http://www.ebay.in/itm/5V-2-Channel-Relay-Board-Module-10A-250AC-Opto-coupler-Arduino-Raspberry-Shield-/321432317541?pt=LH_DefaultDomain_203&amp;hash=item4ad6dbee65" rel="nofollow noreferrer">two-channel relay</a> I am about to use and the circuit is below.</p> <p><img src="https://i.stack.imgur.com/8Fvat.jpg" alt="Circuit to use relay with Arduino"></p> <p>Should I follow the circuit if I am using this relay? The relay has a tolerance of 250&nbsp;V. What if the voltage fluctuates above 250&nbsp;V? I am going to use a 9&nbsp;V battery to power the Arduino. Feel free to explain anything that I may have to know.</p> <p><strong>UPDATE</strong></p> <p>Thanks marla for making it clear that I don't need diodes and transistors. Andy, as you said, I can't keep changing batteries often, and it will limit the system. Shall I use an adapter which reads output 5&nbsp;V and 1&nbsp;amperes? Will that drive the Arduino and be sufficient for both the relays?</p>
<p>The Arduino will easily drive this relay board, and it needs only a very small input current.</p> <p>The board you linked to has a built-in optical isolation circuit, so there is no direct electrical connection between the Arduino-side of the circuit and the relay side. This <em>should</em> protect your Arduino if something goes wrong. For what it's worth, the product description specifies this board is suitable for "AC [...] appliances such as [...] motors". A pump is primarily a motor.</p> <p>The voltage may fluctuate when the pump is started and stopped (<a href="https://en.wikipedia.org/wiki/Counter-electromotive_force" rel="nofollow">Back-EMF</a>). It's hard to say what this might do to the relay board if it goes way over specification. Perhaps you might be happier with a much more robust <a href="http://en.wikipedia.org/wiki/Solid-state_relay" rel="nofollow">solid-state relay</a> (SSR) that has a higher rating than the target load. Something like <em><a href="http://www.dx.com/p/ssr-25da-25a-solid-state-relay-white-134494" rel="nofollow">SSR-25DA 25A Solid State Relay - White</a></em>. Since solid-state relays are non-mechanical, they will not wear-out from repeated switching either.</p> <p>You may also want to build some fail-safe sensors into your project. For example, water level float switches for both high-water and low-water marks.</p>
3023
|programming|string|
Concatenation of non constant character array with a string
2014-06-21T18:16:38.353
<p>I have an Arduino Duemilanove.</p> <p>I read <a href="http://arduino.cc/en/Tutorial/StringAdditionOperator" rel="nofollow noreferrer">this page</a> on string concatenation. Yet, it didn't include my case.</p> <p>I have a non constant character array, that later gets a value.</p> <pre><code>char clat[11]; dtostrf(gps.location.lat(), 11, 6, clat); </code></pre> <p>I want to output this:</p> <pre><code>Latitude: 20.653425 </code></pre> <p>So basically I want a final string that contains: "Latitude:" + the value of the nonconstant array.</p> <p>Is it possible?</p>
<pre><code>char clat[10+11+1] = "Latitude: "; dtostrf(gps.location.lat(), 11, 6, clat+10); </code></pre> <p>Since you've named the buffer 'clat' I'm assuming it will always be used for latitude, so we've pre-initialized its size and contents, and we know where to begin the latitude value.</p> <p>By the way, don't forget to size string buffers one more byte than the length of the maximum length string you intend to put in it.</p> <p>Update 6/23/14:</p> <p>From your other question and your comment to this answer, I'll revise my suggestion to this. The ..printf() functions are particularly easy to use, saves you (mis)counting buffer positions, and don't add much lot more code than the Serial() object already includes:</p> <pre><code>char outbuf[40+1]; // wider than nec, easier than counting char clat[15+1]; clong[15+1]; // workspaces sprintf(outbuf, "Latitude/Longitude: %s %s", dtostrf(gps.location.lat(), 10, 6, temp), dtostrf(gps.location.lng(), 10, 6, temp) ); </code></pre> <p>This works because dtostrf() returns the address of the buffer you gave it; sprintf then takes that string (two of them in this case) when building your final output string.</p> <p>The printf() functions are often deprecated for embedded systems. They're large (but see my comment about that above); and they're non-reentrant, so don't do that! In these low-end systems we don't often multi-thread anyway - just be aware of that if you do. And even if you have to remove them later and go back to printing piece by piece, they can save you a lot of headaches during development.</p> <p>Here's another way that avoids both printf and the 32 bytes of work buffers:</p> <pre><code>char outbuf[40+1]; strcpy(outbuf, "Latitude/Longitude: "); dtostrf(gps.location.lat(), 12, 6, outbuf+strlen(outbuf)); dtostrf(gps.location.lng(), 12, 6, outbuf+strlen(outbuf)); </code></pre> <p>We can't initialize outbuf unless it is 1) static, and 2) not going to be used more than once, since its initial conditions won't be the same the second time around. I've increased the field-widths of dostrf() to be sure the outputs of the won't be run-together for large values.</p>
3029
|programming|string|
appending string to char and vice versa
2014-06-22T17:47:37.207
<p>Some days ago i started a thread. <a href="https://arduino.stackexchange.com/questions/3023/concatenation-of-non-constant-character-array-with-a-sting">concatenation of non constant character array with a sting</a></p> <p>I have a different question but on the same nature (string and chars)</p> <p>what i want is one variable (string or char) that will hold a standard text and the value of gps coordinates latitude and longitude</p> <p>The format is this: "latitude/longitude: 30.111111 20.111111"</p> <p>What i have is a char that holds the standard text and the latitude: "Latitude/Longitude: 30.111111"</p> <p>I also have another char that holds the second value (longitude)</p> <p>The chars were generated with dtostrf():</p> <pre><code>char clat[10 + 20 + 1] = "Latitude/Longitude: "; char clng[10 + 1]; dtostrf(gps.location.lat(), 10, 6, clat+20); dtostrf(gps.location.lng(), 10, 6, clng); </code></pre> <p>I can also make the chars strings:</p> <pre><code>string1 = String(clat); </code></pre> <p>What have i tried: 1.Assigning clng to clat directly via dtostrf()</p> <pre><code>char clat[10 + 20 + 10 + 1] = "Latitude/Longitude: "; dtostrf(gps.location.lng(), 10, 6, clng+31); </code></pre> <p>It didnt work and got unexpected output</p> <ol> <li><p>making clat a string and assign clng via for loop</p> <p>string1 = String(clat); for (int i=0; i&lt;10; i++) string1[i+32]=clng[i];</p></li> </ol> <p>This doesnt append it</p> <p>I run out of ideas here. Any help from more experienced guys?</p>
<p>One thing I noticed is you do not need the <code>+</code> in:</p> <pre><code>char clat[10 + 20 + 1] = "Latitude/Longitude: "; </code></pre> <p>You can just do this:</p> <pre><code>char clat[31] = "Latitude/Longitude: "; </code></pre> <p><strong>A much simpler way to do this is this:</strong></p> <p>Variables to initialize:</p> <pre><code>char subfinal[40] = "Latitude/Longitude: "; String final = ""; //You don't need this, you could always use `String(subfinal)` instead </code></pre> <p>The code inside a function:</p> <pre><code>dtostrf(gps.location.lat(), 10, 6, subfinal+10); subfinal[29] = " "; dtostrf(gps.location.lng(), 10, 6, subfinal+30); final = String(subfinal); </code></pre> <p>I haven't tested it, so let me know if it doesn't work.</p>
3035
|led|
Issues with a basic circuit
2014-06-22T21:46:59.360
<p>I am having some issues with a simple circuit. I would expect this circuit to light up this LED constantly when the Arduino is plugged in. I have the <a href="http://arduino.cc/en/Tutorial/Blink" rel="nofollow">Blink</a> tutorial sketch loaded, but I don't think that should matter with the pins I am using.</p> <p>This is what I think I have going on: Arduino 5V Power --> BB power --> 100 Ohm resistor --> BB line 25 --> <a href="https://www.sparkfun.com/products/11121" rel="nofollow">this LED</a> --> BB line 30 --> BB Ground --> Arduino Ground</p> <p>Please check out this picture for confirmation:</p> <p><a href="https://www.flickr.com/photos/89742360@N03/14482775884" rel="nofollow" title="Arduino Question by nrbergeron, on Flickr"><img src="https://farm6.staticflickr.com/5478/14482775884_81a101e1b7.jpg" alt="Arduino Question"></a></p> <p>Thanks in advance for any help that you can provide!</p>
<p>Figured it out - stupid mistake as expected. The power and ground lines on my bread board don't go all the way across. They break right in the middle, as the lines show. I moved my ground connection to the left a few slots and it worked. Thanks for working through it with me jfpoilpret!</p>
3037
|arduino-uno|
Controlling an LED with the 74HC4067E multiplexer
2014-06-23T02:44:21.150
<p>I am testing a <a href="http://www.ti.com/lit/ds/schs209c/schs209c.pdf" rel="nofollow">74HC4067E MUX</a> setup with my Arduino Uno which I would like to use to selectively light up many LEDs, one at a time. For this first test, I am using a modified version of the <a href="http://arduino.cc/en/Tutorial/Blink" rel="nofollow">blink tutorial</a>. Essentially, I am setting the 4 control pins to digital LOW and setting the input to HIGH, through a resistor appropriate for my LED. I am also providing 5V to the Vcc pin on the MUX. I don't really know why I am doing this, but it seems to work. Here is my code:</p> <pre><code>int led_input = 0; int led_ctrl_1 = 1; int led_ctrl_2 = 2; int led_ctrl_3 = 3; int led_ctrl_4 = 4; void setup() { pinMode(led_input, OUTPUT); pinMode(led_ctrl_1, OUTPUT); pinMode(led_ctrl_2, OUTPUT); pinMode(led_ctrl_3, OUTPUT); pinMode(led_ctrl_4, OUTPUT); } void loop() { // control signal digitalWrite(led_ctrl_1, LOW); digitalWrite(led_ctrl_2, LOW); digitalWrite(led_ctrl_3, LOW); digitalWrite(led_ctrl_4, LOW); // input signal digitalWrite(led_input, HIGH); delay(500); digitalWrite(led_input, LOW); delay(500); } </code></pre> <p><em>I know, the code could be more efficient.</em></p> <p>The blue LED is hooked up to I0 and blinks as it should. The problem comes when I try to change the control pin values. When I change it to, say 6...</p> <pre><code>// control signal digitalWrite(led_ctrl_1, LOW); digitalWrite(led_ctrl_2, HIGH); digitalWrite(led_ctrl_3, HIGH); digitalWrite(led_ctrl_4, LOW); </code></pre> <p>... and I move my LED to I6, I get no blink. I've tested all the pins and it doesn't seem like there is a signal coming from any of them. I assume that I am using the chip wrong, but I'm not sure how. Pictures of my setup follow... any help is greatly appreciated!</p> <ul> <li>Arduino pin 0 maps to chip pin 1 (through resistor) as input.</li> <li>Arduino pins 1-4 map to chip pins 10, 11, 14, and 13 in that order.</li> <li>I have a 5V going to chip pin 24.</li> <li>The LED is connected long leg to chip pin 9 in the images, the grounded.</li> </ul> <p><a href="https://www.flickr.com/photos/89742360@N03/14484539664" rel="nofollow" title="IMG_20140622_221940 by nrbergeron, on Flickr"><img src="https://farm3.staticflickr.com/2898/14484539664_0d67922a44.jpg" alt="IMG_20140622_221940"></a></p> <p><a href="https://www.flickr.com/photos/89742360@N03/14505899703" rel="nofollow" title="IMG_20140622_221954 by nrbergeron, on Flickr"><img src="https://farm6.staticflickr.com/5531/14505899703_d77567e6f9.jpg" alt="IMG_20140622_221954"></a></p> <p><a href="https://www.flickr.com/photos/89742360@N03/14299200018" rel="nofollow" title="IMG_20140622_222012 by nrbergeron, on Flickr"><img src="https://farm3.staticflickr.com/2913/14299200018_60102f3c40.jpg" alt="IMG_20140622_222012"></a></p>
<p>Pin 15 on that MUX is the enable pin, you need to tie it to ground. Otherwise, it's just floating, and it only would have worked by accident.</p> <p>Also, you state:</p> <blockquote> <p>I am also providing 5V to the Vcc pin on the MUX. I don't really know why I am doing this, but it seems to work.</p> </blockquote> <p>The chip needs power to work. The Vcc pin is where you give it the +5V power. Without that, it might still work, but only by accident and depending on the inputs on the other pins.</p>
3039
|serial|sensors|matlab|
Binary serial transmission order of data
2014-06-23T08:38:35.343
<p>I'm implementing a filter for my IMU Sensor and thus I want close to real time data visualized on the computer. I use binary serial communication to facilitate the sending part for the arduino (as far as I know the serial.print is pretty slow). So I split my int16_t in two bytes and send it, like:</p> <pre><code>Serial.write((uint8_t)(gx &gt;&gt; 8)); Serial.write((uint8_t)(gx &amp; 0xFF)); </code></pre> <p>After that i directly send the next number (3 in total by now, maybe up to 7 2byte numbers in the future). I read the thing in matlab with: </p> <pre><code>dt(k) = toc; tic; bindata([1:6],k) = fread(s,[6,1],'int8'); time = cumsum(dt(1:k)); </code></pre> <p>Which reads 6 bytes (3 numbers) and then I recalculate the binary representation, concatenate them and get the original number (if someone can suggest an easier way.. I found matlab pretty unhandy here).</p> <p>The problem is, that the numbers get mixed by the time. Somewhen one byte isn't read or anything, so the bytes get messed up and a nonsense number is produced.One full number (2byte) is skipped for one sample exactly. Instead of this number one number is there twice. The next sample the order is messed up (shifted, such that the first number is second). This process appears after maybe 30 sec, sometimes a few minutes. After the first time it keeps shifting and jumping around.</p> <p>Can someone tell me, what to do here? Can I include some 'breakpoint'/line terminator, where the reader (matlab) knows, that we are at the start of the first number? Or how is this done actually?</p> <p>I guess I have to add my main goal: I want to make the sending as fast for the arduino as possible. No extra calculations should be necessary (if possible). And: the reason for these shifts seems to be the some time delay (slowness). I suspect it to be a slow matlab reading, since I saw fluent processing scripts in HIL reading. The errors have stopped however, since I turned the baude rate down. Only wrong numbers are the problem still.</p> <p>May there be a possibility to loop around the fread and read just store the values after an added 'header'? So let's say a wrong ordering occures. Then I discard everything until the next 'a' char/byte and use the following 6 bytes to produce my 3 values. Then I wait for an 'a' again. For that I would have to loop fread(s,[1,1],'int8'); and search for the header.</p> <p>Full arduino code:</p> <pre><code>// Program to send the gyro/accel data via serialport // corresponding matlab programs: sensing.m and sensing_binary.m // 2 security loops to guarantee a constant sampling time // #define DEBUG #include "GY86.h" #include "Wire.h" GY86 gy86; int16_t ax, ay, az; int16_t gx, gy, gz; uint32_t currenttime = 0; uint32_t starttime = 0; uint32_t starttime2 = 0; // #define OUTPUT_ACCEL_COUNTS #define OUTPUT_GYRO_COUNTS // #define OUTPUT_ACCEL_BINARY // #define OUTPUT_GYRO_BINARY void setup () { Serial.begin(9600); gy86.setup(); } void loop () { currenttime = millis(); if (currenttime-starttime &gt; 9) { while (micros()-starttime2 &lt; 9000) { } starttime2 = micros(); // read raw accel/gyro measurements from device gy86.getSensorValues(&amp;ax, &amp;ay, &amp;az, &amp;gx, &amp;gy, &amp;gz); // testing constants // gx = -29; // gy = 245; // gz = 17; #ifdef OUTPUT_GYRO_COUNTS Serial.print((int)gx); Serial.print(F("\t")); Serial.print((int)gy); Serial.print(F("\t")); Serial.print((int)gz); Serial.print(F("\t")); #endif #ifdef OUTPUT_ACCEL_COUNTS Serial.print(ax); Serial.print(F("\t")); Serial.print(ay); Serial.print(F("\t")); Serial.println(az); Serial.print(F("\t")); #endif #if defined(OUTPUT_ACCEL_COUNTS) || defined(OUTPUT_GYRO_COUNTS) Serial.print(F("\n")); #endif #ifdef OUTPUT_ACCEL_BINARY Serial.write((uint8_t)(ax &gt;&gt; 8)); Serial.write((uint8_t)(ax &amp; 0xFF)); Serial.write((uint8_t)(ay &gt;&gt; 8)); Serial.write((uint8_t)(ay &amp; 0xFF)); Serial.write((uint8_t)(az &gt;&gt; 8)); Serial.write((uint8_t)(az &amp; 0xFF)); #endif #ifdef OUTPUT_GYRO_BINARY Serial.write((uint8_t)(gx &gt;&gt; 8)); Serial.write((uint8_t)(gx &amp; 0xFF)); Serial.write((uint8_t)(gy &gt;&gt; 8)); Serial.write((uint8_t)(gy &amp; 0xFF)); Serial.write((uint8_t)(gz &gt;&gt; 8)); Serial.write((uint8_t)(gz &amp; 0xFF)); #endif starttime = currenttime; } } </code></pre>
<p>If what you want is high speed, the serial baud rate is your main concern. I assume that you are using an Arduino with a serial to USB converter chip, such as the Uno or Mega.</p> <p>Transferring at 115200 baud, you send 11520 bytes/s at normal serial settings (1 start + 8 data + 1 stop bits = 10 bits to send 1 byte of data). With an Arduino running at 16 MHz clock, you can execute 16M / 11520 = 1389 instructions in the time it takes to transmit one byte. So you don't have to worry much about slow library routines, what you have to worry about is how many bytes you send. In that way you are right not to use Serial.print, as it will convert your int to ascii, making all number larger than 99 slower to transmit (for a uint16).</p> <p>When you send data with Serial.write it is first stored in a ring buffer, then transmitted in the background by an Interrupt Service Routine. The ring buffer is typically 64 bytes. Once the the buffer is full, a call to Serial.write will block until a byte has been transmitted, so there is space in the buffer again. Therefore the timing in your main loop isn't really necessary, you can remove it and your sampling rate will adapt to your serial baud rate.</p> <p>Once the data has reached the serial to USB converter chip, it will be transmitted on the USB bus at 12 Mbit/s. I don't know the exact data transfer rate since there's a lot more overhead on USB than on the serial, but you can rest assured that the bottleneck isn't here. I don't think you have to worry about USB cable lengths as there is built-in error detection and retransmit in the USB protocol, and the speed is so much faster than the serial link.</p> <p>In the computer the data can be buffered in several places, it all depends on device drivers and serial libraries used. I'm not an expert here. With no flow control, the drivers/libraries probably have no choice but to drop data if it is receiving more than the end application or later layer can process. Maybe matlab or it's serial implementation or you computer is slow in some way (the data really isn't arriving very fast at all for a modern computer). So you could lower the baud rate or try to deal with lost packets.</p> <p>I have a suggestion for dealing with lost packets: Reserve the upper x bits in each byte you transmit to hold the number of that byte in its sequence. You could f.ex. reserve 2 bits, allowing you to send up to 4 byte packets belonging together. Each byte-packet would have 6 data bits, enabling you to send numbers with 24 bits of precision. To send a uint16:</p> <pre><code>void send_int16(uint16_t data) { Serial.write((0 &lt;&lt; 6) | (data &amp; 0b00111111)); data &gt;&gt;= 6; Serial.write((1 &lt;&lt; 6) | (data &amp; 0b00111111)); data &gt;&gt;= 6; Serial.write((2 &lt;&lt; 6) | (data &amp; 0b00111111)); } </code></pre> <p>Then in matlab you should wait for a sequence of packets numbered 0, 1, 2 in the two uppermost bits, remove the numbering and put the packets together with bitwise operators. If you get a malformed sequence, eg. 0, 2, can discard it and wait for the next byte starting with a zero.</p> <p>I haven't really used matlab, so you are on your own.</p>
3040
|arduino-mega|shields|motor|lcd|arduino-motor-shield|
Are these lcd and motor-shields stackable?
2014-06-23T08:58:57.203
<p>first of all, I'm kindly apologizing for asking such stupid questions, but as my electronic-knowledge is dramatically limited, you are my only hope to get my problem solved.</p> <p>I'm pretty new to Arduino and my plans are to stack a lcd shield on a motor shield, which is stacked on the Arduino. </p> <p>My setup would be the following:</p> <ul> <li><p>Arduino MEGA2560</p></li> <li><p>LCD-Shield <a href="http://www.sainsmart.com/arduino/arduino-shields/lcd-shields/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html" rel="nofollow">http://www.sainsmart.com/arduino/arduino-shields/lcd-shields/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html</a></p></li> <li><p>Motor-Shield <a href="http://www.sainsmart.com/arduino/arduino-shields/motor-shields/sainsmart-l293d-motor-drive-shield-for-arduino-duemilanove-mega-uno-r3-avr-atmel.html" rel="nofollow">http://www.sainsmart.com/arduino/arduino-shields/motor-shields/sainsmart-l293d-motor-drive-shield-for-arduino-duemilanove-mega-uno-r3-avr-atmel.html</a></p></li> </ul> <p>My target is to enter specific values trough the LCD-shield (with its buttons) and to control a stepper-motor related to those.</p> <p>Now to my question: Can I realize my project with the mentioned parts and are the two shields stackable (with head extentions on the motor-shield) without creating interferences?</p> <p>Thank you very much for your time and answers in advance.</p> <p>Best regards,</p> <p>irie</p>
<p>No, it doesn't look like it.</p> <p>The LCD board uses digital pins 4-10 and analog 0</p> <p>The motor board uses digital pins 3-12 if all motors are used.</p> <p>If you need to stack boards look for boards that use I2C since they can share a single data bus.</p>
3041
|gsm|
SerialGSM for GSM shield without SoftwareSerial
2014-06-23T09:40:03.153
<p>SerialGSM is a library for simplifying GSM shields.</p> <p>This is sample code for sending SMS:</p> <pre><code>#include &lt;SerialGSM.h&gt; #include &lt;SoftwareSerial.h&gt; SerialGSM cell(2,3); void setup(){ Serial.begin(9600); cell.begin(9600); cell.Verbose(true); cell.Boot(); cell.FwdSMS2Serial(); cell.Rcpt("+972123456789"); cell.Message("hello world"); cell.SendSMS(); } void loop(){ if (cell.ReceiveSMS()){ Serial.println(cell.Message()); cell.DeleteAllSMS(); } } </code></pre> <p>As you can see, he uses software serial.</p> <p>I intend to use this for my school thesis, but I am using a shield, so I won't be using Software Serial.</p> <p>What bothers me is this line</p> <pre><code>SerialGSM cell(2,3); </code></pre> <p>In my case, do I declare it like this?:</p> <pre><code>SerialGSM cell(0,1); </code></pre> <p>Or will there be conflicts with serial? </p> <p>EDIT: In other words, how do I declare the SeralGSM object using hardware serial and not software serial?</p>
<p>Never mind, i went with the GSM SMS example from arduino 1.0.5 (Don't know the version of arduino IDE that included this) and works fine.</p> <p>If you are considering using the SerialGSM library there is no need to!</p> <p>CAUTION: In the Arduino's library, when you declare the phone number, you have to use international format</p> <p>(Thanks bloomfield for the info you provided in the previous answer)</p>
3054
|power|interrupt|timers|battery|system-design|
Efficient periodic wake up for sensor reads
2014-06-24T14:13:43.253
<p>I've been tasked to do an initial design for an Arduino setup that needs to run very infrequently.</p> <p>Basically, I'd like the system to wake up <em>daily</em> to take some sensor readings and report them back to a central site (the mesh network for this will be my next stage).</p> <p>Since these things are going to be run on battery, I need it to be as insanely efficient as possible, with minimal power drain when not reading the sensor.</p> <p>What facilities does Arduino have to do this?</p>
<p>Please refer to <a href="http://playground.arduino.cc/Learning/ArduinoSleepCode" rel="nofollow">http://playground.arduino.cc/Learning/ArduinoSleepCode</a></p> <p>it explains the details of a the sleep command and interrupts to re-a-wake. Where the power savings is from putting the resources individually into low power mode.</p> <p>In your solution, you may want to put everything in low power, except power_timer1_disable(). Where timer1 would be configured to provide an overflow interrupt, say every 1 minute or longer and then go back to powering all off and return to sleep.</p> <p>Note the article also mentions that the UNO's power supply is a linear regulator, which is very in-efficient. You may want to use your own. You can also get away with just running directly off of 2-3 AA's, if your other circuitry does not care. If this, then I would also suggest enabling the brown out detection, to ensure low battery does not get funny.</p>
3056
|arduino-uno|programming|sketch|tinygps|
Unexpected behavior of sprintf with i32/u32
2014-06-24T15:23:38.073
<p>I'm trying to build a string of characters from several elements given by the <a href="http://arduiniana.org/libraries/tinygpsplus/" rel="nofollow">TinyGPS++ library</a> with the use of sprintf().</p> <p>This is my code making the string and printing it in the serial monitor.</p> <pre><code>char posmsg[100], lat[14+1], lon[14+1]; void sendString(){ //- convert lat/lon dtostrf(gps.location.lat(), 10,6, lat); dtostrf(gps.location.lng(), 10,6, lon); //- sprintf the string sprintf(posmsg, "$%4d-%02d-%02d %02d:%02d:%02d,%s,%s,%i,%i,%i,%i,%i$", gps.date.year(),gps.date.month(),gps.date.day(), gps.time.hour(), gps.time.minute(), gps.time.second(), lat, lon, gps.speed.value(), gps.course.value(), gps.altitude.value(), gps.satellites.value(), gps.hdop.value() ); Serial.println("--------------------"); Serial.println(posmsg); Serial.println("--------------------"); Serial.print("Speed:"); Serial.println(gps.speed.value()); Serial.print("Course:");Serial.println(gps.course.value()); Serial.print("Height:");Serial.println(gps.altitude.value()); Serial.print("Sats:");Serial.println(gps.satellites.value()); Serial.print("HDOP:");Serial.println(gps.hdop.value()); Serial.println("--------------------"); } </code></pre> <p>This is the result and what I expect... (spaces added for readability)</p> <pre><code> Result: -------------------- $2014-06-24 15:17:11, 51.xxxxxx, 5.xxxxxx, 2, 0, 4964, 0, 3660$ -------------------- Speed:2 Course:4964 Height:3660 Sats:8 HDOP:110 -------------------- Expected: -------------------- $2014-06-24 15:17:11, 51.xxxxxx, 5.xxxxxx, 2, 4964, 3660, 8, 110$ -------------------- </code></pre> <p>So in the end of the string the numbers get displaced...</p> <p>According to <a href="http://arduiniana.org/libraries/tinygpsplus/" rel="nofollow">the documentation</a> the type of the variables are all integers or unsigned integers, but the sprintf messes things up.</p> <pre><code> gps.speed.value(); // Raw speed in 100ths of a knot (i32) gps.course.value(); // Raw course in 100ths of a degree (i32) gps.altitude.value(); // Raw altitude in centimeters (i32) gps.satellites.value(); // Number of satellites in use (u32) gps.hdop.value(); // Horizontal Dim. of Precision (100ths-i32) </code></pre> <p>What am I doing wrong?</p>
<p>Ints and unsigned ints are 16 bits on AVR ATmegas. So while the argument passed is a 32-bit value, sprintf() is expecting a 16 bit value. The stack is packed with twice as much data as needed.</p> <p>From the "2,0,4964" bit, it looks like it taking part of the previous/next parameter during processing, which makes me think this even more.</p> <p>You need to use <em>long</em> types, e.g.: %ld or %li and %lu</p>
3059
|programming|c++|
Functions with string parameters
2014-06-24T15:48:57.597
<p>Inside my main loop there is this string:</p> <pre><code>String string1; </code></pre> <p>I have a function that will take string1 as parameter, and use it to send this string as SMS.</p> <pre><code>sendSMS(string1); </code></pre> <p>This is the sendSMS() function (without parameters):</p> <pre><code>void sendSMS() { sms.beginSMS(remoteNumber); sms.print(finalstr); sms.endSMS(); lcd.setCursor(0, 0); lcd.print("Message sent!"); delay(10000); } </code></pre> <p>My questions are:</p> <ol> <li>How do I put the string input parameter in sendSMS?</li> <li>Do I also need to use a function prototype for sendSMS()? (so that it appears three times, 1 in the prototype, 1 in the declaration and one in the call). Or I don't need to use function prototype before the main loop()?</li> </ol>
<p>I'd say to never use String again. When code gets bigger and memory usage will be critical you'll hit a dead-end. I know it's more convenient, but give char arrays a shot. Something like:</p> <pre><code>bool sendSMS(int remoteNumber, char *finalstr){ bool isFinished = 0; sms.beginSMS(remoteNumber); for (int i=0;i&lt;sizeof(finalstr);i++){ sms.print(finalstr); } sms.endSMS(); lcd.setCursor(0, 0); lcd.print("Message sent!"); delay(10000); isFinished = 1; return isFinished; } </code></pre> <p>I changed the function to bool. It means that you can use it inside an if statement, where you would want it completed before continuing with your code.</p> <p>You will need to allocate memory yourself for the array; declare it like this:</p> <pre><code>char stringArray[33] = {'\0'}; </code></pre> <p>Here, I allocate 32 bytes for data and one additional byte for the character that means "end of string" (it's that \0).</p>
3068
|led|button|
Reading button presses with the 74HC4067E multiplexer
2014-06-25T03:11:02.417
<p>My project is progressing quite well, but I am having some issues reading button presses through my MUX.</p> <h1>The Goal</h1> <p>Cycle through twelve buttons and twelve LEDs. When a button is pressed, light up the corresponding LED. I have one MUX for the LEDs which is working great thanks to the stack exchange community. My button MUX is the issue.</p> <h1>The Symptom</h1> <p>I have one button hooked up to the MUX. When it is not pressed, nothing lights up - that's right. But when it is pressed, every LED lights up as it is cycled through. It is as if pressing this button for one of the MUX pins is sending a HIGH signal to all of the MUX pins.</p> <h1>The Pictures</h1> <p><a href="https://www.flickr.com/photos/89742360@N03/14502003495" rel="noreferrer" title="IMG_20140624_225046 by nrbergeron, on Flickr"><img src="https://farm6.staticflickr.com/5545/14502003495_4793545dbc.jpg" alt="IMG_20140624_225046"></a></p> <p>^^ You can see the big honking button in the bottom right. It is connected to 5V and then the MUX pin.</p> <p><a href="https://www.flickr.com/photos/89742360@N03/14502004145" rel="noreferrer" title="IMG_20140624_225054 by nrbergeron, on Flickr"><img src="https://farm4.staticflickr.com/3866/14502004145_f9e52b5ecd.jpg" alt="IMG_20140624_225054"></a></p> <p>^^ I have two multiplexers. The one on the left is for the LEDs and the one on the right is for the buttons (of which I currently [ha!] have only one).</p> <p><a href="https://www.flickr.com/photos/89742360@N03/14500677754" rel="noreferrer" title="IMG_20140624_225113 by nrbergeron, on Flickr"><img src="https://farm4.staticflickr.com/3878/14500677754_53a79981f5.jpg" alt="IMG_20140624_225113"></a></p> <p><a href="https://www.flickr.com/photos/89742360@N03/14315398319" rel="noreferrer" title="IMG_20140624_225123 by nrbergeron, on Flickr"><img src="https://farm4.staticflickr.com/3849/14315398319_94e29448b9.jpg" alt="IMG_20140624_225123"></a></p> <p><a href="https://www.flickr.com/photos/89742360@N03/14478894346" rel="noreferrer" title="IMG_20140624_225136 by nrbergeron, on Flickr"><img src="https://farm3.staticflickr.com/2905/14478894346_2a1be6103f.jpg" alt="IMG_20140624_225136"></a></p> <h1>The Code</h1> <pre><code>// set vars for all the pins int led_input = 0; int led_ctrl_1 = 1; int led_ctrl_2 = 2; int led_ctrl_3 = 3; int led_ctrl_4 = 4; int btn_input = 5; int btn_ctrl_1 = 6; int btn_ctrl_2 = 7; int btn_ctrl_3 = 8; int btn_ctrl_4 = 9; // how many MUX pins? int players = 12; // function to take player number and convert to control pins void ledWrite(int led, boolean val){ if(!val){ digitalWrite(led_input, LOW); }else{ if((led - 8) &gt;= 0){ led = led - 8; digitalWrite(led_ctrl_4, HIGH); }else{ digitalWrite(led_ctrl_4, LOW); } if((led - 4) &gt;= 0){ led = led - 4; digitalWrite(led_ctrl_3, HIGH); }else{ digitalWrite(led_ctrl_3, LOW); } if((led - 2) &gt;= 0){ led = led - 2; digitalWrite(led_ctrl_2, HIGH); }else{ digitalWrite(led_ctrl_2, LOW); } if((led - 1) &gt;= 0){ led = led - 1; digitalWrite(led_ctrl_1, HIGH); }else{ digitalWrite(led_ctrl_1, LOW); } digitalWrite(led_input, HIGH); } } // function to take player number and convert to control pins int btnRead(int btn){ if((btn - 8) &gt;= 0){ btn = btn - 8; digitalWrite(btn_ctrl_4, HIGH); }else{ digitalWrite(btn_ctrl_4, LOW); } if((btn - 4) &gt;= 0){ btn = btn - 4; digitalWrite(btn_ctrl_3, HIGH); }else{ digitalWrite(btn_ctrl_3, LOW); } if((btn - 2) &gt;= 0){ btn = btn - 2; digitalWrite(btn_ctrl_2, HIGH); }else{ digitalWrite(btn_ctrl_2, LOW); } if((btn - 1) &gt;= 0){ btn = btn - 1; digitalWrite(btn_ctrl_1, HIGH); }else{ digitalWrite(btn_ctrl_1, LOW); } return digitalRead(btn_input); } void setup(){ pinMode(led_input, OUTPUT); pinMode(led_ctrl_1, OUTPUT); pinMode(led_ctrl_2, OUTPUT); pinMode(led_ctrl_3, OUTPUT); pinMode(led_ctrl_4, OUTPUT); pinMode(btn_input, INPUT); pinMode(btn_ctrl_1, OUTPUT); pinMode(btn_ctrl_2, OUTPUT); pinMode(btn_ctrl_3, OUTPUT); pinMode(btn_ctrl_4, OUTPUT); } void loop(){ for(int x = 1; x &lt;= players; x++){ if(btnRead(x) == HIGH){ ledWrite(x, true); delay(100); ledWrite(x, false); } } } </code></pre> <p>I know this is a lot to trudge through, and I honestly appreciate any help you are willing to offer. Thanks in advance!</p>
<p>All your unused MUX input pins for the button MUX are floating. You will need to tie all of the unused inputs (those that do not have a physical button attached) to ground. Floating inputs are undefined and cause undefined output.</p> <p>Also, when your attached button is <em>not</em> pressed, its input will also be floating. You can avoid this by connecting the input pin on the MUX to ground using a resistor. That way, when the button is not pressed the input will be low (through the resistor), and when the button is pressed it will be high (through the button connection).</p>
3079
|serial|variables|data-type|
How to retrieve the data type of a variable?
2014-06-25T14:33:26.160
<p>I am using Arduino and I would like to know if there is a function that returns the data type of a variable. That is, I would like to run something as like the following:</p> <pre><code>// Note: 'typeof' is a sample function that should return the data type. Serial.println(typeof(myVar)); </code></pre>
<p>There also a trick using compiler predefined macro. The advantage is it can print any type.</p> <pre class="lang-cpp prettyprint-override"><code>template &lt;class T&gt; String type_name(const T&amp;) { String s = __PRETTY_FUNCTION__; int start = s.indexOf(&quot;[with T = &quot;) + 10; int stop = s.lastIndexOf(']'); return s.substring(start, stop); } </code></pre> <p>Use it like this</p> <pre class="lang-cpp prettyprint-override"><code>double pi = 3.14; const char* str = &quot;test&quot;; Serial.println(type_name(pi)); Serial.println(type_name(str)); </code></pre> <h2>EDIT:</h2> <p>Some improvements based on tim's analyze.</p> <p>First I have a comment on variation that has lower memory requirements. <code>__PRETTY_FUNCTION__</code> is a literal string (a constant) that should not be changed. So my const version that do not use heap is following.</p> <pre class="lang-cpp prettyprint-override"><code>template &lt;size_t N&gt; const char* extract_type(const char (&amp;signature)[N]) { const char* beg = signature; while (*beg++ != '='); ++beg; const char* end = signature + N; for (; *end != ']'; --end); static char buf[N]; char* it = buf; for (; beg != end; ++beg, ++it) *it = *beg; *it = 0; return buf; } template &lt;class T&gt; const char* type_name(const T&amp;) { return extract_type(__PRETTY_FUNCTION__); } </code></pre> <p>A less safe but more efficient version using the fact that offset to type we want extract is a constant (always the same). If function signature changes (like put it in a namespace) the offset will change too. But come on, set it once, write a comment and it will work forever :).</p> <pre class="lang-cpp prettyprint-override"><code>template &lt;size_t N&gt; const char* extract_type(const char (&amp;signature)[N]) { const char* beg = signature + 42; const char* end = signature + N - 2; static char buf[N - 43]; char* it = buf; for (; beg != end; ++beg, ++it) *it = *beg; *it = 0; return buf; } template &lt;class T&gt; const char* type_name(const T&amp;) { return extract_type(__PRETTY_FUNCTION__); } </code></pre> <p>While above is ok ofcourse it can be improved further. Here is a my version of constexpr function mentioned by @tim. It uses constant offset as above to keep it short. This code generates only extracted string of type, the proof is <a href="https://godbolt.org/z/4o1aev6n4" rel="nofollow noreferrer">here</a>.</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;utility&gt; template &lt;class T, std::size_t... I&gt; const char* type_name(std::index_sequence&lt;I...&gt;) { static constexpr char name[] = { __PRETTY_FUNCTION__[I + 60]..., 0 }; return name; } template &lt;class T&gt; const char* type_name(const T&amp;) { return type_name&lt;T&gt;( std::make_index_sequence&lt;sizeof(__PRETTY_FUNCTION__) - 44&gt;()); } </code></pre> <p>The minimum requirement for this is C++14 because of sequence traits. These can be re-implemented (see definition <a href="https://en.cppreference.com/w/cpp/utility/integer_sequence" rel="nofollow noreferrer">here</a>) to adapt it to C++11.</p>
3095
|remote-control|rf|
Auto acknowledge failed with nRF 24L01+ and Arduino
2014-06-26T11:16:49.937
<p>My transceivers are running fine. I've written a few code and got them running. Then I decided to check the auto acknowledgement feature wherein we can return data back to the sender WITHOUT manually changing the radio modes on both units. But I find that the serial monitor always shows "failed to transmit". Why is this happening, because otherwise they work fine?</p> <p>I am using maniacbug's RF24master library.</p> <p>The Tx code is:</p> <pre><code>#include&lt;SPI.h&gt; #include&lt;nRF24L01.h&gt; #include&lt;RF24.h&gt; int msg[1] = {1}; int rec[1] = {0}; bool stat = true; RF24 radio(9,10); const uint64_t pipe[1] = {0xF0F0F0F0E1LL}; void setup() { Serial.begin(57600); radio.begin(); delay(1000); radio.setAutoAck(true); radio.enableAckPayload(); radio.openWritingPipe(pipe[0]); radio.setRetries(15,15); } void loop() { if(stat) { radio.stopListening(); bool ok = radio.write(msg,sizeof(msg)); delay(100); if(ok) {Serial.println("transmitted successfully !!");} else {Serial.println("faileed to transmit");} msg[1]++; if(msg[1]&gt;=200) {msg[1]=1;} stat = false; //delay(20); } if(!stat) { if(radio.isAckPayloadAvailable()) { radio.read(rec,sizeof(rec)); Serial.print("received ack payload is : "); Serial.println(rec[1]); stat = true; } } } </code></pre> <p>and the Rx part is: </p> <pre><code>#include&lt;SPI.h&gt; #include&lt;nRF24L01.h&gt; #include&lt;RF24.h&gt; const uint64_t pipe = 0xF0F0F0F0E1LL; RF24 radio(9,10); int rec[1] = {0}; int ack[1] = {1}; void setup() { Serial.begin(57600); radio.begin(); delay(100); radio.setAutoAck(true); radio.enableAckPayload(); radio.openReadingPipe(1,pipe); radio.startListening(); radio.setRetries(15,15); } void loop() { if(radio.available()) { Serial.println("payload available...."); bool ok = radio.read(rec,sizeof(rec)); if(ok) { Serial.println("message received !!"); Serial.print("integer got is : "); Serial.println(rec[1]); radio.writeAckPayload(1,ack,sizeof(ack)); } else {Serial.println("failed to receive the message");} } } </code></pre>
<p>To achieve that you have to do the following -</p> <pre><code>if ( radio.available() ) { // make sure the read will succeed radio.writeAckPayload( 1, buf, len ); // prep the ack payload radio.read( &amp;got_time, sizeof(unsigned long) ); // also shunts out ack payload } </code></pre> <p>So your program finally becomes - </p> <pre><code>#include&lt;SPI.h&gt; #include&lt;nRF24L01.h&gt; #include&lt;RF24.h&gt; int msg[1] = {1}; int rec[1] = {5}; bool stat = true; RF24 radio(9,10); const uint64_t pipe[1] = {0xF0F0F0F0E1LL}; void setup() { Serial.begin(57600); radio.begin(); delay(100); radio.setAutoAck(true); radio.enableAckPayload(); radio.enableDynamicPayloads(); radio.stopListening(); radio.openWritingPipe(pipe[0]); radio.setRetries(15,15); } void loop() { if(stat) { if(radio.write(msg,sizeof(msg))) { Serial.print( msg[0] ); Serial.println("...tx success"); if(radio.isAckPayloadAvailable()) { radio.read(rec,sizeof(int)); Serial.print("received ack payload is : "); Serial.println(rec[0]); } else { stat = false; //doing this completely shuts down the transmitter if an ack payload is not received !! Serial.println("status has become false so stop here...."); } msg[0]+=3;; if(msg[0]&gt;=100) {msg[0]=1;} } } } </code></pre> <p>And the RX part becomes - </p> <pre><code>#include&lt;SPI.h&gt; #include&lt;nRF24L01.h&gt; #include&lt;RF24.h&gt; const uint64_t pipe[1]= {0xF0F0F0F0E1LL}; RF24 radio(9,10); int rec[1] = {2}; int red; void setup() { Serial.begin(57600); radio.begin(); delay(100); radio.setAutoAck(true); radio.enableAckPayload(); radio.enableDynamicPayloads(); radio.openReadingPipe(1,pipe[0]); radio.startListening(); radio.setRetries(15,15); } void loop() { if ( radio.available() ) { radio.writeAckPayload( 1, rec, sizeof(int) ); radio.read( &amp;red,sizeof(red) );rec[0]+=2; Serial.print("integer got is : "); Serial.println(red); } } </code></pre> <p>Know more about it at the following pages - <a href="https://shantamraj.wordpress.com/2014/07/19/exploring-the-auto-ack-feature-of-the-transceiver/" rel="nofollow noreferrer">https://shantamraj.wordpress.com/2014/07/19/exploring-the-auto-ack-feature-of-the-transceiver/</a> <a href="https://shantamraj.wordpress.com/2014/11/30/auto-ack-completely-fixed/" rel="nofollow noreferrer">https://shantamraj.wordpress.com/2014/11/30/auto-ack-completely-fixed/</a></p>
3097
|bluetooth|
HC-0# Bluetooth module questions
2014-06-26T20:17:28.730
<p>I've been playing with the HC-06 BT module lately, but now I want to do more with it and I'm not sure how to. I was wondering if it's possible to get signal strength from the module, or would I have to purchase another HC-0# module to do so? Also the HC-05, can initiate connection if I'm understanding documentation right, and return available devices in the area? </p>
<blockquote> <p>I was wondering if it's possible to get signal strength from the module</p> </blockquote> <p>No, it doesn't appear so from the data sheet / AT command list.</p> <blockquote> <p>Also the HC-05, can initiate connection if I'm understanding documentation right, and return available devices in the area? </p> </blockquote> <p>Yes, and it can get the signal strengths. You should be able to get an HC-05 module on a breakout board from Ebay for less than $10 delivered. There's also a method to update the HC-06 firmware to be an HC-05 but it's probably easier for you to buy one.</p>
3105
|serial|
For which type of serial communication is Arduino Severino designed?
2014-06-27T21:31:34.097
<p>Arduino has become quite costly where I come from (2/3 of the price of Raspberry PI) so I have created an <a href="http://arduino.cc/en/Main/ArduinoBoardSerialSingleSided3" rel="noreferrer">Arduino Severino clone</a>.</p> <p>I had used the device with the RS-232 Usb-Serial converter. But after a (long) while, the device stopped working. My friend came up with a point that RS-232 communication ranges between +6 to -6 V (with thresholds at +3 and -3 volts). </p> <p>So I have tried FT232 which uses 0 to 5 volts instead. I have a little <del>Chinese</del> <a href="http://www.ftdichip.com/" rel="noreferrer">FTDI</a> chip designed to do that: <img src="https://i.stack.imgur.com/UI2pR.jpg" alt="usb to serial front side"></p> <p><img src="https://i.stack.imgur.com/1hK83.jpg" alt="usb to serial back side"></p> <p>However, after connecting it, it behaves unexpectedly. (it had crashed my PC, one of the communication LEDs is on all the time...) I realised that the Arduino board might get broken for a different reason (an accidental short-circuit is <em>very</em> likely).</p> <p>So for which type of communication is this <em>"Arduino"</em> designed?</p>
<p>The Arduino Severino (Single Sided Serial version 3 - S3V3rino) is designed to work with RS-232 serial interface, not with the TTL serial signal levels of your FT232 board. </p> <p>So, to use your FT232 board to connect your Severino to a USB port, you'll need connections like those in the schematics below:</p> <p><img src="https://i.stack.imgur.com/kIUi8.png" alt="Serial TTL to ATmega328 schematics"></p> <p>So, basically you need these connections:</p> <pre><code> FTDI | ATmega328 | Arduino Severino ---------------------------------------------------- DTR | Pin 1 (thru cap C6) | RESET (thru cap C6) RXI | Pin 3 | TX (D1) TXO | Pin 2 | RX (D0) VCC | Not connected | Not connected CTS | Not connected | Not connected GND | Pin 8 &amp; 22 | Ground </code></pre> <p>That's basically the same Majenko suggested (but with a picture added).</p> <p>I'm not sure you can make these connections directly into the Severino without damaging the board or anything else. You'll probably need to cut the TX/RX traces that go from the ATmega328 to the DB9 female connector on the Severino and wire them to the FTDI header pins.</p> <p>Best would be to modify the Severino EagleCAD schematics to remove all the RS-232 circuitry and replace it by TTL connector as shown in my schematics above and, with that, etch and assembly a new board. It's a lot of work, but can be done.</p> <p>I hope this helps.</p>
3113
|rf|
Arduino diy wireless
2014-06-28T19:36:28.753
<p>Is it possible to do simple wireless on an Arduino, digital, or analog (SDR)? I would like to hook one pin to an antenna (or piece of wire) and generate signals with simple modulations (analog or digital).</p>
<p><a href="https://forum.arduino.cc/index.php?topic=88422.0" rel="nofollow noreferrer">here</a> there's a nice tutorial on how to obtain it.</p> <p>Basically it sets the registers so that a pin outputs a PWM signal at 800 kHz and then modulates that signal in code by just switching the pin and off (pinMode set to INPUT or OUTPUT). If you plug a cable (20 cm and on) to pin 8, and tune your radio to 800Khz you'll hear some noise going on and off.</p> <p>If you read down the forum you'll see people suggesting how to actually send tones, by putting a very small delay (delay(1)) between the on/off of the pin.</p> <p><a href="http://mateslab.weebly.com/am-radio-broadcasting-with-arduino.html" rel="nofollow noreferrer">In this link</a> they guys have ogn further and they even implemented a morse code library.</p> <p>Now I am trying to figure out a way to do the same for a receiver.</p>
3135
|ethernet|
Buffering data from EthernetServer clients
2014-06-30T15:41:19.077
<p>I was trying to write a Telnet server that would be able to accept commands of sorts using the Arduino Ethernet library, and in order to access what the client was saying (to compare it to strings to check what command the client entered), I made a buffer string that would read until <code>\n</code>, which is part of the standard Telnet library. However, the string would never get printed to the serial connection (just for debugging purposes). Here's my code:</p> <pre><code>#include &lt;SPI.h&gt; #include &lt;Ethernet.h&gt; byte mac[] = { 0xDE, 0xAD, 0xBE, 0xFE, 0xED }; // this client's MAC address EthernetServer server(23); // telnet is 23 boolean alreadyConnected = false; void setup() { Ethernet.begin(mac); server.begin(); // open the socket Serial.begin(9600); while (!Serial) { ; // wait for serial to start, Leonardo only } Serial.print("Connect to "); Serial.print(Ethernet.localIP()); Serial.println(":23."); } void loop() { EthernetClient c = server.available(); if (c) { String messageBuffer = ""; if (!alreadyConnected) { c.flush(); Serial.println("New client"); c.println("test post, please ignore"); alreadyConnected = true; } if (c.available() &gt; 0) { char thisChar = c.read(); //server.write(thisChar); //buffer until the client sends a new line if (thisChar == '\n') { Serial.println(messageBuffer); messageBuffer = ""; } else { messageBuffer += thisChar; } } } } </code></pre> <p>Most of this code was copied from the Telnet chat server example, but I changed the <code>Serial.write(thisChar)</code> line, because I wanted to put it into a string first. When this is run, and a user <code>telnet</code>s to the IP, the Arduino prints <code>New client</code>, but when the user sends data, it doesn't print anything.</p> <p>Any suggestions for what I'm doing wrong?</p>
<p>Well, I asked on the #arduino IRC channel, and realized my stupid mistake. I was setting the buffer to <code>""</code> <strong>inside</strong> the loop.</p>
3151
|audio|
Best Arduino board to play sound
2014-07-01T23:59:49.363
<p>I'm looking to purchase an Arduino for a little robot I'm going to make. The reason I've chosen Arduino is because it's much easier to use with servos and LEDs than a Raspberry Pi, but a nice little touch would be to have it play some sounds (voice recordings and mechanical SFX). I was just wondering (now I'm not after opinions here, but looking more at how each of the boards have been designed) what the <em>best</em> Arduino board for playing sound is, or if they are all pretty much the same in this regard.</p> <p>(Note 'pins' was the best tag I could find for this post for lack of a 'sound' or 'speakers' one. If you want to edit it to something more appropriate please do)</p>
<p>If all you need is to play back lo-fi audio then any with PWM will do, which means that any Arduino will do. If you want hi-fi sound then you'll need a DAC, which means either choosing the Due or using a discrete DAC via SPI. If you need decoding of complex audio formats such as MP3 or Vorbis then you'll need either the Due for its power, or a separate audio playback shield that supports the formats you're interested in.</p>
3165
|arduino-uno|programming|i2c|
MCP7940 RTC Library
2014-07-03T18:36:48.717
<p>I am looking to implement a Microchip MCP7940 real time clock into my sensor data logging circuit that I have based on the Uno. Would the most logical solution be to attempt at changing an existing library to work with this clock (ie <a href="https://github.com/jcw/rtclib" rel="nofollow">RTClib</a>), or to begin from scratch and do the configuration directly in my program?</p>
<p>In case anyone comes looking for an answer to this question, here is my solution:</p> <p>I started with the excellent library by jeelabs (link: <a href="https://github.com/jcw/rtclib" rel="nofollow">https://github.com/jcw/rtclib</a>)</p> <p>To create my new library, I changed a few of the register addresses, and added the few functions that I wanted it to do (set alarm, create an ordinal date, manually adjust the time with user input)</p> <p>I posted my code to a Git project: <a href="https://github.com/crako1t/MCP7940-library-for-logger.git" rel="nofollow">https://github.com/crako1t/MCP7940-library-for-logger.git</a></p>
3167
|serial|
Clear existing array when getting new serial command
2014-07-03T21:20:10.413
<p>I'm starting to build my first Arduino project but I'm running into some problems with serial communication.</p> <p>I get serial data from the console and store it in a char array called "data".</p> <p>Then, when I send a new console message to the Arduino, I want it to clear the existing "data" array and store only the new data in that array.</p> <p>I don't understand exactly what's wrong with my code: I believe those nested Serial.available() statements don't work but I have no ideas on how to fix the code.</p> <p>Data is correctly stored by the Arduino but it concatenates the newer string to the old one.</p> <pre><code>int count = 0; char data[30]; boolean dataComplete = false; void setup() { Serial.begin(9600); } void loop() { if (Serial.available() &gt; 0){ if (dataComplete == true){ Serial.println("There is data already, clearing..."); char data[30]; dataComplete = false; } if (dataComplete == false){ Serial.println("New command, collecting..."); while (Serial.available()&gt;0){ char character = Serial.read(); data[count] = character; count++; } dataComplete = true; } } Serial.print("Command received: "); Serial.println(data); delay(1000); } </code></pre> <p>Thanks in advance!</p>
<p>I was read all comments on this question, but all codes was share so verbosing. After that, i create a code with simple functions and less of line. in this case, i think this code will working fine</p> <p>if you set baudrate under 115200, must be add delay() for saving message to char array</p> <pre><code>void loop() { char data[255]; uint8_t k = 0; while (Serial.available()) { data[k] = Serial.read(); k++; } for (int i = 0; i &lt; k; i++) { Serial.print(data[i]); data [i] = '\0'; } //delay(50); } </code></pre>
3175
|sram|eeprom|memory-usage|
How is stack memory used for fuctions and local variables?
2014-07-04T18:15:20.697
<p>I wanted to save some values to the EEPROM and also wanted to free up SRAM by avoiding some variable declarations, but EEPROM memory is byte wise.</p> <p>If I want to store an int value, I have to use some expressions repeatedly. I thought I would make some functions for those. But I am concerned that, if I create a function, it would still occupy SRAM memory, better I declare an int variable instead of using EEPROM.</p> <p>How are the functions and the local variables stored in SRAM? Does it only store the address of the fuction pointer from the flash memory or all the variables and commands are stored on the stack?</p>
<p>I've been trying quite hard to make an example bit of code to demonstrate what the excellent answers here are saying, without success so far. The reason is that the compiler aggressively optimizes things. So far my tests have not used the stack at all, even with local variables in a function. The reasons are:</p> <hr> <ul> <li><p>The compiler may <strong>in-line</strong> the function call, thus the return address might not be pushed onto the stack at all. Example:</p> <p><code>void foo (byte a) { digitalWrite (13, a); } void loop () { foo (5); } </code></p> <p>The compiler turns that into:</p> <p><code>void loop () { digitalWrite (13, 5); } </code></p> <p>No function call, no stack used.</p></li> </ul> <hr> <ul> <li><p>The compiler may pass arguments in <strong>registers</strong>, thus saving it having to push them onto the stack. Example:</p> <p><code>digitalWrite (13, 1);</code></p> <p>Compiles into:</p> <p><code>158: 8d e0 ldi r24, 0x0D ; 13 15a: 61 e0 ldi r22, 0x01 ; 1 15c: 0e 94 05 01 call 0x20a ; 0x20a &lt;digitalWrite&gt; </code></p> <p>The arguments are put into registers and thus no stack is used (apart from the return address for calling digitalWrite).</p></li> </ul> <hr> <ul> <li>Local variables may well be put into registers, again saving having to use RAM. This not only saves RAM but is faster.</li> </ul> <hr> <ul> <li><p>The compiler optimizes away variables you don't use. Example:</p> <p><code>void foo (byte a) { unsigned long bar [100]; bar [1] = a; digitalWrite (9, bar [1]); } void loop () { foo (3); } // end of loop </code></p> <p>Now that's <strong>got</strong> to allocate 400 bytes for "bar" doesn't it? Nope:</p> <p><code>00000100 &lt;_Z3fooh&gt;: 100: 68 2f mov r22, r24 102: 89 e0 ldi r24, 0x09 ; 9 104: 0e 94 cd 00 call 0x19a ; 0x19a &lt;digitalWrite&gt; 108: 08 95 ret 0000010a &lt;loop&gt;: 10a: 83 e0 ldi r24, 0x03 ; 3 10c: 0e 94 80 00 call 0x100 ; 0x100 &lt;_Z3fooh&gt; 110: 08 95 ret </code></p> <p>The compiler optimized away the <strong>entire array</strong>! It can tell that we are really just doing a <code>digitalWrite (9, 3)</code> and that is what it generates.</p></li> </ul> <hr> <p>Moral of the story: Don't try to out-think the compiler.</p>
3182
|pwm|analogwrite|
What is the frequency of PWM output on Arduino
2014-07-05T15:00:15.833
<p>What frequency do Arduinos use for normal PWM when you use analogWrite()?</p> <p>And is it different for different Arduino model? I'm interested specifically in the Mega 2560, but also want to know if it's consistent between models.</p> <p>I've seen a passing references to the Arduino using 500 Hz, which seems really slow. </p>
<p>The PWM signal is generated by timers on the AVR chips. Each timer can generate a PWM signal on two or three different pins. Each pin can have it's own duty cycle, but they share the PWM frequency. You can change the frequency of the PWM by changing the clock source for the timers. By default they use the CPU clock divided by 64, ie. they have their prescaler set to 64 by Arduino initialization code. To confuse things more there are two different PWM modes: fast PWM and phase correct PWM. In fast PWM the timer counts to 255, then overflows and starts over from 0 (256 different states). In phase correct PWM the timer counts to 255, then changes direction and counts downwards to zero, changes direction and so on (510 different states).</p> <p>The Arduino Mega has 5 timers, timer0 - timer4. Because timer0 is also used for the millis and micros functions it uses fast PWM, whereas the other timers are configured for phase correct PWM. This results in different frequencies on different pins:</p> <ul> <li><p>Pin 4 and 13, controlled by timer0:<br> 16 Mhz / 64 / 256 = 976.56 Hz</p></li> <li><p>Other PWM pins, controlled by timer1-4:<br> 16 Mhz / 64 / 510 = 490.20 Hz</p></li> </ul> <p>The calculation is: Clock / Prescaler / PWM mode number of states</p> <p>The situation is the same for all other Arduino boards I know of, except they have less timers that connect to different pins.</p> <p>You can change the PWM frequency by changing the timer prescaler. See this page: <a href="http://playground.arduino.cc/Main/TimerPWMCheatsheet">http://playground.arduino.cc/Main/TimerPWMCheatsheet</a></p> <p>It is also possible to make the timers count to a different value than 255. On the 8 bit timers you will loose an output pin, but on the 16 bit timers you can use the Input Capture Register to define a TOP value. The input capture functionality is a feature rarely used in the Arduino community so you likely won't miss it.</p> <p>The Arduino libraries only allow you to use 8 bit resolution, even on the 16 bit timers. If you want the higher resolution, you will have to write your own analogWrite, or use a library made for the purpose. On the Arduino Mega timer0 and timer2 are 8 bit, while the rest are 16 bit.</p> <p>By changing the mode of the 16 bit timers to make use of the full resolution, in combination with changing the prescaler and the TOP value, you can achieve a very wide range of PWM frequencies.</p> <p>The maximum frequency you can achieve is clock / 4, by setting the prescaler to 1 and TOP to 3 in fast PWM mode - a lower value isn't allowed. This will give you a 4 MHz PWM with 2 bit resolution. It can be on 0%, 25%, 50%, or 75% of the time. A higher TOP value will give you a higher resolution at a lower frequency.</p> <p>For a longer explanation read this <a href="http://www.righto.com/2009/07/secrets-of-arduino-pwm.html">article</a> or refer to the <a href="http://www.atmel.com/Images/Atmel-2549-8-bit-AVR-Microcontroller-ATmega640-1280-1281-2560-2561_datasheet.pdf">datasheet</a>.</p> <p>Changing the prescaler, PWM mode, or TOP value for timer0 will mess with <code>millis()</code> and <code>micros()</code>.</p>
3184
|arduino-uno|ethernet|
Arduino communicating back and forth with PHP server
2014-07-05T17:30:12.147
<p>I am researching to find the best method to work with in order to control the arduino from a web interface (hosted on a web server using PHP) and also sending data from arduino to webserver and save to mySql.</p> <p>2 methods which I have found that a lot use are save the data to a text file or in the url.</p> <p>Which is the best or are there any better methods?</p>
<p>If it's not too much data, a textfile as a database should suffice, if you want something more scalable; I'm quite impressed with node.js: <a href="http://weworkweplay.com/play/raspberry-pi-nodejs/" rel="nofollow">http://weworkweplay.com/play/raspberry-pi-nodejs/</a></p>
3186
|arduino-uno|current|
Does Arduino run AC or DC
2014-07-05T22:54:17.813
<p>Does arduino run AC or DC? Based on my small knowledge on the crystal in an arduino, it seems like AC makes sense. True? No?</p>
<p>All digital logic circuits run on DC.</p> <p>Most Arduino boards include a voltage regulator. You can feed them an input ranging from 7 to 12 volts, and they "clean up" that input and lock it to precisely 5 volts, the voltage needed by the Arduino. </p> <p>They can also run directly off the regulated 5 volts from the USB connector.</p>
3189
|arduino-uno|code-optimization|
Questions on programming logic?
2014-07-06T00:34:23.267
<p>So I am learning arduino code by going through examples and playing with them, and I came across something interesting. I am not fluent in any coding language but I am fully familiarized with computer logic and function so I can read what you suggest just fine. </p> <p>What I want to know is, why are these two code pieces different? </p> <pre><code>const int ledPin = 13; int ledState = LOW; long interval = 1000; void setup() { pinMode(ledPin, OUTPUT); } void loop() { unsigned long currentMillis = millis(); if(currentMillis &gt; interval) { currentMillis = 0; if (ledState == LOW) ledState = HIGH; else ledState = LOW; digitalWrite(ledPin, ledState); } } </code></pre> <p>This is my code, or rather modification to this code: </p> <pre><code>const int ledPin = 13; int ledState = LOW; long previousMillis = 0; long interval = 1000; void setup() { pinMode(ledPin, OUTPUT); } void loop() { unsigned long currentMillis = millis(); if(currentMillis - previousMillis &gt; interval) { previousMillis = currentMillis; if (ledState == LOW) ledState = HIGH; else ledState = LOW; digitalWrite(ledPin, ledState); } } </code></pre> <p>How is it that the first code works, and the second code turns the led on and either terminates or never turns the LED off? The code is designed to blink the LED once every 1 second.</p>
<p><a href="http://en.wikipedia.org/wiki/Two%27s_complement" rel="nofollow">http://en.wikipedia.org/wiki/Two%27s_complement</a> - good read regarding signed numbers in binary format. It really isn't "complex"; the highest bit being "1" denotes a negative number. As there is no "-0" the negative numbers also have an offset of one.</p> <p>If you mix unsigned and signed - you simply get unexpected results. </p> <p>You need to be very precise, i.e. check if the signed number is negative and handle it with care to make it "compatible" with the unsigned number before you use them together. What "care" ends up be in reality depends on what you expect to get out of it, as result.</p>
3192
|serial|arduino-mega|variables|
How to send multi variable information over serial?
2014-07-06T05:29:31.483
<p>I would like to send information between my Arduino and my computer. Is there a way to send multiple variables from one Arduino? If so, how would I go about separating the variables?</p>
<p><strong>You have three options for what you want to achieve (if I understand it right):</strong></p> <ul> <li><strong>Have a fixed length for each variable:</strong> If I know each number is going to be two digits, I can send "1234" and the other side can figure out the numbers are "12" and "34".</li> <li><strong>Have a delimiter character:</strong> Have a character that signals a new variable. For example: "213|1234" would translate into "213" and "1234". You could even use the newline character to signal a new line (with <code>Serial.println();</code>).</li> <li><strong>Do some sort of validation to separate the data:</strong> If sending a favorite number and favorite color, I can send "12RED345BLUE" and the other side it can find that it's "12" (both numbers), then "RED" (all letters), then "345" (three numbers), and finally "BLUE" (again, all letters).</li> </ul>
3198
|power|lcd|
Running an LCD keypad shield from a separate power source
2014-07-06T16:58:01.687
<p>I need to use a motor shield and an LCD keypad shield simultaneously hooked up to a single Arduino Mega Board. Since I can't physically stack them, I decided to reroute all the pins used for the LCD keypad shield. When I reroute all pins <strong>except</strong> the two power pins, the LCD and keypad work fine. But when I disconnect those 2 pins and connect them to any other power source than the Arduino Mega, it fails. The screen becomes either blank / jumble of illegible characters / brief moments of expected output followed by the same jumble.</p> <p>This behavior is really strange since the power pins don't carry any information, they are just power sources. The LCD keypad shield shouldn't be able to discriminate whether the power is coming from the Arduino Mega or not - but it does. I checked with a voltmeter that all power sources I tried are DC 5V. </p> <p>At first I thought this is because the <code>lcd.begin()</code> function is called only once, so I rewrote my code to re-initialize the lcd at every iteration. This doesn't solve the problem.</p> <p>Here is a picture of the setup that works. (rerouting all pins <em>except</em> the power.) Ignore the location of analog input cable, since it doesn't do anything in the current code.</p> <p><img src="https://i.stack.imgur.com/yGRiL.jpg" alt=""></p> <p>And one that fails. The only difference from above is the power source.</p> <p><img src="https://i.stack.imgur.com/60Trk.jpg" alt=""></p> <p>And my code.</p> <pre><code>#include &lt;LiquidCrystal.h&gt; // select the pins used on the LCD panel LiquidCrystal lcd(28, 29, 24, 25, 26, 27); void setup() { lcd.begin(16, 2); lcd.print("Hello World!"); } void loop() { lcd.begin(16, 2); lcd.setCursor(0, 0); lcd.print("Hello World!"); delay(1000); lcd.setCursor(0, 0); lcd.print("Hello Again!"); delay(1000); } </code></pre> <p>Any suggestions?</p>
<p>Those little 16x2 LCDs are quite prone to power fluctuations. Even powered solely by an Arduino I've seen them run OK for a few minutes than turn to showing gibberish. Ensure you have good power connections, bring your power in as close as possible.</p> <p>Maybe a capacitor across the power input to the display might help.</p>
3201
|arduino-uno|lcd|
Arduino based small LCD screen with camera video capturing
2014-07-06T17:11:04.080
<p>i have a idea to create a small screen which displays video recorded from arduino with camera. so camera will be back side of human and screen will be at near to eye. human can see the pictures from back side.</p> <p>i have found <a href="https://electronics.stackexchange.com/questions/29139/processing-ntsc-video-feed-for-spi-display">https://electronics.stackexchange.com/questions/29139/processing-ntsc-video-feed-for-spi-display</a></p> <p>but its not give me a clear idea. is there any one who can advice me for that kind project?</p>
<p>An Arduino doesn't have anywhere near the processing ability to transcode video from a camera unless you had an abysmal frame rate and very low quality. Even then, you would have to add extra storage because the Arduino would be over capacity in a heartbeat.</p> <p>I recommend converting this project to a higher powered board like the Udoo. I have the <a href="http://www.udoo.org/" rel="nofollow">Udoo Quad</a> and it's beastly considering its form factor. You're going to need something a lot bigger than an Arduino!</p>
3203
|arduino-uno|programming|
How can I make my Arduino code work?
2014-07-06T19:12:01.687
<p>I am trying to make an automatic lock which stays open during different times and on different days. I want the door open Monday through Friday 8am to 5pm. On Saturdays and Sundays I want the door locked. I will be using an electric lock strike the + wire to pin 9 and - to ground on arduino. I am using an LED for development purposes for now because I don't have the lock yet. The code I have now works (stays open) for 8am to 5pm through the whole week but i want the door locked for Saturdays and Sundays. This is my code so far:</p> <pre><code>#include &lt;Time.h&gt; #define doorPin 9 void setup() { // put your setup code here, to run once: pinMode(doorPin, OUTPUT); // Connected to relay to activate the door lock setTime(10,1,1,6,7,2014); } void loop() { if (hour()&gt;=8 &amp;&amp; hour()&lt;=17){ digitalWrite(doorPin, HIGH); } else if (weekday()==1 || weekday()==7){ digitalWrite(doorPin, LOW); } </code></pre>
<p>Adding to Annonomus Penguin's answer, it might be cleaner and easier to understand if you extract the variable:</p> <pre><code>bool doorOpen = ( (hour()&gt;=8 &amp;&amp; hour()&lt;=17) &amp;&amp; !(weekday()==1 || weekday()==7) ); </code></pre> <p>Or in my eyes even nicer if you unnegate the last part, ymmv:</p> <pre><code>bool doorOpen = ( (hour()&gt;=8 &amp;&amp; hour()&lt;=17) &amp;&amp; (weekday()!=1 &amp;&amp; weekday()!=7) ); </code></pre> <p>And then use them directly in the code without the if statement:</p> <pre><code>digitalWrite( doorPin, doorOpen ? HIGH : LOW ); </code></pre> <p>This way you make sure that the doorPin always gets set and you din't forget a path like in your if-elseif-nothing version.</p> <p>Another benefit is you can test independently if the doorOpen variable is correct and if the functionality that is triggered by it is correct.</p>
3210
|wifi|flash|
Error building Arduino WiShield Flash example: 'dflash' was not declared in this scope
2014-07-07T01:10:25.670
<p>I'm using WiShield library from: <a href="https://github.com/jcmuller/WiShield" rel="nofollow">https://github.com/jcmuller/WiShield</a></p> <p>What is wrong with this library?</p> <p>The code:</p> <pre><code>/* * Web Server using Flash * * A simple web server example using the WiShield 2.0 * that reads the manufacturing ID from the Flash and * displays it on a webpage. */ #include &lt;WiShield.h&gt; #include &lt;dataflash.h&gt; #define WIRELESS_MODE_INFRA 1 #define WIRELESS_MODE_ADHOC 2 #define FLASH_SLAVE_SELECT 7 #define WIFI_SLAVE_SELECT 10 // Wireless configuration parameters ---------------------------------------- unsigned char local_ip[] = {192,168,1,2}; // IP address of WiShield unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local network const prog_char ssid[] PROGMEM = {"ASYNCLABS"}; // max 32 bytes unsigned char security_type = 0; // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2 // WPA/WPA2 passphrase const prog_char security_passphrase[] PROGMEM = {"12345678"}; // max 64 characters // WEP 128-bit keys // sample HEX keys prog_uchar wep_keys[] PROGMEM = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, // Key 0 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 1 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // Key 2 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // Key 3 }; // setup the wireless mode // infrastructure - connect to AP // adhoc - connect to another WiFi device unsigned char wireless_mode = WIRELESS_MODE_INFRA; unsigned char ssid_len; unsigned char security_passphrase_len; //--------------------------------------------------------------------------- unsigned char mfg_id[4]; void setup() { initShield(); } // This is the webpage that is served up by the webserver const prog_char webpage[] PROGMEM = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n" "&lt;html&gt;&lt;body style=\"margin:100px\"&gt;" "&lt;center&gt;" "&lt;h1&gt;Flash Mfg ID: 000 000 000&lt;/h1&gt;" "&lt;form method=post action=\"/upload\" enctype=\"multipart/form-data\"&gt;" "&lt;b&gt;FS Image Upload&lt;/b&gt;" "&lt;p&gt;" "&lt;input type=file name=i size=40&gt; &amp;nbsp; &lt;input type=submit value=\"Upload\"&gt;" "&lt;/form&gt;" "&lt;/center&gt;" "&lt;/body&gt;&lt;/html&gt;"; void loop() { dflash.read_id(mfg_id); WiFi.run(); } void initShield() { // there is some contention on the SPI between the flash and wifi chip, // so disable both devices at the beginning until they are properly // initialized by their respective libraries pinMode(FLASH_SLAVE_SELECT, OUTPUT); digitalWrite(FLASH_SLAVE_SELECT, HIGH); pinMode(WIFI_SLAVE_SELECT, OUTPUT); digitalWrite(WIFI_SLAVE_SELECT, HIGH); // now init dataflash dflash.init(FLASH_SLAVE_SELECT); // now init wifi WiFi.init(); } </code></pre>
<p>I doubt anything is wrong with the library, but in your initShield and loop methods you refer to a variable called 'dflash' which does not seem to be defined anywhere. </p>
3230
|arduino-uno|programming|interrupt|hardware|
What is causing my Uno to wake up?
2014-07-08T18:16:47.457
<p>NOTE: this code was working perfectly fine in another program.</p> <p>I have a simple piece of code that puts the Arduino to sleep. When it is finished and intergrated into my project, it will only wake the processor up when an alarm from an external RTC triggers one of the hardware interrupts.</p> <pre><code>#include &lt;avr/sleep.h&gt; #include &lt;avr/power.h&gt; void setup(){ Serial.begin(9600); } void loop(){ set_sleep_mode(SLEEP_MODE_PWR_DOWN); //deep sleep mode Serial.println("Device is going to sleep..."); sleep_enable(); //put device to sleep sleep_disable(); //Device restarts here on wake Serial.println("Device is awake..."); delay(1000); //to slow down serial output } </code></pre> <p>In theory, the program should shut down the processor indefinitely because there is nothing available to wake it up.</p> <p>However, the device continues waking itself up immediately after shutting down.</p> <p>I have tried attaching the interrupts hoping it was some kind of anomalous watch-dog function. I have tried tying the interrupt pins to +5V and also (in a separate attempt) to GND. Nothing has helped.</p> <p>What is causing the processor (and/or program) to constantly wake itself up?</p>
<p><code>sleep_enable()</code> <em>allows</em> the MCU to sleep, but it does not <em>cause</em> it to sleep. Call <code>sleep_cpu()</code> after enabling.</p>
3239
|serial|arduino-leonardo|time|
Arduino Leonardo timing Inconsistency
2014-07-09T19:42:51.387
<p>I've got a question regarding the use of Millis() on a Leonardo Arduino. I'm currently using it to time 4 seconds elapsed while sending a serial message every second. These messages play a sound. On the fourth message the sound is different to signify that the Arduino has started an event. </p> <p>I'm running into an issue where the sounds are <strong>occasionally</strong> being played sporadically without a consistent 1 second between them. I'm wondering if there is a better way of doing what I'm doing? During the timing the Arduino is doing nothing else, and the receiving computer is also generally not doing anything taxing. Is this even an issue from the Arduino side? My receiving program is written in C# using System.IO.Ports.SerialPort. </p> <p>The reason this is done through Arduino is because the event started by the Arduino needs to correspond exactly to the sounds, though if this remains unresolved I will need to rework this. </p> <p>Edit: Code as requested.</p> <pre><code>void setup() { //Setup Code } void loop() { //Code that handles other serial messages and various states if (isSpecificState == true) onSpecificState(); } void onSpecificState() { //Setup to handle state long holdStart = millis(); long holdDuration = 0; boolean print1 = false; boolean print2 = false; boolean print3 = false; boolean print4 = false; while(holdDuration &lt;= 4000) { if (holdDuration &gt;= 4000 &amp;&amp; !print4) { Serial.println("tt_sound:2"); print4 = true; } else if (holdDuration &gt;= 3000 &amp;&amp; !print3) { Serial.println("tt_sound:1"); print3 = true; } else if (holdDuration &gt;= 2000 &amp;&amp; !print2) { Serial.println("tt_sound:1"); print2 = true; } else if (holdDuration &gt;= 1000 &amp;&amp; !print1) { Serial.println("tt_sound:1"); print1 = true; } holdDuration = millis() - holdStart; } //Handle state } </code></pre> <p>As I mentioned in the comments, the Arduino is doing nothing else while the timing is happening. </p>
<p><strong>Thoughs:</strong> Unfortunately I have been unable to get to the bottom of this issue. I noticed the problem tends to happen the first time the interaction starts after the computer and Arduino are idle. </p> <p>Without knowing too much about how the serial communication is built I'm guessing that without traffic the connection is put to sleep, or generally inactive, and the sound delay is a result of the connection needing to re-initialize or something of that nature. I cant recall a time when the issue occurred and I had a recent correct previous interaction. Once it works any immediate retrial will also behavior correctly.</p> <p><strong>Solution:</strong> I have since moved my timing/sound playing component within my C# app. The Arduino now signals the start of the timer, and then end of the timer with an immediate start to my event.</p>
3243
|arduino-uno|library|arduino-leonardo|remote-control|ir|
Why PIN3 stays at 1v3 in a IR emitter project?
2014-07-10T07:27:07.787
<p>Here is my very simple IR emitter circuit. OSI5FU5111C-40 is an infrared LED.</p> <p><img src="https://i.stack.imgur.com/0Qaqn.jpg" alt="enter image description here"></p> <p>I am using the IRremote library from <a href="https://github.com/shirriff/Arduino-IRremote" rel="nofollow noreferrer">here</a> in this simple sketch,</p> <pre><code>#include &lt;IRremote.h&gt; unsigned int raw[100]={... *SOME RAW SIGNAL* ...}; IRsend irsend; void setup() { Serial.begin(9600); } void loop() { if (Serial.read() != -1) { for (int i = 0; i &lt; 3; i++) { Serial.print("Start sending ..."); irsend.sendRaw(raw, 100, 38); delay(40); } } } </code></pre> <p>The problem is when I send <code>1</code> to serial monitor,</p> <p>it outputs triple <code>Start sending ...</code> and LED emits no signal. </p> <p>So I test the voltage between PIN3 and GND before and after sending the <code>1</code>. The voltage stays around 1V3.</p> <p>Would someone please give me some advice? Thank you! </p>
<p>A few things. As somebody else suggested, try a normal red LED and make sure that works first.</p> <p>Note that your resistor is allowing too much current through the LED. A high-current LED might tolerate 20 mA (thousandths of an amp.) With a 47 ohm resistor, you're pumping 5/47, or about 106 mA into the LED, which is likely more than 5 times what it is designed to handle. You will quickly burn out your LED. You should use a 270 ohm resistor instead.</p> <p>Also try just setting pin 3 to an output with this line:</p> <pre><code>pinMode(3, OUTPUT); </code></pre> <p>And then manually setting that pin to on:</p> <pre><code>digitalWrite(3, 1); </code></pre> <p>If the LED lights up, you know the pin is working correctly. Then use the code you posted with the same setup, and make sure your LED flashes. If THAT works, try putting your IR LED back in the circuit. </p>
3244
|arduino-uno|arduino-ide|android|
How does one build a door motion sensor project with Arduino Uno board to send alerts to an Android Phone?
2014-07-10T11:25:16.007
<ol> <li>What are the materials I will need for the project? We want the project to work like this: When the door is opened, we get an alert to our Android Phone. </li> <li>What is the circuit structure going to look like?</li> <li>Which is simpler, GPRS, Bluetooth or Wifi to get the alert?</li> <li>What is the best IDE to work on for this project?</li> </ol>
<p>If I could comment on this, I would say that this question really sounds like you haven't actually done any research to look into a solution.</p> <p>But, in simple terms:</p> <ol> <li>Arduino Uno, Android phone, GSM shield, contact sensor or limit switch</li> <li>The sensor or switch needs to be connected to an I/O pin on the Arduino, and will probably need to be connected to 5V.</li> <li>GSM(GPRS) is going to provide the most mobility</li> <li>Arduino</li> </ol>
3248
|led|interrupt|threads|
Multiple independent LED patterns
2014-07-10T19:03:41.753
<p>I have an problem, which at first thoughts (and being new to Arduino) I though was a perfect application for an Arduino. However, after trying and failing to implement it I am doubting myself!</p> <p>Simply - I need to control many LEDs independently, many of which will have their own individual patterns - for example "5 seconds on - 5 seconds off". "continuous flashes" - or sequences such as "2 flashes, pause, 1 flash". Obviously without the luxury of threads I am becoming a little unstuck. Be great to hear if a) Arduino is the best choice and b) if it is - how can I go about this!</p> <p>Thanks in advance :)</p>
<p>I know the post is old, but I checked the example with the array based approach and in my opinion:</p> <pre><code>sizeof(led_timing[i])/sizeof(led_timing[i][0]) </code></pre> <p>will always yield the allocated size (number of elements) of the array - in this case 10. So the timing won't restart until you reached the "end" of the array, using undefined elements. For LED "0":</p> <pre><code>int led_timing[0][10]: 5000,5000, &lt;undefined&gt;, &lt;undefined&gt;, &lt;undefined&gt;, &lt;undefined&gt;, &lt;undefined&gt;, &lt;undefined&gt;, &lt;undefined&gt;, &lt;undefined&gt; </code></pre> <p>Greetings Tommy</p>
3254
|uploading|
Problem uploading big program to arduino
2014-07-11T01:31:49.590
<p>I have an arduino duemilanove with ATmega328.</p> <p>Been doing several experiments with multiple peripherals</p> <p>I had no problem uploading at all</p> <p>But when i try to upload a big program (27,074 bytes (of a 30,720 byte maximum)) it compiles fine, then says uploading...</p> <p>After some time passes i get this error</p> <pre><code>avrdude: stk500_getsync(): not in sync: resp=0x00 </code></pre> <p>The board and serial port connections are fine. Any ideas?</p> <p>PS: Then i tried to upload the blink example, but i get the same error for some reason Everything worked fine before i uploaded my "big" program</p>
<p>The sync error is a common issue that doesn't have one simple solution (as shown <a href="https://arduino.stackexchange.com/questions/17/some-dude-named-avr-wont-let-me-upload-my-program-aka-avrdude-stk500-getsync">here</a>)</p> <p>It means that the computer can't communicate with the processor, but it recognizes that it's there (out of sync). This is probably due to something (a peripheral, stray wire) interfering with the transmission from computer to device.</p> <p>Solutions that have worked in the past:</p> <ul> <li>Unplugging the Arduino for 30 seconds, then plugging it back in.</li> <li>Removing any wires connected to Rx and Tx pins during upload.</li> <li>Soldering components connected to Rx or Tx to the board (in this case, I was using a shield that allowed me to do this)</li> </ul> <p>There are lots of solutions available from different sources on the internet, but I have not come across one that names program size as the reason.</p>
3255
|arduino-mega|bootloader|firmware|
How do I install the firmware on an Arduino Mega clone?
2014-07-11T03:56:57.230
<p>I have a brand new board which is a clone of the Mega2560. I need to install the USB firmware on the 16U2 and the bootloader on the 2650 chip. I have Atmel Studio and a JTAGICE-3. Using those, I can download HEX files compiled with the Arduino IDE, and they run successfully. </p> <p>But I'm having trouble finding Mega-specific instructions for getting the firmware installed so that I can use the Arduino ISP protocol for downloading new sketches. I can find much more information about the Uno than the Mega. And much of the information I do find seems to be dated.</p> <p>1) Which are the right files to download?<br> I've tried to install the 'MEGA-dfu_and_usbserial_combined.hex' to the 16U2 and the 'stk500boot_v2_mega2560.hex' to the 2560. </p> <p>But the IDE won't connect via AVR ISP, and I get no serial communications from a serial sample sketch downloaded with the ICE.</p> <p>2) What are the correct Fuse settings after I flash those files?</p> <p>3) Is there a good way to confirm that the 16U2 USB converter is working correctly in isolation from the 2560 chip?</p>
<p>Let focus on one thing at a time, that is flashing the 16u2. You can see if you've successfully done that when you can see the Arduino in your device-manager.</p> <p>First of, <code>MEGA-dfu_and_usbserial_combined.hex</code> is, as stated on the github page, for the 8u2, not the 16u2. Since you already have a ISP programmer you don't need the dfu functionality. You can just flash the precompiled <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/firmwares/atmegaxxu2/arduino-usbserial/Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex" rel="nofollow">Arduino-usbserial-atmega16u2-Mega2560-Rev3.hex</a> file.</p> <p>The fuses can also be found in the <a href="https://github.com/arduino/Arduino/tree/master/hardware/arduino/firmwares/atmegaxxu2" rel="nofollow">readme.txt on github</a>: <code>-U lfuse:w:0xFF:m -U hfuse:w:0xD9:m -U efuse:w:0xF4:m -U lock:w:0x0F:m</code>. I don't see any difference in the fuses between the 8u2 and 16u2, so they should work for the 16u2 too.</p> <p>Hope this helps.</p>
3260
|arduino-uno|serial|mac-os|
No valid serial ports for Arduino UNO on Mac
2014-07-11T14:48:26.100
<p><strong>UPDATE:</strong> The issue turned out to be with my work laptop. Our IT department has them configured in such a way that the assignment of serial ports is different somehow. When I plugged in on my personal Macbook Pro it all worked perfectly.</p> <hr> <p>I just got my first Arduino. Its an UNO R3. I'm running OS X 10.8.5 (Mountain Lion) and the Arduino IDE 1.0.5</p> <p>Under <strong>Tools>Board</strong> I have Arduino Uno selected</p> <p>Under <strong>Tools>Serial</strong> Port my options are:</p> <ul> <li>/dev/tty.Bluetooth-Serial-1</li> <li>/dev/cu.Bluetooth-Serial-1</li> <li>/dev/tty.Bluetooth-Serial-2</li> <li>/dev/cu.Bluetooth-Serial-2</li> <li>/dev/tty.Bluetooth-Modem</li> <li>/dev/cu.Bluetooth-Modem</li> <li>/dev/tty.Bluetooth-PDA-Sync</li> <li>/dev/cu.Bluetooth-PDA-Sync</li> </ul> <p>I've tried all of them, but when I try to upload a sketch it fails. Most give the following error:</p> <pre><code>avrdude: stk500_recv(): programmer is not responding </code></pre> <p>The two "modem" options return this message:</p> <pre><code>Serial port '/dev/tty.Bluetooth-Modem' already in use. Try quitting any programs that may be using it. </code></pre> <p>I'm at a loss. None of these serial ports seems correct but there aren't any other options.</p> <p>Also under <strong>Tools>Programmer</strong> which option should I be using?</p>
<p>The issue turned out to be with my work laptop. Our IT department has them configured in such a way that the assignment of serial ports is different somehow. When I plugged in on my personal Macbook Pro it all worked perfectly.</p>
3264
|uploading|arduino-pro-mini|
Is it possible to program a few Arduinos at the same time?
2014-07-11T17:19:22.477
<p>I have 10 Arduino Pro Minis and one Arduino Uno. Via breadboard, if I connect Pro Minis in parallel, can I program all of them at same time?</p> <p>Is it possible?</p>
<p>In this case I would recommend considering using multiple USB-to-Serial Ports and simply replacing the ".\arduino-1.5.6-r2\hardware\tools\avr\bin\avrdude.exe" with a batch file that then called 10 (or any number of Serial Ports) of your choice.</p> <hr> <p>I would recommend reading my answer from <a href="https://stackoverflow.com/questions/24688215/programming-arduinos-from-a-centralized-location/24688854#24688854">Programming Arduino's from a centralized location</a>.</p> <p>Where that solution may be a bit more complicated, then needed. But the same pieces would allow you to create a custom programmer that can specifically call the custom avrdude. Allowing the original methods to still exist.</p> <hr> <p>Additionally worth noting. Is that you can turn on verbose for the compiling and uploading from the IDE's preferences. This will display the temporary directory that contains the exact location of the bin file and command executed to upload. Which can then be easily re-executed your convenience. Noting the temporary directory is not immediately destroyed. Where you can also change the arguments to execute different ports and sending it to the background. To call others. So that you can simultaneously upload many devices. </p>
3269
|arduino-uno|
What purpose does the yellow and green LEDs have on the Arduino?
2014-07-12T13:31:11.143
<p>I have wired up a small project with a shift register (see below), but depending on how I put the <a href="http://www.ti.com/lit/ds/symlink/sn74hc595.pdf" rel="nofollow noreferrer">74HC595</a> IC (8-bit shift register with 3-state output register), the green and yellow LEDs of the Arduino stop shining.</p> <p>What are these LEDs for? Do they tell something about a possible damage of the IC/short circuit in the setup?</p> <p><img src="https://i.stack.imgur.com/juRGS.jpg" alt="Enter image description here"></p>
<p>Just wanted to re-iterate that On the MEGA 2560 Revision 3 you can't change the L led pin 13 due to the op-amp like Nick Reported. </p> <p>Spent a couple hours on this scratching my head only to find this out</p>
3270
|wifi|xbee|rf|
Whats the difference between RF options (wifi, xbee, NRF24L01)
2014-07-12T13:31:50.530
<p>When doing RF, you have many options. Three of the most basic are in the title box</p> <ol> <li>WiFi</li> <li>Xbee</li> <li>NRF24L01</li> </ol> <p>What are the practical differences in using them. What is the purpose of each other and the pros and cons. What would you use depending on the application you had?</p> <p>I do not have a project in mind, but i want to start learning about Rf. I searched ebay for wireless devices. but i couldnt understand the differences. My goal is simply learning</p>
<p>There are many different type of RF networks with various advantages and disadvantages. The main things I consider when choosing a wireless communication method are network topology, data rate and power consumption.</p> <p><strong>WiFi:</strong></p> <p>High data rate (54Mbit/s +) but also high power consumption. Used when you need to connect directly to the internet, such as an internet-of-things device, and have an external power source.</p> <p><strong>XBee:</strong></p> <p>Low data rate (250kbit/s) and low power consumption. Used to make mesh-type sensor networks; each XBee device can communication with each other, and <em>through</em> each other via the mesh to devices that are out of range. Used for networks of devices, particular home automation and sensors. <a href="https://en.wikipedia.org/wiki/Xbee">link</a>.</p> <p><strong>Bluetooth:</strong></p> <p>Medium data rate and medium power consumption. IEEE standard has different device profiles to enable interoperability between devices. 'Pairing' type network however, so not useful for sensor networks, but good for controlling devices using a laptop or phone which usually have Bluetooth on board. Communicates with Arduino via serial RX and TX pins. <a href="https://en.wikipedia.org/wiki/Bluetooth">link</a>.</p> <p><strong>Bluetooth Low Energy, ANT, etc:</strong></p> <p>Very low data rate and very low power. These RF chips can run for years on an AA battery and so are used for things like heart rate sensors. The data rate is quite low so only good for transferring a small amount of data such as sensor readings. Most devices are setup as peripherals and can only connect to one 'central' device, so no good for sensor networks. Bluetooth low energy is supported by the latest mobile phones and laptops however. Useful to enable control of a device using a phone or laptop, for example a LED lamp. (See redbearlab for some Arduino options)</p> <p><strong>GSM</strong></p> <p>Phone connection. TODO</p> <p><strong>nRF24L01</strong> <strong>/</strong> <strong>RFM12B</strong> <strong>/</strong> <strong>RFM22B(SI4432)</strong></p> <p>Popular proprietary transceivers. They can connect via SPI and have a lot of fancy features like low power modes, multiple channels, channel hopping, frequency calibration, CRC, retransmit and so on. The nRF24L01 from Nordic Semiconductor <a href="http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01">link</a> operates in the 2.4GHz band, others use the ISM band 433/470/868/915Mhz. These are todays state of the art highly integrated and low cost hardware for reliable telemetry and consumer applications. The range is between 10m and 150m. The SI4432/RFM22B has the range of about 1.5Km.</p> <p><strong>Other RF modules</strong></p> <p>Simple and cheap serial devices. Single transmitter/receiver or transceiver that operate in the ISM band <a href="https://en.wikipedia.org/wiki/ISM_band">link</a>. Often used as garage door opener. Useful for sensor network where interoperability with other devices is not required and you can implement your own protocol. <a href="https://en.wikipedia.org/wiki/RF_module">link</a> </p>
3280
|arduino-uno|
Any problems taking arduino(esque) devices through airport security?
2014-07-13T00:55:09.533
<p>I'm flying out for vacation, and I want to take some of my half-done arduino projects with me to work on. I'm concerned that aiprort security might mistake my devices for something sinister or at bare minimum 'suspicious' and be confiscated. </p> <p>Has anyone ever had any negative experiences taking arduino-esque wiring projects through airport security? </p>
<p>Real world example:</p> <p>I have just flown from JFK - New York to GRU - Sao Paulo (Brazil) (October 2016) with this 'RIAspire UNO R3 Master Beginner Starter Kit for Arduino DIY Discovery - 25 Sensors with RFID, Ultrasonic, Temperature, HC 05 Bluetooth, ESP8266 Wifi' on my hand luggage.</p> <p>There were a lot of wires, detectors and everything.</p> <p>Nothing happened.</p>
3286
|rf|arduino-pro-micro|
nRF24L01+ (RF24) radio with Arduino Micro
2014-07-13T15:57:58.720
<p>I purchased several nRF24L01+ (RF24) radios to use with my Arduino Uno and Micro.</p> <p>Using the <a href="http://maniacbug.github.io/RF24/GettingStarted_8pde-example.html" rel="nofollow noreferrer">GettingStarted</a> sketch and nRF24L01+ connected to my Uno, I get nice debugging info in my serial monitor. However when I connect the nRF24L01+ to my Micro, upload the sketch and open the serial monitor I get no debugging information. There is no info displayed in the serial monitor.</p> <p>Also the Arduino Uno when set to Transmit, does not see the other nRF24L01+. Any help would be appreciated.</p> <p>Here is my pinout to connect the nRF24L01+ to the Micro:</p> <pre><code>Line From Arduino Pin To nRF24L01+ GND GND 1 3V3 3V3 2 CE 9 3 CSN 10 4 SCK SCK 5 MOSI MOSI 6 MISO MISO 7 </code></pre> <p>Here the nRF24L01+</p> <p><img src="https://i.stack.imgur.com/VkpaI.jpg" alt="Nrf24L01+"></p> <p>Sketch</p> <pre><code>/* Copyright (C) 2011 J. Coliz &lt;maniacbug@ymail.com&gt; This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. */ #include &lt;SPI.h&gt; #include "nRF24L01.h" #include "RF24.h" #include "printf.h" // // Hardware configuration // // Set up nRF24L01 radio on SPI bus plus pins 9 &amp; 10 RF24 radio(9,10); // // Topology // // Radio pipe addresses for the 2 nodes to communicate. const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL }; // // Role management // // Set up role. This sketch uses the same software for all the nodes // in this system. Doing so greatly simplifies testing. // // The various roles supported by this sketch typedef enum { role_ping_out = 1, role_pong_back } role_e; // The debug-friendly names of those roles const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"}; // The role of the current running sketch role_e role = role_pong_back; void setup(void) { // // Print preamble // Serial.begin(57600); printf_begin(); printf("\n\rRF24/examples/GettingStarted/\n\r"); printf("ROLE: %s\n\r",role_friendly_name[role]); printf("*** PRESS 'T' to begin transmitting to the other node\n\r"); // // Setup and configure rf radio // radio.begin(); // optionally, increase the delay between retries &amp; # of retries radio.setRetries(15,15); // optionally, reduce the payload size. seems to // improve reliability radio.setPayloadSize(8); // // Open pipes to other nodes for communication // // This simple sketch opens two pipes for these two nodes to communicate // back and forth. // Open 'our' pipe for writing // Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading) if ( role == role_ping_out ) { radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]); } else { radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipes[0]); } // // Start listening // radio.startListening(); // // Dump the configuration of the rf unit for debugging // radio.printDetails(); } void loop(void) { // // Ping out role. Repeatedly send the current time // if (role == role_ping_out) { // First, stop listening so we can talk. radio.stopListening(); // Take the time, and send it. This will block until complete unsigned long time = millis(); printf("Now sending %lu...",time); bool ok = radio.write( &amp;time, sizeof(unsigned long) ); if (ok) printf("ok..."); else printf("failed.\n\r"); // Now, continue listening radio.startListening(); // Wait here until we get a response, or timeout (250ms) unsigned long started_waiting_at = millis(); bool timeout = false; while ( ! radio.available() &amp;&amp; ! timeout ) if (millis() - started_waiting_at &gt; 200 ) timeout = true; // Describe the results if ( timeout ) { printf("Failed, response timed out.\n\r"); } else { // Grab the response, compare, and send to debugging spew unsigned long got_time; radio.read( &amp;got_time, sizeof(unsigned long) ); // Spew it printf("Got response %lu, round-trip delay: %lu\n\r",got_time,millis()-got_time); } // Try again 1s later delay(1000); } // // Pong back role. Receive each packet, dump it out, and send it back // if ( role == role_pong_back ) { // if there is data ready if ( radio.available() ) { // Dump the payloads until we've gotten everything unsigned long got_time; bool done = false; while (!done) { // Fetch the payload, and see if this was the last one. done = radio.read( &amp;got_time, sizeof(unsigned long) ); // Spew it printf("Got payload %lu...",got_time); // Delay just a little bit to let the other unit // make the transition to receiver delay(20); } // First, stop listening so we can talk radio.stopListening(); // Send the final one back. radio.write( &amp;got_time, sizeof(unsigned long) ); printf("Sent response.\n\r"); // Now, resume listening so we catch the next packets. radio.startListening(); } } // // Change roles // if ( Serial.available() ) { char c = toupper(Serial.read()); if ( c == 'T' &amp;&amp; role == role_pong_back ) { printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r"); // Become the primary transmitter (ping out) role = role_ping_out; radio.openWritingPipe(pipes[0]); radio.openReadingPipe(1,pipes[1]); } else if ( c == 'R' &amp;&amp; role == role_ping_out ) { printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r"); // Become the primary receiver (pong back) role = role_pong_back; radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipes[0]); } } } </code></pre>
<p>Of course, <code>9</code> means <code>D9</code> and not <code>A9</code>.</p> <p>Everytime Arduino projects assign a pin with no prefix, it is denoted as data I/O and if the Analog pins are used then it would say <code>A9</code>.</p> <p>The nRF24L01 handles data I/O and not analog input.</p>
3295
|bootloader|arduino-nano|
Arduino Nano not responding with yellow led blinking fast
2014-07-14T11:50:21.537
<p><strong><em>Update</strong>: I started playing with a genuine Deumilanove and exactly same problem happened to it - d13 led blinking, but avrdude says <code>stk500_recv(): programmer is not responding</code></em></p> <p>I uploaded a largish sketch ~15kb to Arduino Nano v3.0 (clone) and that left the board in an unusable state. When connected to USB, a power LED goes on immediately and 1-2 seconds later the yellow "L" starts blinking really fast. <a href="http://www.ebay.com/itm/161091236453" rel="noreferrer">Here's the board I use</a>, it's a cheap clone, but it worked really well before today.</p> <p>Now, when I try to upload a new sketch I get an error:</p> <pre><code>avrdude: stk500_recv(): programmer is not responding </code></pre> <p>I tried making and ISP programmer out of genuine Duemilanove, using <a href="http://letsmakerobots.com/content/make-arduino-isp-programmer" rel="noreferrer">nano's ISP pins</a> and tried following <a href="http://arduino.cc/en/Tutorial/ArduinoISP" rel="noreferrer">official instructions</a> (didn't use any capacitors/resistors). Either way when I click "Burn Bootloader" result is the same error:</p> <pre><code>avrdude: stk500_getsync(): not in sync: resp=0x15 </code></pre> <p>I have connected "debug" leds to D7,8,9 and heartbeat fades in and out in idle, others stay dark. When I click "Burn Bootloader" all leds go dark then it does few quick blinks on 7, then similar pattern for 8, and then heartbeat resumes. Sometimes this sequence is repeated twice.</p> <p>I also tried editing preferences.txt to bypass bootloader, but that didn't help.</p> <p><strong>How do I restore this board or do a low level reset?</strong> It seems to be in some failure mode, with pin 13 oscillating, but I don't know what that means.</p>
<p>Try changing processor type to ATmega328(old bootloader) in Tools->Processor. My Nano board blinked led like it had bootloader but I couldn't upload sketch and that helped.</p>
3297
|wifi|gsm|
Arduino stacking wifi and gsm shield
2014-07-14T13:57:59.687
<p>I'm fairly new to this and I need some help before I buy anything...</p> <p>If I understand correctly I can buy an arduino, couple of shields and just stack them one onto another if they are compatible...</p> <p>I'll be doing some work with an arduino and I would need both WiFi and GSM shields but I'm not sure if they're compatible... On the arduino.cc I saw that they both use pin 7 (GSM as modem reset and WiFi as "handshake") </p> <p>Is there any way I can use both of the shields even though they use the same pin?</p> <p>Thanks</p>
<p>If you will be using Wi-Fi, instead of buying a Wi-Fi shield and a GSM shield, simply buy an Arduino Yún (which will substitute the Arduino and WiFi shield) and connect the GSM shield to it.</p> <p>From <a href="https://www.arduino.cc/en/Guide/GSMShieldLeonardoMega" rel="nofollow noreferrer">How to use the Arduino GSM shield with Arduino Leonardo, Arduino Yun, and Arduino Mega</a>, it shows you how to connect the Arduino Yún with a GSM shield and to use them without any problem with the help of jumper.</p>
3300
|power|battery|
Autonomous Quadcopter power distribution and sensing concerns
2014-07-14T16:25:46.567
<p>I've been programming and testing an Arduino based quadcopter for the past 4 months. Until now I did not need to use an external power source for my sensors. Now I want to use the 'BEC' power from my electronics speed controllers.</p> <p>Each of the 4 ESCs gives 5V @ 2A. I would set these up in a parallel circuit, which would give me 5V @ 8A (theoretically).</p> <p>I also want to use a cheap chinese voltage sensor to sense the voltage from my 5000mAh 25-50c 11.1v battery. I'm not sure if it is safe to connect my batteries wires to my sensor with the 125A that it can put out.</p> <p>My question is whether or not it is safe to have a common ground on Arduino with an 8A power supply AND if it is safe to use a 5V 8A power supply with these sensors.</p> <p>Here is a problem that I've encountered before:</p> <p>while powering my IMU off the BEC and sending motor PWM signals, my sketch would run for about 10 seconds then freeze. It was not until I powered my IMU off the Arduinos 5V power that I was able to run the sketch flawlessly. What could have been causing that?</p> <p>I've made a diagram of my circuit in Fritzing (not actually tested yet due to fear of ruining my sensors). I'm using an Arduino Mega.</p> <p><img src="https://i.stack.imgur.com/ZLogT.jpg" alt="Fritzing diagram"></p>
<p>Your question is quite long. I've broken it up into several parts:</p> <blockquote> <p>whether or not it is safe to have a common ground on arduino with an 8 amp power supply </p> </blockquote> <p>Yes. In fact, if you have any electrical connection (even a signal) between those two, you'll <em>need</em> a common ground to ensure integrity of the data being sent.</p> <blockquote> <p>if it is safe to use a 5 volt 8 amp power supply with these sensors.</p> </blockquote> <p>I didn't see how much they drew. Without a lot of information, I'm going to say <em>yes</em>. If you don't need that much current, consider removing one of them so you only have 6A or 4A, since 8A is quite a bit if you aren't using it (and you might waste electricity in the conversion process). Make sure to have a thick enough wire for it. A best practice scenario would be to use each ESC separately or use two of the ESCs in parallel (with all of the grounds connected!). This would isolate the current to either 4A or 2A.</p> <blockquote> <p>while powering my IMU off the BEC and sending motor PWM signals my sketch would run for about 10 seconds then freeze. It was not until i powered my IMU off the arduinos 5 volt power that I was able to run the sketch flawlessly. What could have been causing that?</p> </blockquote> <p>I'm not quite sure what would be causing that without seeing the code/circuit for that. The only thing I can think of is the grounds weren't connected and the signal got corrupted.</p>
3308
|serial|uploading|arduino-leonardo|bootloader|robotics|
What's wrong with my undetected, unresponsive Arduino Robot?
2014-07-15T11:14:52.647
<p>I was wondering if someone could try and solve a major problem I've been having with a brand new <a href="http://arduino.cc/en/Main/Robot" rel="nofollow">Arduino Robot</a> (similar to an Arduino Leonardo). Any input would be very much appreciated!</p> <p>I've been working with an Arduino Robot on a summer internship for the last week with no major problems. However, a couple of days ago, it stopped running programs and couldn't be detected when being plugged into the computer.</p> <p>When plugged in or turned on, the LCD turns on with nothing displayed on the screen and the power LED also switches on. However, no program is run (I had a working program involving the LCD uploaded at the time it stopped functioning, which would normally run). Also when plugged in, the Arduino is completely undetected by the computer, with the 'Serial Port' option under Tools grayed out, the device not showing up in device manager, and no signs that a device has been plugged-in. I've tried 3 different USB cables - one of which I tested on another device - and 3 different computers (with Windows 7, 8.1 and Linux Ubuntu installed). On the Linux computer, I ran lsusb before and after plugging in the device and saw no change. I've also tried various solutions such as re-installing the drivers and the Arduino software, using MProg and various rebooting/unplugging-replugging variations.</p> <p>So I think the problem is almost definitely with the Arduino Robot itself. I'll give a little information about the problems I encountered previously, to see whether something I did affected it or not.</p> <p>Problem 1:</p> <p>The first problem I had with the robot was entirely by my own fault and was pretty foolish of me (I'm new to electronics - this being my first project involving it). I ran code from <a href="http://www.dfrobot.com/wiki/index.php?title=Arduino_LCD_KeyPad_Shield_%28SKU:_DFR0009%29" rel="nofollow">this website</a> (the first set of coding on the page) to try and see whether I could get the LCD to work - not realizing that it wouldn't work for a different type of LCD. After uploading the code, the speaker made a loud constant buzzing noise. Fortunately after uploading a different code, the problem was resolved. I'm doubtful that this could have affected the robot, but since I'm so new to this I'll leave it to one of you to decide.</p> <p>Problem 2:</p> <p>The next problem was one to do with uploading. The robot worked fine for a couple of days after the first problem until I came across this one:</p> <p>When uploading programs, there would be a 'device disconnecting' sound from the computer and the program would fail to upload (I can give details on the error messages if you need them). I managed to solve the issue using an odd solution involving hitting the reset button at just the right time while a program was uploading.</p> <p>After this, the robot worked for a few hours. In this time I tried to play with the 'turn' function, which didn't seem to work very well at all (the robot would turn angles very different to the ones given) and started creating programs playing around with the LCD. It was at this point the robot stopped functioning properly.</p> <p>So does anyone have any idea what might be wrong? I have no idea how to fix this problem and I've been trying to find a solution for almost 2 full days now. Any input at all would be greatly appreciated.</p>
<p>This incident exactly happened for me just now. I solved it by upload simple sketch and double click on the reset button (the board will be detected for around 8 seconds. once the sketch uploaded successfully, the board should be fixed that time. </p>
3324
|uploading|arduino-ide|avrdude|avr|mac-os|
Arduino compatible's serial port not showing Mac OSX
2014-07-16T14:45:25.937
<p>I bought an Arduino-compatible Freaduino board atmega8 (I selected the board type as Arduino ng or older atmega8). I installed the Arduino IDE on Mac OS X and the FTDI drivers. But my serial port looks like this when I connect the board:</p> <p><img src="https://i.stack.imgur.com/Qjd7o.png" alt="screenshot 1"></p> <p>And when I try to upload the program, this is the error I get:</p> <p><img src="https://i.stack.imgur.com/w97Vv.png" alt="screenshot 2"></p> <p>Can someone tell me what is the mistake? I am clueless.</p> <p><strong>UPDATE</strong>: the problem was I had not installed the driver properly (I guess). I uninstalled and reinstalled them and it worked perfectly. Also made a YouTube tutorial regarding the same. <a href="http://youtu.be/BwatajQO_88" rel="noreferrer">http://youtu.be/BwatajQO_88</a></p>
<p>If you still have problems, like me after following the above, this might help: From this thread: <a href="http://forum.arduino.cc/index.php?topic=292284.msg2229300#msg2229300" rel="nofollow">http://forum.arduino.cc/index.php?topic=292284.msg2229300#msg2229300</a></p> <blockquote> <p>the problem is in the spaces of the device name. To fix that you have to manually edit two (2) txt files of the arduino installation.</p> <p>Go where you have installed it. In my case the path is:</p> <p>/Users/MY_USERNAME/Downloads/Arduino.app/Contents/Java/hardware/arduino/avr</p> <p>Inside this directory you can see files platform.txt &amp; programmers.txt.</p> <p>Inside these files replace -P{serial.port} with "-P{serial.port}". So you simply have to add the quotes.</p> </blockquote> <p>Then restart.</p>
3331
|arduino-uno|
error: redefinition of ' '
2014-07-16T19:35:27.783
<p>When I am trying to compile the following code,</p> <pre><code>int delayTime = 1; int charBreak = 2.1; #include &lt;MemoryFree.h&gt; int rled1 = 1; int rled2 = 2; int rled3 = 3; int rled4 = 4; int rled5 = 5; int gled1 = 6; int gled2 = 7; int gled3 = 8; int gled4 = 9; int gled5 = 10; int bled1 = 11; int bled2 = 12; int bled3 = 13; int bled4 = 14; int bled5 = 15; void setup() { Serial.begin(9600); } int ra[] = {4,288,18464,288,4}; int ga[] = {2,144,9232,144,2}; int ba[] = {1,72,4616,72,2}; int rb[] = {18724,16644,16644,2080,0}; int gb[] = {9362,8322,8322,1040,0}; int bb[] = {4681,4161,4161,520,0}; int rc[] = {2336,16388,16388,2080,0}; int gc[] = {1168,8194,8194,1040,0}; int bc[] = {584,4097,4097,520,0}; int rd[] = {18724,16388,16388,2336,0}; int gd[] = {9362,8194,8194,1168,0}; int bd[] = {4681,4097,4097,584,0}; int re[] = {18724,16644,16644,16388,0}; int ge[] = {9362,8322,8322,8194,0}; int be[] = {4681,4161,4161,4097,0}; int rf[] = {18724,16640,16640,16384,0}; int gf[] = {9362,8320,8320,8192,0}; int bf[] = {4681,4160,4160,4096,0}; int rg[] = {2336,16388,16420,16416,2084}; int gg[] = {1168,8194,8210,8208,1042}; int bg[] = {584,4097,4105,4104,521}; int rh[] = {18724,256,256,256,18724}; int gh[] = {9362,128,128,128,9362}; int bh[] = {4681,64,64,64,4681}; int ri[] = {0,16388,18724,16388,0}; int gi[] = {0,8194,9362,8194,0}; int bi[] = {0,4097,4681,4097,0}; int rj[] = {32,4,16388,18720,16384}; int gj[] = {16,2,8194,9360,8192}; int bj[] = {8,1,4097,4680,4096}; int rk[] = {18724,256,2080,16388,0}; int gk[] = {9362,128,1040,8194,0}; int bk[] = {4681,64,520,4097,0}; int rl[] = {18724,4,4,4,0}; int gm[] = {9362,2,2,2,0}; int bm[] = {4681,1,1,1,0}; int rm[] = {18724,2304,36,2304,18724}; int gm[] = {9362,1152,18,1152,9362}; int bm[] = {4681,576,9,576,4681}; int rn[] = {18724,2304,36,18724,0}; int gn[] = {9362,1152,18,9362,0}; int bn[] = {4681,576,9,4681,0}; int ro[] = {2336,16388,16388,2336,0}; int go[] = {1168,8194,8194,1168,0}; int bo[] = {584,4097,4097,584,0}; int rp[] = {18724,16640,16640,2048,0}; int gp[] = {9362,8320,8320,1024,0}; int bp[] = {4681,4160,4160,512,0}; int rq[] = {2336,16388,16420,2336,36}; int gq[] = {1168,8194,8210,1168,18}; int bq[] = {584,4097,4105,584,9}; int rr[] = {18724,16640,16672,2052,0}; int gr[] = {9362,8320,8336,1026,0}; int br[] = {4681,4160,4168,513,0}; int rs[] = {2048,16644,16644,32,0}; int gs[] = {1024,8322,8322,16,0}; int bs[] = {512,4161,4161,8,0}; int rt[] = {16384,16384,18724,16384,16384}; int gt[] = {8192,8192,9362,8192,8192}; int bt[] = {4096,4096,4681,4096,4096}; int ru[] = {18720,4,4,18720,0}; int gu[] = {9360,2,2,9360,0}; int bu[] = {4680,1,1,4680,0}; int rv[] = {18432,288,4,288,18432}; int gv[] = {9216,144,2,144,9216}; int bv[] = {4608,72,1,72,4608}; int rw[] = {18688,36,2304,36,18688}; int gw[] = {9344,18,1152,18,9344}; int bw[] = {4672,9,576,9,4672}; int rx[] = {16388,2080,256,2080,16388}; int gx[] = {8194,1040,128,1040,8194}; int bx[] = {4097,520,64,520,4097}; int ry[] = {16388,2080,256,2048,16384}; int gy[] = {8194,1040,128,1024,8192}; int by[] = {4097,520,64,512,4096}; int rz[] = {16420,16644,16644,18436,0}; int gz[] = {8210,8322,8322,9218,0}; int bz[] = {4105,4161,4161,4609,0}; int reos[] = {0,4,0,0,0}; int geos[] = {0,2,0,0,0}; int beos[] = {0,1,0,0,0}; int rque[] = {2048,16420,16640,2048,0}; int gque[] = {1024,8210,8320,1024,0}; int bque[] = {512,4105,4160,512,0}; int rexcl[] = {0,18692,0,0,0}; int gexcl[] = {0,9346,0,0,0}; int bexcl[] = {0,4673,0,0,0}; void displayLine(int line) { int myline; myline = line; if (myline&gt;=16384) {digitalWrite(rled1, HIGH); myline-=16384;} else {digitalWrite(rled1, LOW);} if (myline&gt;=8192) {digitalWrite(gled1, HIGH); myline-=8192;} else {digitalWrite(gled1, LOW);} if (myline&gt;=4096) {digitalWrite(bled1, HIGH); myline-=4096;} else {digitalWrite(bled1, LOW);} if (myline&gt;=2048) {digitalWrite(rled2, HIGH); myline-=2048;} else {digitalWrite(rled2, LOW);} if (myline&gt;=1024) {digitalWrite(gled2, HIGH); myline-=1024;} else {digitalWrite(gled2, LOW);} if (myline&gt;=512) {digitalWrite(bled2, HIGH); myline-=512;} else {digitalWrite(bled2, LOW);} if (myline&gt;=256) {digitalWrite(rled3, HIGH); myline-=256;} else {digitalWrite(rled3, LOW);} if (myline&gt;=128) {digitalWrite(gled3, HIGH); myline-=128;} else {digitalWrite(gled3, LOW);} if (myline&gt;=64) {digitalWrite(bled3, HIGH); myline-=64;} else {digitalWrite(bled3, LOW);} if (myline&gt;=32) {digitalWrite(rled4, HIGH); myline-=32;} else {digitalWrite(rled4, LOW);} if (myline&gt;=16) {digitalWrite(gled4, HIGH); myline-=16;} else {digitalWrite(gled4, LOW);} if (myline&gt;=8) {digitalWrite(bled4, HIGH); myline-=8;} else {digitalWrite(bled4, LOW);} if (myline&gt;=4) {digitalWrite(rled5, HIGH); myline-=4;} else {digitalWrite(rled5, LOW);} if (myline&gt;=2) {digitalWrite(gled5, HIGH); myline-=2;} else {digitalWrite(gled5, LOW);} if (myline&gt;=1) {digitalWrite(bled5, HIGH); myline-=1;} else {digitalWrite(bled5, LOW);} } void displayChar(char c) { if (c == 'ra'){for (int i = 0; i &lt;5; i++){displayLine(ra[i]);delay(delayTime);}displayLine(0);} if (c == 'rb'){for (int i = 0; i &lt;5; i++){displayLine(rb[i]);delay(delayTime);}displayLine(0);} if (c == 'rc'){for (int i = 0; i &lt;5; i++){displayLine(rc2[i]);delay(delayTime);}displayLine(0);} if (c == 'rd'){for (int i = 0; i &lt;5; i++){displayLine(rd[i]);delay(delayTime);}displayLine(0);} if (c == 're'){for (int i = 0; i &lt;5; i++){displayLine(re[i]);delay(delayTime);}displayLine(0);} if (c == 'rf'){for (int i = 0; i &lt;5; i++){displayLine(rf[i]);delay(delayTime);}displayLine(0);} if (c == 'rg'){for (int i = 0; i &lt;5; i++){displayLine(rg[i]);delay(delayTime);}displayLine(0);} if (c == 'rh'){for (int i = 0; i &lt;5; i++){displayLine(rh[i]);delay(delayTime);}displayLine(0);} if (c == 'ri'){for (int it = 0; it &lt;5; it++){displayLine(ri[it]);delay(delayTime);}displayLine(0);} if (c == 'rj'){for (int i = 0; i &lt;5; i++){displayLine(rj[i]);delay(delayTime);}displayLine(0);} if (c == 'rk'){for (int i = 0; i &lt;5; i++){displayLine(rk[i]);delay(delayTime);}displayLine(0);} if (c == 'rl'){for (int i = 0; i &lt;5; i++){displayLine(rl[i]);delay(delayTime);}displayLine(0);} if (c == 'rm'){for (int i = 0; i &lt;5; i++){displayLine(rm[i]);delay(delayTime);}displayLine(0);} if (c == 'rn'){for (int i = 0; i &lt;5; i++){displayLine(rn[i]);delay(delayTime);}displayLine(0);} if (c == 'ro'){for (int i = 0; i &lt;5; i++){displayLine(ro[i]);delay(delayTime);}displayLine(0);} if (c == 'rp'){for (int i = 0; i &lt;5; i++){displayLine(rp[i]);delay(delayTime);}displayLine(0);} if (c == 'rq'){for (int i = 0; i &lt;5; i++){displayLine(rq[i]);delay(delayTime);}displayLine(0);} if (c == 'rr'){for (int i = 0; i &lt;5; i++){displayLine(rr[i]);delay(delayTime);}displayLine(0);} if (c == 'rs'){for (int i = 0; i &lt;5; i++){displayLine(rs[i]);delay(delayTime);}displayLine(0);} if (c == 'rt'){for (int i = 0; i &lt;5; i++){displayLine(rt[i]);delay(delayTime);}displayLine(0);} if (c == 'ru'){for (int i = 0; i &lt;5; i++){displayLine(ru[i]);delay(delayTime);}displayLine(0);} if (c == 'rv'){for (int i = 0; i &lt;5; i++){displayLine(rv[i]);delay(delayTime);}displayLine(0);} if (c == 'rw'){for (int i = 0; i &lt;5; i++){displayLine(rw[i]);delay(delayTime);}displayLine(0);} if (c == 'rx'){for (int i = 0; i &lt;5; i++){displayLine(rx[i]);delay(delayTime);}displayLine(0);} if (c == 'ry'){for (int i = 0; i &lt;5; i++){displayLine(ry[i]);delay(delayTime);}displayLine(0);} if (c == 'rz'){for (int i = 0; i &lt;5; i++){displayLine(rz[i]);delay(delayTime);}displayLine(0);} if (c == 'r!'){for (int i = 0; i &lt;5; i++){displayLine(rexcl[i]);delay(delayTime);}displayLine(0);} if (c == 'r?'){for (int i = 0; i &lt;5; i++){displayLine(rques[i]);delay(delayTime);}displayLine(0);} if (c == 'r.'){for (int i = 0; i &lt;5; i++){displayLine(reos[i]);delay(delayTime);}displayLine(0);} if (c == 'ga'){for (int i = 0; i &lt;5; i++){displayLine(ga[i]);delay(delayTime);}displayLine(0);} if (c == 'gb'){for (int i = 0; i &lt;5; i++){displayLine(gb[i]);delay(delayTime);}displayLine(0);} if (c == 'gc'){for (int i = 0; i &lt;5; i++){displayLine(gc2[i]);delay(delayTime);}displayLine(0);} if (c == 'gd'){for (int i = 0; i &lt;5; i++){displayLine(gd[i]);delay(delayTime);}displayLine(0);} if (c == 'ge'){for (int i = 0; i &lt;5; i++){displayLine(ge[i]);delay(delayTime);}displayLine(0);} if (c == 'gf'){for (int i = 0; i &lt;5; i++){displayLine(gf[i]);delay(delayTime);}displayLine(0);} if (c == 'gg'){for (int i = 0; i &lt;5; i++){displayLine(gg[i]);delay(delayTime);}displayLine(0);} if (c == 'gh'){for (int i = 0; i &lt;5; i++){displayLine(gh[i]);delay(delayTime);}displayLine(0);} if (c == 'gi'){for (int it = 0; it &lt;5; it++){displayLine(gi[it]);delay(delayTime);}displayLine(0);} if (c == 'gj'){for (int i = 0; i &lt;5; i++){displayLine(gj[i]);delay(delayTime);}displayLine(0);} if (c == 'gk'){for (int i = 0; i &lt;5; i++){displayLine(gk[i]);delay(delayTime);}displayLine(0);} if (c == 'gl'){for (int i = 0; i &lt;5; i++){displayLine(gl[i]);delay(delayTime);}displayLine(0);} if (c == 'gm'){for (int i = 0; i &lt;5; i++){displayLine(gm[i]);delay(delayTime);}displayLine(0);} if (c == 'gn'){for (int i = 0; i &lt;5; i++){displayLine(gn[i]);delay(delayTime);}displayLine(0);} if (c == 'go'){for (int i = 0; i &lt;5; i++){displayLine(go[i]);delay(delayTime);}displayLine(0);} if (c == 'gp'){for (int i = 0; i &lt;5; i++){displayLine(gp[i]);delay(delayTime);}displayLine(0);} if (c == 'gq'){for (int i = 0; i &lt;5; i++){displayLine(gq[i]);delay(delayTime);}displayLine(0);} if (c == 'gr'){for (int i = 0; i &lt;5; i++){displayLine(gr[i]);delay(delayTime);}displayLine(0);} if (c == 'gs'){for (int i = 0; i &lt;5; i++){displayLine(gs[i]);delay(delayTime);}displayLine(0);} if (c == 'gt'){for (int i = 0; i &lt;5; i++){displayLine(gt[i]);delay(delayTime);}displayLine(0);} if (c == 'gu'){for (int i = 0; i &lt;5; i++){displayLine(gu[i]);delay(delayTime);}displayLine(0);} if (c == 'gv'){for (int i = 0; i &lt;5; i++){displayLine(gv[i]);delay(delayTime);}displayLine(0);} if (c == 'gw'){for (int i = 0; i &lt;5; i++){displayLine(gw[i]);delay(delayTime);}displayLine(0);} if (c == 'gx'){for (int i = 0; i &lt;5; i++){displayLine(gx[i]);delay(delayTime);}displayLine(0);} if (c == 'gy'){for (int i = 0; i &lt;5; i++){displayLine(gy[i]);delay(delayTime);}displayLine(0);} if (c == 'gz'){for (int i = 0; i &lt;5; i++){displayLine(gz[i]);delay(delayTime);}displayLine(0);} if (c == 'g!'){for (int i = 0; i &lt;5; i++){displayLine(gexcl[i]);delay(delayTime);}displayLine(0);} if (c == 'g?'){for (int i = 0; i &lt;5; i++){displayLine(gques[i]);delay(delayTime);}displayLine(0);} if (c == 'g.'){for (int i = 0; i &lt;5; i++){displayLine(geos[i]);delay(delayTime);}displayLine(0);} if (c == 'ba'){for (int i = 0; i &lt;5; i++){displayLine(ba[i]);delay(delayTime);}displayLine(0);} if (c == 'bb'){for (int i = 0; i &lt;5; i++){displayLine(bb[i]);delay(delayTime);}displayLine(0);} if (c == 'bc'){for (int i = 0; i &lt;5; i++){displayLine(bc2[i]);delay(delayTime);}displayLine(0);} if (c == 'bd'){for (int i = 0; i &lt;5; i++){displayLine(bd[i]);delay(delayTime);}displayLine(0);} if (c == 'be'){for (int i = 0; i &lt;5; i++){displayLine(be[i]);delay(delayTime);}displayLine(0);} if (c == 'bf'){for (int i = 0; i &lt;5; i++){displayLine(bf[i]);delay(delayTime);}displayLine(0);} if (c == 'bg'){for (int i = 0; i &lt;5; i++){displayLine(bg[i]);delay(delayTime);}displayLine(0);} if (c == 'bh'){for (int i = 0; i &lt;5; i++){displayLine(bh[i]);delay(delayTime);}displayLine(0);} if (c == 'bi'){for (int it = 0; it &lt;5; it++){displayLine(bi[it]);delay(delayTime);}displayLine(0);} if (c == 'bj'){for (int i = 0; i &lt;5; i++){displayLine(bj[i]);delay(delayTime);}displayLine(0);} if (c == 'bk'){for (int i = 0; i &lt;5; i++){displayLine(bk[i]);delay(delayTime);}displayLine(0);} if (c == 'bl'){for (int i = 0; i &lt;5; i++){displayLine(bl[i]);delay(delayTime);}displayLine(0);} if (c == 'bm'){for (int i = 0; i &lt;5; i++){displayLine(bm[i]);delay(delayTime);}displayLine(0);} if (c == 'bn'){for (int i = 0; i &lt;5; i++){displayLine(bn[i]);delay(delayTime);}displayLine(0);} if (c == 'bo'){for (int i = 0; i &lt;5; i++){displayLine(bo[i]);delay(delayTime);}displayLine(0);} if (c == 'bp'){for (int i = 0; i &lt;5; i++){displayLine(bp[i]);delay(delayTime);}displayLine(0);} if (c == 'bq'){for (int i = 0; i &lt;5; i++){displayLine(bq[i]);delay(delayTime);}displayLine(0);} if (c == 'br'){for (int i = 0; i &lt;5; i++){displayLine(br[i]);delay(delayTime);}displayLine(0);} if (c == 'bs'){for (int i = 0; i &lt;5; i++){displayLine(bs[i]);delay(delayTime);}displayLine(0);} if (c == 'bt'){for (int i = 0; i &lt;5; i++){displayLine(bt[i]);delay(delayTime);}displayLine(0);} if (c == 'bu'){for (int i = 0; i &lt;5; i++){displayLine(bu[i]);delay(delayTime);}displayLine(0);} if (c == 'bv'){for (int i = 0; i &lt;5; i++){displayLine(bv[i]);delay(delayTime);}displayLine(0);} if (c == 'bw'){for (int i = 0; i &lt;5; i++){displayLine(bw[i]);delay(delayTime);}displayLine(0);} if (c == 'bx'){for (int i = 0; i &lt;5; i++){displayLine(bx[i]);delay(delayTime);}displayLine(0);} if (c == 'by'){for (int i = 0; i &lt;5; i++){displayLine(by[i]);delay(delayTime);}displayLine(0);} if (c == 'bz'){for (int i = 0; i &lt;5; i++){displayLine(bz[i]);delay(delayTime);}displayLine(0);} if (c == 'b!'){for (int i = 0; i &lt;5; i++){displayLine(bexcl[i]);delay(delayTime);}displayLine(0);} if (c == 'b?'){for (int i = 0; i &lt;5; i++){displayLine(bques[i]);delay(delayTime);}displayLine(0);} if (c == 'b.'){for (int i = 0; i &lt;5; i++){displayLine(beos[i]);delay(delayTime);}displayLine(0);} delay(charBreak); } void displayString(char* s) { for (int i = 0; i&lt;=strlen(s); i++) { displayChar(s[i]); } } void loop() { displayString("sunil"); Serial.print("freeMemory()="); Serial.println(freeMemory()); } </code></pre> <p>I am getting the following error.</p> <pre><code>sketch_jul17b:63: error: redefinition of 'int gm []' sketch_jul17b:60: error: 'int gm [5]' previously defined here sketch_jul17b:64: error: redefinition of 'int bm []' sketch_jul17b:61: error: 'int bm [5]' previously defined here sketch_jul17b.ino: In function 'void displayChar(char)': sketch_jul17b:139: error: 'rc2' was not declared in this scope sketch_jul17b:164: error: 'rques' was not declared in this scope sketch_jul17b:168: error: 'gc2' was not declared in this scope sketch_jul17b:177: error: 'gl' was not declared in this scope sketch_jul17b:193: error: 'gques' was not declared in this scope sketch_jul17b:197: error: 'bc2' was not declared in this scope sketch_jul17b:206: error: 'bl' was not declared in this scope sketch_jul17b:222: error: 'bques' was not declared in this scope </code></pre> <p>I don't know why this error is occurring.</p>
<p>This can also happen if you have saved a version of the code (for example duplicate file for backup) within the current sketch folder.</p>
3335
|arduino-yun|robotics|signal-processing|
How useful could the Arduino Yun be in computer vision in a robotics project?
2014-07-16T20:49:50.157
<p>I've recently ordered an Arduino Yun and several other components to begin on a small robotics project (based on an old 4x4 RC Truck). Although not mandatory for what I'd like to do, I was wondering how feasible it would be to mount a small camera or two and write some software for the Linux portion of the Yun to do basic image/video analysis such as face detection and computer vision based path finding?</p> <p>Mostly this is a question about the processing power capabilities of the Yun. Has anyone had any luck doing simple image analysis/recognition on this processor?</p> <p>(Also, if anyone with 150+ rep could edit this to create and add the "computer-vision" tag that would be great)</p>
<p>For this application the Arduino YUN is the worst possible solution because</p> <ul> <li><strong>Low</strong> RAM</li> <li><strong>Terrible</strong> Processor</li> <li>No storage (you can add a microSD card though)</li> <li><strong>High</strong> Cost</li> </ul> <p>The raspberry Pi 2, UDOO, RADXA, Ordio, pretty much anything with a <strong>quad core processor</strong> and <strong>1GB of RAM</strong> will do a <strong>decent job</strong>. </p> <p>Face detection is RAM intensive, so you will need to worry about it lagging. </p> <p>Alternatively you could also have the image processing part be done elsewhere like on a server (on a local network this could be your laptop) or something.</p> <p><strong>Personally</strong>,I would never recommend the Arduino YUN because it just simply isnt worth paying the 75$ for when for about the same price you could have a arduino pro micro and a raspberry pi (with a WiFi adapter, mircoSD card etc.) which is capable of doing probably way more than you actually need to.</p>
3341
|hardware|
USB cable connector
2014-07-17T13:48:15.237
<p>The arduino has a USB port which can connect to a computer. The cable used to make this connection has a standard USB connector at one end (that connects to the computer) and a "larger" connector on the opposite end (that connects to the arduino). See picture below: </p> <p><img src="https://i.stack.imgur.com/cDAFp.jpg" alt="enter image description here"></p> <p>What is the name of this "larger" connector? </p>
<p>They are both standard USB. The end which goes into the computer is type A (or USB-A), and the end which goes into the Arduino is type B (or USB-B). The USB-B connector is also commonly used on devices such as printers and scanners. The distinction mainly exists so it's obvious which device is the host (i.e. the computer) and which device is the client (i.e. the Arduino).</p> <p>As a side note, other types of USB connector exist as well. You will probably be familiar with mini and micro USB connectors, which can be found on various devices such as digital cameras and mobile phones.</p>
3345
|attiny|
Is programming the ATTiny85 possible in 1.5?
2014-07-17T18:16:53.837
<p>I upgraded to Arduino 1.5.7 in hopes of using the command line interface for a larger project. However, the old package I was using to program the ATTiny85 chip with the Sparkfun Tiny AVR Programmer no longer works. I'm getting the following error:</p> <pre><code>Third-party platform.txt does not define compiler.path. Please report this to the third-party hardware maintainer. processing.app.debug.RunnerException at processing.app.debug.Compiler.getCommandCompilerCPP(Compiler.java:597) at processing.app.debug.Compiler.compileFiles(Compiler.java:275) at processing.app.debug.Compiler.compileSketch(Compiler.java:642) at processing.app.debug.Compiler.compile(Compiler.java:125) at processing.app.Sketch.build(Sketch.java:1589) at processing.app.Sketch.exportApplet(Sketch.java:1611) at processing.app.Sketch.exportApplet(Sketch.java:1597) at processing.app.Editor$DefaultExportHandler.run(Editor.java:2397) at java.lang.Thread.run(Unknown Source) Caused by: java.lang.NullPointerException at processing.app.helpers.StringReplacer.replaceFromMapping(StringReplacer.java:97) at processing.app.helpers.StringReplacer.replaceFromMapping(StringReplacer.java:89) at processing.app.helpers.StringReplacer.formatAndSplit(StringReplacer.java:37) at processing.app.debug.Compiler.getCommandCompilerCPP(Compiler.java:595) ... 8 more </code></pre> <p>Does a package exist that will allow me to program the chip in 1.5.7?</p>
<p>You can download a version of arduino-tiny for IDE 1.5.x from <a href="https://code.google.com/p/arduino-tiny/" rel="nofollow">here</a>.</p>
3351
|serial|python|debugging|
Debugging i2C from Mac OSX desktop
2014-07-18T14:36:56.677
<p>I have a raspberryPi and Arduino connected via i2C. On the RPi I have a python script that takes int values and simply sends them to the RPi, which in turn echoes them back. I am trying to debug this, since I am unable to send ints larger than 255.</p> <p>One thought was that I might be able to connect the arduino slave directly to my Mac, and then use the Arduino serial monitor to help with debugging.</p> <p>Unfortunately the python script will not run, because I assume i2C can only be run on a Linux kernel.</p> <p>Am I mistaken?</p> <p>This is an edited portion of my python code</p> <pre><code>import smbus import time # for RPI version 1, use "bus = smbus.SMBus(0)" bus = smbus.SMBus(1) # This is the address we setup in the Arduino Program address = 0x04 def writeNumber(value): bus.write_byte(address, value) return -1 def readNumber(): number = bus.read_byte(address) return number </code></pre>
<p>No, your Mac doesn't have I2C support. It was pointed out <a href="https://arduino.stackexchange.com/questions/3351/debugging-i2c-from-mac-osx-desktop#comment6515_3351">in the comments</a> that there might be some legacy port, but it won't be usable due to driver limitations.</p> <p>You're getting a few things confused. USB is it's own technology, separate from I2C/UART/SPI. I'm not sure how you would even <em>wire</em> I2C to your Mac. The serial monitor in Arduino is for USB COM ports, not related to I2C.</p> <p>As far as debugging, there's a few options. First of all, <a href="https://electronics.stackexchange.com/questions/49752/debugging-i2c-bus-using-aCn-oscilloscope">there are a few ways to debug I2C using an oscilloscope</a>. If that's too expensive, you could also get away with a <a href="https://www.sparkfun.com/products/8938" rel="nofollow noreferrer">logic analyzer</a>. The one I just linked was at Sparkfun for $150. If that's still too expensive and you're willing to risk $30, <a href="http://www.ebay.com/itm/2-in-1-USB-Blaster-amp-Logic-Analyzer-UART-SPI-I2C-EPM240-CPLD-Cyclone-IV-FPGA-MCU-/231036000665?_trksid=p2054897.l4275" rel="nofollow noreferrer">you can find cheap ones on eBay</a> (most with little/no documenation).</p> <p>I don't know your code, so I can't advise you on how to fix it. If you need to debug at such a low level, extra hardware is needed.</p> <p>It doesn't seem like a maximum of 255 that odd, since that's the maximum number that you can do with one byte. You might have to split data up into multiple bytes with some sort of delimiter character. With some quick mental math, it seems as two bytes can give you numbers up to 65,535 if you combine both bytes (i.e. <code>10101010</code> + <code>01010101</code> = <code>1010101001010101</code>).</p> <p>Edit: this seems like the Arduino code you want:</p> <pre><code>#include &lt;Wire.h&gt; #define SLAVE_ADDRESS 0x04 int number = 0; int num1 = 0; int num2 = 0; int state = 0; boolean secondByte = false; void setup() { pinMode(13, OUTPUT); Serial.begin(9600); // start serial for output // initialize i2c as slave Wire.begin(SLAVE_ADDRESS); // define callbacks for i2c communication Wire.onReceive(receiveData); Wire.onRequest(sendData); Serial.println("Ready!"); } void loop() { delay(100); } // callback for received data void receiveData(int byteCount){ while(Wire.available()) { if(secondByte) { num2 = Wire.read(); number = (num1 &lt;&lt; 8) + num2; Serial.print("data received: "); Serial.println(number); if (number == 1){ if (state == 0){ digitalWrite(13, HIGH); // set the LED on state = 1; } else{ digitalWrite(13, LOW); // set the LED off state = 0; } } } else { num1 = Wire.read(); } secondByte != secondByte; } } // callback for sending data void sendData(){ Wire.write(num1); Wire.write(num2); } </code></pre> <p>The Python code will have to do the similar thing. Note: the first part of the number (reading left to right) will be sent first.</p>
3361
|bootloader|avr|isp|
I bought USB > FT232RL, can I use it to program a bootloader onto an Arduino?
2014-07-19T15:19:37.643
<p>I bought this thing off of eBay:<br> <img src="https://i.stack.imgur.com/0SNrQ.jpg" alt="USBtoFT232RL"><br> <a href="http://www.ebay.com/itm/161305918505" rel="nofollow noreferrer">eBay Link</a><br> <br> Will it allow me to program an ATmega[xxx] (Arduino clone) with a bootloader?<br> <br> --&gt; If so, how would I go about it? What should I do, and what should I certainly not do?<br> <br> --&gt; If not, what do I need (or where can I learn) to be able to use an Arduino clone with the Arduino IDE?<br> <br> I'm a bit new to Arduino, and since I learned that a fair amount of the clones being sold on eBay don't have a bootloader, I wondered how to fix this. (and the &quot;barebones&quot; seem to be quite a bit cheaper) <br><br> <hr> <br> <strong>Answer</strong> - <em>summarized from different answers below (as I can only mark one answer below as accepted):</em><br></p> <ul> <li>Can you use an FT232R to burn a bootloader onto an AVR (such as an ATmega328)? <ul> <li>=&gt; Yes you can, though it's a bit annoying to do, as it's slow and a bit more complicated than just plug and play. See the first part of <a href="https://arduino.stackexchange.com/questions/3361/i-bought-usb-ft232rl-can-i-use-it-to-program-a-bootloader-onto-an-arduino#3364">Chris Stratton's answer</a> below.</li> </ul></li> <li>I already have a working Arduino style board, can I use that? <ul> <li>=&gt; Yes, you can use for example a UNO-style board to program another. This process is explained here: <a href="http://arduino.cc/en/Tutorial/ArduinoISP" rel="nofollow noreferrer">http://arduino.cc/en/Tutorial/ArduinoISP</a>, which was referenced in the second part of <a href="https://arduino.stackexchange.com/questions/3361/i-bought-usb-ft232rl-can-i-use-it-to-program-a-bootloader-onto-an-arduino#3364">Chris Strattons' answer</a> below.</li> </ul></li> <li>The two options above are too much of a hassle for me, or I don't have an Arduino yet/available, is there another option? <ul> <li>=&gt; Yes, you can buy a USB to ISP (In-System Programmer) board/programmer. They're pretty cheap and are called USBISP or USBASP for example. Here's an example: <a href="http://www.ebay.com/itm/180980285082" rel="nofollow noreferrer">http://www.ebay.com/itm/180980285082</a>, referenced at the end of <a href="https://arduino.stackexchange.com/questions/3361/i-bought-usb-ft232rl-can-i-use-it-to-program-a-bootloader-onto-an-arduino#3363">MatsK's answer</a>. (or an even cheaper one: <a href="http://www.ebay.com/itm/390806886235" rel="nofollow noreferrer">http://www.ebay.com/itm/390806886235</a>).</li> </ul></li> </ul>
<p>In fact, you can, but you are unlikely to enjoy it as it will be fairly slow.</p> <p>While this module is intended for serial communications - which the ATmega won't support until it has a bootloader on it - the chip around which it is built can also be operated in "bitbang" mode:</p> <p><a href="http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf">http://www.ftdichip.com/Support/Documents/AppNotes/AN_232R-01_Bit_Bang_Mode_Available_For_FT232R_and_Ft245R.pdf</a></p> <p>Using reconfigured pins of this wired to the ISP pins of your target, and an implementation of the ISP algorithm running on the PC, it will indeed be possible to load a bootloader on to a new ATmega chip. However, USB is not designed for this type of usage - it is meant to move large blocks of data, rather than to efficiently do sequences of tiny operations. <strong>The result is that the loading process will be drastically slower than with other methods.</strong> You may also spend a fair amount of time tracking down software to do it, or writing your own.</p> <p>If you have an already working Arduino-style board available, you can use that to program your new chip:</p> <p><a href="http://arduino.cc/en/Tutorial/ArduinoISP">http://arduino.cc/en/Tutorial/ArduinoISP</a></p>
3380
|current|
Maximum Current?
2014-07-21T21:47:13.423
<p>This is an extremely noobie question, but I have a 5V at 2A power source. This power source is going to be powering 6 Sharp IR distance sensors(20-150cm) and a few other low current consumption sensors(ie Xbee). </p> <p>My question is if it is safe to simply use that power source without some sort of resistor between the power source and sensors?</p> <p>also the IR sensors have a analog output. Is that same to plug into the arduino's analog pins?</p>
<p>A few other points, in addition to Penguin's excellent answer:</p> <p>Make sure your 5V supply is a REGULATED supply. Unregulated power supplies will exceed their target voltage when unloaded, and "droop" to lower than their target voltage when under heavy load.</p> <p>Quite a few digital components can be destroyed if their input voltage varies too much from 5V, especially over-voltage. TTL is especially sensitive to over-voltage (which destroys the circuit) and to malfunctioning on under-voltage.</p> <p>Even a regulated power supply will have some ripple if you switch heavy loads on it. You might want to use separate, isolated supplies for your high power and low power logic systems.</p> <p>A higher current regulated supply will be "stiffer" and therefore more stable if run at lower loads.</p>
3382
|arduino-uno|arduino-leonardo|
Arduino Controlling through C#
2014-07-22T02:29:43.907
<p>i would like to measure some signals from arduino and send it to a pc using USART and display the results in a c# winform application. Does anyone have such a project example ? Besides, i want to send the data in live time mode, each values should be directly transmitted and then the second measurement ( sample rate 100 kHz ) Thanks a lot </p>
<p>Am I missing the point here or wouldn't the C# just have to open a Serial connection to the board and read and write to that to control the program running on the Arduino? Yes the board is connected by USB, but that's only so it can open a serial connection. To be honest I don't think you will be able to sample at that speed, you might be better looking at ICs that directly interface with GPIO and RS232/USB.</p>
3390
|arduino-uno|serial|motor|
Changing direction of DC motor
2014-07-22T17:42:54.280
<p>i am working on a project which requires changing the direction of the DC motor using arduino. that is I want the DC motor to rotate clockwise when i press key 'A' and anti clockwise when i press key 'D' on my computer.</p> <p>i have v+ and v- input wires from battery. i have connected one end of the DC motor to gnd of the battery. On the other end of DC motor i want to connect V+ and V- input from the battery to spin the DC motor in clockwise and anticlockwise respectively. I have used BC547 npn transistor. i do not know how to change inputs (v+ to v- and vice-versa) using arduino when key is pressed.</p> <p>is there any method other than H-bridge method to do so?</p> <p>i use arduino uno.</p>
<p>Since you have both a V+ and V- you could just use 2 transitors. If you look at an H-bridge, you only need half the circuit. </p> <p>The only problem is that you need V- to disconnect the NPN transistor, and the arduino can only go as low as GND. So you'd need a second transistor to drive it. </p> <p>The same might also be needed for the PNP side, if the arduino voltage is regulated to a lower value than V+. </p> <p>I found this schematic applicable, but only use the left side. The right side of the motor should be connected to ground (or the middle voltage of your battery). , and replace the opto's with normal transistors. <img src="https://i.stack.imgur.com/Ov3qO.gif" alt="enter image description here"></p> <p>Come to think of it, I'm not entirely confident about replacing the bottom opto, since battery-negative is below GND in your case. I think it should work, but I'm still quite new to this stuff.</p> <p>Also make sure you add something like 1k resistors to the base of the transistors (that replace the opto's)</p>
3391
|i2c|
Proxying streaming i2c data(int values) to serial
2014-07-22T18:48:23.477
<p>The following code works correctly in reading single int values. It also works correctly for 3-4 seconds if I 'stream' the values in constantly (Mouse move coordinates) before I get an IO error and the i2C bus connection is dropped. I assume this is some sort of buffer overrun...or? Can anyone get me on the right track here? What changes do I need to make so that I can constantly stream in serial data?</p> <pre><code> #include &lt;Wire.h&gt; #define SLAVE_ADDRESS 0x04 int zeroByte; int state = 0; int receivedValue = 0; int numBytes = 0; bool newData = false; void setup() { pinMode(13, OUTPUT); Serial.begin(9600); // start serial for output // initialize i2c as slave Wire.begin(SLAVE_ADDRESS); // define callbacks for i2c communication Wire.onReceive(receiveData); Wire.onRequest(sendData); Serial.println("Ready!"); } void loop() { delay(100); if(newData){ Serial.println(receivedValue); newData=false; } } // callback for received data void receiveData(int byteCount){ while(Wire.available()) { newData = true; zeroByte = Wire.read(); if(Wire.available() == 2) { receivedValue = Wire.read() | Wire.read() &lt;&lt; 8; } } } // callback for sending data void sendData(){ Wire.write(receivedValue); } </code></pre>
<p>Your I2C bus is operating at 100 kHz. Your serial connection is set to 9600 baud. In case you are sending coordinates at a pace faster than the serial interface can keep up, the buffer will fill up. I assume you are using hardware serial (uno, mega, etc). Once the buffer is filled up Serial.write (which is called by Serial.println) will block until the buffer has free space. But the serial transmission depends on interrupts, and you are calling Serial.write inside an interrupt routine. By defult interrupt routines block other interrupts from happening. So your program gets stuck there and locks up both the serial transmission and the I2C interface.</p> <p>It would be a good idea to put the serial write outside the interrupt routine, in the loop. Make a global variable <code>bool newData = false;</code> and set it true in the receiveData function. In your loop check the flag and transmit the data. Then set the flag to false.</p> <p>You will still experience data loss if the serial interface can't keep up, but your application wont lock up. To solve the data loss simply use a higher baud rate, eg. 115200.</p>
3401
|arduino-uno|serial|accelerometer|
Bit mask first 2 bits of 16 bits for accelerometer
2014-07-23T11:52:31.593
<p>The datasheet for the accelerometer states that:</p> <p><img src="https://i.stack.imgur.com/ogmVl.png" alt="enter image description here"></p> <p>Here is the data output from the accelerometer:</p> <p><img src="https://i.stack.imgur.com/tvidg.png" alt="enter image description here"></p> <p>I have tried to mask the first two bits using a bitwise AND command with B0011111111111111.</p> <p>I tried to use this code, but unfortunately the first 2 bits are still "11" so the value has not changed:</p> <pre><code>int bresult=0b0011111111111111&amp;result; Serial.print(bresult,BIN); </code></pre> <p>How would I bits mask the first two bits and will arduino automatically know how to convert to twos compliment?</p> <p>The variable result is of data type "long"</p> <p>According to an answer, I tried:</p> <pre><code>int bresult= result&lt;&lt;2; Serial.print(bresult,BIN); </code></pre> <p>I got this result which is great but is it possible to remove the last two zeros because this is making my value larger? The image below shows result then bresult.</p> <p><img src="https://i.stack.imgur.com/V32NY.png" alt="enter image description here"></p>
<p>For the arduino, <code>long</code> is 32 bits, <code>int</code> is 16 and <code>char</code> is 8.</p> <p>Save the result in an <code>int</code> not a <code>long</code>. Then Gerben's method <code>int bresult = (result &lt;&lt; 2)/4</code> should work. This is because <code>&lt;&lt; 2</code> moves everything left two bits, but <code>/ 4</code> move every thing right two bits <em>with new bytes the same as the sign bit.</em> So you get a <strong>16 bit</strong> signed variable with the correct number. If you have it as a long you would have to do <code>int bresult = (result &lt;&lt; 18)/(2^18)</code>.</p> <p>BTW Serial.print(bresult,BIN); is always going to give you up to 16 bits. There is no 14 bit type.</p>
3409
|serial|arduino-yun|
Arduino Yun, node.js and serial
2014-07-23T17:19:49.940
<p>I'm trying to bypass Bridge library and read serial directly from nodejs. I'm on the last sys upgrade (1.3) I have correctly installed nodes and serial module via opkg install. I have also commented out the line in the <code>/etc/inittab</code>:</p> <pre><code>#ttyATH0::askfirst:/bin/ash --login </code></pre> <p>This is my arduino code:</p> <pre><code>void setup() { Serial.begin(9600); } void loop() { Serial.println("dudee"); delay(100); } </code></pre> <p>This is my node.js code:</p> <pre><code>var SerialPort = require("serialport").SerialPort var serialPort = new SerialPort("/dev/ttyATH0", { baudrate: 9600, dataBits: 8, parity: 'none', stopBits: 1, flowControl: false }, false); console.log("hello"); serialPort.on("open", function () { console.log('open'); serialPort.on('data', function(data) { console.log('data received: ' + data); }); }); serialPort.on('error', function(err) { console.log('error: '+err); }); serialPort.open(); </code></pre> <p>If I ssh to yun and run the script I don't see any "dudee":</p> <pre><code>~/test# node serial.js hello open </code></pre> <p>While if I open the serial monitor I see it.</p> <p>If I run the node script on my computer (changing the right serial port name) everything works nice and I see the dude..</p> <p>What can it be?</p>
<p>Autosolved thanks to <a href="http://forum.arduino.cc/index.php?topic=194934.15" rel="nofollow">this old forum post</a>.</p> <p>It is <code>Serial1</code> not <code>Serial</code>. In the Arduino code in the Yun <code>Serial</code> is a different object from <code>Serial1</code>. Even if it is not super well document (or at least not in the first dumb google search) here are some links that talks about <code>Serial1</code>:</p> <p><a href="https://www.arduino.cc/en/Tutorial/YunSerialTerminal" rel="nofollow">https://www.arduino.cc/en/Tutorial/YunSerialTerminal</a> <a href="http://andrea-toscano.com/arduino-yun-tcpip-to-serial1-redirect/" rel="nofollow">http://andrea-toscano.com/arduino-yun-tcpip-to-serial1-redirect/</a> <a href="http://crossbar.io/iotcookbook/Arduino-Yun-Disable-Bridge/" rel="nofollow">http://crossbar.io/iotcookbook/Arduino-Yun-Disable-Bridge/</a></p>