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
|
---|---|---|---|---|---|
9740 | |shields|wifi|arduino-motor-shield|adafruit| | Arduino Motor Shield and Adafruit CC3000 WiFi Shield Compatibility | 2015-03-31T11:56:26.100 | <p>My question is similar to this one: <a href="https://arduino.stackexchange.com/questions/3892/motor-shield-and-wireless-transceiver-compete-for-same-pins">Motor shield and wireless transceiver compete for same pins</a>
But not exactly the same!</p>
<p>I would like to know if the solution is as practical, though.</p>
<p>I have an Arduino Mega 2560 R3, with an Arduino Motor shield plugged into it. Now I want to use the Adafruit CC3000 WiFi shield. It plugs in fine, but when reading the specifications, it wants to use pins 13, 12, 11 which are also used by the Motor shield. I also want to use pin 10 as a servo is plugged into it. This is all on a robot so I don't have space to wire the shield separately through a breadboard or similar. </p>
<p>It should perhaps also be noted that I have the motor shield on top of the wifi shield so that the wifi shield can use the ICSP ports which the motor shield doesn't have, therefore any redirecting of pins on the CC3000 will mean that the motor shield pins will also be affected unless I redirect them too, and at that point I feel like it would be all a bit of a mess.</p>
<p>The solution to the other question was indeed to redirect the relevant pins to other free pins on the micro-controller board. However, I noticed that the Adafruit shield has a second row of connector holes next to the main pin holes. In the <a href="https://learn.adafruit.com/downloads/pdf/adafruit-cc3000-wifi.pdf" rel="nofollow noreferrer">shield documentation</a> I found, I didn't find any specific reference to these parts and in what situations they could be used, but maybe this is one of them. </p>
<p>My concern with using these is that (as you can see in the second image below, ignoring the coin!), the ports are wired together in the board. Does this mean that it won't make any difference which I use; if I connect a second row of pins/connectors to these points will it simply transmit the same data down both sides? I don't know enough about how electronics work at that level to understand the consequences.</p>
<p>So really my question is: can I use the outside row of ports for my motor shield and the inside row for the wifi shield? </p>
<p><img src="https://i.stack.imgur.com/YSc44.jpg" alt="Adafruit WiFi Shield"></p>
<p><img src="https://i.stack.imgur.com/TpAAY.jpg" alt="Underside of shield"></p>
<p><strong>EDIT:</strong> </p>
<p>So I've spent until now on the Adafruit forums trying to get some help with this and I still am not all the way there... maybe at this point someone here can cast fresh eyes over my problem.</p>
<p>The Adafruit CC3000 uses both the dedicated ICSP pins and pins 3, 11-13 to transmit the same data. The reason for this is to do with compatibility between different Arduino boards and their versions. E.g. apparently the Uno uses those pins whilst the mega uses some of the pins in the 50s range. I'm not sure what to make of this as the Uno and most of the boards seem to have the ICSP pins, so if they're not used for this purpose then what's the point of connecting to them? Anyway. </p>
<p>As it was explained to me, even if the board can use the ICSP pins to communicate with the microcontroller, it is still sending data via the other pins. So the main pins are essentially useless at this point. To make them useful again, the idea is that you sever the wires that are sending the data through them (often referred to as trace wires). This means that only the ISCP ones will be active for what they are needed, and the main pins will be free for other uses. This is what I ended up doing to my board for pins 11-13, and then for pin 3 I cut the trace wire and wired up the connection to pin 2 as these can both be used for an IRQ (interrupt request) on the Mega and I need pin 3 for the motor shield. The lighting on these pictures isn't the best, but you can see what I've done (the lower part of the second image shows where I made the cuts and the top image shows the wire connection):
<img src="https://i.stack.imgur.com/p88FG.jpg" alt="Top view">
<img src="https://i.stack.imgur.com/HdtVH.jpg" alt="Underside view"></p>
<p>After doing that I have been testing the shield connected to both my Mega and my Uno and they both produce the same results. This is using the Adafruit-created library called <code>Adafruit_CC3000_Library</code>. It starts the initialisation, then whilst it's trying to run the code it gets stuck. I traced the problem to a while(1) loop of which you can only exit by meeting a condition which is never met in my case: <code>if (*pucReceivedData == HCI_TYPE_EVNT)</code>. This may be because <code>pucReceivedData</code> is not initialised properly, but I don't know why and whether it has to do with my modifications. This happens in the <code>hci_event_handler</code> method of <code>evnt_handler.cpp</code>. This is through the main file and <code>wlan.cpp</code> so I won't write it here as it is simple enough to follow. </p>
<p>It should also be noted that this shield doesn't work properly with the later versions of the arduino IDE (1.5+) so I had to reinstall 1.0.6. To be honest, I got the same problem on both versions so who knows.</p>
<p>I realise that this is a very specific problem, but I figure that this may leave someone with a lot fewer issues in the future. If anyone has any bright ideas, even if just for testing then I would be grateful.</p>
| <p>It works!</p>
<p>First I'll say thanks to the moderators/support staff from Adafruit. One dude in particular has tried to help me constantly for the past couple of days or so.</p>
<p>So, following on from my edit, Adafruit told me that the ICSP pins are connected to the control part of the board via the main pins. I should have seen it actually, but I obviously didn't examine and understand it properly. This means that although I severed the connection between the main pins and the centre, the ICSP and 11,12,13 were still connected together. What I actually needed was for the ICSP pins to be connected to the controls to receive the data, and the main pins to be detached from them. So I de-soldered the solder jumpers that I had originally put on the connector plates on the underside of the board (which connect the ISCPs to the main pins), then soldered wire from the ICSP side to the associated breakout holes which are the ones on the inside of the cuts that I made on the board. Here is a picture:</p>
<p><img src="https://i.stack.imgur.com/HQFUw.jpg" alt="New wiring on board" /></p>
<p>If anyone tries to do this, beware of where you are wiring to! I was very careful to make sure I matched the connecting wires to the correct pins. I have tested it several times (using the example test file that comes with the library) and it works as it should. It works on my Uno R3 and my Mega 2560 R3, which is great, as now pins 11-13 are free to use for my motor shield, or potentially any other shield which may need those pins.</p>
<p>I hope this helps someone else in the future. There doesn't seem to be any information on this particular combination of shields, but as these projects are becoming more popular this may prove to be useful.</p>
|
9748 | |pins| | Can I damage an arduino by setting pins high with no load | 2015-03-31T19:22:21.997 | <p>I have an Arduino project that has 15 different output pins set. Some are currently attached to devices and others are not. Will testing my program cause a problem / damage if it sets pints to HIGH that do not have anything connected to them?</p>
| <p>Nope, you should be just fine.</p>
<p>Having a pin set to any state while unplugged will not cause any problems with your microcontroller.</p>
|
9752 | |millis| | millis() function with a button press | 2015-04-01T00:23:10.007 | <p>I am trying to use the <code>millis()</code> function to turn on a pin for a specified interval then turn off and turn on a second pin. It is intended to power a relay and offer a visual cue to when the cycle is over. Several of these need to eventually be running, most likely three, so using <code>delay()</code> won't work. I plan to add additional "button pins" for each input. The LED lights up but gets stuck in the loop and doesn't cycle out. It seemed like a simple program but I can't crack it for some reason. </p>
<p>Is there a much better method to do this? There will be two optical sensors and one pushbutton switch attached to an air driven crushing machine. The two optical sensors will be used only as time indicators with LEDs and the pushbutton will power the relay. Forgive my shortcomings as a programmer, I am learning the programming language still. </p>
<pre><code>const int ledPin = 2; // the number of the LED pin
const int buttonPin = 3; // Button pin number
// Variables will change:
long previousMillis = 0; // will store last time LED was updated
int buttonState = 0; // Checks if button is pushed
int buttonPush = 0; // Toggles between 0 to hold state
long interval = 1000; // interval at which to blink (milliseconds)
void setup() {
// set the digital pin as output:
pinMode(ledPin, OUTPUT);
pinMode(buttonPin, INPUT);
}
void loop()
{
unsigned long currentMillis = millis();
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
buttonPush = 1;
if (buttonPush == 1){
if(currentMillis - previousMillis > interval) {
previousMillis = millis();
digitalWrite(ledPin, HIGH);
}
else {
buttonPush = 0;
}
}
else {
digitalWrite(ledPin, LOW);
}
}
}
</code></pre>
<p>Edit: Thank you for looking over the code, you guys are awesome. There were a couple questions regarding clarity of the final application so I will elaborate. I am going to attempt to clean it up. I had a feeling something was wrong with:</p>
<pre><code>if (buttonState == HIGH) {
buttonPush = 1;
</code></pre>
<p>but I couldn't put my finger on it. </p>
<p>Eventually the system will function with two heating elements to soften plastic, which I will either add an optical sensor to since it will probably get triggered a few hundred times a day, or just a pushbutton to start a timer so the plastic isn't left in too long. A green LED will be illuminated to indicate the system is on. When the plastic object is placed in the heating element it triggers the optical sensor (or the operator pushes a pushbutton to start the timer) that will then illuminate a red LED to indicate heating. When the specified time interval has expired, the LED will revert back to green to show the cycle is complete. The plastic object is then removed and placed in a pneumatic crushing device with a green system on LED. The operator then pushes a pushbutton which turns on a red indicator LED and a relay to power the solenoid on the pneumatic press for a specified amount of time to allow the plastic to cool and crystallise. When that interval has expired, the system will revert back to illuminating the green LED and will end power to the relay allowing the press to release.</p>
<p>The pneumatic press and the heating system works awesome, I just need better control of the time intervals used. The end result needs to be consistent.</p>
<p>I am going to try all suggestions and will post what ended up working if I reach that point or find an answer that functions. </p>
| <p>The simplest way I can think of is something like this:</p>
<pre><code>unsigned long lastPress = 0;
unsigned long stateOneTime = 2000; //runs until two seconds elapse
unsigned long stateTwoTime = 4000; //runs after state one until 4 seconds from first press
...
if(/*input is active*/) lastPress = millis();
...
if(millis() - lastPress < stateOneTime){
//set output for first state
//active for 2 seconds
} else if (millis() - lastPress < stateTwoTime){
//set output for second state
//active an additional 2 seconds
} else {
//set output to the "off" state
}
</code></pre>
<p>Many improvments could be made, like going more of a state machine route (separating the time checks from the branches) or paramaterizing the state lengths better (durations would make more sense than total time from start, but be slightly more complicated to code).</p>
<p>I think the key to making your life easier while working on this code will be separating the input segment from the output segment. It will help keep the code easy to read and modular.</p>
|
9770 | |library| | mega include a library | 2015-04-01T19:53:03.707 | <p>This question is a little related to this one: <a href="https://arduino.stackexchange.com/questions/9702/how-to-compile-and-upload-the-specific-cpp-h-code">How to compile and upload the specific (.cpp + .h) code?</a></p>
<p>I've installed <a href="https://github.com/justintconroy/MdbBillValidator" rel="nofollow noreferrer">MdbBillValidator</a> to my arduino libraries collection. I tried both on ubuntu & windows.</p>
<p>How can I include it? Default inclusion, by arduino ide, was:</p>
<pre><code>#include <MdbSerial.h>
#include <wiring_private.h>
#include <MdbBillValidator.h>
#include <MdbMaster.h>
#include <Arduino.h>
void loop() {
}
void setup() {
}
</code></pre>
<p>And here is error comes in:</p>
<pre><code>/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp: In function ‘void __vector_37()’:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:289:23: error: ‘TXB8’ was not declared in this scope
UCSR1B |= (1 << TXB8);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:291:24: error: ‘TXB8’ was not declared in this scope
UCSR1B &= ~(1 << TXB8);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp: In function ‘void __vector_52()’:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:314:23: error: ‘TXB8’ was not declared in this scope
UCSR2B |= (1 << TXB8);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:316:24: error: ‘TXB8’ was not declared in this scope
UCSR2B &= ~(1 << TXB8);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp: In function ‘void __vector_55()’:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:339:23: error: ‘TXB8’ was not declared in this scope
UCSR3B |= (1 << TXB8);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:341:24: error: ‘TXB8’ was not declared in this scope
UCSR3B &= ~(1 << TXB8);
^
In file included from /usr/lib/avr/include/avr/iom2560.h:38:0,
from /usr/lib/avr/include/avr/io.h:160,
from /usr/lib/avr/include/avr/pgmspace.h:88,
from /home/asiniy/sketchbook/libraries/MdbBillValidator/Arduino.h:8,
from /home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:31:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp: At global scope:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:554:135: error: expected ‘)’ before numeric constant
MdbSerial MdbPort1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1 UCSZ12, UCSZ11, UCSZ10, UPM11, UPM10, UMSEL11, UMSEL10);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:554:189: error: no matching function for call to ‘MdbSerial::MdbSerial(ring_buffer*, ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, int, int, int, int, int, int, int, int, int, int, int)’
MdbSerial MdbPort1(&rx_buffer1, &tx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UCSR1C, &UDR1, RXEN1, TXEN1, RXCIE1, UDRIE1, U2X1 UCSZ12, UCSZ11, UCSZ10, UPM11, UPM10, UMSEL11, UMSEL10);
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:554:189: note: candidates are:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:352:1: note: MdbSerial::MdbSerial(ring_buffer*, ring_buffer*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, volatile uint8_t*, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t, uint8_t)
MdbSerial::MdbSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer,
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:352:1: note: candidate expects 20 arguments, 19 provided
In file included from /home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.cpp:38:0:
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.h:52:7: note: MdbSerial::MdbSerial(const MdbSerial&)
class MdbSerial
^
/home/asiniy/sketchbook/libraries/MdbBillValidator/MdbSerial.h:52:7: note: candidate expects 1 argument, 19 provided
</code></pre>
<p>What I need to do to avoid this error and get the code worked?</p>
| <p>Could you try adding this to your program?</p>
<pre><code>#define RXB8 1
#define TXB8 0
#define UPE 2
#define OVR 3
#define FE 4
#define UDRE 5
#define RXC 7
#define FRAMING_ERROR (1<<FE)
#define PARITY_ERROR (1<<UPE)
#define DATA_OVERRUN (1<<OVR)
#define DATA_REGISTER_EMPTY (1<<UDRE)
#define RX_COMPLETE (1<<RXC)
</code></pre>
<p>I found someone with similar code, who had these defines and as your code seems to miss/cannot find something, this might fix it.
Though I'm not sure if these defines apply in your specific implementation. For that I should have to see the code where the error is pointing at.</p>
|
9773 | |prototype| | How are PCB's programmed? | 2015-04-02T00:46:42.053 | <p>So recently I have been looking into prototyping my arduino project and there are a lot of tutorials online on how to take your Arduino and using a software such as Eagle to make a PCB layout but I was wondering how you would get the Arduino program onto that PCB. Surely in large scale circuit manufacturing they wouldn't have a usb attached so that they upload a program into each and every one of their circuits?</p>
| <p>cheers Brandan :)</p>
<p>I would suggest for you to make your own programmer. Then you will know a lot about programming and so on. If you want to program a chip on pcb, you have to have output pins of ISP. Throw these pins you will pump your code to Atmega chip.</p>
<p>Software <a href="http://khazama.com/project/programmer/" rel="nofollow">Khazama</a> is "old" and tested one. It really works :) <a href="http://www.atmel.com/microsite/atmel_studio6/" rel="nofollow">AVR studio</a> is also good one</p>
<p>Hardware <a href="http://www.fischl.de/usbasp/" rel="nofollow">USBasp</a> There are ready pcb layouts in eagle. Building your own HW will be a bit more expensive than buying one, but if we count in experience it will be priceless :) </p>
<p>Also you can use bootloader. Check in google there are plenty of tutorials.</p>
|
9783 | |pins|motor|i2c|spi| | I2C or SPI to control 6 motors? | 2015-04-02T09:35:32.137 | <p><sup>I am a hobbyist & know little about electronics.</sup></p>
<p>I am making a robot arm, like <a href="http://www.lynxmotion.com/c-124-al5a.aspx" rel="nofollow">this one</a>. For which I will need 2 stepper motors (for elbow & shoulder joint) & 4 simple DC motors.</p>
<p>Which means I will need to allocate a lot of pins on my board (Uno).</p>
<p>So I was just reading about I2C & then eventually SPI. My question is:</p>
<ol>
<li>Is it possible to control 6 motors (or atleast 2 steppers) with I2C or SPI (assuming the motors are powered by seperate source), if so can you point me to someone's example code.</li>
<li>If not possible, how do I overcome the shortage of pins, because I have already dedicated them to many sensors.</li>
</ol>
| <p>For the stepper motors, the easiest way to work with them is by using a very common <a href="https://www.pololu.com/product/1182" rel="nofollow noreferrer">A4988 board</a> which is widely used with 3D printers. The controls are very easy and for them I send you <a href="https://arduino.stackexchange.com/questions/8965/stepper-motor-controller-using-leonardo-pro-micro/8977#8977">this question</a> which I answered some time ago.</p>
<p>Then, you say that you haven't got a lot of connections left on your UNO board, so I think that SPI would't be very useful, as it takes 3 pins for the data transmission (SCLK, MOSI, MISO) plus one pin for every device you connect.</p>
<p>The best way (even if it is a little slower that SPI) is to use I2C, which needs that you leave unused analog input pins A4 and A5, as they are the I2C BUS. Unfortunately I haven't any knowledge about I2C DC motor drivers.</p>
<p>For the steppers, I suggest to take a look at <a href="http://www.ebay.co.uk/itm/Serial-I2C-Microstepping-Motor-Driver-DC-PWM-CNC-Raspberry-Pi-Aduino-1-2A-/111177026930" rel="nofollow noreferrer">this</a>, but it depends by your budget for what you can buy.</p>
<p>You could fix the pin shortage problem by adding some <a href="http://www.nxp.com/documents/data_sheet/74HC_HCT595.pdf" rel="nofollow noreferrer">74HC595</a> shift registers. They aren't very expensive (less than a dollar, or if you live in europe, .5€) and they can be daisy-chained. To control them, see the <a href="http://arduino.cc/en/tutorial/ShiftOut" rel="nofollow noreferrer">Arduino website tutorial</a>.</p>
<p>Finally, if the pins that you use are inputs, use a <a href="http://www.nxp.com/documents/data_sheet/74HC_HCT165.pdf" rel="nofollow noreferrer">74HC165</a>, which is the opposite of a 595. As always, see the <a href="http://arduino.cc/en/tutorial/ShiftIn" rel="nofollow noreferrer">Arduino website tutorial</a>.</p>
|
9794 | |arduino-uno|sensors|hardware| | Don't pee there! Device | 2015-04-02T17:08:52.393 | <p>I want to make a device with a sensor I can attach to the places my dog likes to mark. When sensor becomes wet I want a buzzer to make a loud noise to scare the animal and notify me I need to encourage the dog to go outside. Any suggestions on what sensor to use.</p>
| <p>You probably will want a moisture sensor like <a href="http://www.ebay.co.uk/itm/like/370999421770?limghlpsr=true&hlpv=2&ops=true&viphx=1&hlpht=true&lpid=108&chn=ps&device=c&adtype=pla&crdt=0&ff3=1&ff11=ICEP3.0.0-L&ff12=67&ff13=80&ff14=108" rel="nofollow">this one</a> (there are many variations of this).</p>
<p>This will return one signal when dry, and another when wet.</p>
<p>You will need a Buzzer to make a sound as well (Or a piezo speaker if you feel like getting more advanced) in order to make a sound.</p>
<p>Your sketch should have, in its <code>loop</code>, an <code>if</code> statement checking if the moisture sensor has returned the wet signal (The signal will depend on the sensor you get) and, in the block that executes if there is a signal, a statement driving the buzzer and a delay before turning it off.</p>
<p>Bear in mind that you want to keep the Arduino itself away from the moisture sensor, as your Arduino probably won't survive the dog's doings.</p>
|
9795 | |arduino-uno|motor|pwm|digital|h-bridge| | Switching a dual h bridge in parallel | 2015-04-02T17:25:54.787 | <p>I'm using a dual h bridge to control two dc motors on an inverted pendulum (cart-pole system). At the moment, I have to send two different pulse width modulated signals to the two enable pins to control the two motor speeds and four digital write commands to control the directions. </p>
<p>Ideally, I want to switch the two motors simultaneously in the same direction and with the same speed. So, I'd like to be able to control both motors' speeds with only one pulse width modulation signal and control both motor directions with only two digital write commands. </p>
<p>Is there a way I can do with with Arduino? Can one PWM signal from a single arduino pin be sent to two enable pins at the same time? Can the same be done for a single digital output pin? If so, how can I accomplish this?</p>
| <p>You can connect a single output to as many input loads as you like, provided the current is sufficient to hold the output voltage within the input thresholds. See the datasheet for the H bridge to find out what the input load and thresholds are, and compare them with the output from the Arduino.</p>
|
9798 | |arduino-uno|pins|communication|display|shift-register| | Shift registers. What, how and why? | 2015-04-02T18:04:42.423 | <p>I'm making a project and I'm using multiple 1 digit 7 segment displays. I haven't plugged them all on my arduino because currently I'm just testing. The problem is on the I/O ports. Obviously I need to use shift registers and since it's my first time ever using them I need to know more about them. After googling, I found that the specific model I bought outputs 8 pins and you can stack up to 8 in series. So lets do the math. <code>8 shift register</code> x <code>8 pins each SR</code> = <code>64 new pins</code> It seems cool but assuming I'm using 28 displays let's do the math again.
28 displays, each display has 8 pins (8 for segments and 2 as common cathode)
<code>28</code> x <code>8</code> = <code>224</code> required pins.
Is is possible to expand the I/O pins by 224 pins? How many shift registers can I stack together? Also which is better, the single digit display or the 4 digit display?</p>
| <p>You can buy these displays on eBay for a few dollars. A bit of soldering and you are done (although also pre-assembled ones are available). They can be daisy-chained. Example:</p>
<p><img src="https://i.stack.imgur.com/dEbzN.jpg" alt="6 x 4-digit 7-segment display modules"></p>
<p>You only need 5 wires to the Arduino: Gnd/5V/MOSI/SCK/SCK.</p>
<p><img src="https://i.stack.imgur.com/YhNOe.jpg" alt="modules in operation"></p>
<p>Also, 64-dot displays for displaying arbitrary text:</p>
<p><img src="https://i.stack.imgur.com/8Z5oV.jpg" alt="8x8 LED matrix"></p>
<p>Again, only 5 wires.</p>
<p>I have Arduino libraries for driving both sorts of display on <a href="http://www.gammon.com.au/forum/?id=11516" rel="nofollow noreferrer">
Interfacing LED displays with the MAX7219 driver </a>.</p>
|
9801 | |i2c|library|wire-library| | pcDuino 3B Wire library errors | 2015-04-02T19:28:51.790 | <p>I recently purchased a pcDuino 3B and I am very pleased with the Board so far. I can use the preinstalled arduino IDE to program the board from the board and run programs.</p>
<p>However, when I came to use I2C, it generated a load of errors with the built-in libraries when I tried to compile. I don't know why it did this, it does it when trying to compile any program using I2C. Here is the error list (Yes, I am using an Adafruit display library that works fine with exactly the same sketch on my laptop):</p>
<pre><code>In file included from /usr/share/arduino/hardware/arduino/pcduino/cores/arduino/Stream.h:26:0,
from /usr/share/arduino/hardware/arduino/pcduino/libraries/Wire/Wire.h:9,
from Stopwatch_new.ino:1:
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/Print.h:47:23: error: ‘byte’ has not been declared
In file included from Stopwatch_new.ino:1:0:
/usr/share/arduino/hardware/arduino/pcduino/libraries/Wire/Wire.h:41:23: error: ‘byte’ has not been declared
Stopwatch_new.ino:5:51: error: cannot allocate an object of abstract type ‘Adafruit_RGBLCDShield’
/home/ubuntu/Arduino/libraries/AdafruitLCD/Adafruit_RGBLCDShield.h:68:7: note: because the following virtual functions are pure within ‘Adafruit_RGBLCDShield’:
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/Print.h:47:17: note: virtual int Print::write(int)
Stopwatch_new.ino:5:23: error: cannot declare variable ‘lcd’ to be of abstract type ‘Adafruit_RGBLCDShield’
/home/ubuntu/Arduino/libraries/AdafruitLCD/Adafruit_RGBLCDShield.h:68:7: note: since type ‘Adafruit_RGBLCDShield’ has pure virtual functions
Stopwatch_new.ino: In function ‘void updateScreen()’:
Stopwatch_new.ino:125:27: error: call of overloaded ‘String(float&, int)’ is ambiguous
Stopwatch_new.ino:125:27: note: candidates are:
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/WString.h:44:14: note: String::String(unsigned int, unsigned char)
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/WString.h:43:14: note: String::String(int, unsigned char)
/usr/share/arduino/hardware/arduino/pcduino/cores/arduino/WString.h:42:14: note: String::String(unsigned char, unsigned char)
</code></pre>
<p>It seems that no one else is having this issue.</p>
<p>Just to clarify, the issue is not with my code or the library, it compiles fine on my other computer running WINDOWS but same Arduino version (1.5.3), same sketch code and same library code.</p>
<p>Help much appreciated, thanks!</p>
| <p>It turns out that the libraries for compiling were incomplete. Having copied the libraries for the official IDE, it worked fine.</p>
|
9811 | |arduino-uno|led| | How to use an 8x8 LED Matrix? | 2015-04-02T23:13:04.363 | <p>I have a LED Matrix just like this one</p>
<p><img src="https://i.stack.imgur.com/S4JeL.jpg" alt=""></p>
<p>but couldn't find the data sheet for it (1855AS)
I asked around in my country and one guy told me to try attaching one side to 5v and the other to GND. Some LEDs worked fine and others didn't light up at all. In the end one if not more got burned.</p>
<p>So I'm here asking if anyone can tell me a way to figure out how it works.
I would appreciate the help!</p>
| <p>As you are testing the correct functionality of LEDs on matrix board, which means the LEDs are multiplexed together. The fastest way to check the pinout is to use a multimeter in continuity test mode and then connect the positive or signal wire ( the red one ) to an fixed pin (usually start with one ) and the with negative or gnd wire ( the black one ) connect it one by one to the all the remaining pins. When you have finished move the signal wire to the next pin and rescan all the pins, repeat all the steps for every pins on the matrix board.
I don't recommend you to use directly 5v because it can be dangerous and you can damage the LEDs of the matrix display as there isn't a current limiting resistor.</p>
|
9815 | |arduino-uno|motor|pins|servo|wires| | Adding a steering servo | 2015-04-03T05:20:15.540 | <p>I got a Sparkfun Redbot Kit a while back. I ended up building it vanilla and it was a good introduction to the board (the board is basically Uno and a motor shield in one) and the toys that came with it. I figured if could scavenge an RC car, I'd get a more robust redbot. I found an old RC Rock Crawler, it has a basic suspension, two motors, and a steering servo.<br>
Unfortunately, I encountered a problem. The steering servo only has two wires. I loaded the <em>Servo</em> -> <em>Sweep</em> example that is default in the Arduino IDE to see if I could make it work regardless. I tried all the different all the different wire/header combinations on the servo headers:</p>
<ol>
<li>When I attach the wires to gnd and # I get a buzzing noise.</li>
<li>When I attach the wires to gnd and pow the servo turns left or, if I swap the wires, it turns right.</li>
<li>When I attach the wires to pow and # nothing happens.</li>
</ol>
<p>I currently can't take advantage of the servo headers on the board (or at least I don't know how to). I was hoping that I could that there might be a work around, I just don't know what it is.<br>
The obvious answer is that I could run both motors off of only one of the headers and use the other to control the steering (thats how the original board from the car was wired), but I can get a faster car if each motor has its own header, and I'm all about the vroom vroom...</p>
<p>I'm running the whole thing off the default 6v (4 AA) battery pack. I might be able to wire in the extra 2 AA's for the extra 3v but I don't want mess with the wiring on the pack unless I know it's going to work.</p>
<p>I have an accelerometer connected to the A4 A5 header block and the motors connected too (I checked w/o them connected but there was no difference). </p>
<p><img src="https://dlnmh9ip6v2uc.cloudfront.net/assets/7/6/b/4/6/520026ca757b7f2344958fd5.jpg" alt="A basic image of all the headers on the RedBot board">
<em>Image courtesy of <a href="https://learn.sparkfun.com/tutorials/getting-started-with-the-redbot" rel="nofollow">https://learn.sparkfun.com/tutorials/getting-started-with-the-redbot</a></em><br>
More info on the redbot board <a href="https://www.sparkfun.com/products/12097" rel="nofollow">https://www.sparkfun.com/products/12097</a></p>
| <p>If the motor you are using has only two wires, and as you described it's response to the direct connection to the power, it can't be a servo. The motor is a normal dc motor.
If you want to control the amount of the turns on your rc car you should try to play with the pwm signal, I don't know if it will work or not but at least you will have tried. And remember not to connect the motor directly on the micro's pin if there no motor pins on your red board.</p>
|
9828 | |potentiometer| | How to I measure the duration of touch with a soft potentiometer? | 2015-04-03T14:17:30.853 | <p>I'm having a soft pot meter here and I would like to register the duration of the touch event. I'm having a different variable, which keeps going from 1024 to 0 , which regularly takes 60 seconds, but for every second you touch the soft pot meter the count adds 50 up to 1024. Like returning the clock backward. </p>
<p>How would I register/code this?</p>
<p><img src="https://i.stack.imgur.com/NtBgH.jpg" alt="Softpot meter"></p>
| <p>You have to go with timer interrupts. Here is the documentation: <a href="http://playground.arduino.cc/code/timer1" rel="nofollow">http://playground.arduino.cc/code/timer1</a></p>
<p>Roughly, when you detect a press, an interrupt is raised and the same thing goes for releasing. Using the timer values from both these events, you can accurately measure the time that the press lasted.</p>
|
9831 | |ir|data-type| | IR trouble with raw buffer | 2015-04-03T19:16:30.040 | <p>I am attempting to send a RAW IR code using the IRremote.h library. The process for capturing IR pulses is easy to find on the web, but the process for sending them again is not. After a few days, i pieced the following code together:</p>
<pre><code>#include <IRremote.h>
IRsend irsend;
void setup() {
}
void loop() {
int IRsignal[] = {
// ON, OFF (in 10's of microseconds)
90, 86,
174, 88,
86, 88,
86, 88,
86, 88,
86, 88,
86, 88,
86, 88,
86, 174,
88, 86,
174, 88,
86, 2340,
88, 86,
174, 88,
86, 88,
86, 88,
86, 88,
86, 88,
86, 88,
86, 88,
86, 174,
88, 86,
174, 88,
86, 0};
irsend.sendRaw(IRsignal, 10, 38);
delay(1000);
}
</code></pre>
<p>When I run it, i get the following error:</p>
<blockquote>
<p>ir_test.ino: In function 'void loop()': ir_test.ino:65:38: error:
invalid conversion from 'int*' to 'unsigned int*' [-fpermissive] In
file included from ir_test.ino:3:0:
/Applications/Arduino.app/Contents/Resources/Java/libraries/RobotIRremote/src/IRremote.h:143:8:
error: initializing argument 1 of 'void IRsend::sendRaw(unsigned
int*, int, int)' [-fpermissive] void sendRaw(unsigned int buf[],
int len, int hz);
^ Error compiling.</p>
</blockquote>
<p>I am not sure what I did wrong, or how to convert the data types. Any tips or ideas?</p>
| <p>Use <code>unsigned int IRsignal[]</code> instead.</p>
<p>Also, your array is 48 items long, not 10. So <code>irsend.sendRaw(IRsignal, 48, 38);</code></p>
|
9835 | |c++| | Problem with declaring 2D vector in Arduino | 2015-04-04T07:48:47.770 | <p>I have included the STL library in Arduino and i can run a program with 1D vector.
But i am getting error while declaring a 2D vector. </p>
<pre><code>#include <StandardCplusplus.h>
#include <serstream>
#include<vector>
#include<iterator>
using namespace std;
vector <vector<int> > grid;
vector<int> col(5,3);
grid.push_back(col);
void setup()
{
Serial.begin(9600);
}
void loop()
{
for(int i = 0; i < 5; i++)
{
Serial.println(grid[[0][i]);
}
}
</code></pre>
<p>And the error is </p>
<pre><code>'grid' does not name a type.
</code></pre>
<p>Do i need to add another header file?</p>
| <p>The error is coming from </p>
<pre><code> grid.push_back(col);
</code></pre>
<p>You cannot have this line at the top-most level outside a function / main. Move it inside <code>setup</code> or <code>loop</code>.</p>
|
9840 | |library|c| | Problem importing a library in .h file | 2015-04-04T14:43:57.127 | <p>I have following code:</p>
<p><strong>MyApp.ino</strong>:</p>
<pre><code>#include "DfRobotLcdShield.h"
void setup() {
}
void loop() {
}
</code></pre>
<p><strong>DfRobotLcdShield.h</strong>:</p>
<pre><code>#include <LiquidCrystal.h>
</code></pre>
<p>When I try to compile, I'm getting the error:</p>
<pre><code>In file included from MyApp.ino:1:0:
c:\temp\build5856181074637812172.tmp\DfRobotLcdShield.h:4:27: fatal error: LiquidCrystal.h: No such file or directory
#include <LiquidCrystal.h>
^
compilation terminated.
Error compiling.
</code></pre>
<p>When I add</p>
<pre><code>#include <LiquidCrystal.h>
</code></pre>
<p>directly to the .ino file, it works. I'm using the latest Arduino-IDE 1.6.3.</p>
| <p>This seems to be a general problem of the Arduino IDE: It only recognizes libraries that are included in the (primary) <code>.ino</code> file.</p>
<p>If you look at the invocation of the compiler, the path to any given library is only added if this library's header file is included in the <code>.ino</code> file.</p>
<p>I tested this with the EEPROM library. If this library is included in the <code>.ino</code> file, the compiler is called with</p>
<pre><code>avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/eightanaloginputs -I/usr/share/arduino/libraries/EEPROM /tmp/build2678545434708654378.tmp/test.cpp -o/tmp/build2678545434708654378.tmp/test.cpp.o
</code></pre>
<p>where the important part is the <code>-I/usr/share/arduino/libraries/EEPROM</code>.</p>
<p>If I now remove <code>#include <EEPROM.h></code> (but still have it in another header file which in turn is included in the <code>.ino</code> as in your case), the compiler call changes to</p>
<pre><code>avr-g++ -c -g -Os -Wall -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=100 -I/usr/share/arduino/hardware/arduino/cores/arduino -I/usr/share/arduino/hardware/arduino/variants/eightanaloginputs /tmp/build2678545434708654378.tmp/test.cpp -o/tmp/build2678545434708654378.tmp/test.cpp.o
</code></pre>
<p>where now the include path to the library is missing.</p>
<h2>TL;DR</h2>
<p>If you need to use a library, just (also) add an include to the <code>.ino</code> file. It doesn't cost you anything and will solve your problem ;)</p>
<hr />
<h3><code>#include <file></code> vs. <code>#include "file"</code></h3>
<p>From the <a href="https://gcc.gnu.org/onlinedocs/cpp/Include-Syntax.html" rel="nofollow noreferrer">gcc documentation</a>:</p>
<ul>
<li><em>#include <file></em> is used for system header files. It searches for a file named file in a standard list of system directories. [...]</li>
<li><em>#include "file"</em> is used for header files of your own program. It searches for a file named file first in the directory containing the current file, then in the quote directories and then the same directories used for <file>. [...]</li>
</ul>
|
9843 | |arduino-uno|serial|timers| | Calculating time between Serial events | 2015-04-04T18:13:02.570 | <p>I am trying to calculate time between two serial events. Using Arduino UNO R3 with 16MHz default clock source.
I am using timer 1 with pre-scale of 64 to get time per one count = 4000ns. This i am choosing at random without any specific reason.
Sending character 'o' to start the timer and character 'k' to stop it and hence calculate the time in between. The ISR routine calculates how much times the timer overflows.
The code is:</p>
<pre><code> unsigned int t;
unsigned int c;
char r;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(13, OUTPUT);
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
TIMSK1 = (1<<TOIE1);//enable timer overflow interrupt
sei();
//SREG = (1<<8);//enable global inteerupt
}
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()>0)
{
r=Serial.read();
if(r=='o')
{
TCNT1=0;
TCCR1B |= (1<<CS11)|(1<<CS10);//64 pre-scale & start
Serial.println(TCNT1);
}
else if(r=='k')
{
Serial.println(TCNT1);
TCCR1B = 0;//stop timer
t=TCNT1+(c*65536);
t=t*(4*10^(-9));
Serial.print("overflows = ");
Serial.println(c);
Serial.print("time = ");
Serial.println(t);
c=0;
t=0;
}
}
}//loop
ISR(TIMER1_OVF_vect)
{
c++;
}//isr
</code></pre>
<p>But, on serial monitor only the block of if(Serial.read()=='o').... is executing. The flow does not enter the second else if block.</p>
<p>What is wrong with this code? How long does the Serial buffer hold its vale ?</p>
<p><strong>EDIT:</strong> I got the code working for checking for 'k'. But the timer value it calculates is very less than compared to what it should be. Is anything wrong with the timer settings. Setting CS10=CS11=1 gets the pre-scaler value to 64.</p>
<p>Hence, the time for 1 count should be = 1/(16MHz/64) .</p>
<p>Is anything wrong with this?</p>
| <p>I'd read the result of <code>Serial.read()</code> to a variable and check this variable, because otherwise the first <code>Serial.read()</code> will have already read the 'k'. I reckon you can remove the <code>Serial.available()</code> check.</p>
<pre><code>void loop() {
int chr = Serial.read();
if(chr=='o')
{
TCNT1=0;
TCCR1B |= (1<<CS11)|(1<<CS10);//64 pre-scale & start
}
else if(chr=='k')
{
t=TCNT1;
TCCR1B = 0;//stop timer
t=t+(c*65536);
c=0;
Serial.println(t);
t=0;
}
}//loop
</code></pre>
|
9850 | |current|arduino-micro| | Using Arduino Micro With 12V Buzzer | 2015-04-04T21:17:08.233 | <p>I have an interesting situation. I wonder if anyone can help?</p>
<p>I have:</p>
<ul>
<li>4x Arduino Micros loaded with the basic Blink sketch</li>
<li>5x <a href="http://uk.rs-online.com/web/p/magnetic-buzzer-components/7243184/" rel="nofollow">12 volt buzzers</a></li>
<li>A desk full of completely fresh Duracell AA and 9v batteries</li>
</ul>
<p>If I connect (using VIN and GND) any of the Arduino Micros to either a 9v battery, or a 12v network of 8 AA batteries, then they run the blink sketch, and the appropriate LED flashes on the Arduino as expected.</p>
<p>If I connect any of the buzzers to either a 9v battery, or a 12v network of 8 AA batteries, then they buzz as expected.</p>
<p>If I connect both a buzzer and an Arduino in parallel to either a 9v battery, or a 12v network of 8 AA batteries, then the Arduino works fine, <strong>but the buzzer makes barely an inaudible whimper</strong>.</p>
<p>If I connect only a buzzer to the Arduino and battery, it works fine. If whilst the buzzer is buzzing I connect the Arduino, then on every ON or OFF of the blink sketch LED, the buzzer gets quieter and quieter until it can barely be heard.</p>
<p>These buzzers are rated to work at 25mA, so it really astounds me that they can't be run off a battery together with an Arduino.</p>
<p>Any help would be appreciated!</p>
<p>Thanks</p>
<p>Dave</p>
| <p>Attach your voltmeter across the battery, and measure the available voltage when different things are attached; or attach it in series, and measure current draws. You probably will find that a 9V battery's voltage is under 8 volts when a mix of multiple Arduinos and buzzers is attached. That voltage may be too low to activate the buzzer.</p>
<p>A powerstream.com web page called <em><a href="http://www.powerstream.com/9V-Alkaline-tests.htm" rel="nofollow noreferrer">9V Alkaline tests</a></em> shows how rapidly a 9V battery's voltage drops when heavy currents (more than a few dozen milliamps) are drawn from it, and a batteriesinaflash.com <a href="http://www.batteriesinaflash.com/lithium/9v/12x-ultralife-9v-lithium-battery-1200mah-for-alarm-home-safety" rel="nofollow noreferrer">web page</a> includes the following diagram that shows battery voltage quickly falling below 8.5 V in its first minutes of life when 27 mA is drawn from it. <img src="https://i.stack.imgur.com/egLKW.gif" alt="9v-lithium-comparison.gif"></p>
<p>For some models of Arduino, eg the <a href="http://arduino.cc/en/main/arduinoBoardUno" rel="nofollow noreferrer">Uno R3</a>, various <a href="http://forum.arduino.cc/index.php?topic=5536.0" rel="nofollow noreferrer">posts on the web</a> list currents from 25 mA up to 45 mA, depending on LED and sleep settings. Currents for the <a href="http://arduino.cc/en/Main/arduinoBoardDuemilanove" rel="nofollow noreferrer">Duemilanove</a> from 10 mA up are reported. The <a href="http://arduino.cc/en/Main/arduinoBoardMicro" rel="nofollow noreferrer">Arduino Micros</a> in your tests probably use a little more current than <a href="http://arduino.cc/en/Main/arduinoBoardProMini" rel="nofollow noreferrer">Pro Mini</a> boards (which have no USB), and although it's unlikely they will use as much or more current than the buzzers, they still may drag the voltage down to a level where the buzzers won't work.</p>
<p>If your system needs to be battery powered, consider using separate batteries for different devices, to avoid problems like you saw. Alternatively, use heavier-duty batteries, eg <a href="https://en.wikipedia.org/wiki/List_of_battery_sizes#Cylindrical_lithium-ion_rechargeable" rel="nofollow noreferrer">good-sized lithium-polymer units</a>. Also review posts about decreasing Arduino power usage via sleep, disconnecting the power LED, and using large capacitors to buffer power surges.</p>
<p><em>Edit:</em> Given that voltage measurements show enough voltage being available, the suggested use of capacitors or inductors to isolate circuits may be a good idea. </p>
<p>When adding a capacitor, locate it physically close to the power-using board or component. For electrolytic capacitors, attach the capacitor's + terminal to the high side, eg to the +5, +9, or +12 side, and attach its - terminal to ground.</p>
<p>When adding ferrite beads, wrap the supply wire through the bead several times, if there's room. The picture below illustrates the idea. </p>
<p>An electrolytic capacitor across a circuit acts as a voltage reservoir. It also gives high-frequency signals an easy path to ground, reducing interference. A ferrite bead or other inductor impedes high frequency signals, again reducing interference.</p>
<p><img src="https://i.stack.imgur.com/T9qkj.jpg" alt="enter image description here"></p>
|
9857 | |serial| | Can I make the Arduino ignore serial print | 2015-04-05T11:27:50.980 | <p>I like having serial communication for debugging and testing purposes but after a while it takes away too much speed from the sketch. </p>
<p>Is it possible to have the Arduino ignore serial.print and serial.println throughout my code, without turning it into a comment or placing every serial printing inside for example "if(debug == true)" statements?</p>
<p>Thanks in advance.</p>
| <p>Yet another solution is to implement a dummy Serial device. That would be a class that as HardwareSerial inherits from Stream and implements the necessary virtual member functions with dummy functions. </p>
<pre><code>class NullSerial : public Stream {
public:
virtual size_t write(uint8_t) { return (1); }
virtual int available() { return (0); }
virtual int read() { return (0); }
virtual int peek() { return (0); }
virtual void flush() {}
...
void begin(unsigned long, uint8_t) {}
void end() {}
...
};
NullSerial Serial;
</code></pre>
<p>As Serial is not defined as a weak symbol the application would need to use a Steam variable for output. And bind this to the HardwareSerial or the NullSerial.</p>
<pre><code>#if defined(DEBUG)
Stream& trace = Serial;
#else
NullSerial noSerial;
Stream& trace = noSerial;
#else
#endif
...
trace.print(42);
</code></pre>
<p>This is not complete as all the HardwareSerial member functions (that the sketch uses) are needed but gives the general idea how to use OOP to solve the problem. </p>
<p>Cheers!</p>
|
9864 | |atmega328|c|data-type| | Convert uint8_t array to uint32_t array | 2015-04-05T20:07:41.950 | <p>I have this array of bytes, that I need to convert to an array of unsigned ints. Also the function (<code>btea</code>) that needs it, seems to need a pointer. </p>
<p>I'm currently using <code>reinterpret_cast</code> which seems to work, but I'd like to know how/why. I'm pretty new to <code>C</code>. It also seems kind of dirty. I could use a for loop, and bitshift everything into a separate int array variable, but that seems wasteful.</p>
<pre><code>uint8_t data[] = {1,2,3,4,5,6,7,8};//can be any multiple of 4 bytes
btea(reinterpret_cast<uint32_t*>(data), sizeof(data)/4, encryption_key);
radio.write(data, sizeof(data));
...
void btea(uint32_t *v, int n)
{
...
}
</code></pre>
<p>Any pointers (pun intended) are much appreciated.</p>
| <p>@mpflaga's answer gives a great alternative, but I thought I'd explain why your code works (grossly simplified). </p>
<p>All the reinterpret cast does is let the compiler know how wide of a variable it assumes is in each element of the array. When you access <code>data[1]</code>, it uses one byte at an offset of one byte from <code>data[0]</code>. When you cast to uint32_t and access <code>data[1]</code>, it uses 4 bytes at an offset of 4 bytes. </p>
<p>If your memory looks like this (each square is one byte)... </p>
<p><img src="https://i.stack.imgur.com/gec1a.png" alt="enter image description here"></p>
<p>...before the cast you are interpreting it as the top layout, after the cast you interpret it as the bottom layout. It's still exactly the same in memory, you're just telling the compiler to use it differently. The reason that using a union is better is that it is safer. Your code would read garbage after the end of the array if its length <em>wasn't</em> divisible by 4.</p>
<p>One other quick note, be careful with the sizeof() operator on arrays - it always gives the length in bytes regardless of the element size.</p>
|
9867 | |battery|solar| | Day-night powered Arduino | 2015-04-05T22:40:32.647 | <p>What should I do to have an Arduino Pro Mini 5V (clone) powered by a 5V solar panel during the day and by battery during night which will be charged during the day by the solar panels.</p>
<ul>
<li>is there any guide out there?</li>
<li>is it possible with the 5V version of Arduino Pro Mini or will I have to buy the 3.3V</li>
<li>I prefer to make the circuits by myself rather than buying them (for example: the charging circuit.)</li>
</ul>
| <p>This would be better answered on Stack Exchange Electrical Engineering.</p>
<p>Also <a href="https://arduino.stackexchange.com/questions/665/powering-arduino-with-solar-panels?rq=1">see this question and answers</a>. This is not quite the same and the answers there are OK but less than complete or correct, but it adds to the resource available. </p>
<p>You need a battery charging controller, a PV (solar) panel capable of producing somewhat more than maximum battery voltage and enough energy to operate your circuit and a battery with enough voltage to operate the device and enough capacity to store the energy.</p>
<p>Current drain will vary with total circuit. You can measure this will a milliammeter. I'll assume that 50 mA continuous will be enough. Less or much less may suffice. I have a pro mini clone operating at 20 mA on 5V at present and with due care you may be able to operate one with less or much less current depending on application and what your circuit needs are.</p>
<p>Looking at solar current needs at present, the average solar current needed is about Icircuit x 24/SSH mA where SSH = average sunshine hours per day. eg if you had 4 hours of sunshine per day but want to run the circuit for 24 hours a day the sun must provide (24 hours per day)/(4 hours of sun) = 6 x as much current as the circuit needs on average. So if your circuit needs 50 mA continuous the PV panel must provide 6 x 50 mA = 300 mA for 4 hours per day. You will see below that this is not a trivial amount. </p>
<p>Sunshine hours per day may be found for sites worldwide using the excellent www.gaisma.com The <a href="http://www.gaisma.com/en/location/iraklion.html" rel="nofollow noreferrer"><strong>average sunshine hours per day for Iráklion</strong></a> may be found at that link and other locations in Greece can be found <a href="http://www.gaisma.com/en/dir/gr-country.html" rel="nofollow noreferrer"><strong>here</strong></a> but will probably be similar.<br>
For Iráklion the SSH may be found in the 1st line of the 4th chart.<br>
Average hours/day of equivalent full sunshine = kWh/m^2/day = a peak of 8.53 hours in June and a low of 2.08 hours in December.<br>
Wow!
I think that is about as sunny a place in Summer as anywhere on earth not in the polar regions. In Winter it gets about the same SSH as in <a href="http://www.gaisma.com/en/location/manukau.html" rel="nofollow noreferrer">my city</a>. You can calculate PV sizing for peak summer - but if you want year round operation you should use the worst case winter month and add a bit for bad days.<br>
For Iraklion us say 2 SSH per day so the panels needs to provide 24/2 = 12 x winter average load. So per 10 mA of load yo need 120 mA of panel and if the mean load is 50 mA you need 12 x 50 = 300 mA panel output.</p>
<p>Battery voltage needs to be > 5V at all times.<br>
An easy cheap available starting solution is to use a 6B lead acid battery.
These are easyish to charge and provide a relatively stable operating voltage.<br>
Vmax_charge is <strong>about</strong> 7V so an 8V or 9V PV panel is "about right". 9V is a common voltage for hobby applications. An alternative is to use a 12V panel. this is probably more suitable as they are widely available and cost per energy out is often lower. This wastes MOST of the panel output but still MAY be the cheapest option in many cases. (A 12V x 600 mA panel is rated at about 18V x 0.6A ~= 10 Watts. Actual Arduino load = 50 mA x 5V x 12:1 = 3 Watts) </p>
<p>At 50 mA load you need 24/2 x 50 mA = 600 mA PV output in full sun.<br>
PV panel sizing is not as may be expected. It is easiest to get a panel that makes at least enough voltage and enough current. This is because panel RATED voltages are usually higher than the voltages they are used at. eg 12V system PV panels are usually rated at 18V max power voltage- so an 18W panel provide 18V at 1 A BUT if attached directly to a 12V battery the input to the battery = 12V x 1A = 12 Watts. There are ways around this but at first, just concentrate on panel mA.</p>
<p>So, you "need" a 600 mA panel for a 50 mA load.<br>
Or a 60 mA panel for a 5 mA load.<br>
Or a 6 mA panel for a 0.5 mA load.<br>
Obviously, reducing load current is going to help panel sizing.<br>
So knowing what your application really needs is essential.</p>
<p>Batery is easier.<br>
If you use 6V lead acid then for one day you need.<br>
Hours x load = mAh.<br>
Here load=24 hours. mA = 50 in this example.<br>
mAh = 24 x 50 mA = 1200 mAh = 1.2 Ah. This is the capacity of about the smallest LA battery commonly available. In practice you want to discharge your battery by only a small % of its actual capacity so use a 2.4 Ah or 3.5 Ah or larger. 7Ah is not vastly dearer and will last far longer and will have several days of reserve capacity for bad weather.</p>
<p>Charging can now be discussed - but I'll stop here and see what is said about the above. We can add charging and other detail if it seems useful to do so. </p>
<p><img src="https://i.stack.imgur.com/F3oG9.jpg" alt="enter image description here"></p>
<p>An easy battery to use is 2 x LiIon or LiPo cells in series. </p>
|
9877 | |ethernet| | Set the timeout - Ethernet Shield library | 2015-04-06T12:13:19.783 | <p>Does anyone know if you can set the time for the timeout Ethernet Shield library? Let me explain:</p>
<p>I created a very simple function (below) that attempts to connect to an address if it is not accessible returns 0 if it is available returns 1. Problem is that when the site is not available, the microcontroller is waiting for an answer for a long time, wanted to reduce it.</p>
<pre><code>uint8_t ping(const char* address)
{
EthernetClient http;
if(http.connect(address, 80)) {
http.stop();
return 1;
}
else
return 0;
}
</code></pre>
| <p>In the stream class there is a setTimeout(ms) function. e.g.</p>
<pre><code>String str;
Serial.setTimeout(5000) ;
str = Serial.readStringUntil('\r');
</code></pre>
<p>Where this does timeout the initial connection attempt in http.connect(). Whereas I found it also important to timeout each line, as a web page may not disconnect at the end or not send anything.</p>
<pre><code>int httpGetHeaders() {
String request, response;
int result = 0;
long startOfHttpResponseTime;
client.setTimeout(1000) ;
response = "";
inHeaders = true;
startOfHttpResponseTime = millis();
while((client.connected()) && inHeaders && ((long)(millis() - startOfHttpResponseTime) < HTTP_RESPONSE_TIMEOUT)) {
String header = client.readStringUntil('\n');
header.trim(); // trim off white spaces including CR and LF at end.
Serial.print(F("head["));
Serial.print(header.length());
Serial.print(F("]:\""));
Serial.print(header);
Serial.println(F("\""));
if (!header.length()) { // first blank line indicates end of headers
inHeaders = false;
Serial.println(F("No longer in Headers"));
}
else {
if (header.startsWith("HTTP")) {
Serial.println(F("HTTP Found"));
int firstspace = header.indexOf(" ");
result = header.substring(firstspace + 1, header.indexOf(" ", firstspace + 1)).toInt();
Serial.print(F("result = "));
Serial.println(result);
}
}
}
Serial.print(F("Result code = "));
Serial.println(result);
return result;
}
</code></pre>
<p>You may want to review the whole code at <a href="https://github.com/lansing-makers-network/StatusBotArduino/blob/master/StatusBotArduino.ino" rel="nofollow">https://github.com/lansing-makers-network/StatusBotArduino/blob/master/StatusBotArduino.ino</a> I have reduced the connection to a sequence of commands that can be used consectutively in the desired order to meet different needs. The above is just to read a headers response.</p>
|
9890 | |arduino-uno|bluetooth| | Install Bluetooth inside a home theater, How? | 2015-04-07T07:42:17.817 | <p>I have a 5.1 home theater(old one), I would like to transform it into a audio streaming system. I have a Arduino UNO and HC-05 Bluetooth Module, and I don't know how to install it in my home theater(if it does). solution please... </p>
| <p>I don't think this will be feasible. There are two main issues:</p>
<p><strong>1.</strong> I don't think there's a sensible way to get the HC-05 module to work with A2DP. It's great for a simple serial connection, but Bluetooth-enabled media devices generally won't connect to it if they're looking for audio streaming systems (as far as I know).</p>
<p><strong>2.</strong> The Uno probably isn't powerful enough. Even if you could get the audio data into it, I don't think it will be able to decode the information to an analog audio signal in real-time.</p>
<p>Something like a Raspberry Pi with a suitable Bluetooth module might be a better choice for this.</p>
|
9899 | |serial|arduino-ide|chipkit| | Serial structure data transfer between an Arduino and a Linux PC | 2015-04-07T13:20:38.743 | <p>I use the Arduino compatible <a href="http://www.digilentinc.com/Products/Detail.cfm?NavPath=2,892,1193&Prod=CHIPKIT-WF32" rel="nofollow">chipKIT WF32</a> board. I want to transfer structure data between my board and a Linux PC. Can I do it like the following?</p>
<pre><code>struct data d;
char *tx = (char*)d;
Serial.print(tx);
</code></pre>
<p>Even if the above code works, the data type size in Arduino and on Linux will vary. Is there a way to serialize the data, like <a href="https://en.wikipedia.org/wiki/Protocol_Buffers" rel="nofollow">Protocol Buffers</a> on Arduino?</p>
| <p>I usually send structures from arduino via serial port to PC <del>and use the memcpy function to do it.</del>
Let's say you have the struct data d (<em>as pointed by the comments the memcpy as unnecessary. Use cast or union</em>):</p>
<pre><code> struct data state;
len = sizeof(state);
Serial.write((uint8_t *)&state,len);
</code></pre>
<p>It is useful to create a starting and ending character to delimit your important data and make sure you receive all data and good information.
Let me give you one of my recent work example:</p>
<pre><code>...
void send_state(){
len = sizeof(state);
Serial.write('S');
Serial.write((uint8_t *)&state, len);
Serial.write('E');
return;
}
...
</code></pre>
<p>In this example the struct state is preceded with "S" (start) and succeeded with "E".
Then in python, for example, you can get the data using the unpack function. In my case:</p>
<pre><code>...
# wait for data from arduino
myByte = port.read(1)
if myByte == 'S':
data = port.read(39)
myByte = port.read(1)
if myByte == 'E':
# is a valid message struct
new_values = unpack('<c6BH14B4f', data)
...
</code></pre>
<p>See if arduino sends data in little endian. The one I have used to send it. </p>
|
9900 | |motor| | Connecting an AB phase encoder motor to arduino | 2015-04-07T13:32:30.687 | <p>i'm trying to understand how to connect this motor:</p>
<p>"Mitsumi 334P/R AB"</p>
<p><a href="http://www.ebay.com/itm/Mitsumi-334P-R-AB-phase-encoder-encodes-tacho-motor-speed-disk-DC3V-24V-5V-6V-/221702525894?pt=LH_DefaultDomain_0&hash=item339e8013c6" rel="nofollow noreferrer">Link to the motor i bought</a></p>
<p><img src="https://i.stack.imgur.com/UST5F.jpg" alt="enter image description here"></p>
<p>connections are:</p>
<p>GND - Obvious.</p>
<p>5v - Obvious.</p>
<p>rest of the connections are a bit confusing to me and i do not want to fry my arduino trying.</p>
<ul>
<li>do i need a driver or this looks like a built in one?</li>
<li>do i need to add any electrical components like resistors and capacitors ect?</li>
</ul>
| <p>It's just a regular motor, with a (optical) rotary encoder inside. So the first two <code>motor</code> pins are to run the motor. So connect to VCC and GND, or GND and VCC, if you want to run it in reverse. (VCC doesn't have to be 5v; it can be 3v to 30v).</p>
<p>Connect A and B to a digital input pin. You can see what kind of signal you can expect in the screenshot of the oscilloscope, attached to the ebay-listing. So you can measure the speed, and relative position of the motor-shaft.</p>
|
9904 | |led|variables| | How do I turn on or off an array of LEDs based on the value of a variable? | 2015-04-07T14:59:25.383 | <p>I've created a function whereby an int ('cleanCount') automatically goes up or down (0-1000) based on the situation. The value changes every few milliseconds. </p>
<p>Based on the value, I would like to turn on or off LEDs. Let's say for every increment of '100' another LED goes on. So if the value is 359 there are 3 leds on, if It would been 899 there would've been 8 LEDs on. </p>
<p>I could simply write</p>
<pre><code>if (cleanCount <= 100) { // turn on NO LEDs
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
...
}
...
else if (cleanCount <= 500) { // turn on 4 LEDs
...
digitalwrite(led3, HIGH);
digitalwrite(led4, HIGH);
digitalwrite(led5, LOW);
digitalwrite(led6, LOW);
...
}
</code></pre>
<p>but that would be a big pile of code which could be way more efficient. Perhaps.. my code isn't even correct.</p>
<p>So how could this be more efficient or perhaps actually working?</p>
<hr>
<p><em>The whole code, here below.</em></p>
<pre><code>int cleanCount = 1000;
int softpotPin = A0; //analog pin 0
void setup () {
Serial.begin(9600);
digitalWrite(softpotPin, HIGH); //enable pullup resistor
}
void loop() {
int softpotReading = analogRead(softpotPin);
if (softpotReading < 980) { // IF AANGERAAKT
digitalWrite(werktIeLED, HIGH);
++cleanCount;
Serial.println(cleanCount);
delay(16); // 5x zo snel als leeglopen
}
else if (softpotReading > 980) { // IF NIET AANGERAAKT
digitalWrite(werktIeLED, LOW);
--cleanCount;
Serial.println(cleanCount);
delay(64); // 1000 / 60 seconden
}
else { // Als er een fout optreed..
Serial.println("Fout!");
digitalWrite(werktIeLED, HIGH);
delay(250);
digitalWrite(werktIeLED, LOW);
delay(250);
}
}
</code></pre>
| <p>You can use the barGraph example from the Arduino code examples. This gives a bar-type graph and not point. I will give rough explination why it will work and the need not to re-invent the wheel.</p>
<pre><code> int sensorReading = analogRead(analogPin);
// map the result to a range from 0 to the number of LEDs:
int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);
// loop over the LED array:
for (int thisLed = 0; thisLed < ledCount; thisLed++) {
// if the array element's index is less than ledLevel,
// turn the pin for this element on:
if (thisLed < ledLevel) {
digitalWrite(ledPins[thisLed], HIGH);
}
// turn off all pins higher than the ledLevel:
else {
digitalWrite(ledPins[thisLed], LOW);
}
}
</code></pre>
<p><code>int ledLevel = map(sensorReading, 0, 1023, 0, ledCount);</code></p>
<p>This will give you the point in the array, 0-10, for 0-1000, if you replace <code>1023</code> with <code>1000</code></p>
<p>Simplified <code>map()</code> function:</p>
<p><code>int point = sensorReading*10/1000</code> this gives you a range of 0-10, the int keeps it from having decimal points.</p>
<p>As you can see from the for loop it turns on all the LEDs that are in the array to the end and then turns off those not needed.</p>
|
9907 | |arduino-uno|analogread| | Why does the ADC overflow when using an external Aref? | 2015-04-07T15:57:58.770 | <p>I'm using an LM35 temperature sensor, and it outputs 190 mV (which agrees with 19°C). I'm using an external reference voltage which I measure as 417mV. (This is set by the pin "aRefCntrl"). So I should have a reading around 467, but I get 1023, i.e. the ADC overflows. When I use the internal 1.1V reference I get a correct reading. Any ideas?</p>
<p>This is my code (Arduino waits for a request from the PC to send the data):</p>
<pre><code>#define lm35 A0
#define aRefCtrl 10
void setup() {
pinMode(aRefCtrl, OUTPUT);
digitalWrite(aRefCtrl, 0);
analogReference(EXTERNAL);
analogRead(lm35); // dummy read
Serial.begin(9600);
}
void loop() {
if ( Serial.available() ) {
Serial.read(); // PC's request is a single byte
int temperature = analogRead(lm35);
Serial.println(temperature);
}
}
</code></pre>
<p><strong>follow-up</strong> on Ignacio's comment: would a decoupling capacitor do? (I can't test for the moment, I have to order some)</p>
| <p>The minimum reference voltage is 1.0 V according to the atmega328 <a href="http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf" rel="nofollow">datasheet</a>. See table 29-15. ADC Characteristics.</p>
|
9914 | |led| | Arduino turns LEDs off when set 'high', opposite direction as coded | 2015-04-07T19:56:53.723 | <p>I've got a function that decreases over time (1000 / 60 seconds) and by touching a softPotentiometer you can increase that value. By every increment of 200 a LED is lid. So for 0-200, 1 LED; 201-400, 2 LEDs; etc. And since it decreases over time while doing nothing, if it drops below a certain value, a LED is shut off.</p>
<p>However, I've got a (amateur) coded set up, but somehow it lids the LEDs in the opposite direction. In a way that, I've coded it that if it's above 800, lid 5 LED's. However, it will only lid one LED when it's dropped below the 800, in the area of 601-800.</p>
<p>That's exactly the opposite of what I want. So what am I doing wrong here? </p>
<hr>
<p>My code:<br>
<em>And with amateur, I mean that I didn't use arrays and therefor write everything multiple times..</em></p>
<pre><code>int cleanCount = 1000;
int IsItWorkingLED = 13;
int softpotPin = A0; //analog pin 0
int LED1 = 1;
int LED2 = 2;
int LED3 = 4;
int LED4 = 5;
int LED5 = 7;
void setup () {
Serial.begin(9600);
digitalWrite(softpotPin, HIGH); //enable pullup resistor
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(7, OUTPUT);
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
}
void loop() {
int softpotReading = analogRead(softpotPin);
if (softpotReading < 980) { // IF TOUCHED
digitalWrite(IsItWorkingLED, HIGH);
++cleanCount;
Serial.println(cleanCount);
delay(16); // Drain 5 times as fast
}
else if (softpotReading > 980) { // IF NOT DTOUCHED
digitalWrite(IsItWorkingLED, LOW);
--cleanCount;
Serial.println(cleanCount);
delay(64); // 1000 / 60 seconds
}
else { // Als er een fout optreed..
Serial.println("Something wrong!");
digitalWrite(IsItWorkingLED, HIGH);
delay(250);
digitalWrite(IsItWorkingLED, LOW);
delay(250);
}
if (cleanCount >= 0 && cleanCount <= 200) {
Serial.println("Knal 1 LED aan");
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED3, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED5, LOW); // turn the LED on (HIGH is the voltage level)
}
else if (cleanCount >= 201 && cleanCount <= 400) {
Serial.println("Knal 2 LEDs aan");
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED3, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED5, LOW); // turn the LED on (HIGH is the voltage level)
}
else if (cleanCount >= 401 && cleanCount <= 600) {
Serial.println("Knal 3 LEDs aan");
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED4, LOW); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED5, LOW); // turn the LED on (HIGH is the voltage level)
}
else if (cleanCount >= 601 && cleanCount <= 800) {
Serial.println("Knal 4 LEDs aan");
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED5, LOW); // turn the LED on (HIGH is the voltage level)
}
else if (cleanCount >= 801 && cleanCount <= 1000) {
Serial.println("Knal 5 LEDs aan");
digitalWrite(1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(4, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(5, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(7, HIGH); // turn the LED on (HIGH is the voltage level)
}
else {
Serial.println("Just..do nothing");
}
}
</code></pre>
| <p>Try reversing the if statements.
You say:</p>
<blockquote>
<p>I've coded it that if it's above 800, lid 5 LED's.</p>
</blockquote>
<p>And your code is:
<code>(softpotReading < 980) { // IF TOUCHED</code></p>
<p>The code describes: <code>IF softpotReading IS SMALLER THAN 980, DO{ code.. }</code></p>
<hr>
<p>In dutch (as OP is dutch, and to be honest his English somehow confuses me a bit, to be sure it's not the other way around also):</p>
<p>Ik denk dat je de IF statements verkeerd om hebt.
Je beschrijft dat bij een waarde hoger dan 800 de ledjes aan gaan...</p>
<p>Echter staat in je code <code>(softpotReading < 980) { // IF TOUCHED</code>
Wat dus zal betekenen dat de code wordt uitgevoerd als die < (kleiner dan) 980 is.</p>
<hr>
<pre><code> if (softpotReading > 980) { // IF TOUCHED
digitalWrite(IsItWorkingLED, HIGH);
++cleanCount;
Serial.println(cleanCount);
delay(16); // Drain 5 times as fast
}
else if (softpotReading <= 980) { // IF NOT DTOUCHED
digitalWrite(IsItWorkingLED, LOW);
--cleanCount;
Serial.println(cleanCount);
delay(64); // 1000 / 60 seconds
}
</code></pre>
|
9925 | |led| | A LED should be lit when 'high'. Why does mine only burn with 'low'? | 2015-04-08T08:12:49.787 | <p><sup>This is my followup question based on a serie of one project. Go my to profile to read 'm all.</sup></p>
<p>So I'm building something which includes a function that has a count (1000) that decreases over time, but by pressing a soft pot meter the count increases. By every increment of 200 one LED is lit. So if the count is 837 4 LEDs are burning. </p>
<p>In my previous question I had issues lighting the LEDs, because they didn't burn even when the code was, as far as I could see correct. Instead it did the opposite of what I coded. Now I changed my code the opposite direction, </p>
<p>writing:</p>
<blockquote>
<p>digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)</p>
</blockquote>
<p>Which actually set the LED to bright. While is I'd write it 'HIGH' it would dim. </p>
<p>So my actual question is: How could my LED be lit if it's set to 'low', while you have to set it to 'high' to be actually popping off light?</p>
<hr>
<p><strong><em>My complete code:</em></strong></p>
<pre><code>int cleanCount = 1000;
int IsItWorkingLED = 13;
int softpotPin = A0; //analog pin 0
int LED1 = 1;
int LED2 = 2;
int LED3 = 4;
int LED4 = 5;
int LED5 = 7;
void setup () {
Serial.begin(9600);
digitalWrite(softpotPin, HIGH); //enable pullup resistor
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
digitalWrite(LED1, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (HIGH is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (HIGH is the voltage level)
}
void loop() {
int softpotReading = analogRead(softpotPin);
if (softpotReading < 980) { // IF TOUCHED
digitalWrite(IsItWorkingLED, HIGH);
++cleanCount;
Serial.println(cleanCount);
delay(8); // Increase 5 times as fast
}
else if (softpotReading > 980) { // IF NOT TOUCHED
digitalWrite(IsItWorkingLED, LOW);
--cleanCount;
Serial.println(cleanCount);
delay(32); // Decrease slowly
}
else { // If there is something wrong..
Serial.println("Something wrong!");
digitalWrite(IsItWorkingLED, HIGH);
delay(250);
digitalWrite(IsItWorkingLED, LOW);
delay(250);
}
if (cleanCount <= 200) {
Serial.println("Knal 1 LED aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 201 && cleanCount <= 400) {
Serial.println("Knal 2 LEDs aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 401 && cleanCount <= 600) {
Serial.println("Knal 3 LEDs aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, HIGH); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 601 && cleanCount <= 800) {
Serial.println("Knal 4 LEDs aan");
digitalWrite(LED1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED3, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED4, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(LED5, HIGH); // turn the LED on (LOW is the voltage level)
}
else if (cleanCount >= 801 && cleanCount <= 1000) {
Serial.println("Knal 5 LEDs aan");
digitalWrite(1, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(2, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(4, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(5, LOW); // turn the LED on (LOW is the voltage level)
digitalWrite(7, LOW); // turn the LED on (LOW is the voltage level)
}
else {
Serial.println("Just..do nothing");
}
}
</code></pre>
| <p>An LED wants positive voltage to flow from the anode to the cathode (the + terminal to the - terminal)</p>
<p>You can wire it to a digital pin 2 different ways. (In both cases you'll also need a current limiting resistor to avoid burning out your LED and/or your digital pin, but ignore that for this discussion.)</p>
<p>You can wire the positive terminal of the LED to +5V, and the negative terminal to a digital pin. It sounds like this is what you've done. When you do that, if you set the digital output to HIGH, then both terminals of the LED are connected to +5V, so the LED will be off. Set the output to LOW, and it gets connected to ground. Now current flows out of the +5V rail, through the LED, into the grounded digital pin, and the LED lights up.</p>
<p>You can reverse that wiring instead. Connect the positive terminal of the LED to a digital pin and the negative side to ground. Now, when you set the pin to HIGH, +5V flows out of the pin, through the LED, and into the ground connection, so the LED lights. Set the pin to LOW and both sides of the LED are connected to ground, so it turns off.</p>
<h1>Edit:</h1>
<p>Note that you talk about voltage levels and dimming LEDs. If you're using digital outputs and HIGH or LOW, you can only turn the LED on or off. There's no way to vary its brightness.</p>
<p>You can, however, hook an LED to a PWM (Pulse Width Modulation) pin and set up that pin for analog output. In PWM, the Arduino switches the LED on and off rapidly. Set it to the highest output value, 255, and the LED stops flashing and is on 100% o the time. Set the output to 128, and the LED is on half the time and off half the time. Set the output to 64, and the LED is on 1/4 of the time and off 3/4 of the time, and so on.</p>
<p>When you flash a light fast enough, our eyes average out the brightness, and a light that's on 1/4 of the time looks 1/4 as bright as a light that's on 100% of the time.</p>
<p>Most Arduinos have a limited number of analog outputs. The Arduino model you're using might not have 7 analog outputs.</p>
|
9926 | |arduino-uno|bluetooth|uploading|bootloader| | Uploading over Bluetooth Low Energy - bootloader not responding | 2015-04-08T08:13:14.243 | <p>I'm working on sketches uploading over BLE. I had to write my own uploader (looking at avrdude sources with one eye) so i can change uploading behaviour as needed and it's working over USB just perfect but it does not get response from bootloader if trying over Bluetooth LE.</p>
<p>My hardware:</p>
<ul>
<li>Arduino Uno (and i'm having Arduino Mega2560)</li>
<li>HM-10 BLE module</li>
</ul>
<p>As HM-10 does not support DTR/RTS i had to add my own software reboot:</p>
<p>In brief: it reads incoming bytes on interrupt event and compares to reset command passed in ble_setup. If it's equal then it uses watchdog timer to reboot the board. If it's not equal it stores byte in byffer, then sketch loop() just returns incoming byes back ("echo").</p>
<pre><code>#include <avr/wdt.h>
const char *ble_reset_cmd;
int ble_reset_index = 0;
int ble_available = 0; // chars available
int ble_byte; // income buffer as 1 char
int *ble_bytes = &ble_byte; // income buffer
boolean delete_ble_bytes = false;
//#define BLE_DEBUG
// reboot Arduino board using Watchdog timer
void reboot() {
// #ifdef BLE_DEBUG
Serial.println("rebooting ...");
// #endif
// digitalWrite(13, HIGH);
// delay(2000);
wdt_enable(WDTO_15MS);
while(1) { };
}
void ble_setup(int baud, const char *reset_cmd) {
Serial.begin(baud);
ble_reset_cmd = reset_cmd;
}
int Serial_available() {
return ble_available;
}
int Serial_read() {
if (ble_available < 0)
return -1;
int inByte = ble_bytes[--ble_available];
if (ble_available == 0 && delete_ble_bytes) {
// restore buffer as 1 char buffer
delete[] ble_bytes;
ble_bytes = &ble_byte;
delete_ble_bytes = false;
}
return inByte;
}
void serialEvent() {
if (Serial.available() <= 0)
return;
int inByte = Serial.read();
if (inByte == ble_reset_cmd[ble_reset_index]) {
// entered char is cmd character
if (ble_reset_cmd[++ble_reset_index] == 0)
reboot();
#ifdef BLE_DEBUG
Serial.write("ble_index = ");
Serial.print((byte)ble_reset_index);
Serial.write('\n');
#endif
} else {
// entered char is NOT cmd character
if (ble_reset_index > 0) {
// got character not from cmd, so we should to return characters
// starting ble_reset_cmd until current index and then this character
ble_available = ble_reset_index + 1;
ble_reset_index = 0;
#ifdef BLE_DEBUG
Serial.print("Copy ");
Serial.print((byte)(ble_available - 1));
Serial.println(" bytes");
#endif
// recreate input buffer using cmd characters
ble_bytes = new int[ble_available + 1];
delete_ble_bytes = true;
ble_bytes[0] = inByte;
for (int i=0; i<(ble_available-1); i++) {
ble_bytes[i + 1] = ble_reset_cmd[ble_available - i - 2];
}
ble_bytes[ble_available] = 0; // null-terminated array
#ifdef BLE_DEBUG
Serial.print("input buffer now contains ");
Serial.print(ble_available);
Serial.println(" bytes");
#endif
} else {
#ifdef BLE_DEBUG
Serial.println("ble_index = 0");
#endif
// pass inByte next ...
ble_available++;
ble_byte = inByte;
}
}
}
// -----------------------------------
int led = 13;
int ledHIGH = 0;
void setup() {
ble_setup(9600, "AT+RESET");
Serial.print("ready\n");
pinMode(led, OUTPUT);
}
void loop() {
while (Serial_available() > 0) {
int inByte = Serial_read();
// Serial.write('>');
// Serial.write(inByte);
// Serial.write('\n');
ledHIGH = 1- ledHIGH;
digitalWrite(led, ledHIGH);
Serial.write(inByte); // echo
}
}
</code></pre>
<p>As i said it's working good for USB uploading:
right after rebooting bootloader waits for upload commands and start to reply:</p>
<pre><code>015-04-07 21:22:10.860 Apploader[11226:303] Apploader v0.1
2015-04-07 21:22:12.772 Apploader[11226:303] DTR/RTS supported by Serial, resetting
2015-04-07 21:22:13.075 Apploader[11226:303] draining ...
2015-04-07 21:22:13.327 Apploader[11226:303] drain done
2015-04-07 21:22:13.328 Apploader[11226:303] Send: 0 [0x30] [0x20]
2015-04-07 21:22:13.328 Apploader[11226:303] draining ...
2015-04-07 21:22:13.723 Apploader[11226:303] drain done
2015-04-07 21:22:13.724 Apploader[11226:303] Send: 0 [0x30] [0x20]
2015-04-07 21:22:13.724 Apploader[11226:303] draining ...
2015-04-07 21:22:13.977 Apploader[11226:303] drain done
2015-04-07 21:22:13.978 Apploader[11226:303] Send: 0 [0x30] [0x20]
2015-04-07 21:22:13.979 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:13.980 Apploader[11226:303] Recv: . [0x10]
2015-04-07 21:22:13.980 Apploader[11226:303] Send: A [0x41] . [0x81] [0x20]
2015-04-07 21:22:13.984 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:13.984 Apploader[11226:303] Recv: . [0x04]
2015-04-07 21:22:13.985 Apploader[11226:303] Recv: . [0x10]
2015-04-07 21:22:13.985 Apploader[11226:303] Send: A [0x41] . [0x82] [0x20]
2015-04-07 21:22:13.988 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:13.988 Apploader[11226:303] Recv: . [0x04]
2015-04-07 21:22:13.989 Apploader[11226:303] Recv: . [0x10]
2015-04-07 21:22:13.989 Apploader[11226:303] Send: B [0x42] . [0x86] . [0x00] . [0x01] . [0x00] . [0x01] . [0x01] . [0x01] . [0x03] . [0xff] . [0xff] . [0xff] . [0xff] . [0x00] . [0x80] . [0x04] . [0x00] . [0x00] . [0x00] . [0x80] . [0x00] [0x20]
2015-04-07 21:22:13.996 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:13.997 Apploader[11226:303] Recv: . [0x10]
2015-04-07 21:22:13.997 Apploader[11226:303] Send: E [0x45] . [0x05] . [0x04] . [0xd7] . [0xc2] . [0x00] [0x20]
2015-04-07 21:22:14.000 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:14.001 Apploader[11226:303] Recv: . [0x10]
2015-04-07 21:22:14.003 Apploader[11226:303] Send: P [0x50] [0x20]
2015-04-07 21:22:14.004 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:14.008 Apploader[11226:303] Recv: . [0x10]
</code></pre>
<p>But when trying over BLE bootloader stops listening in 200ms and then launches sketch, i can see sketch setup() started as it prints "ready". Also i can see it actually reboots the board as it sends "rebooting".</p>
<pre><code>015-04-07 21:23:30.287 Apploader[11253:303] Apploader v0.1
2015-04-07 21:23:30.296 Apploader[11253:1503] CBCentralManager state is 5
2015-04-07 21:23:31.297 Apploader[11253:303] BleSerialDevice: open()
2015-04-07 21:23:31.298 Apploader[11253:303] Waiting for peripheral to be discovered ...
2015-04-07 21:23:31.591 Apploader[11253:1503] Found peripheral: <CBPeripheral: 0x100401940 identifier = D92ECAAB-51A5-44D5-8C6C-536CD797867E, Name = "Ardu", state = disconnected>
2015-04-07 21:23:31.593 Apploader[11253:1503] Stop scanning
2015-04-07 21:23:31.595 Apploader[11253:1503] Connecting to <CBPeripheral: 0x100401940 identifier = D92ECAAB-51A5-44D5-8C6C-536CD797867E, Name = "Ardu", state = disconnected>
2015-04-07 21:23:32.025 Apploader[11253:1503] Connected to peripheral <CBPeripheral: 0x100401940 identifier = D92ECAAB-51A5-44D5-8C6C-536CD797867E, Name = "Ardu", state = connected>
2015-04-07 21:23:32.041 Apploader[11253:1503] Discovered services for peripheral <CBPeripheral: 0x100401940 identifier = D92ECAAB-51A5-44D5-8C6C-536CD797867E, Name = "Ardu", state = connected>
2015-04-07 21:23:32.042 Apploader[11253:1503] Discovered service <CBService: 0x103701450>
2015-04-07 21:23:32.043 Apploader[11253:1503] Discovered service <CBService: 0x1037015f0>
2015-04-07 21:23:32.043 Apploader[11253:1503] Discovered service <CBService: 0x103701630>
2015-04-07 21:23:32.044 Apploader[11253:1503] Discovered characteristics for service <CBService: 0x103701630>
2015-04-07 21:23:32.044 Apploader[11253:1503] Discovered characteristic <CBCharacteristic: 0x1037005c0>
2015-04-07 21:23:32.045 Apploader[11253:1503] Subscribed to Rx value
2015-04-07 21:23:32.046 Apploader[11253:303] Connected successfully
2015-04-07 21:23:33.342 Apploader[11253:303] BleSerialDevice: open()
2015-04-07 21:23:33.343 Apploader[11253:303] already connected, exiting
2015-04-07 21:23:33.343 Apploader[11253:303] DTR/RTS supported by Serial, resetting
2015-04-07 21:23:33.594 Apploader[11253:303] Within interval
2015-04-07 21:23:33.595 Apploader[11253:303] Perform reset
2015-04-07 21:23:33.596 Apploader[11253:303] Send: A [0x41] T [0x54] + [0x2b] R [0x52] E [0x45] S [0x53] E [0x45] T [0x54]
2015-04-07 21:23:33.647 Apploader[11253:303] Skip draining after reset
2015-04-07 21:23:33.648 Apploader[11253:303] Send: 0 [0x30] [0x20]
2015-04-07 21:23:33.648 Apploader[11253:303] Draining for 200 ms ...
2015-04-07 21:23:33.649 Apploader[11253:303] Start reading
2015-04-07 21:23:33.712 Apploader[11253:1503] Rx value received 15 bytes: r [0x72] e [0x65] b [0x62] o [0x6f] o [0x6f] t [0x74] i [0x69] n [0x6e] g [0x67] [0x20] . [0x2e] . [0x2e] . [0x2e] . [0x0d] . [0x0a]
2015-04-07 21:23:33.713 Apploader[11253:1503] _characterRead = true
2015-04-07 21:23:33.780 Apploader[11253:1503] Rx value received 6 bytes: r [0x72] e [0x65] a [0x61] d [0x64] y [0x79] . [0x0a]
2015-04-07 21:23:33.780 Apploader[11253:1503] _characterRead = true
2015-04-07 21:23:33.850 Apploader[11253:303] Finish reading
2015-04-07 21:23:33.851 Apploader[11253:303] Drained 21 bytes
2015-04-07 21:23:33.852 Apploader[11253:303] Send: 0 [0x30] [0x20]
2015-04-07 21:23:33.853 Apploader[11253:303] Draining for 200 ms ...
2015-04-07 21:23:33.853 Apploader[11253:303] Start reading
2015-04-07 21:23:33.982 Apploader[11253:1503] Rx value received 2 bytes: 0 [0x30] [0x20]
2015-04-07 21:23:33.983 Apploader[11253:1503] _characterRead = true
2015-04-07 21:23:34.054 Apploader[11253:303] Finish reading
2015-04-07 21:23:34.055 Apploader[11253:303] Drained 2 bytes
2015-04-07 21:23:34.056 Apploader[11253:303] Send: 0 [0x30] [0x20]
2015-04-07 21:23:34.056 Apploader[11253:303] Reading 1 bytes ...
2015-04-07 21:23:34.057 Apploader[11253:303] Start reading
2015-04-07 21:23:34.057 Apploader[11253:303] _characterRead = false
2015-04-07 21:23:34.184 Apploader[11253:1503] Rx value received 1 bytes: . [0x00]
2015-04-07 21:23:34.185 Apploader[11253:1503] _characterRead = true
2015-04-07 21:23:34.186 Apploader[11253:303] Finish reading
2015-04-07 21:23:34.186 Apploader[11253:1503] Rx value received 2 bytes: 0 [0x30] [0x20]
2015-04-07 21:23:34.186 Apploader[11253:1503] _characterRead = true
2015-04-07 21:23:34.186 Apploader[11253:303] Recv: . [0x00]
2015-04-07 21:23:34.187 Apploader[11253:303] stk500_getsync() attempt 1 of 5: not in sync: resp=0x00
</code></pre>
<p>Once again - bootloader stops listening in 200 ms instead of 1-1.5 secons as over USB:</p>
<pre><code>2015-04-07 21:23:33.596 Apploader[11253:303] Send: A [0x41] T [0x54] + [0x2b] R [0x52] E [0x45] S [0x53] E [0x45] T [0x54]
...
2015-04-07 21:23:33.780 Apploader[11253:1503] Rx value received 6 bytes: r [0x72] e [0x65] a [0x61] d [0x64] y [0x79] . [0x0a]
</code></pre>
<p>I expect bootloader to reply with 0x14 0x10 as over USB:</p>
<pre><code>2015-04-07 21:22:13.978 Apploader[11226:303] Send: 0 [0x30] [0x20]
2015-04-07 21:22:13.979 Apploader[11226:303] Recv: . [0x14]
2015-04-07 21:22:13.980 Apploader[11226:303] Recv: . [0x10]
</code></pre>
<p>As you can see later communication over Bluetooth is working good, as i receive exactly what was sent (0x30 0x20)</p>
<p>So when sketch is launched it's ok.</p>
<p>My ideas what's wrong:</p>
<ol>
<li>baud rate</li>
</ol>
<p>Since serial.begin(N) is invoked after bootloader stops and launch sketch bootloader by default uses another baud rate? Is it correct? HM-10 default daud rate is 9600 and in sketch i also use 9600. </p>
<ol start="2">
<li>wrong wire connection?</li>
</ol>
<p>Bluetooth-arduino:
rx -> tx
tx -> rx
Since its working for sketch i believe it's ok. Do i need any capacitors or resistors?</p>
<p>Any thoughts are highly appreciated!</p>
<p><strong>UPDATE</strong>:</p>
<p>It seems i've found <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/bootloaders/atmega/ATmegaBOOT_168.c" rel="nofollow">Uno bootloader source code</a> and bootloader baud rate is 19200 by default</p>
<pre><code>/* set the UART baud rate */
/* 20060803: hacked by DojoCorp */
//#define BAUD_RATE 115200
#ifndef BAUD_RATE
#define BAUD_RATE 19200
#endif
</code></pre>
<p><strong>UPDATE2</strong>:</p>
<p>I'm in stuck as in this tutorial 115200 is used:
<a href="http://makezine.com/projects/diy-arduino-bluetooth-programming-shield/" rel="nofollow">http://makezine.com/projects/diy-arduino-bluetooth-programming-shield/</a></p>
<p>in step 8. "build the programmer circuit" R1 2.2K is set on arduino rx pin. Why? Another thing i can't understand is that SoftwareSerial baud rate is set to 38400 but BT module baud rate is set 115200 using "AT" command. why?</p>
| <p>The bootloader used on the Uno is <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/bootloaders/optiboot/optiboot.c" rel="nofollow noreferrer">optiboot</a>. But it contains the same "feature" of skipping straight to the application program if the reset source wasn't external.</p>
<p>You could remove this feature and reprogram the bootloader to the chip (using an external programmer).</p>
<p>Alternatively you can use a dirty trick, and jump into the bootloader right after this check of the reset source happens. It happens to be right in the beginning, so not much has happened. The problem is that optiboot makes the assumption that the system is in a freshly reset state. So either you can write a flag to EEPROM to indicate that you just made an intentional WDT reset, or you can jump and hope for the best(not really recomendable).</p>
<p>You could also write a routine to reset the system to the same state as after a reset. But it might not be trivial since there are a lot of reserved memory addresses that Atmel (the manufacturer of AVR's the microcontroller used on the uno, mega, and others) recommends you never write to. So basically you would have to more or less manually set a lot of registers to their reset default (usually zero), in the right order (eg. first tri-state / set pins to input).</p>
<p>You can jump to the bootloader using this inline assembler code:</p>
<pre><code>asm volatile ("jmp 0x7e00");
</code></pre>
<p>Optiboot fits in 512 bytes = 256 AVR words. The bootloader address can be found in the <a href="http://www.atmel.com/images/Atmel-8271-8-bit-AVR-Microcontroller-ATmega48A-48PA-88A-88PA-168A-168PA-328-328P_datasheet_Complete.pdf" rel="nofollow noreferrer">datasheet</a> Table 27-13. Boot Size Configuration, ATmega328/328P. It is printed in the datasheet as the word address, but the avr-as assembler takes the byte address. Word address 0x3f00 * 2 = 0x7e00 byte address.</p>
<p>You can also see the address in <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/bootloaders/optiboot/optiboot_atmega328.lst" rel="nofollow noreferrer">optiboot_atmega328.lst</a> where code starts at byte address 0x7e00.</p>
<p>In order to jump past the boot source check we find the first address in optiboot_atmega328.lst that comes after the check. It is 0x7e0a. We then modify our bootloader jump:</p>
<pre><code>asm volatile ("jmp 0x7e0a");
</code></pre>
<p>You will want to make this jump first thing after a reset. We want to skip the Arduino initialization code. As per suggestion by user <a href="https://arduino.stackexchange.com/users/8216/comintern">Comintern</a> in another question you can write a <code>main</code> routine with a longer prototype to make the linker prefer it over the one shipped with Arduino:</p>
<pre><code>int main(int argc, char** argv) {
if (/* is your bootloader reset flag set in EEPROM */) {
// first clear the flag
// ...
// Jump to bootloader, after reset source check (optiboot on atmega328)
asm volatile ("jmp 0x7e0a");
}
// Else proceed same as Arduino main
init();
#if defined(USBCON)
USBDevice.attach();
#endif
setup();
//The one shot loop...
loop();
if (serialEventRun) serialEventRun();
//Put whatever else you need to do between before the unending loop here.
for (;;) {
loop();
if (serialEventRun) serialEventRun();
}
return 0;
}
</code></pre>
<p>Note:</p>
<p>Using these jumps depends on your bootloader being exactly the one referenced. AFAIK that is the one the Uno ships with, but that could change in the future.</p>
<p>The code is untested.</p>
<p>The <code>main</code> overwrite trick depends on the linker exhibiting this behaviour which I think is also prone to change (it could be guaranteed by c/c++ standard, I don't know that).</p>
|
9931 | |arduino-mega|usb| | Arduino Mega 2560: Busted Atmega 16U2 | 2015-04-08T10:59:31.667 | <p>I just bought an Arduino Mega2560 R3 and it doesn't connect to my Laptop. The connection is somewhat random, sometimes it connects and sometimes it doesn't.</p>
<p>Can someone help me identify whats the problem?</p>
<p>When it gets connected I can upload sketches.</p>
<p>I would like to remove the Atmega 16U2 and replace it with ftdi USB to Serial, would it be possible?</p>
| <p>You can use your USB/Serial adapter to program the 2560 as the Arduino uses the 16u2 as the same thing to program the mega. You shouldn't remove the 16u2, just wait till you get the programmers and reflash the 16u2 with its firmaware and it will work, I actually had the same problem where the DFU didn't work and the 16u2 stopped responding, after reflashing the firmware it worked. The firmaware can be found under(as of 1.6.0):</p>
<p><code>...\Arduino\hardware\arduino\avr\firmwares\atmegaxxu2\MEGA-dfu_and_usbserial_combined.hex</code> </p>
<p>You need to connect the Serial pins on the FTDI and Mega in the below fashion:</p>
<pre><code> FTDI MEGA
GND<----------->GND
CTS<----------->GND
VCC<----------->VCC
TXD<----------->RX0
RXD<----------->TX0
RTS/DTR<---||-->RST
</code></pre>
<p>The Capacitor between the <code>DTR</code> pin and <code>RST</code> pin are needed this should be 100nF.</p>
<p><img src="https://i.stack.imgur.com/6oMHQ.jpg" alt="enter image description here"></p>
<blockquote>
<p>I have bought an I |SP programmer but it will take 3 weeks to reach and no I dont have another arduino, TBH I'm scared to buy another one... – echo_salik</p>
</blockquote>
<p>If you are buying clones, those will more than likely give issues as they will be cutting back on costs in places, i.e. QC checks.</p>
|
9943 | |arduino-yun| | Find external router IP from Arduino Yun inside router network | 2015-04-08T19:32:13.263 | <p>I want two Arduino Yuns in different private networks to communicate, i.e., behind two distinct routers of which at least one does <em>not</em> have dynamic DNS, so its external IP may change from time to time. </p>
<p>To be reachable, this Yun could forward its router's external IP to the other Yun which has a fixed DNS name. But for this to work, it must be able to determine its router's external IP. </p>
<ul>
<li><p>How can the Yun find out that the external IP of the router has changed? The Yun will be runnning all the time. </p></li>
<li><p>If the external router IP has changed (i.e., my Fritz.Box disconnects in the night and may receive a different IP when it reconnects), how can the Yun determine the new external IP? </p></li>
</ul>
<p>If this is not the right place to ask, I'm happy for pointers to somewhere else (Server Fault SE forum?).</p>
| <p>You can write a program that updates its own external IP every couple of minutes/hours, or when it doesn't get a response from another Yún/PC/server.</p>
<p>You can use this link (or find another site of the web that gives you your external IP address): <a href="http://www.realip.info/api/p/realip.php" rel="nofollow">http://www.realip.info/api/p/realip.php</a></p>
<p>This link has a beautifully formatted information that you can easily extract. I have a similar solution on one of my servers that have a dynamic IP...</p>
|
9946 | |arduino-uno|c|avr-gcc| | Running C for arduino | 2015-04-08T22:46:41.350 | <p>Is there a compiler that I can use to run C on an arduino or any other way so that I can upload C programs to my arduino?</p>
| <p>Perhaps you should look into here
<a href="https://github.com/arduino/Arduino/wiki/Build-Process" rel="nofollow noreferrer">https://github.com/arduino/Arduino/wiki/Build-Process</a></p>
<p>Arduino uses avr-gcc compiler. Basically, it is a C compiler.</p>
<p>There is an step by step on how to customize this process using an avr-gcc compiler of your own here
<a href="http://www.wikihow.com/Write-Arduino-Software-in-C" rel="nofollow noreferrer">http://www.wikihow.com/Write-Arduino-Software-in-C</a></p>
<p>But I best recommend you downloading the arduino IDE on the official website to get things going. It has all the serial pairing stuff you don't really need to know to get started.</p>
<p>Hope it helps.</p>
|
9952 | |arduino-uno|matlab| | Problem with deploying matlab simulink mode to Arduino UNO | 2015-04-09T09:10:05.067 | <p>I encounter a problem when deploy matlab simulink model to Arduino UNO</p>
<p>Following shows the error</p>
<pre><code>*The call to realtime_make_rtw_hook, during the after_make hook generated the following error:
The build failed with the following message: The system cannot find the path specified
The build process will terminate as a result.
The build failed with the following message: The system cannot find the path specified。
Component: Simulink | Category: Block error*
</code></pre>
<p>When type >> getenv('path')</p>
<pre><code>ans =
C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;E:\MathWorks\runtime\win64;E:\MathWorks\bin;E:\MathWorks\polyspace\bin;C:\Program Files\MATLAB\R2014b\runtime\win64;C:\Program Files\MATLAB\R2014b\bin;C:\Program Files\MATLAB\R2014b\polyspace\bin;C:\Program Files\Microsoft Windows Performance Toolkit\
</code></pre>
<p>I did not see anything wrong with the path. I tried to solve the problem following the "<a href="http://www.mathworks.com/matlabcentral/answers/168555-what-does-the-path-in-the-system-cannot-find-the-path-specified-refer-to" rel="nofollow">http://www.mathworks.com/matlabcentral/answers/168555-what-does-the-path-in-the-system-cannot-find-the-path-specified-refer-to</a>". However it does not work.</p>
<p>Anyone know how to solve it?</p>
<p>OS:Win8.1 Matlab 2014b 64bit</p>
| <p>Right click on your MATLAB shortcut and click "run as administrator". See if helps. Then do all the necessary steps and see if it happens again.</p>
<p>Also test with x86 version. I have seen lots of these kinds of error with x64 version. Always had compiling related issues with MATLAB x64 and Simulink!</p>
|
9955 | |programming| | Why use .h files with .cpp? | 2015-04-09T10:48:48.310 | <p>At school, our teacher always taught us to use .hpp (C++ Header files) with our .cpp (C++ files). But Arduino seems to use .h files (with .cpp links?).</p>
<hr>
<p>When someone is programming in C (without C++ compiler) they have the chance to get linked to a .cpp file through a .h file? </p>
<ul>
<li>So why isn't a .cpp file always with a .hpp file? </li>
<li>What are the drawbacks of using .hpp files with your .cpp files?</li>
</ul>
<p>This is not to start a discussion on what's best, please provide an answer with arguments that are not based on "what you like to do more".</p>
| <p>The extension you use for a header file doesn't technically matter because the compiler never sees it. You could name it with the extension <code>.this-is-a-header-file</code> and it would probably still work.</p>
<p>The compiler only handles the C/C++ source files, typically named <code>.c</code> and <code>.cpp</code>. However, before that happens, the preprocessor goes through and looks for any <code>#include</code> lines. When it sees one, it basically copies the entire contents of the included file into the source file before it gets compiled.</p>
<p>This is normally used to include header files. However, the preprocessor doesn't know or care about different programming languages. All it does is process the raw text so there's nothing stopping you from including any text file you like, with any name or extension.</p>
<p>Choosing to use <code>.h</code> or <code>.hpp</code> is mostly just personal preference. You could certainly argue that it lets you (as a programmer) distinguish between C/C++ code more easily.</p>
<p>However, the reason why <code>.h</code> is more common is probably that C and C++ code is mixed so freely. You can generally compile C code as C++ without any problems, in which case it's the context (rather than the file itself) that tells you if it's C or C++. It's also possible to write a library in C++ which only exposes a C interface, meaning it could be used by C programs.</p>
<p>You could definitely include a C++-specific header file in a C program by mistake. All that would happen is that the compiler wouldn't understand the contents of that header file. Sensible development environments don't link to a project/library when it sees a <code>#include</code> directive (the Arduino IDE is the only one which does this, as far as I'm aware).</p>
|
9965 | |arduino-mega|sensors|robotics| | Detect movement on moving robot? PIR Sensor | 2015-04-09T22:52:48.097 | <p>I am working on a human following robot project and I am trying to achieve this with 1 Ultrasonic sensor that makes sure the robot won't crash into something and 3 PIR sensors that will detect human movement.</p>
<p>The robot has an Ultrasonic Sensor and a PIR sensor attached to the front and a PIR sensor attached to the right side and another PIR sensor attached to the left side.</p>
<p>If the front PIR reads HIGH, then the robot will move forward. If the left or right PIR reads HIGH, then the robot will start turning in a 360 degree motion to the left/right side and will keep on doing so until the front PIR reads HIGH, and the robot moves forward again.</p>
<p>I am currently working with this build and I am having issues with the sensors. Sometimes they read HIGH when they shouldn't and sometimes they read LOW when they should be reading HIGH.</p>
<p>So my question is, what can I do to help the PIR sensors with getting the correct reading and is it possible to do so while the robot is turning? </p>
<p>Also, how will calibration work here? Am I able to let the robot turn slowly in 360 degree motion so the 3 PIR sensors will be calibrated with the rooms surrounding or is this a dumb question? If so I'm sorry, I am pretty new to PIR sensors.</p>
<hr>
<p>UPDATE:</p>
<p>Thanks for the help everyone. I have now replaced the side PIR sensors with Ultrasonic sensors. I have kept the front PIR sensor though. It is working a lot better than with the side PIR sensors and I thank you all for your input.</p>
| <p>Try using <I><b>heat detectors</b>(technically speaking, <b>Infrared sensors</b>)</I> (along with >1 Ultrasonic sensors and PIR motion sensors for greater accuracy) with 1 ultrasonic sensor.
Comment if you want more help.</p>
|
9973 | |bluetooth| | Is it possible for a HC-05 Bluetooth module to have multiple slaves | 2015-04-10T07:37:41.120 | <p>For a project I am interested in using the HC-05 Bluetooth module to control five LEGO Mindstorms Bricks simultaneously. For this to work the Bluetooth module will obviously have to be paired / connected with the five bricks at the same time. This means that the HC-05 Bluetooth module will have to be master in the piconet and the five bricks the slaves. </p>
<p>Is there anyone who has any experience with using the Arduino Uno and HC-05 Bluetooth module to send data to multiple, connected, slaves? If not, are there any alternative Bluetooth modules? And if Bluetooth modules compatible with the Arduino Uno cannot connect to multiple slaves at the same time, are there other ways that an Arduino can control multiple Bluetooth slaves at the same time?</p>
| <p>After some research, it looks like multiple slaves aren't possible with this particular module. </p>
<p>According to <a href="http://en.wikipedia.org/wiki/Bluetooth#Implementation" rel="nofollow">Wikipedia</a> the Bluetooth technology allows a master to communicate with 7 slaves, but this option isn't implemented in the HC-05.</p>
|
9976 | |led|electronics| | 7-Segment Common Anode | 2015-04-10T09:24:13.980 | <p>I accidently bought a "Common Anode" 7-segment display instead of a "Common Cathode".</p>
<p>I understand that the polarity of the leds within the display is 'reversed'. So instead of putting the common pin on GND I have to put it to 5v (with current limiting resistor)</p>
<p>My questions on this are:</p>
<ol>
<li>Can I still use only one current limiting resistor on the common pin? Instead of a resistor on every segment pin.</li>
<li>Can I use the pins from arduino to drive it (withouth pull-up/pull-down?) By making the signal <code>LOW</code> the current will flow from 5V common anode to the arduino and thus the segment wil light?</li>
<li>Can I still use a shift register to drive the segment led? (By inversing the outputs (in software))</li>
</ol>
<hr>
<p><strong>Obviously I would like to have wiring more like this</strong> (but then I would ofcourse change the GND line to a 5V line.</p>
<p><img src="https://i.stack.imgur.com/S6MnF.jpg" alt="Better wiring"></p>
<hr>
<p><strong>The wiring below is the worst-case wiring I can think of.</strong></p>
<p><img src="https://i.stack.imgur.com/t9mfh.png" alt="Wiring"></p>
<p>^ So can I avoid this, when using a <code>Common Anode 7-segment display</code> or am I forced to buy a <code>Common Cathode 7-segment display</code>?</p>
| <p>Peter and Gerben have already said what is needed , but I wish to explain things even further.<br><br>
A normal small 7-Segment display consumes only <b>70-80mA</b> when all segments are HIGH.So you can use the Arduino directly without damaging it. Also note, depending on the quality of the project, you could either use a common resistor for all segments, or use separate ones. Separate ones will give much brighter light and better quality.<br>
A medium size one will require max consumption of around <b>400mA</b> current, so use cheap transistors.<br>
A large size one will require max consumption of upto <b>1.5-2A</b> current , so use MOSFETS or other high current Transistors.<br>
An Extra Large one will require max consumption of upto <b>10-25A</b> current, so use good MOSFETS or maybe even Relays.<br><br>
<I><b>Usage</b><br>
Small- Wrist watches<br>
Medium- Small clocks<br>
Large- Big clocks<br>
Extra Large- Very big clocks like ones in Railway stations<br>
</I></p>
|
9986 | |arduino-uno|arduino-nano|voltage-level| | Arduino voltage drop while communicating with another Arduino | 2015-04-10T13:06:55.540 | <p>I have an Arduino Uno rev 3 and an Arduino Nano in my Setup. I want to create a proof of concept, where one Arduino triggers the other via the Digital IOs.
Arduino 1 sets a blinking signal on a digital pin (500ms delay between high/low), which is received by arduino 2. If the signal is high, Arduino 2 triggers a LED (digital pin to LED+; LED- over 330 Ohm resistor to ground), so the signal gets looped through somehow. The grounds of the two Arduinos are connected, too.</p>
<p><img src="https://i.stack.imgur.com/UBWWU.png" alt="Schematic"></p>
<p>Code Arduino #1:</p>
<pre><code>void setup() {
DDRD |=_BV(PD7); //Sets Digital Pin 7 as Output
}
void loop() {
PORTD |=_BV(PD7); // equivalent with digitalWrite(7, HIGH);
delay(500);
PORTD &=~_BV(PD7); // equivalent with digitalWrite(7, LOW);
delay(500);
}
</code></pre>
<p>Code Arduino #2:</p>
<pre><code>void setup() {
DDRD &=~_BV(PD7); //Sets Digital Pin 7 as Input
DDRD |=_BV(PB0); //Set Digital Pin 8 as Output
}
bool set = false;
void loop() {
if((PIND&_BV(PD7))==_BV(PD7)) { //true if digital pin 7 is set
if(!set) {
//PORTB |= _BV(PB0);
digitalWrite(8, HIGH);
set = true;
}
} else {
//PORTB &=~_BV(PB0);
digitalWrite(8, LOW);
set = false;
}
}
</code></pre>
<p>But instead of emitting a bright light, which can be seen if connecting the blinking signal directly to the LED, it emits a faint light. The voltmeter also shows an significant Voltage drop. Whilst the digital pin should have a voltage of ~5V when set to HIGH (never reached because of inner resitance inside the arduino), it measures about 1.6-1.8V.
I also switched the both Arduinos which showed the same result, so it shouldn't be a hardware defect.</p>
<p>Thanks in Advance!</p>
| <p>the line <code>DDRD |=_BV(PB0);</code> should be <code>DDRB |=_BV(PB0);</code> currently PB0 is set as an input so when you set it high it is just turning on the pull-up resistor, which is basically adding another ~10k in series with the LED, hence the dim light.</p>
|
9994 | |arduino-uno|ethernet|temperature-sensor| | Dallas Temperature Sensor DS18B20 not showing correct Result with Ethernet Shield | 2015-04-10T23:33:16.227 | <p>I am using Arduino Uno R3 board and a wiznet W5100 ethernet Shield. The temperature from the One wire sensors before using Ethernet Shield was showing correct. However later after connecting the shield, the temperature is showing to be 85. The server and everything else works fine, but the data is all wrong. Now I am pretty sure the connections are correct and it is not in parasite mode. Any suggestions of how I might get the accurate reading ? </p>
<pre><code>/*
Web Server
A simple web server that shows the value of the analog input pins.
using an Arduino Wiznet Ethernet shield.
*/
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {
0xF0, 0xBF, 0x97, 0x67, 0xF6, 0x98
};
IPAddress ip(192, 168, XXX, XXX);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
EthernetServer server(80);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
sensors.begin();
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.println(sensors.getTempCByIndex(0));
Serial.print("Siddhartha Temperature ");
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}
void loop() {
// listen for incoming clients
EthernetClient client = server.available();
if (client) {
Serial.println("new client");
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
Serial.write(c);
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 2");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
float sensorReading = sensors.getTempCByIndex(0);
client.print("Temperature ");
client.print(analogChannel);
client.print(" is ");
client.print(sensorReading);
Serial.println(sensorReading);
client.println("<br />");
}
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}
</code></pre>
| <p>The Solution was actually much simpler. Apparently the Ground on the voltage I/O ports wasn't the right place to connect the ground terminal of the sensor. rather The Ground of the Digital I/O should be connected. Mistake retrieved by trail and error!! Its working just fine now. </p>
|
9998 | |arduino-uno|uploading| | Not able to upload any code to Arduino Uno | 2015-04-11T03:36:18.890 | <p>NOTE: Using the Arduino Uno</p>
<p>I am WORKING on a project that I have to submit in a few days. My arduino was all set up and was working fine. </p>
<p>Project:Arduino controls a 9v motor depending on the command given. As the arduino only provides 5v , i added a 9v battery to it through a transistor</p>
<p>I decided to add new code into the arduino but when I tried it failed. I have uploaded code thousands of times before (successfully) all of a sudden the IDE keeps giving the following message</p>
<blockquote>
<p>avrdude: ser_open(): can't open device "\.\COM3": Access is denied.</p>
</blockquote>
<p>I have looked up for a lot of solutions on this forum and elsewhere. Here are the things I have tried so far:</p>
<ol>
<li>Changing the COM port </li>
<li>Disabling all the other devices CONNECTED to COM</li>
<li>Tightening the CONNECTIONS</li>
<li>Re installing all the drivers and the IDE</li>
<li>Rebooting the system</li>
<li>Using another laptop to upload code</li>
</ol>
<p>All the above have given me the same output for some reason. The built in LED light and the power LED switch on when the board is CONNECTED to a power source (my laptop). Could the board have been damaged by any chance ? How can I check if the board is spoilt ? Should I buy a new board ? </p>
| <p>I have a post <a href="https://arduino.stackexchange.com/questions/13292/have-i-bricked-my-arduino-uno-problems-with-uploading-to-board">Have I bricked my Arduino Uno? Problems with uploading to board</a> - that describes various tests you can carry out to isolate where the problem is.</p>
|
10005 | |analogread|electronics| | How exactly is voltage measured on an Arduino? | 2015-04-11T17:53:02.253 | <p><em>How do the analog pins on an Arduino measure voltage?</em></p>
<p>Do they either measure current and calculate the voltage with Ohm's law? (If so, why can we only read voltage and not current directly?)</p>
<p>Or do they compare the unknown input voltage with a known internal one? (If so, how does that work? What's the known voltage?)</p>
| <p>I'm not sure what the answer is or why no one has addressed the second part of your question. To calculate current you need to know voltage and resistance (I=E/R). The ADC is giving you the voltage but I don't know what value to use for resistance in order to calculate the current. I do better with digital electronics but I suspect you might be able to use a resistor divider network to measure the voltage drop across a known resistor to measure current but do not take my word for this.</p>
|
10011 | |arduino-leonardo|library|timers|arduino-micro| | TCCR1A and TCCR2A on Leonardo | 2015-04-11T19:50:03.470 | <p>I'm trying to use the <a href="https://github.com/jscrane/TTS" rel="nofollow">TTS library for Arduino</a> on an Arduino Micro board, which is based on the Leonardo. When I try to compile my sketch I get some errors;</p>
<pre><code>/libraries/TTS/TTS.cpp: In function 'void soundOff()':
/libraries/TTS/TTS.cpp:355: error: 'TCCR2A' was not declared in this scope
/libraries/TTS/TTS.cpp:355: error: 'COM2B1' was not declared in this scope
/libraries/TTS/TTS.cpp: In function 'void soundOn()':
/libraries/TTS/TTS.cpp:382: error: 'TCCR2A' was not declared in this scope
/libraries/TTS/TTS.cpp:382: error: 'COM2B1' was not declared in this scope
/libraries/TTS/TTS.cpp:382: error: 'WGM20' was not declared in this scope
/libraries/TTS/TTS.cpp:383: error: 'TCCR2B' was not declared in this scope
/libraries/TTS/TTS.cpp:383: error: 'CS20' was not declared in this scope
/libraries/TTS/TTS.cpp:383: error: 'WGM22' was not declared in this scope
/libraries/TTS/TTS.cpp:384: error: 'OCR2B' was not declared in this scope
/libraries/TTS/TTS.cpp:385: error: 'TCNT2' was not declared in this scope
/libraries/TTS/TTS.cpp: In function 'void sound(byte)':
/libraries/TTS/TTS.cpp:424: error: 'OCR2B' was not declared in this scope
/libraries/TTS/TTS.cpp:425: error: 'TCNT2' was not declared in this scope
</code></pre>
<p>Googling revealed that the Leonardo uses different timers. And other things I don't understand! But I couldn't piece together an answer beyond that.</p>
<p>What are the correct constants to use for Leonardo boards, and is there a way I can update the library to work across both?</p>
| <p>Apparently the library in <a href="https://github.com/jscrane/TTS" rel="nofollow noreferrer">the OP's link</a> has been updated to support the Leonardo, so this problem should now be solved.</p>
|
10012 | |arduino-uno|shields| | MP3 Shield stacked on DMX Shield - Arduino Uno | 2015-04-11T20:10:21.130 | <p>We are using Arduino Uno revision 3, with TinkerKit DMX Shield rev. 4 and Sparkfun Mp3 Shield.</p>
<p>We uploaded the Mp3 Shield example called FilePlayer and after we open the serial monitor, the interface is there and working. The problem is that it won't output the music from the SD card.</p>
<p>If we ONLY stack the Mp3 Shield onto Arduino, it works.</p>
<p>Is there some king od incompatibility between the DMX and Mp3 Shield, and if there is, what would be the solution, maybe some kind of bypass, since we aren't that familiar with what pins the DMX shield uses for it's purpose. ATM the Tinkerit site is down so we can't acess the TinkerKit DMX Shield datasheet.</p>
| <p>Yes, overlapping is a problem, by default the MP3 Shield uses digital pins 2(DREQ),6(mp3CS),7(mp3DCS),8(RST),9(SD-CS),11(MOSI),12(MISO),13(SCK)</p>
<p>The Tinkerkit DMX Master Shield R4 uses 2(RE-ENn),3(VTX),4(VRX),5(DE-EN),6(D6)</p>
<p>So there are conflicts with D2 DREQ vs RE-ENn and D6 mp3CS vs D6.</p>
<p>The DMX Master Shield basically converts the UNO's serial to DMX. If nothing is at first included into the Sketch for this, then the problem is with only D6. Leave this jumper OFF. And I suspect the MP3 Shield will work stacked.</p>
<p>To use them together you can move the pins, as demonstrated at <a href="https://www.youtube.com/watch?v=behMgV3tUr4" rel="nofollow">https://www.youtube.com/watch?v=behMgV3tUr4</a>. Noting that is for different pins. And of course you will need to subsequently change their definition, in the sketch.</p>
|
10020 | |string|float| | float precision in arduino | 2015-04-12T08:55:30.723 | <p>I am reading a string which i have to convert into a float with a maximum of precision.I didn't want to use toFloat() function since it make a truncation so i made my own code.
My problem is that the final result is also approximated.
I need a precision of 4 digits after the float.I read the documentation about float in the arduino website.They say it should be maximum 7 digits of precision but i don't get it.When i test my code on the value of '23,459' ,all i get is 23,46.
Any suggestions?</p>
<pre><code>void setup() {
Serial.begin(9600);
}
int longu=0;
char data='2';
String data2="23,459";
float val=0;
int posVir=0;
int t=0;
float postVir=0;
float preVir=0;
int lonPostVir=0;
int lonPreVir=0;
float posvir2=0;
void loop()
{
lonPostVir=(data2.substring(posVir+1)).length();
lonPreVir=(data2.substring(0,posVir)).length();
longu=data2.length();
posVir=data2.indexOf(",");
preVir=(data2.substring(0,posVir)).toFloat();
postVir=(data2.substring(posVir+1)).toFloat();
posvir2=postVir*pow(10,-lonPostVir);
val=preVir+postVir*pow(10,-lonPostVir);
Serial.println(val);
}
</code></pre>
| <p>Just write the amount of numbers you want to get float here Serial.println(val); after the val.
example:
Serial.println(val, 5);
It will give 5 digits after the decimal point</p>
|
10024 | |ir|remote-control|testing|induino| | How to make universal remote controller? | 2015-04-12T10:44:21.337 | <p>I am trying to make simple TV remote using Arduino.</p>
<p>I got <a href="http://www.zovirl.com/2008/11/12/building-a-universal-remote-with-an-arduino/" rel="nofollow noreferrer">this</a> link from Google for making a remote.</p>
<p>Code uploaded perfectly on my device. But all it does is blink a the LED on pin 13.</p>
<p>I hope I have got right code. I have tested it on my TV at home. Is that the correct way of testing it?</p>
<p>IR receiver I have is TSOP-15</p>
<p>P.S. I am completely new to Arduino </p>
<p>The below shown is my Arduino board(induino r3)</p>
<p><img src="https://i.stack.imgur.com/bwboE.jpg" alt="enter image description here"></p>
| <p>As you've stated in your question, the TSOP-15 is a receiver. That means it detects infrared signals rather than sending them out.</p>
<p>To make a remote control with that code, you need a simple infrared light emitting diode.</p>
<p>It's also important to note that you need to know what signals to send. Different TVs will have different IR codes, depending on the manufacturer. That information can be detected using your receiver module along with your TV's proper remote control.</p>
|
10032 | |arduino-uno|motor| | Arduino Uno + 2 Monster Motor Shields | 2015-04-12T14:30:56.973 | <p>I've got an Arduino Uno and two Sparkun's Monster Motor Shields.
The aim is to control 4 motors.</p>
<p>There is no problem to control 2 DC motors with single motor shield. There's a <a href="https://www.sparkfun.com/products/10182" rel="nofollow">manual</a> on how to do it .</p>
<p>But how can I control all of motors (address commands to each of them) when I stack motor shields one on one?</p>
<p>Thanks in advance.</p>
| <p>Not really the answer to your question, but an alternative solution, which has proven to work in my case.
We were working on a line-following robot with an ATMega 328P (Same as arduino, but withouth shields) and thus we wired an shield directly. For the shield we used, we only needed 4 inputs (pwm left, pwm right, direction left, direction right). Try to find out what your shield is using, on which pin, and you can drive the shield directly withouth stacking them (as they then would use the same pin).</p>
<hr>
<p>My alternative solution would be to use 1 driver. And wire the motors parrallel.
If you choose to use 1 shield, you can stack it. But for other shields you have to check which pins to use. There is no drawback on using one shield, the only thing is that the motor driver will draw more current, but they're basically designed for this.
<img src="https://i.stack.imgur.com/o53ic.png" alt="motor driver schematic"></p>
|
10041 | |pwm|analogread| | Can I connect a PWM pin on one Arduino to an analog input on another? | 2015-04-12T21:36:34.357 | <p>I was considering several different ways to send simple data from one Arduino to another when I though, why not connect a PWN pin of one Arduino to the analog pin on another? I could send simple messages for one to the other by setting different values on the PWM pin. This seems like it would work, except for the fact the the PWM pins mimic voltages with pulses. </p>
<p>Is this a reliable way to link two Arduinos, If I only want to communicate 4 states? Also, will I need to include some additional components in the connection (resister, capacitor, etc.)</p>
<p>All it needs to do is send a 2v pulse for yes and a 5 v pulse for no. It needs to do this about 6 times an hour. </p>
| <p>Full solution to receive <strong>PWM</strong> signal and convert <strong>to</strong> a like <strong>analogRead()</strong> one. Its based on @Cortex_systems answer and Id like to share it to help others with a more comprehensive answer.</p>
<pre><code>int var = pulseIn(digitalPin, HIGH, 4200);
if (var == 0 && digitalRead(digitalPin) == 1) {
var = 2100;
}
var= map(var, 0, 2100, 0, 1023);
</code></pre>
<p>Here is the why:</p>
<ul>
<li>You can not just read PWM signal to analog pin in arduino. We will
receive the PWM in a digital pin with its <em>pinMode set to input</em> and read it with pulsIn(pinNum, high/low, timeout). </li>
<li>pulseIn() records the length of the pulse. Longest pulse in PWM is 2100 microseconds. </li>
<li>Timeout is set to 4200 for 2 cycles of PWM. Without this
it will wait for a new high and freeze the code in cases that PWM is
0 or 255.</li>
<li>At max and min this will read 0, so in that case check with digitalRead() to determine and adjust.</li>
<li>Finally, map the result so it appears like an analogRead().</li>
</ul>
<p>Note! This adds a delay of up to 4.2 milliseconds to code.</p>
|
10052 | |arduino-uno|serial|communication|processing-lang| | General Question about fast Serial Communication and Arduino | 2015-04-13T08:16:18.733 | <p>I'm looking for a fast (and safe, in terms of stability) way to send sensor data from an Arduino UnoR3 in real time to a Computer (in my case a MacBook Pro) with a sample rate of at least 1kHz.</p>
<p>I tried following:</p>
<ul>
<li><p>Sending sensor values with the related timestamp (in microseconds):
I use 7 bytes for each sample [1 Header byte, 2 bytes for the sensor value (10/(16)bit-Int), and 4 bytes for a 32-bit unsigned long (time in microseconds)] and send them right away.</p></li>
<li><p>On the receiving end i mainly use Processing (Im relatively new to Processing though): Reading the bytes in, converting them in integers and safe them in a file or plot them.</p></li>
</ul>
<p>For sampling rates of 1sample/10ms my code runs smooth and i even can plot the data in "real-time".</p>
<p>For higher frequencies i ran into following problems:</p>
<ul>
<li><p>If i want to plot things, my peripherals freeze and program stops after some time. I have no clue why... maybe serial buffer overflow??</p></li>
<li><p>If i just save the data in a text file (without plotting) it works but with a delay of around 20-30seconds on total sampling times of 10seconds (10000 samples).
Meaning that somewhere seems to be a bottleneck and i cant keep up with the sent samples from the Arduino.
Is it possible that the serial bus is the bottleneck here? How can i speed things up? (I'm working with a baudrate 115200bits/s and also 230400bits/s)</p></li>
</ul>
<p>How can i improve this while still be able to process data in almost real-time (e.g plotting). Is this even possible or do you recommend logging the data in a text file first and then plot? </p>
<p>Will it helps to send the data in packages (10samles = 70bytes)?</p>
<p>I added a timestamp on each sample, since i observed some delay between the actual sensor measurement and the input on the receiving end. I thought that would allow me to plot and postprocess accurately in "real"-time (with a little delay). Any other ideas?</p>
<p>I would appreciate some input and advice!</p>
<p>Thanks in advance!</p>
| <p>You are sending data at ~70kbps. Provided you use serial rate greater than this (115.2 kbps or faster on the Arduino) there should be no problem, assuming you samples are processed quickly enough. This seems to be the case.</p>
<p>Your problem seems to be on the Mac. With a quad core CPU on a fast multitasking machine this should not be an issue. If you are having problems this would be in how you are processing the data. I am not familiar with <code>Processing</code> but you could do this in any language. You need to separate the data logging from the processing and display task. This could be as simple as running a logger and piping the data into a display program.</p>
<p>This is not an Arduino issue (or even a Mac issue), you should ask on <a href="https://stackoverflow.com/">https://stackoverflow.com/</a>. NOTE if you want help there you will need to give more detail of the code you are running in the Mac.</p>
|
10062 | |arduino-uno| | Infra Red Send Hex Code | 2015-04-13T20:05:42.473 | <p>I am using an arduino nano with the standard arduino IR remote library. For now I am using the Irrecord sketch. However, I want to have some pre - programed codes for remotes I don't have. I found this <a href="http://www.remotecentral.com/cgi-bin/codes/" rel="nofollow">site</a> which apparently has the hex of an endless number of remotes. When I use the regular IR decode, the hex of any remote I use, is only a couple of characters. However at this site the typical amount is at least 100.</p>
<p>This is the hex for a Toshiba model's sleep command:</p>
<p>0000 006c 0022 0002 0157 00ab 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0040 0016 0016 0016 0040 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0016 0016 0016 0016 0016 0016 0040 0016 0016 0016 0040 0016 0016 0016 0040 0016 0040 0016 0040 0016 05f0 0157 0055 0016 0e52</p>
<p>So, finally after all that if you are still with me my question is, how would I send that command with the IRRemote library.</p>
| <p>That seems to be pronto hex format for codes. A quick google showed this explanation: <a href="http://www.remotecentral.com/features/irdisp2.htm" rel="nofollow">http://www.remotecentral.com/features/irdisp2.htm</a> and this sample code: <a href="https://gist.github.com/probonopd/5793692" rel="nofollow">https://gist.github.com/probonopd/5793692</a></p>
|
10069 | |sensors|arduino-ide| | Using Arduino to show images in Serial Monitor | 2015-04-14T08:56:46.927 | <p>Some time ago I came across a Vedic in which a person has hacked an optical mouse's camera and displayed the image in the Serial Monitors.<br>
My question:<br>
How to use Serial Monitor to display an image captured by the Arduino</p>
| <p>Based on <a href="http://frenki.net/2013/12/convert-optical-mouse-into-arduino-web-camera/" rel="nofollow">this guide</a>, he doesn't actually display the images on the serial monitor, only the image data for each pixel.</p>
<p>Then another program (Javascript and some HTML) on the PC side collects the data and converts it to a greyscale image.</p>
|
10076 | |compile| | "variable must be const" fix for Arduino progrem | 2015-04-14T16:24:20.833 | <p>I am trying to upload to my nano the code <a href="http://www.righto.com/2010/11/improved-arduino-tv-b-gone.html" rel="nofollow">attached</a>. It is giving me an error saying variable must be const about something I am trying to put in progrem. I learned that installing a older version of the compiler worked. However I was wondering is there a way to just edit the code to make it work. I tried putting const before it but it didn't work. It is on line 78 and 79 of the first file.</p>
<p>const extern PGM_P *NApowerCodes[] PROGMEM;</p>
<p>const extern PGM_P *EUpowerCodes[] PROGMEM;</p>
|
<p>Using the source from <a href="http://arcfn.com/files/arduino-tv-b-gone-1.2.zip" rel="nofollow">this link</a> I got it to compile following these steps.</p>
<hr>
<ul>
<li>Before opening the sketch in the Arduino:
<ul>
<li>Rename TVB.pde to TVB.ino</li>
<li>Rename WORLDcodes.cpp to WORLDcodes.h</li>
</ul></li>
</ul>
<hr>
<ul>
<li>Open the sketch (TVB.ino) in the Arduino IDE</li>
</ul>
<hr>
<ul>
<li><p>Edit main.h and change:</p>
<pre class="lang-C++ prettyprint-override"><code>// The structure of compressed code entries
struct IrCode {
uint8_t timer_val;
uint8_t numpairs;
uint8_t bitcompression;
uint16_t const *times;
uint8_t const*codes;
};
</code></pre>
<p>to:</p>
<pre class="lang-C++ prettyprint-override"><code>// The structure of compressed code entries
struct IrCode {
uint8_t timer_val;
uint8_t numpairs;
uint8_t bitcompression;
uint16_t const *times;
uint8_t const*codes PROGMEM;
};
</code></pre>
<p>That is, add <code>PROGMEM</code> to the <code>codes</code> line.</p></li>
</ul>
<hr>
<ul>
<li><p>Edit TVB.ino and change:</p>
<pre class="lang-C++ prettyprint-override"><code>extern PGM_P *NApowerCodes[] PROGMEM;
extern PGM_P *EUpowerCodes[] PROGMEM;
extern uint8_t num_NAcodes, num_EUcodes;
</code></pre>
<p>to:</p>
<pre class="lang-C++ prettyprint-override"><code>#include "WORLDcodes.h"
</code></pre>
<p>This avoids some linker problems in the original code.</p></li>
</ul>
<hr>
<ul>
<li><p>Edit WORLDcodes.h and delete the line:</p>
<pre class="lang-C++ prettyprint-override"><code> #include "main.h"
</code></pre></li>
</ul>
<hr>
<ul>
<li><p>Continue editing WORLDcodes.h and change:</p>
<pre class="lang-C++ prettyprint-override"><code>const struct IrCode *NApowerCodes[] PROGMEM = {
</code></pre>
<p>to:</p>
<pre class="lang-C++ prettyprint-override"><code>const struct IrCode * const NApowerCodes[] PROGMEM = {
</code></pre>
<hr>
<p>And also change:</p>
<pre class="lang-C++ prettyprint-override"><code>const struct IrCode *EUpowerCodes[] PROGMEM = {
</code></pre>
<p>to:</p>
<pre class="lang-C++ prettyprint-override"><code>const struct IrCode * const EUpowerCodes[] PROGMEM = {
</code></pre></li>
</ul>
<p>It should now compile OK.</p>
|
10078 | |arduino-uno|sensors| | Responding to a broken laser beam? | 2015-04-14T18:30:03.103 | <p>Firstly, I must apologise as I'm a complete noob but the Arduino kits / lego pieces are fantastic and I can't stop tinkering. Unfortunatley my knowledge does not match my passion.</p>
<p>I picked up a laser from <a href="http://www.amazon.co.uk/FamilyMall-KY-008-Transmitter-Module-Arduino/dp/B00KYHL7HO" rel="nofollow">Amazon: FamilyMall(TM) KY-008 Laser Transmitter Module 650nm 5V Diode For Arduino AVR PIC</a>.</p>
<p>I'm wondering what the middle pin is good for and if I can somehow manage to detect and respond to the beam being broken? </p>
<p>Thanks for looking. :)</p>
| <p>Without a data sheet or the device on hand not sure what the middle pin is used for. On the topic of detecting a broken beam the item you purchased is purely an emitter, in order to detect the beam being broken there are two main ways, using a photodetector on the "opposite end" of the beam but this means having wires trailing the same path as the laser beam, alternatively you could mount a mirror where the beam lands and reflect it back to a photodetector mounted close to the laser diode. You would them use the arduino to detect the state of the photodetector.</p>
|
10080 | |arduino-uno|motor|pwm|servo| | How to precisely control servo motor by changing duty cycle? | 2015-04-14T21:56:07.940 | <p>I developed a PWM using timer1,using arduino uno and digital output, and identified that when I send a wave with duration of 0.6ms in High level, the motor goes to 0º. If I send 2.1ms, it goes to 180º. I tried to make a relationship between these scales to send the angle and change the time period in order to achieve that angle and it did not work.</p>
<p>I would like to move with a precision of 1 degree, is that possible? Just adjusting the time period.</p>
<p>The model of the motor is mg996r.
Maybe I am missing something.</p>
<p>My code just generates an interrupt over 50 microsencods and I use this to set the frequency of 50Hz and the duty cycle in ms using digitalWrite associated with pin 9.</p>
<pre><code>#include <TimerOne.h>
double t = 0.0;
double period = 0;
void setup()
{
t = 0;
Serial.begin(9600);
pinMode(9, OUTPUT);
Timer1.initialize(50);
Timer1.attachInterrupt( timerIsr ); // attach the service routine here
}
void loop()
{
// Main code loop
// TODO: Put your regular (non-ISR) logic here
if (Serial.available() > 0) {
float grau = Serial.parseFloat();
// receive data as angle
if (grau > 180) grau = 180;
if (grau < 0) grau = 0;
// set period for that angle
// relationship developed between angle and period in ms
//set it to period
period = (0.00833*grau + 0.6)*1E-3;
}
}
/// --------------------------
/// Custom ISR Timer Routine
/// --------------------------
void timerIsr()
{
t += 50E-6;
if (t <= period) {
digitalWrite(9, HIGH);
}
else if (t < 20E-3) { // periodo max de 20ms -> 50Hz
digitalWrite(9, LOW);
}
else {
t = 0;
}
}
</code></pre>
<p><strong>UPDATE</strong>:</p>
<p>I just got it working by creating a timer1 interrupt on CTC mode with a frequency of 100kHz and counting the necessary time to get increments (~ 10us each) of around 1 degree on my servo motor.</p>
<p>More info <a href="https://arduino.stackexchange.com/questions/10389/why-timer1-does-not-generate-correct-period-on-ctc-mode-with-a-resolution-of-5us">here</a>.</p>
| <p>The best is to use 10us Period, instead of 50us.<br>
That precision will be close to 1°</p>
|
10091 | |arduino-uno| | Scope error in arduino PinChangeInt library | 2015-04-15T10:49:26.817 | <pre><code>#include<PinChangeInt.h>
#define SensorPin 2
int ledPin = 10;
int BuzzerPin = 12;
volatile byte blip = 0;
void blipcount(){
blip++;
};
void setup() {
// put your setup code here, to run once:
pinMode(SensorPin,INPUT);
pinMode(ledPin,OUTPUT);
pinMode(BuzzerPin,OUTPUT);
PCintPort::attachInterrupt(SensorPin,blipCount,FALLING);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(SensorPin)==HIGH){
digitalWrite(ledPin,HIGH);
digitalWrite(BuzzerPin,HIGH);
Serial.print("blipcoun:\t");
Serial.println(blip,DEC);
}
if(digitalRead(SensorPin)==LOW){
digitalWrite(ledPin,LOW);
digitalWrite(BuzzerPin,LOW);
}
}
</code></pre>
<p>I am using arduino uno for a project.I need to record when my sensor gives a high value but i need it to read only falls in pulses.The program is giving error as</p>
<pre><code>Arduino: 1.6.3 (Windows 8.1), Board: "Arduino Uno"
Sense.ino: In function 'void setup()':
Sense.ino:14:38: error: 'blipCount' was not declared in this scope
Error compiling
</code></pre>
<p>please tell me what is the problem with the function.</p>
<p>The library link is
<a href="https://code.google.com/p/arduino-pinchangeint/downloads/list" rel="nofollow">https://code.google.com/p/arduino-pinchangeint/downloads/list</a></p>
<p>tested the code on both 1.72 and 2.19</p>
| <p>You have a typo:</p>
<pre><code>PCintPort::attachInterrupt(SensorPin,blipCount,FALLING);
</code></pre>
<p>Should be:</p>
<pre><code>PCintPort::attachInterrupt(SensorPin,blipcount,FALLING);
^
</code></pre>
<p>Note the lower-case "c".</p>
|
10092 | |arduino-uno|ir| | Isolating IR receiver from disruption? | 2015-04-15T11:03:37.110 | <p>I'm using a simple IR receiver connected to the Arduino through A0 analog pin. The problem is that I want to stabilize the output of IR receiver when it's not receiving an IR signal from a specific IR source, or at least minimizing the disruption to a specific range that I can handle, no matter where its position, But in my case moving the IR receiver a few inches in any direction will results in different voltage output. the difference between values on disruption is very random to handle. </p>
<p>What can I do to isolate IR receiver, may be a specific material or a specific color?</p>
| <p>I would suggest two things. First You could put electrical tape around the receiver in such a way that it will only pick up signals from a certain direction. Also you could use low and high pass filters to accept input only in the 38khz range(range of most infra red remotes). Keep in mind that you will need a couple of rounds for it to work effectively.</p>
|
10095 | |arduino-mega|motor|firmware| | how to send input values from host computer to arduino | 2015-04-15T16:21:24.717 | <p>how to send input values from host computer to arduino,such that speficing the number of rotations for a stepper motor etc</p>
| <p>The easiest method is to use the serial communication. Use the sample code at <a href="http://arduino.cc/en/Tutorial/SwitchCase2" rel="nofollow">http://arduino.cc/en/Tutorial/SwitchCase2</a>, upload that to an Arduino, start the serial monitor (Ctrl+Shift+M), make sure the baud rate is the same as set in the code (9600 in this case), then write the commands and send them to the Arduino.</p>
<p><strong>Edit</strong>
Since the serial characters are usually read one by one you need a character that will signal the end of the string. This is usually a newline <code>\n</code>, but can be any character you choose (and can be sent to Arduino). </p>
<p>Sample code (<code>processString</code> would be your function to do something with the string):</p>
<pre><code>char buf[64];
byte cnt = 0;
void loop()
{
while (Serial.available()>0) {
byte c = Serial.read();
// Check for terminator character or the size of buffer
if (c == '\n' || cnt >= 63) {
// Add the terminating 0
buf[cnt] = 0;
// Process the full string
processString(buf);
// Prepare to read the next string
cnt = 0;
} else {
// Not terminator - add to string
buf[cnt++] = c;
}
}
}
</code></pre>
|
10101 | |usb| | Is it possible to detect host usb device connected to arduino? and how? | 2015-04-15T19:36:18.900 | <p>let's say that I've connected an arduino uno to a pc, or to a mobile phone via usb .. how can I detect the device type and the running operation system if it's possible?</p>
| <p>I did not try to go further, but I know there is some information passing on <em>Serial1</em> when you plug a device.</p>
<pre><code>void setup() {
Serial.begin(115200);
Serial1.begin(250000);
}
void loop() {
if(!Serial1.available()) {
Serial.println("OFF");
delay(500);
}
else {
Serial.println("ON");
Serial1.end();
delay(500);
Serial1.begin(250000);
}
}
</code></pre>
<p>Maybe you can try to see if depending on the device, information is persistent, in which case you should be able to detect a specific device / kinf of device ?
I'll look at it tomorrow, maybe will have more code to show...</p>
|
10106 | |bluetooth| | Program arduino via USB while using a Bluetooth module (HC-06) | 2015-04-15T23:03:25.770 | <p>I have my Arduino Nano connected to the <a href="http://www.banggood.com/HC-06-Wireless-Bluetooth-Transceiver-RF-Main-Module-Serial-For-Arduino-p-80364.html" rel="nofollow noreferrer" title="HC-06">HC-06</a> module (with the RX/TX pins).</p>
<p>My issue is that when I try to upload new code to my Arduino (via the Arduino IDE, through the USB connection) the Arduino IDE doesn't succeed. </p>
<p>I get this error: </p>
<blockquote>
<p>avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00</p>
</blockquote>
<p>I believe that it is just trying to upload the code to the HC-06 (instead of the Arduino). Is there a way to overcome this issue?. </p>
<p>Thanks.</p>
<p>Note: I found this entry <a href="https://stackoverflow.com/questions/27175937/arduino-program-upload-while-btooth-module-connected-avrdude-stk500-getsync">https://stackoverflow.com/questions/27175937/arduino-program-upload-while-btooth-module-connected-avrdude-stk500-getsync</a> indicating that it wasn't possible (that I need to unplug the module). I am trying to confirm it. </p>
| <p>The link in question was correct... you do need to unplug it.</p>
<p>The Arduino's serial chip uses pins 0 and 1 to communicate with the ATmega 328 PU chip onboard, thus you have two independent devices connected to the same wires and both the Arduino main chip and the Bluetooth module are trying to communicate at the same time (rendering all data unreadable by the computer).</p>
|
10112 | |led|pwm| | How to make sure Arduino's PWM pulses are phase shifted? | 2015-04-16T06:41:35.583 | <p>I'd like illuminate my room solely with several RGB LED strips using Arduino's PWM (together with LED amplifier and few transistors). </p>
<p>I want the Arduino to control 2 independent chains of LED strips, and I want to make sure, that the LEDs would not blink simultaneously, creating a very strong stroboscopic effect in my room. </p>
<p>How to delay three Arduino's PWM pins half a phase relative to the other three?</p>
| <p>Why not put a capacitor (and current limiting resistor) in the circuit for each color of each LED? (The output from the Arduino would lead first to a current limiting resistor, value picked to limit the current to the LED to it's max, as usual. Then a small capacitor between the signal line and ground.) That will average out the output and change a square wave output to a DC output (With a fair amount of ripple in it.) The ripple shouldn't matter, but the LEDs won't turn fully off, so the strobe effect should be all but eliminated, and the apparent brightness of each output should be the same.</p>
<p>Then you can use unmodified PWM and don't have to mess with the timers on your Arduino (which affects other things besides PWM.)</p>
|
10115 | |arduino-uno| | How to discard same string received at Arduino | 2015-04-16T11:24:44.297 | <p>I don't want the same string to be printed again and again. I'm getting the data into an Excel sheet.</p>
<pre><code>byte readValue1=0;
byte readValue2=0;
int add=0;
int row=0;
int Zigbee1=0,Zigbee2=0,Zigbee3=0;
void setup() {
Serial.begin(9600);
Serial.println("CLEARDATA");
Serial.println("LABEL,Time,Zigbee,a1,a2,a3,a4,a5,a6,a7");
row++;
}
void loop(){
String a1,a2,a3;
String c1,c2,c3;
int b;
if (Serial.available()>21){
if(Serial.read() == 0x7E) {
for(int i=0; i<10; i++){
byte discard = Serial.read();
}
add = Serial.read();
if(add == 33)
{
a1 = func1();
if(a1==c1){
b=0;
}
else
{
b = a1.length();
}
if(b != 0)
{
Zigbee=1;
Serial.print("DATA,TIME,"); Serial.print(Zigbee);
Serial.print(","); Serial.println(a1);
row++;
}
}
else if(add == 48)
{
a2 = func1();
b = a2.length();
if(b != 0)
{
Zigbee=2;
if(a2!=c2){
Serial.print("DATA,TIME,"); Serial.print(Zigbee);
Serial.print(","); Serial.println(a2);
}
c2=a2;
row++;
}
}
else if(add == 69)
{
a3 = func1();
b = a3.length();
if(b != 0)
{
Zigbee=3;
Serial.print("DATA,TIME,"); Serial.print(Zigbee);
Serial.print(","); Serial.println(a3);
row++;
}
}
}
}
}
</code></pre>
| <p>i solved it out by using comparing the received bits in that frame..
here is my code..</p>
<pre><code> if(add == 33)
{
a1 = func1();
b = a1.length();
if(b != 0)
{
Zigbee=1;
if(a1!=c1)
{
Serial.print("DATA,TIME,"); Serial.print(Zigbee);
Serial.print(","); Serial.println(a1);
}
c1=a1;
row++;
}
}
else if(add == 48)
{
a2 = func1();
b = a2.length();
if(b != 0)
{
Zigbee=2;
if(a2!=c2){
Serial.print("DATA,TIME,"); Serial.print(Zigbee);
Serial.print(","); Serial.println(a2);
}
c2=a2;
row++;
}
}
else if(add == 69)
{
a3 = func1();
b = a3.length();
if(b != 0)
{
Zigbee=3;
if(a3!=c3)
{
Serial.print("DATA,TIME,"); Serial.print(Zigbee);
Serial.print(","); Serial.println(a3);
}
c3=a3;
row++;
}
}
</code></pre>
|
10117 | |library| | Arduino IDE doesn't find header file | 2015-04-16T13:40:57.677 | <p>I'm trying to start with the SainSmart 4x20 serial LCD, and copied the library to the Arduino library:</p>
<p><img src="https://i.stack.imgur.com/QLGNM.png" alt="enter image description here"></p>
<p>So <code>LiquidCrystal_I2C.h</code> is included. But when I try to compile an example sketch it says </p>
<blockquote>
<p>Arduino: 1.7.0 (Windows 7), Board: "Arduino Uno"</p>
<p>HelloWorld_i2c.pde:2:31: fatal error: LiquidCrystal_I2C.h: No such file or directory</p>
<p>compilation terminated.</p>
<p>Error compiling.</p>
</blockquote>
<p>Any ideas how to fix this?</p>
| <p>I copied the SainSmart library to the IDE's library folder, not noticing that there was already a folder named "LiquidCrystal". Apparently the files added to the existing folder are being ignored. </p>
<p>Renaming the SainSmart library before adding it solves the problem.</p>
|
10123 | |arduino-yun|voltage-level| | output of yun is not 3.3 | 2015-04-16T16:22:35.557 | <p>After execute the program of below, the 13 pin output is 4.8v. Why it's not 3.3v?</p>
<pre><code>void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(13, HIGH);
}
</code></pre>
| <p>The Atheros chip on the Yún is run off 3.3V, but the AVR chip, which is what is connected to the external pins, runs off 5V. What you are seeing is normal (a bit low though, but within spec).</p>
|
10129 | |lcd|arduino-nano| | Converting Arduino LCD Programs to Serial I2C LCD code | 2015-04-16T18:10:15.653 | <p>I just got a Serial LCD and wanted to test it out with a game. I found this <a href="http://eturnerx.blogspot.com/2012/08/arduino-lcd-hunt-wumpus-conversion.html" rel="nofollow">site</a> with game conversions and wanted to use <a href="http://eturnerx.com/files/arduino/003_wumpus_hunt_eturnerx_arduino_lcd.html" rel="nofollow">this game</a>. However since my serial LCD use the LiquidCrystalic2 library the code in its current state won't work. Is there a simple method of converting or porting liquidcrystal to LiquidCrystalic2? Or if someone knows of a simple game in regards to hardware that uses a serial lcd and could direct me to a link that would be great.</p>
| <p>i got my lcd working on I2C following the steps in this link <a href="http://forum.arduino.cc/index.php?topic=128635.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=128635.0</a></p>
|
10139 | |arduino-uno|wifi|tcpip| | Wi-Fi Module communication? | 2015-04-16T21:39:34.477 | <p>I bought a Arduino Wi-Fi Module it does not have any manual or catalog </p>
<p>my project is to turn on/off a motor wireless
<img src="https://i.stack.imgur.com/EvYip.jpg" alt="enter image description here">
it is working grate for the serial/usb cable but i couldn't make it work for wireless/wifi</p>
<p>after some walking around i found that my wifi module is making a wifi network called "HL-link_A49D"
with password from 1-8 and after network scanning i found that the module ip is 192.168.16.254/ username and pass are admin/admin
here is what i found </p>
<p><img src="https://i.stack.imgur.com/hanz4.jpg" alt="enter image description here"></p>
<p>my question is how could i connect to the wifi module and send commands to it ?</p>
| <p>Good detective work so far!<br>
In the admin page you found one can see the name of the module: <code>HLK-RM04</code>. Googling on that I found the <a href="http://www.hlktech.net/product_detail.php?ProId=39" rel="nofollow">manufacturer/seller page</a>. </p>
<p>A PDF with some information can be found <a href="http://www.hlktech.net/inc/lib/download/download.php?DId=21" rel="nofollow">here</a>.</p>
<p>Also one link with <a href="http://rayshobby.net/first-impression-on-hlk-rm04-serial-to-wifi-module/" rel="nofollow">somebody's experience</a> with the module.</p>
<p>For other projects you might want to try as well the ESP8266 - very cheap and seems a lot of people have experience with it, so you might find more information on the net.</p>
|
10144 | |library| | Accel Stepper help, stepper not going backwards | 2015-04-16T21:58:31.007 | <p>So my question is that I am trying to use a arduino library called Accel Stepper to control a stepper motor, I made code that makes the stepper motor move one rev clockwise and then one rev counter clockwise </p>
<p>however as i run the code, the motor has no problem going clockwise, however when it comes to reversing the shaft of the motor stays still and doesn't move while the whole motor itself vibrates, what could be my problem? </p>
<p>here is my code: </p>
<pre><code> // MultiStepper.pde
// -*- mode: C++ -*-
//
// Shows how to multiple simultaneous steppers
// Runs one stepper forwards and backwards, accelerating and decelerating
// at the limits. Runs other steppers at the same time
//
// Copyright (C) 2009 Mike McCauley
// $Id: MultiStepper.pde,v 1.1 2011/01/05 01:51:01 mikem Exp mikem $
#include <AccelStepper.h>
int user = 800;
// Define some steppers and the pins the will use
AccelStepper stepper2(AccelStepper::DRIVER, 9,8 );
AccelStepper stepper3(AccelStepper::DRIVER, 4, 7);
void setup()
{
stepper2.setMaxSpeed(1000);
stepper2.setSpeed(300);
}
void loop()
{
// Change direction at the limits
stepper2.moveTo(user);
stepper2.setSpeed(300);
stepper2.runSpeedToPosition();
if (stepper2.distanceToGo() == 0){
stepper2.moveTo(-stepper2.currentPosition());
stepper2.setSpeed(300);
stepper2.runSpeedToPosition();
}
}
</code></pre>
| <p>to reverse the direction try passing negative speed value to speed</p>
<p>like</p>
<p>stepper2.setSpeed(-300); </p>
|
10147 | |interrupt| | Intterupts For Arduino | 2015-04-17T00:26:32.223 | <p>I am making a moving robot that will be autonomous in many respects. However if something goes wrong I want to be able to use a remote to push a button and it stop in its tracks no matter what function its in. My understanding is that interrupts can do that. The official site I did not find to be helpful. Any ideas? Or if the scheduler library would be of use.</p>
| <p>If you are using an arduino uno, pin 2 and 3 are the hardware interrupt pins. You may send rising , falling, high or low signals to these pins using a Bluetooth module (for eg). Say for eg when you press the remote switch, Bluetooth gets a low signal and triggers an interrupt. If the output of Bluetooth is connected to pin 2, then in the setup you have to declare </p>
<pre><code>attachInterrupt(0, stoprobo, LOW);
</code></pre>
<p>And in the function stoprobo, you can write the code to stop your robot.</p>
|
10156 | |arduino-uno|uploading|usb|linux| | ttyACM0 no such file or directory On Ubunutu 14.04 | 2015-04-17T11:00:30.867 | <p>I have an Arduino Uno which communicated with the computer (Ubunutu 14.04) fine till 6 days ago (I assume some software update is to blame).</p>
<p>Now when trying to upload I get</p>
<p>processing.app.SerialNotFoundException: Serial port '/dev/ttyACM0' not found. Did you select the right one from the Tools > Serial Port menu? at processing.app.Serial.(Serial.java:191) at processing.app.Serial.(Serial.java:77) at processing.app.debug.Uploader.flushSerialBuffer(Uploader.java:77) at processing.app.debug.AvrdudeUploader.uploadViaBootloader(AvrdudeUploader.java:175) at processing.app.debug.AvrdudeUploader.uploadUsingPreferences(AvrdudeUploader.java:67) at processing.app.Sketch.upload(Sketch.java:1671) at processing.app.Sketch.exportApplet(Sketch.java:1627) at processing.app.Sketch.exportApplet(Sketch.java:1599) at processing.app.Editor$DefaultExportHandler.run(Editor.java:2380) at java.lang.Thread.run(Thread.java:745)</p>
<p>When I sudo ls /dev/ttyA*</p>
<p>I get</p>
<pre><code>ls: cannot access /dev/ttyA*: No such file or directory
</code></pre>
<p>So it does not look like a permission issue.</p>
<p>when I lsusb</p>
<p>I get</p>
<pre><code>Bus 001 Device 002: ID 8087:8000 Intel Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 003 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 002 Device 003: ID 04f2:b39a Chicony Electronics Co., Ltd
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
</code></pre>
<p>So it does not even see the device (which is connected and pulling current).</p>
<p>when I dmesg before and after connecting the Arduino, I don't see anything new.</p>
<p>I tried switching USB cables, and switching USB ports on the machine (both ports work with a mouse), but in vain.</p>
<p>What went wrong and how do I fix it ?</p>
<p>Thanks,
David.</p>
| <p>Ok, it sounds like there is an issue with the ATMega(8/16)U2 chip or its surroundings. It might just need its firmware refreshing (which can be done with another Arduino as a programmer) or it might be plain dead.</p>
<p>Another possibility is the USB socket itself. I have two UNOs, one which is perfectly fine, and one where I need to hold the cable at just the right angle for it to connect properly. You can try using a fine needle to try and raise the four metal strips in the USB connector a fraction to make better contact.</p>
|
10160 | |serial|edison| | What are the different types of high-speed serial data transfer protocols, and how do they work (ex: baudrate, synchronous vs asynchronous, etc)? | 2015-04-17T16:43:14.867 | <p>Otherwise worded: How do I resolve my understanding about baud rates and high speed serial data transfer?</p>
<p>From what I understand, serial communication is relatively slow. By slow, I mean that the fastest common rate of transmission of data is 115.2 kBaud. </p>
<p>However, also from what I understand there are fast ways of transferring data serially. I know that some serial configurations through Firewire or Ethernet can transfer data at speeds that are orders of magnitude higher than 115.2 kBaud. These data streams are able to be read on simple computers that you can buy from Staples. I don't know how these systems receive data at such a high speed if common baud rates are so low. </p>
<p>I know something is wrong with my understanding of it all. I am new to electrical engineering and I am trying to teach myself some basic ideas for my research project - with much frustration. I know that I need to have a system that can receive a pulse train at a minimum speed of 10MHz (hopefully up to 500MHz). I will then program it to process this data. The system that I currently have to receive the data is an Arduino certified product:</p>
<p><a href="http://store.arduino.cc/product/E000052" rel="nofollow">http://store.arduino.cc/product/E000052</a></p>
<p>Programming in the Arduino language is not a problem, I already know how to do this. I just want to understand what I can do to receive this data stream. Do I need something faster than this? Or will this suffice? I'm more interested in the theory than the device; it is more valuable for me to bolster my education than for me to solve my problem (though it needs to be solved). </p>
| <p>The other answers have really good info in them, but I'd still like to expound a bit on the different types of serial protocols, and how they vary in speed. I'll also mention a few devices and show some comparisons. <strong>For <em>synchronous</em> vs <em>asynchronous</em> and what that means, see Majenko's really good answer.</strong></p>
<h1>Clarification:</h1>
<p>Your phrasing of "receive a pulse train at a minimum speed of 10MHz" is quite confusing to me. Perhaps this is because when I hear "pulse train" I think you mean you want to read pulse widths in order to obtain data, ie: like the PPM pulse train used in Radio Control communication signals. </p>
<p>Is what you mean simply that you want 10Mbps (megabit per second) transmission rates? If so, the Arduino Intel Galileo can do <a href="https://www.arduino.cc/en/ArduinoCertified/IntelGalileo" rel="nofollow noreferrer">SPI serial communication at a rate of up to <strong>25MHz</strong></a>, or you can do Ethernet communication with this board up to <strong>10 MHz</strong> or <strong>100 MHz</strong> (see previous link as well). Note that some Ethernet devices can communicate up to <strong>1000 MHz</strong> (like the <a href="http://www.orangepi.org/" rel="nofollow noreferrer">Orange Pi Plus</a>), but the Intel Galileo only goes up to <strong>100 MHz</strong>, according to the link above. </p>
<p>USB3.1 serial communication, if a device supports it, however, can be done up to <strong>10Gbps</strong>. </p>
<h1>Standard RS-232 0-5V (TTL) Serial, and example:</h1>
<p>Now, as for standard RS-232-type serial done with TTL logic levels (ie: signal voltage levels 0 to 5V), via a UART (piece of hardware that allows this type of asynchronous communication protocol), I have written C++ code on a PC and on a standard Arduino (ex: Nano, Uno, or Pro Mini--under $10 cost + $2 external UART) which communicates at <strong>250kbaud</strong> (though <strong>2Mbaud</strong> is possible on an Arduino Uno--see Connor Wolf's answer <a href="https://arduino.stackexchange.com/questions/296/how-high-of-a-baud-rate-can-i-go-without-errors">here</a>). </p>
<p>When communicating via a serial UART type device, plugged into a PC via a USB plug, a Windows-based computer sees it as a "COM" port. The UART simply does USB to RS-232 TTL data conversion, so I can use this COM port as a serial port on the PC. Since pretty much every Arduino supports standard Serial communication, even the cheapest ones, this is very appealing to me to learn how to write C++ code to do this. I spent the last couple weeks working on my communication code. </p>
<p>At a serial communication speed of <strong>250kbaud</strong> (<strong>250kbps</strong> in my case) I am able to transfer 25-byte binary data packets from my PC to my sub-$10 Arduino at a rate of up to <strong>1000 packets/sec</strong>, while doing error checking on the Arduino receiving the data. In my case, each packet contains 8 commands, plus error checking bytes and a couple other things, to control an RC vehicle.</p>
<hr>
<h1>Here's a few key serial protocols, and their associated speeds, to be aware of.</h1>
<p>All of these are different types of serial communication protocols:</p>
<ol>
<li><h2>I2C:</h2>
<p>Normal Arduino (ex: Uno) default speed is 100kbps; it can be increased to 400kbps. Some non-Arduino devices can do 1Mbps or 3.4Mbps.</p></li>
<li><h2>SPI:</h2>
<p>Arduino default speed is 4Mbps. Normal Arduinos can go up to 8Mbps; Galileo can do 25Mbps. I have seen some devices (ex: Wiznet W5200 Ethernet chip), which can do SPI serial communication up to 80Mbps (<a href="http://feilipu.me/2013/08/03/wiznet-w5200-arduino-shield/" rel="nofollow noreferrer">source</a>).</p></li>
<li><h2>RS-232 TTL via UART:</h2>
<p>This is what most people mean I think when they just use the word "serial" without specifying it further by saying "SPI," "I2C," etc. Whenever you see the term "baud" or "baudrate," this is the type of serial communication they are referring to too. Hardware (UART)-based serial communication is done via pins 0 and 1 on most Arduinos. Normally, the "high-end" speed is considered 115200bps, but I regularly use 250kbps on an Arduino. Up to 2 Mbps is theoretically possible under the right conditions for the Atmel AVR-based Arduinos, like the Uno. See Connor Wolf's answer <a href="https://arduino.stackexchange.com/questions/296/how-high-of-a-baud-rate-can-i-go-without-errors">here</a>. Arduino also includes a software serial library for this type of serial communication on any of the Arduino's pins, and I have used it up to 250kbps. I haven't yet tested it beyond that speed, but being software-based, I'd expect it to become unreliable much beyond that.</p></li>
<li><h2>USB:</h2>
<p>USB Speeds (<a href="https://en.wikipedia.org/wiki/USB" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/USB</a>)<br>
USB 1.0: Low Speed mode (1.5Mbps), Full Speed mode (12Mbps)<br>
USB 2.0: High Speed (480Mbps)<br>
USB 3.0: SuperSpeed (5Gbps)<br>
USB 3.1: SuperSpeed+ (10Gbps) </p></li>
<li><h2>Ethernet:</h2>
<p>Standard rates are 10/100/1000 Mbps. </p></li>
</ol>
<hr>
<h1>Conclusions:</h1>
<ul>
<li>If you must have a minimum of 10MHz (AKA mbps) communication rates, you can use the SPI, USB, or Ethernet protocols. I2C and RS-232 TTL serial are too slow. </li>
<li>If you really want the ~500MHz communication rate, you can use USB 2.0 or higher, or Ethernet 1000Mbps. All the rest are too slow. </li>
</ul>
<p>Note that embedded boards and devices, microcontrollers, etc, can <em>all</em> do some type of serial communication, even if it's just slow <a href="https://en.wikipedia.org/wiki/Bit_banging" rel="nofollow noreferrer">bit-banged</a> RS-232 TTL-type or SPI-type serial. Nevertheless, some high-end devices can do really high speed serial communication via USB, USB 3.0, high-speed Ethernet, high-speed SPI, etc. When it comes to really fast serial communication methods (~3Mbps and higher), <em>synchronous</em> techniques must generally be used rather than <em>asynchronous</em> techniques, as the errors in clock-rates caused by using separate clocks begin to be too pronounced.</p>
<p>You just need to look at your actual needs. For most of my needs, 250kbaud is plenty fast using the built-in UART inside every cheapo low-end AVR-based Arduino device. Your needs, however may be different.</p>
|
10174 | |programming| | Communicating with Arduino | 2015-04-18T11:07:30.157 | <p>In this <a href="https://arduino.stackexchange.com/questions/4436/send-processing-color-data-into-arduino">Question</a> how does the code <code>Processing</code> work?
Which programming language is it written in? How to run it?</p>
| <p>"Processing" is a simplified programming language/environment based on Java. It's designed to be very easy for non-programmers to use, and is quite a popular choice for using alongside Arduino projects.</p>
<p>You can download it for free (and get lots of tutorials/documentation) from here:</p>
<ul>
<li><a href="https://processing.org" rel="nofollow">https://processing.org</a></li>
</ul>
<p>As a side note, the Arduino IDE was based on Processing, so it will probably look familiar!</p>
|
10185 | |arduino-uno| | What is the physical location of the U1A symbol on Arduino Uno? | 2015-04-19T03:00:23.567 | <p>I'm trying to find an easy way to allow an Arduino Uno to determine if it's being powered from USB or the DC barrel jack. In <a href="http://forum.arduino.cc/index.php?topic=120693.0" rel="noreferrer">this thread</a>, one user recommends wiring the output of the on-board comparator op-amp (U5A pin 1) into the digital input pin.</p>
<p>I couldn't find U5A on the <a href="http://www.arduino.cc/en/uploads/Main/arduino-uno-schematic.pdf" rel="noreferrer">current schematic</a>, but I think he's actually referring to U1A pin 1. Is this correct?</p>
<p>Unfortunately, I'm not sure where on the physical Arduino that device is located. I have one in front of me, and almost none of the parts are labeled on the silk screen. How do I find out where it is? I've googled for Arduino Uno part placement schematics, but all I'm finding are blurry unlabeled low-res images.</p>
| <p>The op-amp is a LM358 so you can look at the ICs themselves. Also it's a dual comparator with 8 pins. On my example image below you can see it below the crystal. I can't comment if that's the correct way to sense what you need, but it seems the comparator output should be 1 if there is external power applied. You could check with a multimeter.</p>
<p><img src="https://i.stack.imgur.com/bANvw.jpg" alt="enter image description here"></p>
|
10187 | |arduino-ide| | Difference between print() and println() | 2015-04-19T11:27:03.537 | <p>What is the difference between print( ) and println( )?<br>
I see none when I run a code.</p>
| <p>print() print which you want but in one line.</p>
<p>For example,</p>
<pre><code>Serial.print("Hello");
</code></pre>
<p>Then output in Serial Monitor look like,</p>
<pre><code>HelloHelloHelloHelloHello
</code></pre>
<p>println() print same things but in new line.</p>
<p>For example,</p>
<pre><code>Serial.println("Hello");
</code></pre>
<p>Then output in Serial Monitor look like,</p>
<pre><code>Hello
Hello
Hello
Hello
Hello
</code></pre>
|
10189 | |programming| | Alternative to Tone( ) | 2015-04-19T14:29:58.407 | <p>Is there any way to make sounds using an Arduino without using the tone function?<br>
It must be possible via this new method to control frequency of sound.</p>
| <p>Thanks a lot, but anyway, I got an answer myself.<br>
I can use the simple delaymicroseconds( ) .<br>
Also, I can use timer interrupts to do basically the same thing<br>
And these are a lot less complicated than the other answers I got.</p>
|
10190 | |avr| | Porting Arduino code to AVR/C++ input not working? | 2015-04-19T14:55:10.920 | <p>So. I'm trying to read an input on the Arduino Nano using C++/AVR/Eclipse instead of the regular arduino IDE.
The code below is working in the arduino IDE</p>
<pre><code>void setup() {
// put your setup code here, to run once:
pinMode(13, OUTPUT);
pinMode(5, INPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(5)){
digitalWrite(13,1);
}else{
digitalWrite(13,0);
}
}
</code></pre>
<p>I'm porting the code to AVR/C++ in Eclipse, regular blinking leds is working... but I can't read inputs for some reason...</p>
<pre><code>#define F_CPU 16000000UL //16MHz
#include <avr/io.h>
#include <util/delay.h>
#define set_bit(Y,bit_x) (Y|=(1<<bit_x))
#define clear_bit(Y,bit_x) (Y&=~(1<<bit_x))
#define isset_bit(Y,bit_x) (Y&(1<<bit_x))
#define toggle_bit(Y,bit_x) (Y^=(1<<bit_x))
int main( ){
DDRB = 0xFF;//Setting all portB pins to output (D13/PB5 - LED)
DDRD = 0x00;//Setting all portD pins to input (D5 /PD5 - INPUT)
while(1){
if(isset_bit(PORTD,PD5)){//if input... doesn't work?
set_bit(PORTB,PB5);//Set output (Tested to be working)
}else{
clear_bit(PORTB,PB5);//Clear output
}
}
}
</code></pre>
| <p>During the creation of this question I found out the answer... Though I wanted to share it with you guys for later reference.
It has been quite a time since I have worked with AVR. </p>
<p><strong>You should read pins from PINx</strong></p>
<p><strong>You should set pins in PORTx</strong></p>
<p><strong>Set DDRx to 1 for OUTPUT and to 0 for INPUT</strong></p>
<p>^ This is fun because PIC/Microchip MCU's use 1 for input and 0 for output.</p>
<p>See code below:</p>
<pre><code>#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#define set_bit(Y,bit_x) (Y|=(1<<bit_x))
#define clear_bit(Y,bit_x) (Y&=~(1<<bit_x))
#define isset_bit(Y,bit_x) (Y&(1<<bit_x))
#define toggle_bit(Y,bit_x) (Y^=(1<<bit_x))
int main( ){
DDRB = 0xFF;
DDRD = 0x00;
while(1){
if((PIND&(1<<PD5))){
set_bit(PORTB,PB5);
}else{
clear_bit(PORTB,PB5);
}
}
}
</code></pre>
|
10192 | |pins|arduino-nano|system-design| | Best Header for Arduino Nano | 2015-04-16T23:03:43.857 | <p>I would like to be able to create permanent projects with my arduino Nano but be able to remove the nano in order to use it in other projects. The arduino Nano has 30 pins so I would be looking for some kind of female 30 pin header. Most of the headers that I found like that are too narrow because they are for IC's. Any ideas?</p>
| <p>I use the female headers from the original Nano manufacturer: <a href="http://gravitech.us/2015feheanas.html" rel="nofollow">http://gravitech.us/2015feheanas.html</a></p>
|
10196 | |arduino-uno|programming|sketch|c| | Arduino error in code | 2015-04-19T20:34:39.293 | <p>i'm making a project and i came across the follwing error.
Whan i'm trying to compile and upload the code i'm getting those errors:</p>
<pre><code>ShiftRegisterTest1.ino:In function 'int* return_pins(int)'
displays.ino:9: error: expected primary-expression before '{' token
displays.ino:9: error: expected `;' before '{' token
displays.ino:12: error: expected primary-expression before '{' token
displays.ino:12: error: expected `;' before '{' token
displays.ino:15: error: expected primary-expression before '{' token
displays.ino:15: error: expected `;' before '{' token
displays.ino:18: error: expected primary-expression before '{' token
displays.ino:18: error: expected `;' before '{' token
displays.ino:21: error: expected primary-expression before '{' token
displays.ino:21: error: expected `;' before '{' token
displays.ino:24: error: expected primary-expression before '{' token
displays.ino:24: error: expected `;' before '{' token
displays.ino:27: error: expected primary-expression before '{' token
displays.ino:27: error: expected `;' before '{' token
displays.ino:30: error: expected primary-expression before '{' token
displays.ino:30: error: expected `;' before '{' token
displays.ino:33: error: expected primary-expression before '{' token
displays.ino:33: error: expected `;' before '{' token
displays.ino:36: error: expected primary-expression before '{' token
displays.ino:36: error: expected `;' before '{' token
displays.ino:39: error: expected primary-expression before '{' token
displays.ino:39: error: expected `;' before '{' token
displays.ino:42: error: expected primary-expression before '{' token
displays.ino:42: error: expected `;' before '{' token
displays.ino:45: error: expected primary-expression before '{' token
displays.ino:45: error: expected `;' before '{' token
displays.ino:48: error: expected primary-expression before '{' token
displays.ino:48: error: expected `;' before '{' token
displays.ino:51: error: expected primary-expression before '{' token
displays.ino:51: error: expected `;' before '{' token
displays.ino:56: error: expected primary-expression before '{' token
displays.ino:56: error: expected `;' before '{' token
Error compiling
</code></pre>
<p>I don't really understand why since the code (see below) should be working.</p>
<pre><code>int * return_pins(int get_number)
{
static int rp[8];
switch(get_number)
{
//DP, A, B, C, D, E, F, G
case 48: //0
rp[8] = {0, 1, 1, 1, 1, 1, 1, 0};
break;
case 49: //1
rp[8] = {0, 0, 1, 1, 0, 0, 0, 0};
break;
case 50: //2
rp[8] = {0, 1, 1, 0, 1, 1, 0, 1};
break;
case 51: //3
rp[8] = {0, 1, 1, 1, 1, 0, 0, 1};
break;
case 52: //4
rp[8] = {0, 0, 1, 1, 0, 0, 1, 1};
break;
case 53: //5
rp[8] = {0, 1, 0, 1, 1, 0, 1, 1};
break;
case 54: //6
rp[8] = {0, 1, 0, 1, 1, 0, 1, 1};
break;
case 55: //7
rp[8] = {0, 1, 1, 1, 0, 0, 0, 0};
break;
case 56: //8
rp[8] = {0, 1, 1, 1, 1, 1, 1, 1};
break;
case 57: //9
rp[8] = {0, 1, 1, 1, 1, 0, 1, 1};
break;
case 65: //A
rp[8] = {0, 1, 1, 1, 0, 1, 1, 1};
break;
case 70: //F
rp[8] = {0, 1, 0, 0, 0, 1, 1, 1};
break;
case 69: //E
rp[8] = {0, 1, 0, 0, 1, 1, 1, 1};
break;
case 80: //P
rp[8] = {0, 1, 1, 0, 0, 1, 1, 1};
break;
case 72: //H
rp[8] = {0, 0, 1, 1, 0, 1, 1, 0};
break;
//DP, A, B, C, D, E, F, G
case 45: //-
default:
rp[8] = {0, 0, 0, 0, 0, 0, 0, 1};
break;
}
return rp;
}
</code></pre>
<p>What this code does is to basicaly get an <code>int</code> ad input and based on this number it returns an <code>int array</code>. It's a very simple code which is called inside the <code>loop()</code> method which is located on an other file.</p>
<p><strong>Also i'm using Atmel Studio 6 instead of the original Arduino IDE but i dont think it has to do something with the problem :/</strong></p>
| <p>Have you tried compiling without the "static" keyword. I think the compiler is complaining because it sees multiple statements trying to make an assignment to a static variable. Even if your logic is such that only one of the assignments will ever be executed the compiler doesn't know that.</p>
|
10202 | |uploading| | Uploading/Flashing different programs to two different Arduino uCs, using one USB | 2015-04-20T15:33:59.713 | <p>I'm designing a custom dual-uC board, where I want there to be two Arduinos both running different programs - kind of dual core arduino. In order to load new programs onto the uCs, yes, I could have two USB ports each connected to one of the uCs (say a ATmega32u4). But I'm trying to work out strategies with just one USB port (and no usb-hub).</p>
<p>Also, I don't need the USB functionality for general use, only for program updates.</p>
<p>Option 1:</p>
<p>Switch access to each USB capable Arduino (e.g. ATmega32U). Program one uC, toggle switch, program other uC</p>
<p>EDIT: this is fine, however I ideally want to use zero additional end-user buttons - I want the end-user to do as little as possible.</p>
<p>Option 2:</p>
<p>The arduino UNO has two devices, ATmega16U2 and a ATmega328. During normal operation the 16U operates as a usb-to-serial. However, I'm aware that there are custom firmwares that allow different functionality (such as USB-Joystick etc) - it is possible to switch firmawares between a custom-firmware and default firmware, to allow the ATmega328 to be programmed normally but also to run the custom program. But it seems that Arduino.h doesn't support the ATmega16U2, so I would have to program this device using the AVR or another framework.</p>
<p>Alternatively, the ATmega32U4 is supported by Arduino.h but there doesn't seem to be Arduino usb-serial 'firmware' for the 32U (only the 8U & 16U)</p>
<p>Option 3:</p>
<p>Can I use a ATmega32u4 with Arduino-ISP programming an ATmega328p?</p>
<p>EDIT: above seems valid:
<a href="https://petervanhoyweghen.wordpress.com/2012/09/16/arduinoisp-on-the-leonardo/" rel="nofollow">https://petervanhoyweghen.wordpress.com/2012/09/16/arduinoisp-on-the-leonardo/</a> </p>
<p>Other simple recommended approaches?</p>
<p>EDIT: the firmware update should be physically as hands off as possible, as to be used by end-user, and preference for solutions that require zero additional buttons/etc</p>
<p>UPDATE: </p>
<p>I tried the Arduino as ISP method (option 3), and it works</p>
| <p>Provided that you are okay with producing a customized PC side tool (which you would probably want anyway for user convenience) automated target selection should be far superior to manual.</p>
<p>You should be able to use one ATmega16u2 with a minimally customized firmware as a front end to program two distinct ATmega328p's. This could be as simple as selecting the target based on the baud rate, having it hold the de-selected one in reset the whole time, and using some resistors on the shared TX lines for safety. Last I checked the stock firmware used a soft serial at some rates, and that can be put on different pins, so it could be another way to de-conflict and select targets.</p>
<p>Your idea of using a 32u4 both as a functional part and as a buddy-programmer for another part is perfectly valid too - you can do that programming to a serial bootloader (it should be a simple matter to port the 16u2 firmware, or find another example), or via the ISP pins. </p>
<p>Now that I think about it, there's been a version of this question here before, as I remember writing about an idea for using two ATmega328p's permanently wired to a stock USB-serial, but with their bootloaders customized to use unique baud rates, and a little logic added so that on reset each would leave its serial TX pin tristated if it didn't detect bootloader traffic at its individually unique baudrate, thus allowing the other to be programmed without interference.</p>
|
10208 | |arduino-uno|voltage-level| | SMD Voltage Regulator 662k very hot, how to repair it? | 2015-04-20T18:10:30.320 | <p>I think I made a mistake. Now, the 662k on my Arduino Uno very hot about 90°C.</p>
<p>I test it, it can be programmed and can run blink program normally.</p>
<p>There is a switch for voltage choose. Now, run in 3.3v mode get 2.8v and in 5v mode get 4.8v.</p>
<p>What should I do?</p>
<p>If 662k be replaced, can I use that Arduino normally in the future.</p>
<p><img src="https://i.stack.imgur.com/zOAUA.jpg" alt="enter image description here"></p>
| <p>From the picture I guess it is a roboduino. The only voltage regulator is the 662k, it is <strong>too small</strong> compared to other voltage regulators!!! (have a look at the size and sink of the official arduino), so it is normal that the temperature is high. (arduino uno can get up to 1A and the regulator is bigger)</p>
<p>To reduce temperature just <strong>use the lowest input source</strong> (for instance, for arduino 5 volts, use 7 volts source, not 12 volts source). The bigger input voltage, the higher temperature in the regulator.</p>
<p>Solutions.</p>
<ul>
<li>replace the 662K with another 662K one.</li>
<li>use a bigger voltage regulator. Since 66K space is tight (SOT-23) and no sink space I suggest to solder a TO-92 like voltage regulator. Not nice solution, but handy. </li>
</ul>
|
10209 | |programming|variables| | Global Variable not able to be accessed in function? | 2015-04-20T18:46:22.853 | <p>I am trying to compile an Arduino program that takes analog input. However, when I declare multiple global variables, it often will not compile and because it throws an error that the variables aren't within scope of the functions within the program. I am not super familiar with Arduino IDE, but this doesn't programmatically make sense to me.</p>
<p>This is the program:</p>
<pre><code>/*
* By Hannah Perner-Wilson, www.plusea.at
* Modified 3/30/2012 By Brian E Kaminski, www.AdvancerTechnologies.com
*
* IMPORTANT!!:
* Scroll down to set your serial port
* Scroll down to set your thresholds
*/
import processing.serial.*;
// definition of window size
// you can change the size of the window as you like
// the thresholdGraph will be scaled to fit
// the optimal size for the thresholdGraph is 1000 x 400
int xWidth = 1200;
int yHeight = 750;
// xPos input array, using prefix
int[] xPosArr= {0,0,0,0,0,0};
//
int[] messageArr= {0,0,0,0,0,0};
// Arrays for threshholding
int[] threshMax= {0,0,0,0,0,0};
int[] threshMin= {0,0,0,0,0,0};
// variables for serial connection. portname and baudrate are user specific
Serial port1;
//Set your serial port here (look at list printed when you run the application once)
String V3 = Serial.list()[1];
String portname1 = V3;
int baudrate = 9600;
int prefix = 10001;
boolean myCatch = false;
String serialIN = "";
String serialINPUT = "";
String buffer = "";
int value = 0;
// ThresholdGraph draws grid and poti states
ThresholdGraph in;
void setup(){
// set size and framerate
size(xWidth, yHeight);
frameRate(25);
background(255);
strokeWeight(5);
stroke(0);
smooth();
strokeCap(ROUND);
// establish serial port connection
port1 = new Serial(this, portname1, baudrate);
port1.bufferUntil('\n') ;
println(Serial.list()); // print serial list
// create DisplayItems object
in = new ThresholdGraph();
// THRESHOLD VALUES:
// using the thresholdGraph you can determine the MIN and MAX values
// of your sensors. Enter these here. They must lie between 0 and 1000.
//MIN trashhold
threshMin[0] = 20; // one
threshMin[1] = 20; // two
threshMin[2] = 20; // three
threshMin[3] = 20; // four
threshMin[4] = 20; // five
threshMin[5] = 20; // six
//MAX trashhold
threshMax[0] = 600; // one
threshMax[1] = 600; // two
threshMax[2] = 600; // three
threshMax[3] = 600; // four
threshMax[4] = 600; // five
threshMax[5] = 600; // six
}//end setup
// draw listens to serial port, draw
void draw(){
// listen to serial port and trigger serial event
while(port1.available() > 0){
serialIN = port1.readStringUntil('\n');
//println((int)float(serialIN));
if(serialIN != "")
serialEvent(serialIN);
else
Serial.println("found empty");
}
// threshold serial input
threshHolding();
// draw serial input
in.update();
}//end draw()
</code></pre>
<p>The error that are being thrown are:</p>
<pre><code>testproject.ino:100:17: error: 'threshHolding' was not declared in this scope
testproject.ino:103:3: error: 'in' was not declared in this scope
Error compiling.
</code></pre>
| <p>The problem is that this is not an Arduino Sketch, but a processing file which is noted by the initial import statement that is Java based. Because the Arduino IDE is not very sophisticated, it didn't shout out obvious errors such as <code>import type not defined</code> or even <code>ThresholdGraph</code> not defined. </p>
<p>To use this file it is necessary to use the following IDE: <a href="https://processing.org/reference/environment/" rel="nofollow">https://processing.org/reference/environment/</a></p>
|
10211 | |remote-control| | Signal noise on R/C car channel output | 2015-04-20T20:29:54.720 | <p>Doing a little project for work and trying to get the Arduino hooked to an RC car to read the throttle channel output and send that via bluetooth to a nearby laptop which will output an animation based on that speed.</p>
<p>Initial test worked very well and signals from my airplane Tx were solid with very little variance. Once the proof of concept worked, we went ahead and purchased a Traxxas car. I have a wire going from pin 5 to the signal wire on the Rx. With the serial monitor up and arduino powered via my usb cable, the #s jump from the 1400 (where its supposed to be) to 6000 and sometimes 11000. Even more interesting, is when I engaged the throttle via the transmitter, values went down to 30-50...?? I removed the Rx from the car and powered it via the 5v on arduino...#s are solid.</p>
<p>So, it appears the battery or esc is giving a lot of interference. Do I need to use a different kind of wire? If so, what kind of wire? Or ground it somehow?</p>
| <p>Old post, but here was my solution. Had to pickup some shielded cable. Pics below should clearly explain how everything was wired up.</p>
<p><a href="https://i.stack.imgur.com/QvScY.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QvScY.jpg" alt="Wiring into Arduino"></a></p>
<p><a href="https://i.stack.imgur.com/BqEx9.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BqEx9.jpg" alt="Wiring into reciever"></a></p>
|
10224 | |power| | Exceed AREF voltage | 2015-04-21T19:07:20.740 | <p>Let's say that I use a 5V Arduino board, and I set AREF to 3V, thus 0-3V equals to 0-1023 of the analog inputs. </p>
<p>If I exceed the AREF voltage, powering an analog pin with 4V, could that damage the analog input pin? If not, what would be the reading?</p>
<p>Thank you. </p>
| <p>The reading would saturate at 1023 when the voltage on the input pin exceeds AREF. </p>
<p>The datasheet (for the ATmega328P) states as absolute maximum rating for the "Voltage on any Pin except -RESET with respect to Ground" V<sub>CC</sub> + 0.5 V. So applying 4 V to AREF for a 5 V Arduino board should not (necessarily) damage the ATmega. (But you also won't be able to extend the 10-bit resolution range, if that is what you're after...)</p>
<p>In short, choose the reference voltage above the maximum expected voltage.</p>
|
10230 | |arduino-uno|interrupt| | Arduino Watchdog Timer | 2015-04-21T22:15:56.623 | <p>I want to work with interrupts and heard that the watchdog timer is effective way to deal with them. I haven't been able to find a good tutorial on them though and was wondering if someone could head me in the right direction or give me a couple tips and an example.</p>
| <p>For the Uno, you can set an interrupt on digital pins 2 and 3. Check out <a href="http://www.arduino.cc/en/Reference/attachInterrupt" rel="nofollow">http://www.arduino.cc/en/Reference/attachInterrupt</a> for more details.</p>
<p>Here is the example code from that page:</p>
<pre><code>int pin = 13;
volatile int state = LOW;
void setup()
{
pinMode(pin, OUTPUT);
attachInterrupt(0, blink, CHANGE);
}
void loop()
{
digitalWrite(pin, state);
}
void blink()
{
state = !state;
}
</code></pre>
<p>In this case, blink() will be called anytime pin 0 changes state. If you only want the rising or falling edge, change the call to attachInterrupt to say RISING or FALLING instead of CHANGE.</p>
|
10236 | |arduino-pro-mini|avrdude|isp|clones|arduinoisp| | Problem programming Mini Pro via Arduino as ISP | 2015-04-22T03:19:19.173 | <p>I just picked up a pair of Arduino Mini Pro 5v clone boards (Inland, sold at Microcenter, currently $4 USD) and I wanted to use my Uno as an ISP like I've done with ATmega328 and ATtiny85 chips before. I've programmed the Uno with the instructions at <a href="http://www.arduino.cc/en/Tutorial/ArduinoISP">the ArduinoISP tutorial page</a> and I've connected up the Uno to the Mini Pro using the instructions at <a href="http://www.arduino.cc/en/Hacking/MiniBootloader">this page</a>. I cannot get the Arduino IDE or avrdude from the command line to successfully program these boards no matter what I try. Except that I can use the Arduino IDE to burn a new bootloader to the Mini Pro.</p>
<p>I've connected up the status LEDs as well (pins 7, 8 and 9), and I can see that the programmer has an error condition (pin 8) when I attempt to program anything besides the bootloader. </p>
<p>Here is my avrdude command line where I tried to set the fuses on the Mini Pro:</p>
<pre><code>avrdude -P /dev/tty.usbmodema0121 -b 57600 -c avrisp -p atmega328p -U lfuse:w:0xff:m -U hfuse:w:0xdb:m -U efuse:w:0xfd:m
</code></pre>
<p>I get the following back from avrdude:</p>
<pre><code>avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x1c
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x1c
avrdude done. Thank you.
</code></pre>
<p>I've not had any problems with using pretty much this exact same setup, but with a ATmega328 or ATtiny85 chip on a breadboard with avrdude in the past, so I'm at a loss as to what is happening here. </p>
<p>I've also taken a look at the ArduinoISP code, and I'm not really sure what the resp=0x1c is. I don't see a 0x1c value defined in the STK Definitions section of the code, so I'm not sure what might be causing this. </p>
<p>Any pointers here would be appreciated. And yes, I do know that I can use the Uno board with the ATmega328 chip pulled to use as a programmer as well. But I want to be able to overwrite the bootloader area with my own code like I can with a regular ATmega328 chip.</p>
<p>Thanks!</p>
| <p>After poking around for a bit more, it turns out my problem was the baud rate. I could make it work by setting it to 19200, just a little slower. Alternatively, you can modify the ArduinoISP sketch to enable higher baud rates. I used <a href="http://forum.arduino.cc/index.php?topic=48784.5">this post</a> to enable 115200 baud and I was able to successfully use avrdude at the higher rates.</p>
<p>Not sure how I missed this before, but it's an easy to solve at least.</p>
|
10255 | |arduino-due|spi|digital|resistor| | How to interface DS1801 digital resistor with Arduino DUE SPI interface? What clock rate so use? | 2015-04-22T21:53:46.397 | <p>I am trying to program a digital resistor and set it's wiper resistance. The general circuit looks a little like this where "pot" represents the <a href="http://datasheets.maximintegrated.com/en/ds/DS1801.pdf" rel="nofollow noreferrer">Maxim DS1801 digital resistor</a> and DUE is, of-course the 3.3v Arduino DUE. </p>
<pre><code>POT DUE
CLk ----> SCK
D ----> MOSI
RST ----> CS (ChipSelect) (PIN10)
</code></pre>
<p>Now so far, I have sucessfully been able to interface with the DS1801, but I am having issues determining how to properly set the wiper resistance values. The DS1801 datasheet says the it accepts a 16bit input and from application example online it looks like the values range from 0 to 64. Here is my code:</p>
<pre><code>// include the SPI library:
#include <SPI.h>
// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
int mute = 64;
int loud = 63;
int soft = 0;
void setup() {
// set the slaveSelectPin as an output:
pinMode (slaveSelectPin, OUTPUT);
// initialize SPI:
SPI.setBitOrder(LSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);
SPI.begin();
delay(10);
digitalPotWrite(mute, mute);
}
void loop() {
// Raise the volume from off to loud
for(int i = 0; i <= 63; i++){
digitalPotWrite(i, i);
delay(5);
}
}
void digitalPotWrite(int left, int right) {
// take the SS pin low to select the chip:
digitalWrite(slaveSelectPin, HIGH);
// send in the address and value via SPI:
SPI.transfer(left);
SPI.transfer(right);
// take the SS pin high to de-select the chip:
digitalWrite(slaveSelectPin, LOW);
}
</code></pre>
<p>I THINK my issue lies with setting the clock rate for the DS1801. The data sheet say the chip runs at 10MHz which is why I wrote</p>
<pre><code>SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);
</code></pre>
<p>to divide the 84MHz default speed down to 10MHz.</p>
<p>Anyone have suggestions on why my code is not working??? At the moment, I have LED's connected to chip with series resistors to limit current below 2mA. The resistors just blink randomly with the code posted above. </p>
<p><img src="https://i.stack.imgur.com/K8HKw.jpg" alt="enter image description here"></p>
<p><img src="https://i.stack.imgur.com/4S4LY.jpg" alt="enter image description here"></p>
| <p>Well, it turns out that apparently my issue was not having the AGND pin hooked up. In addition to that, I was trying to switch the wiper resistance value too quickly. By putting at least a 10ms delay between calls, it works much better.</p>
<p>Also, it does seem to work even at 10MHz just fine... </p>
|
10257 | |wifi|arduino-yun|remote-control| | Sending values to an Arduino Yun across different networks | 2015-04-22T23:40:30.873 | <p>I have quite a lot of experience with Arduino but have recently been faced with a challenge that has stumped me. The project is to create a robot that can be controlled from a separate network than it is on. I had the idea of using the Yun board to receive the values. Does anyone know a way I could have a computer send data to a Yun on a different network? (Maybe through a website?)</p>
| <p>Basically your yun is a linux box with a arduino connected to it on port /dev/ttyATH0.<br>
If you know linux that should answer all your questions about what is possible.
I have setup my own bridge and communicate via html to my robot using cgi script and lua.<br>
I have demoed this on a web contest and you can see it in action on this video from 15:25 onwards <a href="https://www.youtube.com/watch?v=q0CnB7Yzpfg&index=3&list=PLCSjf7QmP3TCOLIw0lMPbwHtKrO-nwfKG" rel="nofollow">https://www.youtube.com/watch?v=q0CnB7Yzpfg&index=3&list=PLCSjf7QmP3TCOLIw0lMPbwHtKrO-nwfKG</a></p>
|
10262 | |arduino-mega| | Why does the pin 2 of arduino Mega stay always HIGH? | 2015-04-23T12:50:05.783 | <p>Without declaring the pin 2 as INPUT or OUTPUT, it remains constantly HIGH. Can anyone explain why is it so?</p>
| <p>Pin 2 connects to the controller's PE4, which is a GPIO pin, which can also be used for PWM. You should be able to use it either as input or output, and both high and low. It could be that setup initializes it as output high, while you would usually have uninitialized pins as input.</p>
<p><img src="https://i.stack.imgur.com/U9ZfI.png" alt="enter image description here"></p>
<p>Have you tried to make it low, or make it input?</p>
<pre><code>digitalWrite(2, LOW);
</code></pre>
<p>should make it low, while</p>
<pre><code>pinMode(2, INPUT);
int pin2Status = digitalRead(2);
digitalWrite(13, pin2Status);
</code></pre>
<p>will copy the status of pin 2 to the on-board LED.</p>
|
10270 | |arduino-nano|robotics| | Arduino Robot Chasis | 2015-04-23T16:15:57.383 | <p>I am looking into building a robot with my Arduino Nano but I don't want to shell out more then 50 bucks. Does anyone have any suggestions for a four wheel robot chassis at this price that I could use to make my robot mobile?</p>
| <p>There's plenty of <a href="http://www.ebay.com/itm/Hot-sale-4WD-Robot-Smart-Car-Chassis-with-Speed-Encoder-DC-3V5V6V-for-Arduin-EEW-/291423639383?pt=LH_DefaultDomain_3&hash=item43da33d757" rel="nofollow">options on ebay</a>, you will have to add a DC motor <a href="http://www.ebay.com/itm/L9110S-H-bridge-Stepper-Motor-Dual-DC-motor-Driver-Controller-Board-New-GA-/181650502852?pt=LH_DefaultDomain_15&hash=item2a4b36b4c4" rel="nofollow">driver</a> and optionally, sensors, but these are a good starting point.</p>
|
10280 | |display| | 2 digit number to 2x 1 digit | 2015-04-23T20:56:26.573 | <p>Suppose I have a number with 2 digits, 42.
It is an integer, received from my RTC</p>
<p>Now for my 7 segment displays, I will need 2 separate numbers:</p>
<ul>
<li>4 on display 1.</li>
<li>2 on display 2.</li>
</ul>
<p>How do I slice this number in 2?</p>
| <p>Numbers retrieved from an rtc are usually returned as a char or integer.</p>
<p>On this basis, you want</p>
<pre><code>ones_column = bytefromrtc % 10;
tens_column = (bytefromrtc / 10) % 10;
hundreds_column = (bytefromrtc / 100) % 10;
</code></pre>
<p>the <code>%</code> operator returns the modulus - if you divide 42 by 10, the answer is 4, with a remainder of 2. % returns the remainder, in this example, 2.</p>
<p>To do the tens column, first get rid of the last digit by dividing by 10, then do the modulus as above. Since bytefromrtc is not a float, if you divide it, you lose the remainder - 42 / 10 = 4, not 4.2.</p>
<p>If the output is a word, or integer, or long integer, the method is exactly the same, except for the number of digits you can get out.</p>
|
10281 | |arduino-uno|arduino-mega|i2c|interrupt|mpu6050| | Multiple interrupt lines connection | 2015-04-23T21:00:54.273 | <p>In my project I need to connect more then 10 I2C sensors(MPU-6050) to Arduino Mega and an interrupt line for each sensor is essential.
Since the Arduino Mega only has several interrupt slots (digital 2, 3, 21,29,19,18), how can it be achieved? Is that using a multiplexer every time I switch sensors and also switching interrupt lines solve the problem?</p>
<p>The code I'm using is Jeff Rowberg's MPU-6050 DMP example, which means interrupt line is essential and important, also very sensitive (a wrong change can cause sudden stop).. </p>
<pre class="lang-cpp prettyprint-override"><code>// I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class using DMP (MotionApps v2.0)
// 6/21/2012 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2013-05-08 - added seamless Fastwire support
// - added note about gyro calibration
// 2012-06-21 - added note about Arduino 1.0.1 + Leonardo compatibility error
// 2012-06-20 - improved FIFO overflow handling and simplified read process
// 2012-06-19 - completely rearranged DMP initialization code and simplification
// 2012-06-13 - pull gyro and accel data from FIFO packet instead of reading directly
// 2012-06-09 - fix broken FIFO read sequence and change interrupt detection to RISING
// 2012-06-05 - add gravity-compensated initial reference frame acceleration output
// - add 3D math helper file to DMP6 example sketch
// - add Euler output and Yaw/Pitch/Roll output formats
// 2012-06-04 - remove accel offset clearing for better results (thanks Sungon Lee)
// 2012-06-01 - fixed gyro sensitivity to be 2000 deg/sec instead of 250
// 2012-05-30 - basic DMP initialization working
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2012 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
// I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
//#include "MPU6050.h" // not necessary if using MotionApps include file
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include "Wire.h"
#endif
// class default I2C address is 0x68
// specific I2C addresses may be passed as a parameter here
// AD0 low = 0x68 (default for SparkFun breakout and InvenSense evaluation board)
// AD0 high = 0x69
//MPU6050 mpu;
MPU6050 mpu(0x69); // <-- use for AD0 high
/* =========================================================================
NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
depends on the MPU-6050's INT pin being connected to the Arduino's
external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
digital I/O pin 2.
* ========================================================================= */
/* =========================================================================
NOTE: Arduino v1.0.1 with the Leonardo board generates a compile error
when using Serial.write(buf, len). The Teapot output uses this method.
The solution requires a modification to the Arduino USBAPI.h file, which
is fortunately simple, but annoying. This will be fixed in the next IDE
release. For more info, see these links:
http://arduino.cc/forum/index.php/topic,109987.0.html
http://code.google.com/p/arduino/issues/detail?id=958
* ========================================================================= */
// uncomment "OUTPUT_READABLE_QUATERNION" if you want to see the actual
// quaternion components in a [w, x, y, z] format (not best for parsing
// on a remote host such as Processing or something though)
//#define OUTPUT_READABLE_QUATERNION
// uncomment "OUTPUT_READABLE_EULER" if you want to see Euler angles
// (in degrees) calculated from the quaternions coming from the FIFO.
// Note that Euler angles suffer from gimbal lock (for more info, see
// http://en.wikipedia.org/wiki/Gimbal_lock)
//#define OUTPUT_READABLE_EULER
// uncomment "OUTPUT_READABLE_YAWPITCHROLL" if you want to see the yaw/
// pitch/roll angles (in degrees) calculated from the quaternions coming
// from the FIFO. Note this also requires gravity vector calculations.
// Also note that yaw/pitch/roll angles suffer from gimbal lock (for
// more info, see: http://en.wikipedia.org/wiki/Gimbal_lock)
#define OUTPUT_READABLE_YAWPITCHROLL
// uncomment "OUTPUT_READABLE_REALACCEL" if you want to see acceleration
// components with gravity removed. This acceleration reference frame is
// not compensated for orientation, so +X is always +X according to the
// sensor, just without the effects of gravity. If you want acceleration
// compensated for orientation, us OUTPUT_READABLE_WORLDACCEL instead.
//#define OUTPUT_READABLE_REALACCEL
// uncomment "OUTPUT_READABLE_WORLDACCEL" if you want to see acceleration
// components with gravity removed and adjusted for the world frame of
// reference (yaw is relative to initial orientation, since no magnetometer
// is present in this case). Could be quite handy in some cases.
//#define OUTPUT_READABLE_WORLDACCEL
// uncomment "OUTPUT_TEAPOT" if you want output that matches the
// format used for the InvenSense teapot demo
//#define OUTPUT_TEAPOT
#define LED_PIN 13 // (Arduino is 13, Teensy is 11, Teensy++ is 6)
bool blinkState = false;
// MPU control/status vars
bool dmpReady = false; // set true if DMP init was successful
uint8_t mpuIntStatus; // holds actual interrupt status byte from MPU
uint8_t devStatus; // return status after each device operation (0 = success, !0 = error)
uint16_t packetSize; // expected DMP packet size (default is 42 bytes)
uint16_t fifoCount; // count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO storage buffer
// orientation/motion vars
Quaternion q; // [w, x, y, z] quaternion container
VectorInt16 aa; // [x, y, z] accel sensor measurements
VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z] gravity vector
float euler[3]; // [psi, theta, phi] Euler angle container
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
// packet structure for InvenSense teapot demo
uint8_t teapotPacket[14] = { '$', 0x02, 0,0, 0,0, 0,0, 0,0, 0x00, 0x00, '\r', '\n' };
// ================================================================
// === INTERRUPT DETECTION ROUTINE ===
// ================================================================
volatile bool mpuInterrupt = false; // indicates whether MPU interrupt pin has gone high
void dmpDataReady() {
mpuInterrupt = true;
}
// ================================================================
// === INITIAL SETUP ===
// ================================================================
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
TWBR = 24; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
// initialize serial communication
// (115200 chosen because it is required for Teapot Demo output, but it's
// really up to you depending on your project)
Serial.begin(115200);
while (!Serial); // wait for Leonardo enumeration, others continue immediately
// NOTE: 8MHz or slower host processors, like the Teensy @ 3.3v or Arduino
// Pro Mini running at 3.3v, cannot handle this baud rate reliably due to
// the baud timing being too misaligned with processor ticks. You must use
// 38400 or slower in these cases, or use some kind of external separate
// crystal solution for the UART timer.
// initialize device
Serial.println(F("Initializing I2C devices..."));
mpu.initialize();
// verify connection
Serial.println(F("Testing device connections..."));
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
// wait for ready
Serial.println(F("\nSend any character to begin DMP programming and demo: "));
while (Serial.available() && Serial.read()); // empty buffer
while (!Serial.available()); // wait for data
while (Serial.available() && Serial.read()); // empty buffer again
// load and configure the DMP
Serial.println(F("Initializing DMP..."));
devStatus = mpu.dmpInitialize();
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
// make sure it worked (returns 0 if so)
if (devStatus == 0) {
// turn on the DMP, now that it's ready
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
// enable Arduino interrupt detection
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(0, dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();
// set our DMP Ready flag so the main loop() function knows it's okay to use it
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
// get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
// ERROR!
// 1 = initial memory load failed
// 2 = DMP configuration updates failed
// (if it's going to break, usually the code will be 1)
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
// configure LED for output
pinMode(LED_PIN, OUTPUT);
}
// ================================================================
// === MAIN PROGRAM LOOP ===
// ================================================================
void loop() {
// if programming failed, don't try to do anything
if (!dmpReady) return;
// wait for MPU interrupt or extra packet(s) available
while (!mpuInterrupt && fifoCount < packetSize) {
// other program behavior stuff here
// .
// .
// .
// if you are really paranoid you can frequently test in between other
// stuff to see if mpuInterrupt is true, and if so, "break;" from the
// while() loop to immediately process the MPU data
// .
// .
// .
}
// reset interrupt flag and get INT_STATUS byte
mpuInterrupt = false;
mpuIntStatus = mpu.getIntStatus();
// get current FIFO count
fifoCount = mpu.getFIFOCount();
// check for overflow (this should never happen unless our code is too inefficient)
if ((mpuIntStatus & 0x10) || fifoCount == 1024) {
// reset so we can continue cleanly
mpu.resetFIFO();
Serial.println(F("FIFO overflow!"));
// otherwise, check for DMP data ready interrupt (this should happen frequently)
} else if (mpuIntStatus & 0x02) {
// wait for correct available data length, should be a VERY short wait
while (fifoCount < packetSize) fifoCount = mpu.getFIFOCount();
// read a packet from FIFO
mpu.getFIFOBytes(fifoBuffer, packetSize);
// track FIFO count here in case there is > 1 packet available
// (this lets us immediately read more without waiting for an interrupt)
fifoCount -= packetSize;
#ifdef OUTPUT_READABLE_QUATERNION
// display quaternion values in easy matrix form: w x y z
mpu.dmpGetQuaternion(&q, fifoBuffer);
Serial.print("quat\t");
Serial.print(q.w);
Serial.print("\t");
Serial.print(q.x);
Serial.print("\t");
Serial.print(q.y);
Serial.print("\t");
Serial.println(q.z);
#endif
#ifdef OUTPUT_READABLE_EULER
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetEuler(euler, &q);
Serial.print("euler\t");
Serial.print(euler[0] * 180/M_PI);
Serial.print("\t");
Serial.print(euler[1] * 180/M_PI);
Serial.print("\t");
Serial.println(euler[2] * 180/M_PI);
#endif
#ifdef OUTPUT_READABLE_YAWPITCHROLL
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial.print("ypr\t");
Serial.print(ypr[0] * 180/M_PI);
Serial.print("\t");
Serial.print(ypr[1] * 180/M_PI);
Serial.print("\t");
Serial.println(ypr[2] * 180/M_PI);
#endif
#ifdef OUTPUT_READABLE_REALACCEL
// display real acceleration, adjusted to remove gravity
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
Serial.print("areal\t");
Serial.print(aaReal.x);
Serial.print("\t");
Serial.print(aaReal.y);
Serial.print("\t");
Serial.println(aaReal.z);
#endif
#ifdef OUTPUT_READABLE_WORLDACCEL
// display initial world-frame acceleration, adjusted to remove gravity
// and rotated based on known orientation from quaternion
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetAccel(&aa, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetLinearAccel(&aaReal, &aa, &gravity);
mpu.dmpGetLinearAccelInWorld(&aaWorld, &aaReal, &q);
Serial.print("aworld\t");
Serial.print(aaWorld.x);
Serial.print("\t");
Serial.print(aaWorld.y);
Serial.print("\t");
Serial.println(aaWorld.z);
#endif
#ifdef OUTPUT_TEAPOT
// display quaternion values in InvenSense Teapot demo format:
teapotPacket[2] = fifoBuffer[0];
teapotPacket[3] = fifoBuffer[1];
teapotPacket[4] = fifoBuffer[4];
teapotPacket[5] = fifoBuffer[5];
teapotPacket[6] = fifoBuffer[8];
teapotPacket[7] = fifoBuffer[9];
teapotPacket[8] = fifoBuffer[12];
teapotPacket[9] = fifoBuffer[13];
Serial.write(teapotPacket, 14);
teapotPacket[11]++; // packetCount, loops at 0xFF on purpose
#endif
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
}
</code></pre>
| <p>Just FYI, the interrupt is not essential. If you can write efficient code you can read an MPU(DMP) without it (UNO, been there, done that). But that is only for one MPU. I doubt if an UNO can keep up with 10, no idea about the faster processors. In any case, even with interrupts, I doubt if an UNO could keep up with 10. Keep googling and you will find a note how to change the sampling rate to slow the MPU down. </p>
<p>The code you referenced provides AHRS (Attitude Heading Reference System) - I would be real curious to see what projects needs 10 of those :) Sounds like fun.</p>
|
10288 | |arduino-uno|motor| | Proportional water flow control | 2015-04-24T02:08:58.247 | <p>I've been looking at water flow control with Arduino and I'm finding a huge difficulty in managing to do an 'analog' control on water flow. The mainstream solution seems to be the well known solenoid valve, however those seem to be binary (full flow, no flow), and I'm looking for a more variable answer.</p>
<p>Is it possible to get middlegrounds with solenoids? Maybe actuating them with less voltage or amperage will cause it to partially actuate? If not, does anyone know of embedded solutions using servos or steppers maybe?</p>
| <p>Do you use a pump to circulate the water flow, if so maybe you have a better result with a variable pump speed (PWM), in state of a variable valve opening.</p>
|
10291 | |isr| | The code of ISR executes twice | 2015-04-24T07:02:00.857 | <p>i am using Arduino Mega.. ANd this is the code: </p>
<pre><code>void bump(void);
void setup()
{
pinMode(19,INPUT);
attachInterrupt(4,bump,HIGH);
pinMode(13,OUTPUT);
}
void loop()
{
}
void bump()
{
for(float i = 0; i < 90000; i++){
digitalWrite(13,HIGH);
}
for(float i = 0; i < 10000; i++){
digitalWrite(13,LOW);
}
}
</code></pre>
<p>Although i give +5 V to it once, the LED will blink twice...!
What is the solution?</p>
| <p>After wondering over it for quite a long time, I finally came to the conclusion, that the interrupt should be made to trigger at RISING edge, <strong>if I want it to go into ISR the moment it gets HIGH.</strong> </p>
<p>Hence the setup line was change to </p>
<pre><code>attachInterrupt(4,bump,RISING);
</code></pre>
<p>And the cod e works well.<br>
I suppose that is because, when it receives a HIGH signal, than the period for which it receives HIGH is a bit long, during which it adds another interrupt into the queue, and so the ISR is executed once again.</p>
|
10293 | |arduino-due| | Is it harmful to write to unused bits in PORT registers? | 2015-04-24T07:52:59.783 | <p>Background:
I'm looking at writing a library to drive an LED matrix panel (one of these:<a href="http://www.adafruit.com/product/607" rel="nofollow">http://www.adafruit.com/product/607</a>) from my newly acquired Arduino Due. My background is C++ programming, not electronics.</p>
<p>I'm planning to experiment with various optimisations of the code for memory and speed, but one constant is that I would like to be able to send the data to the matrix with single memory writes to port registers without having to use masking operations to leave certain bits unaffected. As I need to send 6 bits of data with a clock signal, I figured this could be easy with an 8 bit write to one byte of a port register. The 8th bit/pin could be used as the latch or some other used line.</p>
<p>Looking at the nice pinout diagram that someone has kindly put together (<a href="http://forum.arduino.cc/index.php/topic,132130.0.html" rel="nofollow">http://forum.arduino.cc/index.php/topic,132130.0.html</a>), I was pretty shocked to discover that my plans weren't going to be as easy as I would have liked. There are only two circumstances where there are whole bytes of port registers that connect to digital pins (Port A byte 1 and Port D byte 0). All other bytes have "holes" in them, for example Port C byte 0 has no connection for bit 0, but has bits 1-7;</p>
<p>While two complete bytes is enough (I actually only need to use 13 pins to control the display, plus ground connections), the pins of the available two are spread out in a way that would make it a little awkward for me to make a stripboard shield as I intended due to the pins on the Arduino boards not being evenly spaced (why is that?) and I'm guessing that since most of the digital pins in Port A byte 1 are used for communication pins (including RX0 and TX0) I would lose my ability to print to the debug log. As a result, I've ruled out using those port registers.</p>
<p>That leaves me with bytes 0 and 1 of Port C. There are just enough pins available with those bytes and they are grouped nicely on the double connector at the bottom of the board (Digital pins 33-40 and 48-51), however some bits in those bytes are not mapped to Arduino IO pins.</p>
<p>Would it be bad if I were to write to bits of a port register that do not have Arduino IO pins assigned to them? Would the answer depend on whether I had set those bits to be inputs or outputs using the Output Write Enable Registers? I'm assuming that these bits are used for IO pins on the SAM3X8E chip but just not made available to the Arduino boards.</p>
| <p>If the pins have no connection to the outside world (i.e., they don't have any actual pin associated with them on the SAM3X chip) then writing to the PORT (or indeed any other register associated with them) will have no effect whatsoever.</p>
<p>If they have a pin but that pin is not connected to anything, then there will be little effect. There may be slightly increase current draw as the pin switches on/off, or you enable/disable the internal pullup resistor, but that's all.</p>
<p>If the pin exists and is connected to something on the board - maybe a button or LED, then you will basically be providing an output to that item. If it's an LED it will flash. However, if it's a button, and you provide an output opposite of its active state (i.e., provide a HIGH when it normally connects to ground when you press it) and that button lacks any current limiting resistance, then you could risk burning out that IO pin if the button gets pressed.</p>
<p>If the pin just goes straight to a header, then as long as nothing gets connected to that header then there will be no effect other than as detailed in the "pin present on the chip but not connected".</p>
|
10299 | |led|potentiometer| | How can I best control various high power LEDs without using PWM | 2015-04-24T13:44:52.557 | <p>I want to be able to dim various high powered (20mA) LEDs in an array (8X12 LEDs). I do not need individual control, but would like to be able to dim each row (or two rows together) so that I can create gradients. </p>
<p>An important caveat is that I can't use pulse width modulation (PWM) as there should be no flashing whatsoever, even if it is invisible to humans. </p>
<p><strong>How can I best achieve this?</strong>
(I do not care about energy efficiency)</p>
<p>The fist thing I found which seemed to be the right solution in the beginning is using digital potentiometers as explained in <a href="http://www.arduino.cc/en/Tutorial/SPIDigitalPot" rel="nofollow">this tutorial</a>. However they only support low currents so I can't use one channel for 8 or 16 LEDs.
Maybe I could use various digipots in parallel with one Arduino, each powering 1 LED per channel? But that sounds overcomplicated and a nightmare to wire up. Is there a more elegant solution? </p>
| <p>The figure below illustrates a method of current control. It shows four LEDs in a 2x2 arrangement; one would adapt the number of LEDs in series or parallel in accord with how one's array is wired, what voltages are available, LED current requirements, transistor power limitations, etc. <em>[Edit: See transistor-power example calculation at end.]</em></p>
<p>Each separately-controlled group of LEDs would need one such circuit. Each circuit needs one control voltage (eg, from a DAC or a digital potentiometer voltage divider circuit) and needs one transistor per series chain.</p>
<p><img src="https://i.stack.imgur.com/9vx8w.jpg" alt="figure 1, cc circuit"></p>
<p><strong>Circuit Operation:</strong></p>
<p>Suppose the following conditions hold.</p>
<ul>
<li>Q1 and Q2 are equivalent transistors and V<sub>be</sub> is 0.7 V typ. (one diode drop)</li>
<li>D1, D2, D3, D4 are equivalent LEDs</li>
<li>Resistors R1, R2 are small and equal (eg 1–30Ω)</li>
<li>V1 is some fixed DC voltage, eg about 1 V</li>
<li>V > 2*V<sub>f</sub> + V<sub>be</sub> + V<sub>R</sub> where V<sub>f</sub> = typical forward voltage of D1...4 </li>
</ul>
<p>Under these conditions, V1 will drive current into the bases of Q1 and Q2, causing transistor-amplified current to flow through R1 and R2 and maintain the condition V1 = V<sub>be</sub> + V<sub>R1</sub> = V<sub>be</sub> + V<sub>R2</sub>. </p>
<p>Here is a concrete example: Suppose we want 23 mA through each LED and that R1=R2=17Ω. V<sub>R</sub> = IR = 0.023 mA · 17 Ω = 0.391 V. If V<sub>be</sub> is about 0.7 V, then we set V1 = 0.7 + 0.391 V or about 1.09 V to get 23 mA through each LED. More generally, to get current I through the LEDs we solve V1 = V<sub>be</sub> + V<sub>R</sub> = 0.7 + IR = 0.7 + I·17.</p>
<p><strong>Base current:</strong></p>
<p>The amount of current required from the V1 voltage source depends on transistor <a href="http://en.wikipedia.org/wiki/Bipolar_junction_transistor#h-parameter_model" rel="nofollow noreferrer">h<sub>FE</sub> or β</a>.
Eg, if β is about 100 and I<sub>LED</sub> is 20 mA then each transistor will need about 20/100 mA or about 200 μA of base drive. This amount of current probably could be delivered by a voltage divider based on an AD5206 (the digital potentiometer chip that's used in the <a href="http://www.arduino.cc/en/Tutorial/SPIDigitalPot" rel="nofollow noreferrer">SPIDigitalPot</a> tutorial mentioned in the question).</p>
<p><strong>Power Dissipation:</strong></p>
<p>The AD5206 digital potentiometer datasheet shows an absolute maximum rating for Package Power Dissipation of (T<sub>J</sub>MAX-T<sub>A</sub>)/θ<sub>JA</sub>. If ambient T<sub>A</sub> is 25℃ and θ<sub>JA</sub> is 70°C/W (as for a SOIC package) this gives (150-25)/70 = 1.8 W max package power. However, it would be reasonable to limit dissipation to under half a watt. In the 10 KΩ version of the AD5206, that means a little less than 2.9 mA maximum per channel. [I = √(0.5 W /(6 channels * 10000Ω)).] If several low-beta transistors are used to drive several strings of LEDs, 2.8 mA might be marginal.</p>
<p><strong>Voltage-divider Linearity:</strong></p>
<p>Only a small fraction of the current through a voltage divider can be drawn off without upsetting the division ratio. A <a href="http://en.wikipedia.org/wiki/Buffer_amplifier#Voltage_buffer_examples" rel="nofollow noreferrer">unity gain buffer</a> amplifier [as in the following figure] can be used to increase linearity of voltage-divider output by providing a high-impedance connection to the divider.</p>
<p><img src="https://i.stack.imgur.com/rZykZ.jpg" alt="figure 2, unity gain buffer with voltage divider input"></p>
<p>(In the figure above, R1 and R2 are not related to R1 and R2 of the previous figure. Here, R2 represents a digitally-variable resistor. Choose R1 and R3 so that V1's range is from slightly below V<sub>be</sub> to slightly above V<sub>be</sub> + I<sub>max</sub>R, where I<sub>max</sub> is the maximum LED current desired. For example: Suppose V=5 V, that R2's total resistance is 10 KΩ, that R is 15Ω, that V<sub>be</sub> is 0.7 V, and I<sub>max</sub> is 25 mA. Let R<sub>T</sub> = R1+R2+R3. Now R3/R<sub>T</sub> = V<sub>be</sub>/V = 0.7/5 = 0.14, and R1/R<sub>T</sub> = (V - V<sub>be</sub> - I<sub>max</sub>R)/V = (5 - 0.7 - 0.025·15)/5 = 3.925/5 = 0.785. Thus R1+R3 = 0.925·R<sub>T</sub>, whence 0.075·R<sub>T</sub> = R2 = 10 KΩ, giving R<sub>T</sub> = 133 KΩ, R1 = 105 KΩ, and R3 = 19 KΩ. With these R1 and R2 values, each digital pot step should give a change in LED current of 25/256 mA, or about 98 μA.)</p>
<p><em>[Edit: When V1 is set to less than V<sub>BE</sub>, no current will flow through the LEDs. That is, to turn off the controlled LEDs, set V1 to V<sub>BE</sub> or less.]</em></p>
<p><strong>PWM with RC filter:</strong></p>
<p>It may be worthwhile to experiment with using a PWM-driven low pass <a href="http://en.wikipedia.org/wiki/RC_circuit" rel="nofollow noreferrer">RC filter</a> to supply V1, possibly avoiding need for buffer amplifiers and digital potentiometers. See eg “Arduino’s AnalogWrite – Converting PWM to a Voltage”
by Scott Daniels at <a href="http://provideyourown.com/2011/analogwrite-convert-pwm-to-voltage/" rel="nofollow noreferrer">provideyourown.com</a>, and also see the <a href="http://sim.okawa-denshi.jp/en/PWMtool.php" rel="nofollow noreferrer">filter-calculation page</a> it refers to. You might need an oscilloscope to verify the design and its quality of results, and might need to use several RC filter stages in a row to adequately filter out ripple, but it can be done, at the cost of slower response to control changes.</p>
<p><strong>Transistor-power example calculations:</strong></p>
<p>Letting V<sub>CE</sub>, I<sub>CE</sub>, V<sub>BE</sub>, and I<sub>BE</sub> represent collector-to-emitter and base-to-emitter voltages and currents, transistor power dissipation is V<sub>CE</sub>·I<sub>CE</sub>+V<sub>BE</sub>·I<sub>BE</sub>. Because V<sub>BE</sub>·I<sub>BE</sub> is likely to be sub-milliwatt, we ignore it in following, taking P ≅ V<sub>CE</sub>·I<sub>CE</sub>.</p>
<p>In the LED-driving circuit, V<sub>CE</sub> = V – V<sub>LEDs</sub> – V<sub>sense</sub>, where V<sub>LEDs</sub> is the series voltage across the chain of LEDs the transistor controls, and V<sub>sense</sub> is the voltage across the sense resistor (ie, across R1 or R2 in the top figure).</p>
<p>In general, it is a good idea to keep V<sub>sense</sub> small (under a volt) to allow a wider compliance range – ie, so that LED current is the same over a wider range of variation of supply voltage V. Thus, the approximation V<sub>CE</sub> ≅ V – V<sub>LEDs</sub> is reasonable.</p>
<p>Here is a concrete example: Suppose we have eight LEDs in series, and they are white LEDs with about 3.6 V forward drop at 20 mA. [LEDs of different colors may have different drops; eg see <a href="http://www.oksolar.com/led/led_color_chart.htm" rel="nofollow noreferrer">LED color chart</a> at oksolar.com.] Then V<sub>LEDs</sub> = 8·3.6 V = 28.8 V. We need V<sub>(BR)CEO</sub> > V > V<sub>LEDs</sub> + V<sub>BE</sub> + V<sub>sense</sub>, where V<sub>(BR)CEO</sub> = collector-emitter breakdown voltage (which is 40 V min. for 2N3904 or 2N2222). Allowing a volt for V<sub>sense</sub> and 0.7 V for V<sub>BE</sub> we have V > 28.8 + 0.7 + 1 = 30.5 V. Let's suppose V=32 V. Then P < (32–28.8)·0.020 W = 64 mW. Thus a small general purpose NPN transistor will work, for example a 2N3904 (rated at 350 mW to 1 W, depending on package, before derating for ambient and heatsinking) or a 2N2222 (similarly rated).</p>
<p>For a second example, suppose V<sub>LEDs</sub> = 8·1.7 V = 13.6 V (for, eg, eight infrared LEDs at 50 mA) and V=32 V. Then P ≅ (32–13.6)·0.050 W = 920 mW, so a larger (and heatsinked) transistor would be needed. Or, V could be decreased, say to 16 V, giving P ≅ (16–13.6)·0.050 W = 120 mW, allowing use of a small transistor.</p>
<p>For a third example, suppose eight LEDs are paralleled (rather than seriesed), that V<sub>LEDs</sub> = 2.0 V at 20 mA, that V<sub>sense</sub> is about 0.4 V at desired operating point, and that V=5 V. The transistor will need to drop 5-2-0.4 V = 2.6 V at 160 mA, which is 416 mW, probably large enough to require a heatsink. [Note: if LEDs are placed in parallel and driven by a single transistor, some of them probably will be dimmer than others; “current hogging” may occur in some of the LEDs, making them brighter than the others. However, many cheap flashlights connect LEDs in parallel without individual current control.]</p>
|
10308 | |arduino-uno|arduino-mega|mpu6050| | How to clear FIFO buffer on MPU6050? | 2015-04-25T01:05:24.787 | <p>my MPU6050 works very unstable , the problem is unable clear excessed FIFO buffer on MPU6050, I am using Jeff Rowberg's MPU library and according to his DMP example but without using interruptions,here is my modified code but I've tried several method listed in the library to clear buffer but doesn't work.. </p>
<p>Thanks very much! </p>
<pre><code>#include "I2Cdev.h"
#include "MPU6050_6Axis_MotionApps20.h"
#include "Wire.h"
MPU6050 mpu(0x69); //AD0=High
//MPU control/status vars
bool dmpReady = false;
uint8_t mpuIntStatus; //actual interrupt status byte
uint8_t deviceStatus; //device status , 0 = success ,
uint16_t packetSize; //expected DMP packet size (defult 42) -- ?
uint16_t fifoCount; //count of all bytes currently in FIFO
uint8_t fifoBuffer[64]; // FIFO buffer storage
// orientation/motion vars
Quaternion q; // [w, x, y, z] quaternion container
VectorInt16 aa; // [x, y, z] accel sensor measurements
VectorInt16 aaReal; // [x, y, z] gravity-free accel sensor measurements
VectorInt16 aaWorld; // [x, y, z] world-frame accel sensor measurements
VectorFloat gravity; // [x, y, z] gravity vector
float euler[3]; // [psi, theta, phi] Euler angle container
float ypr[3]; // [yaw, pitch, roll] yaw/pitch/roll container and gravity vector
volatile bool mpuInterrupt = false;
//void dmpDataReady() {
// mpuInterrupt = true;
//}
// put your setup code here, to run once:
void setup() {
//join I2C bus
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
TWBR = 48; // 400kHz I2C clock (200kHz if CPU is 8MHz)
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
//initialize serial communication
Serial.begin(115200);
while(!Serial); //common for Leonardo issues
//initialize the mpu
Serial.println("Call MPU6050 Lib to initialize devices...");
mpu.initialize(); //initialize I2C device by using MPU6050 library
//verify connection
Serial.println("Tesing device connections");
Serial.println(mpu.testConnection() ? F("MPU6050 connection test successed ") : F("MPU6050 connection test failed"));
// //wait for begin , uncomment if we need wait user interruption
// Serial.println("Press any button to begin");
// while (Serial.available() && Serial.read()); // empty buffer
// while (!Serial.available()); // wait for data
// while (Serial.available() && Serial.read()); // empty buffer again
//load and configure DMP
Serial.println("initializing DMP");
deviceStatus = mpu.dmpInitialize(); //use MPU6050 library to inilisalize the dmp
//feed offsets
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
//make sure it works
if (deviceStatus == 0) {
Serial.println("DMP initialization success, now enable DMP for use");
//turn on DMP
mpu.setDMPEnabled(true); //use MPU6050 library to enable DMP)
//wait for first interrup . currently just leave it false automatically
mpuInterrupt == false;
//let main llop know it's ok to use DMP, set dmpRead flag to ture
dmpReady = true;
Serial.println("DMP is ready to use.");
//get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
//ERROR! , device status !=0 when initializing DMP
Serial.print("DMP initialization failed when using MPU6050 library:");
if (deviceStatus == 1) {
Serial.println(" intial memory load failed");
} else if (deviceStatus == 2) {
Serial.println(" failed to update DMP configuration");
} else {
Serial.print(" unknow error with code: ");
Serial.println(deviceStatus);
}
}
}
int ticket = 1;
void printOnlyOnce (String message){
if (ticket == 1){
Serial.println(message);
ticket = 0 ;
} else {
return;
}
}
void loop() {
//if DMP not ready don't do anything
if (!dmpReady) {
printOnlyOnce("MAIN LOOP: DMP disabled");
return;
} else {
//testing overflow
if (fifoCount == 1024) {
mpu.resetFIFO();
Serial.println("FIFO overflow");
} else {
//wait for enough avaliable data length
while (fifoCount < packetSize) {
//waiting until get enough
fifoCount = mpu.getFIFOCount();
}
//read this packet from FIFO buffer
mpu.getFIFOBytes(fifoBuffer,packetSize);
//track FIFO count here is more then one packeage avalible
//reset fifo count
fifoCount -= packetSize ;
Serial.println(fifoCount);
if (fifoCount > 2) {
////// clear fifo buffer
}
//display stage
// display Euler angles in degrees
mpu.dmpGetQuaternion(&q, fifoBuffer);
mpu.dmpGetGravity(&gravity, &q);
mpu.dmpGetYawPitchRoll(ypr, &q, &gravity);
Serial.print("ypr\t");
Serial.print(ypr[0] * 180/M_PI);
Serial.print("\t");
Serial.print(ypr[1] * 180/M_PI);
Serial.print("\t");
Serial.println(ypr[2] * 180/M_PI);
}
}
}
</code></pre>
| <p>What if we can increase the size of the FIFo Buffer.</p>
<pre><code>uint8_t fifoBuffer[64]; // FIFO storage buffer
</code></pre>
<p>What if I change it to lets say:</p>
<pre><code>uint8_t fifoBuffer[1024]; // FIFO storage buffer
</code></pre>
<p>and then change :</p>
<pre><code>if ((mpuIntStatus & 0x10) || fifoCount == 16384) { // I changed 1024 -> 16384
// reset so we can continue cleanly
mpu.resetFIFO(); // Resets the FIFO buffer when set to 1 while FIFO_EN equals 0.
Serial.println(F("FIFO overflow!"));
// otherwise, check for DMP data ready interrupt (this should happen frequently)
}
</code></pre>
<p>Please check these changes.</p>
|
10313 | |motor| | Activate a DC motor for a fixed amount of time | 2015-04-25T08:07:18.307 | <p>I have a single simple DC motor that upon a condition I wish to let it run for 3 minute. How can I do it in Arduino? a simple addition to the code will be great help.</p>
<p>As I use Adafruit motor shield this is my current code:</p>
<pre><code>#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
AFMS.begin(); // create with the default frequency 1.6KHz
}
void loop() {
IOvalue = 1000
if (IOvalue = 1000) {
//this is the motor I wish to run for 3 min
myMotor->setSpeed(25);
myMotor->run(FORWARD);
delay(100);
}
}
</code></pre>
<p>Thanks a lot</p>
| <pre><code>#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
boolean motorRunning = false;
unsigned long motorStartMillis;
unsigned long motorRunMillis = 180000;
void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
AFMS.begin(); // create with the default frequency 1.6KHz
}
void loop() {
IOvalue = 1000
if (IOvalue = 1000) {
//this is the motor I wish to run for 3 min
myMotor->setSpeed(25);
myMotor->run(FORWARD);
motorStartMillis = millis();
motorRunning = true;
}
// check if motor is running and time-to-run has elapsed
if( motorRunning && (millis()-motorStartMillis > motorRunMillis) )
{
myMotor->setSpeed(0);
myMotor->run(RELEASE);
motorRunning = false;
}
}
</code></pre>
|
10317 | |lcd| | Arduino 16x2 LCD Black Boxes | 2015-04-25T10:47:43.720 | <p>I hooked up a 16x2 Arduino compatible LCD yesterday and made sure all the connections were according to the program and the schematics provided all over the web. My contrast is adjusted perfectly but the problem is that there are black boxes on the top line while the lower one is empty.</p>
<p><a href="https://i.stack.imgur.com/LO0Vk.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LO0Vk.jpg" alt="Black boxes on top row only of LCD"></a></p>
<p>I know this question has been asked many times but no one has answered the question other than saying, "Check your contrast pin". I'm using the default sample code provided in the Arduino IDE.
HELP!</p>
<p>Regards.</p>
| <p>Alright guys thanks for everything! I've found the solution. It was a bad solder.</p>
|
10320 | |arduino-uno| | Do I have to use an external power supply when connecting an ultrasonic sensor to Arduino? | 2015-04-25T14:27:10.383 | <p>This might be a very stupid question but please bear with me. So I am using an HC-SR04 Ultrasonic sensor model (5 V) and I want to connect it to Arduino Uno. Do I have to use an external power supply for the ultrasonic sensor (just like with the motors) in order to connect it to the Arduino? Or can I just use the 5 V pin?</p>
| <p>From the question I assume you power your Arduino via USB in which case you don't need an external supply. The HC-SR04 draws 15 mA with is far below the specifications for USB. I did this myself some time ago:</p>
<p><img src="https://i.stack.imgur.com/J5bNc.jpg" alt="enter image description here"></p>
|
10326 | |power|ethernet| | Is my Arduino Ethernet Shield broken? | 2015-04-25T15:40:46.550 | <p>I have an Arduino setup from which I can control my RGB LED strip from my computer using LAN.</p>
<p>It worked like a charm in the start, but after two days, my Ethernet Shield W5100 for Arduino Uno stopped working, and I can't figure out why.</p>
<p>When I connect the Ethernet Shield, the red LED "pwr" is solid red and the "FULLD" flashes orange every second.</p>
<p><strong>The setup:</strong></p>
<p>I have followed an Adafruit guide, connecting the Arduino as such: <img src="https://i.stack.imgur.com/VOa9Y.gif" alt="Image from Adafruit.com" /></p>
<p>On top of the Arduino, I have the Ethernet Shield. All this is powered by an 12V/4A power supply connected to the Arduinos 2.1mm jack.</p>
<p>As I said, this setup worked fine for a few days. While it was on, I noticed the Arduino getting somewhat hot, but some google searches assured me that Arduino Uno can handle high temperatures, so I did not pay any attention to it.</p>
<p>The LED strip is not too long - about 2 meters with about 150 LEDs.</p>
<p><strong>What I have tried:</strong></p>
<ul>
<li>When I detach the Arduino from my breadboard, the Ethernet Shield
will still not connect</li>
<li>I have tried connecting the Shield to another Power Supply (Computer USB) using another Arduino, but the Shield would still not connect.</li>
<li>I have added a debugging Serial.print message in the Arduino loop function. When using serial monitor, this message is printed over and over again (as if it is stuck in a reset loop)</li>
<li>I have verified for MAC address collisions, even changed the MAC address of the Shield multiple times.</li>
</ul>
<p>Have I somehow burned the Ethernet Shield? Why won't it work anymore?</p>
| <p>I'm sorry to tell you but i think you damaged your board severely that's because you took more energy from the pins than an arduino can handle.</p>
<p>150 LEDs takes way too much power for the arduino to handle as you can see <a href="https://www.arduino.cc/en/Main/ArduinoBoardUno" rel="nofollow">here</a>.</p>
<p>So you likely burnt something on your board and might have to replace it :/
make sure which board is damaged(the arduino itself or the shield) before replacing it.</p>
<p>If the ATmega328P(The chip on the arduino) is damaged then this should be an easy fix.</p>
<p>Instead of what you did, you shoud have powered the LED strip from another power supply(not from the arduino pins) and used the arduino to turn "this power supply" on and off(probably using transistors).</p>
|
10339 | |arduino-uno|gsm| | Turn on led by phone and phone contacts | 2015-04-26T08:40:30.400 | <p>I would like ask for help. Can you give me an advice how to create (contacts) nubers who can turn on led.</p>
<pre><code>#include <GSM.h>
#define PINNUMBER ""
GSM gsmAccess;
GSMVoiceCall vcs;
char numtel[20];
void setup()
{
pinMode(13, OUTPUT);
Serial.begin(9600);
while (!Serial) {
;
}
Serial.println("Receive Voice Call");
boolean notConnected = true;
while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
vcs.hangCall();
Serial.println("Waiting for a call");
}
void loop()
{
switch (vcs.getvoiceCallStatus())
{
case IDLE_CALL:
break;
case RECEIVINGCALL:
Serial.println("RECEIVING CALL");
vcs.retrieveCallingNumber(numtel, 20);
digitalWrite(13, HIGH);
vcs.answerCall();
vcs.hangCall();
digitalWrite(13, LOW);
break;
}
delay(1000);
}
</code></pre>
| <p>So, <code>retrieveCallingNumber</code> is documented in <a href="http://www.arduino.cc/en/Reference/GSMVCSRetrieveCallingNumber" rel="nofollow">here</a>. It "retrieves the calling number, and stores it" in a character array passed as second argument.</p>
<p>The simplest solution to check if this number is among the allowed ones is to <a href="http://www.arduino.cc/en/Tutorial/StringConstructors" rel="nofollow">construct</a> a <a href="http://www.arduino.cc/en/Reference/String" rel="nofollow">string</a> from this and <a href="http://www.arduino.cc/en/Tutorial/StringComparisonOperators" rel="nofollow">compare</a> it against a predefined string for equality. (If you have more than one allowed number, repeat for all.)</p>
<p>Something like this:</p>
<pre><code>vcs.retrieveCallingNumber(numtel, 20);
String s = String(numtel);
if (s == "allowed number goes here") {
// toggle LED etc.
}
</code></pre>
|
10340 | |arduino-uno|button| | My button control working in reverse | 2015-04-26T11:39:45.150 | <p>I built this circuit to learn button control. </p>
<p><img src="https://i.stack.imgur.com/2lLCK.png" alt="My setup"></p>
<p>But my code (or button) is working in reverse. I want to initialize led flash effect when the button is pressed with this code</p>
<pre><code>buttonState = digitalRead(8);
if (buttonState == HIGH)
doFlash();
</code></pre>
<p>Instead the effect runs continuously and pauses if I push and hold the button. If change the condition as <code>if (buttonState == LOW)</code> code is working as expected. (Effect starts when I push the button.)</p>
<p>This is just the opposite of what I read in tutorials. What is wrong in my circuit or code?</p>
<p>Full code:</p>
<pre><code> void setup(){
for(int i=2;i<=6;i++)
pinMode(i,OUTPUT);
pinMode(8,INPUT_PULLUP);
}
void loop(){
int buttonState;
buttonState = digitalRead(8);
if (buttonState == LOW)
doFlash();
}
void doFlash() {
int i;
for (i=2;i<=6;i++) {
digitalWrite(i,HIGH);
delay(100);
digitalWrite(i,LOW);
}
for (i=6;i>=2;i--) {
digitalWrite(i,HIGH);
delay(100);
digitalWrite(i,LOW);
}
}
</code></pre>
| <p>i had the same problem and no body solved it for me.but i got the solution and it works.<a href="https://i.stack.imgur.com/4Nn1L.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4Nn1L.gif" alt="enter image description here"></a></p>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.