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
|
---|---|---|---|---|---|
8348 | |serial|arduino-due| | Has anyone used an Arduino to transfer software to an Apple IIe? | 2015-01-31T23:34:11.700 | <p>Yes, you read that right. An <code>Apple IIe</code>.</p>
<p>I have many retro computers and I was thinking that since the <code>Apple II</code> line of computers (especially the <code>IIe</code>) have pretty speedy serial ports that it should be somewhat simple to use an Arduino to send data to/from the Apple.</p>
<p>My issue is that all of my every-day computers are USB based with no RS232 serial. I guess I could boot up an old Linux laptop that has a serial port but that seems too cumbersome given my limited desk space. :-)</p>
<p>Anyway, I've Googled but I'm not finding anything.</p>
<p>Since most <code>Apple IIe</code> disk images are pretty small (<144k or so) they should fit pretty easily into, say, an Arduino DUE that I have. Or better yet, using the DUE to mount as a USB device that could send over to the IIe would be great.</p>
<p>So, my question is, does anyone know of any site that explains how this could be done?</p>
<p>Thanks!</p>
<p><strong>EDIT</strong></p>
<p>OK, turns out it WAS pretty easy getting the Arduino DUE to send to the Apple IIe. I simply connected 3 wires from TX1/TR1/GND to the Apple IIe serial port (SSC).</p>
<p>Now, when I launch ADT Pro and start sending, the IIe is receiving garbage. Bunch of "9d9d9d9d" all over the place. </p>
<p>Here's my code:</p>
<pre><code>// ADT.ino
int incomingByte = 0;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
}
void loop() {
if(Serial.available() > 0) {
while(Serial.available() > 0) {
incomingByte = Serial.read();
}
Serial1.write(incomingByte);
delay(100);
}
}
</code></pre>
<p>The ADT Pro software is set to send the data over the USB port and it's obviously sending data to the IIe. I'm just wondering if the formatting is wrong or something.</p>
| <p>You need to adapt the levels. Arduino Due operates on 0 - 3.3 V. Apple IIe is either on 0 - 5 V or +/- 12 V (depends which port you are using). There are standard ICs to do the level adaptation.</p>
|
8353 | |avr|avrdude|isp| | In system programming for avr? | 2015-02-01T07:49:18.203 | <p>I generally use sockets for AVRs in standalone circuits, but sometimes I sell my items and therefore I soldier the chip on the circuit. As you guess I can upgrade the code inside the chip with socket simply putting the chip out and putting it into the programmer board, but It doesn't work the same way with the ones which are soldiered on the circuit.</p>
<p>I know there are some ISP devices like USBtinyISP etc., but I want to be more professional and know exactly how an in system programmer work.</p>
<p>Do I have to use Avrdude If I design my own In system programmer? Isn't there any way that is more universal?</p>
<p>I searched the internet for a long time and I found only hobbyist stuff. Can anyone explain or simply direct me to a good source that explains this topic? Thank you in advance.</p>
| <p>You can use an ISP using the Arduino UI - simply select your programmer (tools->programmer) then "upload using programmer" (under the file menu).</p>
<p>Alternatively, you could use a pre-programmed AVR to do the programming - see <a href="http://www.atmel.com/images/doc0943.pdf" rel="nofollow">http://www.atmel.com/images/doc0943.pdf</a> for the spec. I think an AtTiny would be enough, depending on how big your program is, you might need some external storage. You could set it up with a "read" and a "write" option, so you program your dev AVR normally, then use an AtTiny to suck the data off, then push it up to one of the others. This is left as an exercise to the reader.</p>
<p>In any case, you would just need access to the 6 pins - VCC(power), GND(ground), RST(reset), SCK(clock), MISO(master->slave) and MOSI (slave->master). Note that the RST pin has to go high/low at specific times during the programming, so if programming from another AVR, it will need to be a data pin.</p>
|
8357 | |pins|pwm|analogwrite| | Why does a Piezo Buzzer not require a PWM digital pin (Gallileo Gen2)? | 2015-02-01T13:20:28.247 | <p>According to my current (poor) understanding, only the PWM pins (with the ~) among the digital pins (ignoring Analog pins) can be passed to <code>analogWrite()</code>. I understand the servo therefore - since interfaced by a variable voltage signal - must be connected to such a PWM pin.</p>
<ul>
<li>Why is the humble Piezo Buzzer not bound to this condition? </li>
<li>Why can I connect the buzzer to a digital pin that is not PWM (and so should only be able to output binary LOW, HIGH voltage at some consistent frequency) and still achieve a varying sound by calls to the <code>tone()</code> function? </li>
<li>Surely under the limitations of being digital and non-PWM, the pin could only cause some consistent buzzer frequency?</li>
</ul>
<p>I'm reading online that the Piezeo Buzzer does indeed require a PWM digital pin, but I can connect it to any digital pin on my Galileo gen2 and have it function seemingly correctly (differing tones produced).</p>
<p>Also, since slightly relevant; what exactly is the difference between a PWM digital pin and an analog pin, in terms of output? They both use PWM, right? Why can't even a PWM digital pin read analog input?</p>
| <p>The signals that you mention are of different nature.</p>
<p>1) The PWM signal is a digital signal (output voltage is either ground or supply) that is modulated in time. It has a fixed period and its duty cycle varies from 0% (always ground) for value 0, to 100% (always supply) for value 255, the middle value being a signal that switches between ground and supply with 50% of its period at ground and 50% of its period at supply.</p>
<p>2) A servo is controlled by a signal that has a fixed period of 20 ms and a pulse of varying duration (between 0.5 to 2.5 ms).</p>
<p>3) A tone for a buzzer has a variable period (or variable frequency - both being linked by the equation frequency * period = 1). The period is audible if is is between 0.06 ms (15 kHz) and 60 ms (15 Hz) (the exact value change from person to person. If the frequency is higher than 15 kHz, you are entering ultra-sonic.</p>
<p>All three signals are digital in their voltage and modulated in time. But the modulation is very different as indicated above and the Arduino driver is therefore different for each one.</p>
|
8358 | |arduino-uno|analogread|pulsein| | Is it possible to use FrSky D8R-II Plus 8ch 2.4Ghz ACCST Receiver with an arduino Uno? | 2015-02-01T14:58:28.600 | <p>I'm in the process of buying a receiver and transmitter for my quad copter project. Would it be possible to use this receiver or a similar one to control the quad. I'm trying to read the signals using Pulse in. I'm inexperienced in RC and I only found one tutorial on how to do this. </p>
<p>I know that the receiver will have to be wired up to the analog pins on the arduino however, the receiver has an operating voltage of 3.5V-10V and an operating current of 100mA which exceeds the 40mA of the arduino board. I have seen videos of people using silar 2.4Ghz receivers on arduino Nanos without problems. Has anyone on this board done something similar and if so, can thou guide me?</p>
| <p>I've used plenty of receivers like this with arduino.</p>
<p>The operating current is not really an issue; It is drawing power off of the 5v line, not the digital pins, which is capable of 100mA. In any case they usually have an extra "bat" line that you could plug in to a BEC from one of your speed controllers, and then just connect signal and ground lines to the arduino.</p>
<p>pulseIn works, but not ideally (especially for quadcopters). reading with pulseIn tends to have quite a bit of noise, and runs slow. Those receivers pulse around 50-60Hz, so reading those signals with pulseIn (which has to wait for the signal to finish) will take too long. I say "too long" because in all the open source quad copter programs I've looked at the sensor-read/stabilize update loop needs to run at 100 Hz or more.</p>
<p>What you need to use is the interrupt functionality of the AVR. That way you can detect the time between changes in state of the input pulse without causing the rest of the program to stop. This can get somewhat complicated so I'm not going to write a tutorial here. I recommend you research it yourself and ask new, specific questions here if you have any.</p>
<p>It doesn't magically fix everything for you though; the Uno only has 2 external interrupts. I think most arduino based quads use arduino megas or Leonardos, which have more. I know the APM 2 board has a separate chip converting those 8 single channel PPM signals into a single 8 channel PPM signal that goes into the main controller, despite the fact that it is a mega. </p>
<p>You can look into Aeroquad and Multiwii for inspiration. ArduPilot is open source as well but their code is messier, which makes reading it much more difficult. I don't think it is impossible to use an Uno, but it will be difficult.</p>
|
8368 | |bluetooth| | Bluetooth shield/module for file transfer? | 2015-02-01T23:55:05.653 | <p>I'm currently working on a project that requires to display images on a touchscreen on my arduino. These images are neither stored in arduino nor any memory card. I want to be able to send the images via Bluetooth from an app and display it on the touchscreen. The problem is I couldn't find a good and solid Bluetooth shield or module that provide file transfer via bluetooth from an iOS app to arduino. If you can name a few bluetooh shields or modules that'd be great. In the thread below, someone claimed hc-05 works. Can anyone support that claim? Thanks.
<a href="http://forum.arduino.cc/index.php?topic=208306.0" rel="nofollow">http://forum.arduino.cc/index.php?topic=208306.0</a></p>
| <p>I would use an HC-05 (or HC-06 - there seems to be little difference) - You will need to do your own file transfer protocol - for small images, zmodem or xmodem (usual file-over-serial) are probably completely overly complex. You would also need your own app for the phone.</p>
<p>Alternatively, you could use a network (ethernet or wifi) addon on your arduino - I think I read the Arduino Yun has built in ethernet and wifi.<a href="http://arduino.cc/en/Tutorial/WebServer" rel="nofollow">http://arduino.cc/en/Tutorial/WebServer</a> has a webserver, this could be adapted to accept uploaded files. You can then use a webbrowser on your phone (or indeed anywhere else!) to send the files. If you want to send from outside your local network, you may need to set up port forwarding on your router (google: port forward) - the port you want to forwards is 80.</p>
|
8371 | |led|pwm|analogwrite| | analogWrite never outputs a non-zero voltage | 2015-02-02T01:24:21.823 | <p>With a very simple connection of an LED (which can withstand 5V) to ground and to a pin on my Galileo gen2, I can never output a non-zero voltage from the pin via <code>analogWrite</code>, regardless of whether the pin is digital or analog (although PWM digital works)</p>
<p>The LED is in the correct bias and I'm calling <code>pinMode(pin, OUTPUT)</code> before attempting to call <code>analogWrite(pin, 255)</code> (or any 2nd parameter in-between), even though it's not even necessary.<br>
The LED glows if I call <code>digitalWrite(pin, HIGH)</code> on both analog and digital pins, but does not glow at all for <code>analogWrite(pin, 255)</code> with the same configuration and pins, nor does it for any 2nd param in [0, 255]. This holds for whether the call is attempted in <code>loop()</code> or <code>setup()</code>.</p>
<p>The only possible way I can get the LED to receive any power from <code>analogWrite</code> is through a digital PWM pin, but I know the other digital pins can still produce square-waves with timers and the analog pins should certainly be able to use PWM.</p>
<p>(So far, I've been to scared of short-circuits to connect the analogWrite output straight into an analog input to read the voltage)</p>
<p>Is there something I don't understand about the underlying board, or am I experiencing some strange malfunction?</p>
<p>Thanks,<br>
Tyson</p>
| <p>I am not sure where you are getting your LEDs but the ones I purchase do not survive 5 volts. You need to put a resistor in series with then, something in the 220 to 510 ohm range. When you get some resistors test your LEDs you may have damaged them as well. A good indication of this if there color if obviously off and or dim. If the timers are set up correctly the digitalwrite will set the PWM value, somewhere from 8 to 16 bits depending on the Arduino and timer used. This PWM output will appear to control the brightness of the LED. It does this by simply turning it on and off at a speed the eyes cannot follow. the longer it is on the brighter it is. Hopefully this will help you get your arms around the circuit.</p>
|
8375 | |arduino-uno|button|digital| | Why are pin 18 and 19 always HIGH? | 2015-02-02T05:38:41.513 | <p>I wired my switch just like in the default button program. I know it works because it works fine on other pins, just not pin 18 or 19. What am I doing wrong?</p>
<pre><code>const int buttonPin = 18; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
}
else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}
</code></pre>
| <p>The analog pins function as digital pins number 14 - 19, with 14 being A0 and 19 being A5. I had hooked it up backwards. </p>
<pre><code>This time we're gonna get funky
Everybody check your pins
Check check check check your pins
Check check check check your pins
</code></pre>
<p><img src="https://i.stack.imgur.com/zeUmI.png" alt="enter image description here"></p>
|
8390 | |sensors| | How do I use this sound sensor? | 2015-02-02T22:24:15.883 | <p>I bought one of <a href="http://www.ebay.com/itm/171505106187?_trksid=p2059210.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT" rel="nofollow noreferrer">these</a>:</p>
<p><img src="https://i.stack.imgur.com/04v2jm.jpg" alt="1Pcs New Sound Detection Sensor Module Voice Sensor for Arduino Best"></p>
<p>There are 3 pins on it:</p>
<ul>
<li>5V</li>
<li>GND</li>
<li>OUT</li>
</ul>
<p>My guess is that OUT is an analogue signal that I can measure with my Arduino, am I right?</p>
<p>I am using the "Analogue Output" example code but I just get 5V all the time, it does not seems to change with the sound levels.</p>
<p>Am I doing something wrong? What am I adjusting with the blue square on the board? Should I maybe do that?</p>
| <p>The wording on this particular eBay item is pretty poor but there are plenty of similar products with better descriptions that are photographically identical... <a href="http://www.ebay.co.uk/itm/1x-Sound-Sensor-Detection-Module-LM393-Electret-Microphone-for-Arduino-/231034416834" rel="nofollow">example</a> that make a little bit more sense.</p>
<p>Anyway, I don't think this gives an analog value output, the LM393 is a comparator, so I think the blue dial sets the 'threshold level' and any sounds over that level cause a logic low. i.e. it compares the audio level and the dial and when one exceeds the other it gives a signal.</p>
<p>The features also say "The output effective signal is low level" which is probably Chinglish for the signal is a logic low, i.e. when the sound is heard it goes to 0V rather than 5V which is what I think you were expecting.</p>
<p>In summary: This device is is more like a Clapper, it detects a loud noise and sends a digital low signal.</p>
<p>Try making a loud noise with the same setup you already have, and if not try adjusting the potentiometer by turning it, but not too far! It probably only turns 180-270º.</p>
|
8397 | |serial| | what is the use of "<<=" operator? | 2015-02-03T10:32:12.877 | <p>I recently read this piece of code and I dont know what is the use of "<<=" in the for loop:</p>
<pre><code>for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
</code></pre>
<p>This is the entire code:</p>
<pre><code>//Created August 23 2006
//Heather Dewey-Hagborg
//http://www.arduino.cc
#include <ctype.h>
#define bit9600Delay 100
#define halfBit9600Delay 500
#define bit4800Delay 188
#define halfBit4800Delay 94
byte rx = 6;
byte tx = 7;
byte SWval;
void setup() {
pinMode(rx,INPUT);
pinMode(tx,OUTPUT);
digitalWrite(tx,HIGH);
delay(2);
digitalWrite(13,HIGH); //turn on debugging LED
SWprint('h'); //debugging hello
SWprint('i');
SWprint(10); //carriage return
}
void SWprint(int data)
{
byte mask;
//startbit
digitalWrite(tx,LOW);
delayMicroseconds(bit9600Delay);
for (mask = 0x01; mask>0; mask <<= 1) {
if (data & mask){ // choose bit
digitalWrite(tx,HIGH); // send 1
}
else{
digitalWrite(tx,LOW); // send 0
}
delayMicroseconds(bit9600Delay);
}
//stop bit
digitalWrite(tx, HIGH);
delayMicroseconds(bit9600Delay);
}
int SWread()
{
byte val = 0;
while (digitalRead(rx));
//wait for start bit
if (digitalRead(rx) == LOW) {
delayMicroseconds(halfBit9600Delay);
for (int offset = 0; offset < 8; offset++) {
delayMicroseconds(bit9600Delay);
val |= digitalRead(rx) << offset;
}
//wait for stop bit + extra
delayMicroseconds(bit9600Delay);
delayMicroseconds(bit9600Delay);
return val;
}
}
void loop()
{
SWval = SWread();
SWprint(toupper(SWval));
}
</code></pre>
| <p>As stated in the other answers, the <code><<=</code> operator shifts the byte to the left; however, the number '1' after it specifies how far to shift it - so, <code>2 <<= 2</code> == 8.
Possibly clearer in binary:</p>
<p><code>00000001 <<= 1</code> == <code>00000010</code></p>
<p><code>00000010 <<= 1</code> == <code>00000100</code></p>
<p><code>00000001 <<= 2</code> == <code>00000100</code></p>
|
8419 | |arduino-uno|voltage-level| | Set Arduino digitalRead reference voltage | 2015-02-04T06:53:23.777 | <p>I wanted to know if the reference voltage for the <code>digitalRead()</code> function could be set to a particular voltage, either with an external reference or internally. </p>
<p>In the Arduino reference under the constants heading they have mentioned that they use 3V as reference for the boards I'm using (an Arduino Uno R3). But I want to change it to be a little lower. </p>
<p>Is it possible and if so how?</p>
| <p>You could try not <code>digitalRead</code>, but <code>analogReadVoltage</code>. <a href="http://arduino.cc/en/Tutorial/ReadAnalogVoltage">Analog Read Voltage</a></p>
<p>From Arduino examples:</p>
<pre><code>/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
Serial.println(voltage);
}
</code></pre>
|
8425 | |sd-card|spi| | How to access multiple SPI interfaces on Arduino | 2015-02-04T11:48:56.320 | <p>I have worked on <a href="http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus">SPI</a> devices connected with an Arduino one at a time. How do I work with two different SPI devices at the same time?</p>
| <p>Assuming you just want to connect two SPI slave devices to the SPI bus and use them in a mutually exclusive way under software control, with the Arduino as the master, then you just need to make sure you use a different pin for the slave select (SS) on each SPI device.</p>
<p>When you want to talk to one slave, you hold its SS low and drive the other high. Do the opposite to talk to the other slave.</p>
<p>There are some devils in the detail using multiple slaves, and <a href="https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi">these are explained in more depth here</a>, but in general, it's quite common and OK to use more than one SPI device as a slave.</p>
<p><a href="http://www.dorkbotpdx.org/blog/paul/better_spi_bus_design_in_3_steps">This blog post</a> will give you more information and is a good place to start reading.</p>
|
8441 | |atmega328| | WORDS in ATmega328 datasheet note | 2015-02-05T10:49:25.450 | <p>I came across something strange while reading the datasheet for the microcontroller in the Arduino Uno board.</p>
<p>It is the (8) note in pg.296-297 of <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">this datasheet</a>: what does WORDS mean in that context?</p>
| <p>The notation is being used to indicate that the 16-bit address (as formed by the central bytes of a Write Program Memory Page instruction) is the address of a program-memory <em>word</em>, rather than a program-memory <em>byte</em>.</p>
<p>The size of program memory is specified in bytes, but it often is addressed as words. For example, the PC (program counter) register contains word addresses.</p>
<p>For some instructions, when the Z register is used to address program memory, it contains a word number and a byte selector:</p>
<blockquote>
<p>The Z-register in the Register File is used to access the Program memory. This 16 bits register pair is used as a 16 bits pointer to the Program memory. The 15 most significant bits selects the word address in Program memory. Because of this, the word address is multiplied by two before it is put in the Z-register. ... The least significant bit of the Z Address Register selects either Low byte (0) or High
byte(1) of the Program memory word. — <a href="http://www.atmel.com/Images/doc1233.pdf" rel="nofollow">AVR108: Setup and Use of the LPM Instruction</a>, page 1</p>
</blockquote>
<p><em>Note:</em> Some of the low bits of the word address in a “Write Program memory page” serial programming instruction are treated as don't-cares. The number of don't-care bits depends on flash page size, which in Atmel AVR devices is 32, 64 or 128 words, depending on device series.</p>
<p>For example (as shown in Table 129 on page 304 of <a href="http://www.atmel.com/images/doc2467.pdf" rel="nofollow">doc2467.pdf</a>) the ATmega128 with 128-word (256-byte) flash pages has seven don't-care bits in the low byte of the address.</p>
<pre><code>Table 129. SPI Serial Programming Instruction Set
-----------Instruction Format----------
Instruction Byte 1 Byte 2 Byte 3 Byte 4 Operation
Write Program 0100 1100 aaaa aaaa bxxx xxxx xxxx xxxx
Memory Page Write Program Memory
Page at address a:b.
</code></pre>
|
8446 | |arduino-uno|voltage-level| | Connecting a LSM9DS0 9DoF module to Arduino Uno | 2015-02-05T16:38:55.820 | <p>I got a bit confused by Sparkfun's <a href="https://learn.sparkfun.com/tutorials/lsm9ds0-hookup-guide" rel="nofollow">hookup guide</a> for <a href="https://www.sparkfun.com/products/12636" rel="nofollow">this 9DoF breakout</a> module.</p>
<p>It says the VDD-in on the breakout <em>"should [get voltage] regulated between 2.4V and 3.6V"</em>, yet in their example they do not hook it up to the Arduino's 3.3V pin, but instead they use the 5V and a bi-directional logic level converter.</p>
<p>Do I need to use the logic level converter, or can I just hook the module up to the 3.3V pin of my Arduino Uno without damaging the breakout module?</p>
| <p>I might be missing the part of the hookup guide you're looking at but I can't see it being hooked up to 5V. </p>
<p>In the "Simple Hardware Hookup (I2C)" section they show two possiblilities a 5V Arduino hooked up via a logic level converter and a 3.3V Arduino hooked up directly. The logic level converter will need a 5V & 3.3V connection from the Arduino, but not the IMU.</p>
|
8450 | |arduino-uno|serial|xbee|communication| | XBEE coordinator WITH or WITHOUT Arduino? | 2015-02-05T19:14:31.827 | <p>I am building a wireless system that has got an Arduino with a XBEE as the 'end user' and I need to acquire data/control that Arduino from a PC graphical interface.
As far as I'm aware there are two options to obtain the communication:</p>
<ol>
<li><p>I could use another Arduino with XBEE (coordinator) that is connected to my PC (serial) to control the 'end user'. The code is stored in this Arduino which works as a bypass between PC and XBEE. </p></li>
<li><p>I could simply use a XBEE without Arduino (coordinator) connected to my PC to control the 'end user'. The code should be stored within the PC or the XBEE to establish communication and control data transmission to different end users (???)</p></li>
</ol>
<p>As I am new to the Arduino world, would you please direct me to the best/easiest solution to obtain such thing?</p>
| <p>If you want just to control and receive data from your end user, option 2 is easy to implement. </p>
<p>You can use any programming language that supports serial communication such as python, node.js, etc.</p>
<p>What you have to is to note how your coordinator is recognized by your operating system (in windows as com1 port, unix-like as ttyACM or similar) and open it from your preferred language.</p>
<p>After that, you establish a protocol that should be agreed with your Arduino. For example. Suppose you want to collect data from end user, so, you send a message from the coordinator connected in your PC with a code #data through the serial. When the Arduino receives it, it decodes the message and return something like #d125 where it says it is sending the data and the value is 125 (supposing integer values).</p>
<p>Making sure you already have configured the XBees in the same network by setting Same PAN id and cross setting the destination address of each one so they send packates to each other. </p>
<p>I am supposing you are using AT transparent mode where they just send whatever comes in the serial interface, in this mode they work basically sending chunks of bytes and it is up to you to establish a protocol to provide a good flow of data. In this mode there is no guarantee that your packet will reach the destination. In order to fully extend the XBee usage, you'd need the API mode where all the transmission checks are done. </p>
<p>But for you purpose, AT mode seems enough. </p>
|
8453 | |ethernet| | Arduino over a Network | 2015-02-05T20:20:10.917 | <p>I am new to arduino programming. I want to sense temperature and send it to a server in my college. I am using Arduino Uno R3 board which has ATmega 328P micro-controller. I am able to get serial output on my PC but is there a way in which I can send temperature data to the server in a packet format using Arduino Programmer and not using Ethernet Shield ? Please answer in a less complex way. </p>
| <p>Use an <a href="http://arduino.cc/en/Guide/ArduinoYun" rel="nofollow">Arduino Yún</a>: it's a Leonardo coupled with a CPU running GNU/Linux (a flavour of OpenWRT).</p>
<p>Using the Bridge library, your sketch can delegate tasks to the linux side.</p>
<p>HttpClient example (Examples > Bridge > HttpClient) GETs a page from the Arduino web site, but the HttpClient class may POST whatever data to a server of choice.</p>
<p>There is also a nice example called <a href="https://www.temboo.com/arduino/yun/update-google-spreadsheet" rel="nofollow">SendDataToGoogleSpreadsheet</a> (Examples > Bridge > Temboo > SendDataToGoogleSpreadsheet): it accumulates sensor readings on a google spreadsheet. I've used something like that on a <a href="https://github.com/ffissore/badger" rel="nofollow">project of mine</a>.</p>
|
8457 | |serial|arduino-mega| | Serial.read() vs. Serial.readBytes()? | 2015-02-05T21:56:19.323 | <p>I'm trying to do some fairly simple serial communication and have things partially working, but am pretty confused about a couple results I'm getting. </p>
<p>For a little background, I'm using an Arduino Mega 2560 to try to communicate with a Dynamixel servo (MX-64) over TTL (half-duplex, asynchronous) with Tx1 and Rx1. Basically I construct some byte arrays as instructions, send them over to the servo (with <code>Serial1.write()</code>), and then read back a reply. I've actually gotten it to work pretty well if I use <code>Serial1.readBytes()</code>, specifying the length of the buffer (number of bytes I'm expecting). I'm also reading back what I originally sent (first) as well as the response (second), since I have Tx1 and Rx1 tied together (required in my setup because this servo only has one data wire).</p>
<p>However I don't understand the difference between <code>Serial.readBytes()</code> and <code>Serial.read()</code>. If I do <code>Serial.read()</code> just prior to <code>Serial.readBytes()</code>, it comes back with -1, meaning no bytes to read... but then <code>Serial.readBytes()</code> gives me the byte stream I was expecting from the buffer! What's going on here? </p>
<p>Similarly, <code>Serial.available()</code> seems sort of broken in that it tells me there are no bytes to read (returns 0), but then I can read the bytes I'm expecting with <code>Serial.readBytes()</code>. Additionally, I can do <code>Serial.readBytes()</code> after there's nothing left (or rather, there shouldn't be any bytes left...) and it will give me some bytes, but they're total garbage. </p>
<p>I think maybe there's something I don't understand about the way the serial buffer works, but can't find a good resource on it and the Arduino reference pages are kind of useless. Any clues about the difference in how these operate would be much appreciated!</p>
| <p>readBytes is blocking until the determined length has been read, or it times out (see Serial.setTimeout()). Where read grabs what has come, if it has come in. Hence available is used to query if it has.</p>
<p>Note that it takes time for a message to go out and to receive either the echo or response. So simply checking the RX buffer immediately after sending something, is expected to be empty for some time. That is where readBytes sites and waits. And I bet the default setTimeout of 1s is sufficient, to get the response.</p>
<p>This is why you see the Serial.read() inside a while or if Serial.available. Hence I typically employ something like the following: Which emulates readBytes (for the most part).</p>
<pre><code> #define TIMEOUT = 3000;
loop {
char inData[20];
unsigned long timeout = millis() + TIMEOUT;
uint8_t inIndex = 0;
while ( ((int32_t)(millis() - timeout) < 0) && (inIndex < (sizeof(inData)/sizeof(inData[0])))) {
if (Serial1.available() > 0) {
// read the incoming byte:
inData[inIndex] = Serial.read();
if ((c == '\n') || (c == '\r')) {
break;
}
Serial.write(inData[inIndex++]);
}
}
}
</code></pre>
<p>Above code was quickly written and untested. But gets the idea across.</p>
|
8465 | |serial|arduino-leonardo| | Uploading new sketch to Leonardo-type boards when you've changed the HID mode | 2015-02-06T03:22:19.837 | <p>I have Sparkfun Pro Micro (Leonardo compatible board). I got it because I plan to build my own array of controls for use in flight/racing sims.</p>
<p>My starting point is LeoJoy, and I didn't have any trouble getting this up and running. Installed just fine, and I have a programmable HID joystick available in windows. It seems to work by modifying the RAWHID code in the default libraries to spoof being a HID joystick. However, my board was now stuck in joystick mode, with no available COM ports for uploading new sketches.</p>
<p>Resetting the board (by grounding the RST pin), enables the COM port, but very, very briefly. Not enough time to send new sketches.</p>
<p>After about an hour of trying different timing, I finally did upload an empty sketch to the board before it went into Joystick mode. So I'm good for now, but I'm a bit worried that I'm going to have to repeat this every time I want to make a change to my program.</p>
<p>Am I doing something completely noobish here? Is this the correct way to program a board that has been forced to act as a joystick? Is there a better way?</p>
<p>Perhaps there's some code I can put into my sketch that will delay the change of USB behavior for a few seconds. That way, it will allow me to recompile and submit my sketches after a reset without having to rush the timing.</p>
| <p>From Sparkfun's page <a href="http://f">Pro Micro Hook-upGuide</a></p>
<p>When a Pro Micro is externally reset (by pulling the RST pin low), it’ll only briefly (<750ms) start the bootloader before continuing on to the sketch. If you need the bootloader to run longer, resetting twice quickly will get the Pro Micro to enter bootloader mode for eight seconds.</p>
<p>Hope that helps! If not there are some other procedures you might want to look into.</p>
|
8468 | |sensors| | Will a magnetometer give distorted values if there is a magnet near? | 2015-02-06T08:20:11.473 | <p>I am not entirely sure how a magnetometer works in IMU units, so I was wondering how a magnet near the sensor affects readings?</p>
| <p>The IMU magnetometer is made to measure the magnetic filed of the earth, which magnitude is a few 10 - 60 uT (micro-Tesla). You cannot measure it near to a large magnet that may generate 1 T or more: the magnetometer will saturate.</p>
|
8473 | |serial|rs232| | How to get serial data in Arduino from a barcode scanner? | 2015-02-06T09:29:49.943 | <p>I want to interface my barcode scanner with an Arduino using RS232. I have connected 2 (RX), 3 (TX) and 5 (GND) of the RS232 with the corresponding pins of MAX232. I am taking TTL outputs on Arduino pins 6 and 7.</p>
<p>This is the code of the Arduino program:</p>
<pre><code>#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // RX, TX
void setup() {
Serial.begin(9600);
}
void loop() {
// run over and over
if (mySerial.available()) {
byte x = mySerial.read();
Serial.println(x);
}
}
</code></pre>
<p>I am not getting any output on the serial monitor when I scan a product.</p>
| <p>I tried this as well, for some reason it is NOT WORKING on pins 6 and 7, but it works perfectly using pins 10 and 11 instead. Of course, you still need to add the <code>mySerial.begin()</code>.</p>
|
8480 | |serial|arduino-mega| | How to connect twenty different serial devices to an Arduino Mega? | 2015-02-06T16:38:01.277 | <p>I want to connect 20 serial devices to the same Arduino Mega.How to do this?I know that multiplexing is the way but how to do that</p>
| <p>You can use the SoftwareSerial library and declare instances to communicate with your serial devices. I am not sure if you can declare 20 such different instances but if at all you do, use the function: <a href="https://www.arduino.cc/en/Reference/SoftwareSerialListen" rel="nofollow">listen()</a> to switch between those serial devices. This, probably, is as close as it gets to multiplexing as you mentioned. </p>
<p>I've tried with 2 such SoftwareSerial instances for communicating with GPS module and GSM module and the listen() function worked flawlessly.</p>
<p>Cheers!</p>
|
8486 | |arduino-uno|serial| | Writing serial data, just once after read | 2015-02-07T01:02:41.993 | <p>I have developed a program and the idea is that when it receives serial data (any single character) it returns a single random number.</p>
<p>I have it working but it returns 3 x random numbers one after another for each read that it does and I can't figure out why.</p>
<pre><code>int led = 13;
char incomingByte = 10;
long randNumber;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
Serial.begin(9600);
}
// the loop routine runs over and over again forever:
void loop() {
// delay(1000); // wait for a second
if (Serial.available() > 0) {
// read the incoming byte:
incomingByte = Serial.read();
// say what you got:
// Serial.print("I received: ");
randNumber = random(1, 2000);
Serial.println('PL' + randNumber);
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
}
}
</code></pre>
| <p>When you enter a single character into the Serial Monitor and press Enter, three bytes are sent: the character, a carriage return, and a linefeed. <code>Serial.read()</code> only reads a single byte, so data is available three times.</p>
<p>Either loop reading until no more bytes are available, check for and discard any CRs and LFs, or use a serial terminal that doesn't require pressing Enter to send data.</p>
|
8502 | |serial|arduino-ide| | How to prevent the Serial Monitor from closing upon re-uploading sketch? | 2015-02-08T02:07:13.630 | <p>I'll be teaching a year 10 class on the Intel Galileo gen2 and there'll be a wide (but high-level) programming curriculum, which includes introduction to console printing, using <code>Serial</code>.</p>
<p>I'd like the students to be able to write their printing code in <code>setup()</code> so that it's only printed once and easily readable by them. However, it's impossible to be fast enough to upload a sketch and open the Serial Monitor (which flat out refuses to open before the sketch has started), and the Serial Monitor closes itself upon re-uploading code.</p>
<p>Without unnecessary (and potentially for the students, confusing) use of the <code>delay</code> function in <code>setup()</code>, it's impossible to read any output originating from <code>setup()</code>; only things printed in <code>loop()</code> (which are constantly re-printed) are ever discoverable.</p>
<p>So; is there a way to somehow keep the Serial Monitor open, or make it capture output from before it's opened, or delay the entire running of the sketch (rather than chucking in delays)?</p>
<p>We'll be using the standard Arduino IDE.</p>
<p><strong>EDIT</strong></p>
<p>This script was run in one of two conditions...</p>
<pre><code>void setup() {
Serial.begin(9600);
// ensure Serial is ready
delay(1000);
for (int i=0; i < 10000; i++) {
Serial.println(i);
}
}
void loop() {
}
</code></pre>
<p>When the Serial Monitor was opened <strong>immediately</strong> after upload, all numbers from and including 0 to 9999 were recorded in the monitor. </p>
<p>When the Serial Monitor was opened around 5s <strong>after</strong> upload, only numbers upward of 2243 were observed. This suggests the sketch WAS being re-run (else no numbers would have been captured; the sketch runs in significantly less time than 5s) but that all numbers between 0 and 2243 were not captured by the monitor; as if opening the Serial Monitor late enough to cause a re-run causes some monitor overhead.<br>
This strange loss of numbers is NOT time dependent: increasing the initial delay from 1s to 4s (and waiting longer after upload before opening the Serial) did not at all vary the soonest number recorded, suggesting it is some 'line' based overhead
(but of course, how could anything fail for 2243 lines?!)</p>
<p>With that mystery aside, this negates the automatic re-running of the sketch upon Serial Monitor opening from being actually useful.</p>
| <p>Have you tried hitting the reset button while the serial monitor is open? I have done this on other Arduino boards to capture stuff in the setup loop that was occurring too fast. Otherwise using Serial1 for output connected via a FTDI cable may be the way to go.</p>
|
8504 | |mosfet| | Using an Arduino to switching a grounded load powered by a 12 Volt supply | 2015-02-08T03:15:01.573 | <p>I wish to use a MOSFET to drive a 12V rated LED strip from an Arduino.<br>
The negative side of the LED strip must be connected to ground, so that means that the driving MOSFET must be between +12V and the LED strip. </p>
<p>This is what I have tried so far. </p>
<p><img src="https://i.stack.imgur.com/T4jlD.png" alt="led strip mosfet arduino"></p>
<p>The <strong><em>load must be between</em></strong> my <strong><em>mosfet</em></strong> and my car battery <strong><em>GND</em></strong>.</p>
| <p>In your existing arrangement.</p>
<p>Swap to P Channel FET<br />
Swap drain and source leads (right hand two).</p>
<p>This will work for up to 5V feed to LEDs.</p>
<p>To get 12v operation you will need to add a driver between the FET gate and the Arduino.<br />
see circuit diagram below.</p>
<hr />
<p>To operate with FET on the HIGH (V+) side when V+ is greater than the rduino's supply voltage, the FET must either</p>
<ul>
<li><p>Be P Channel with FET source to +12V and FET drain to load+ or</p>
</li>
<li><p>An N Channel with gate drive above V+.</p>
<p>The gate drive to the FET must go to about +12V to turn it off.<br />
The Arduino will only drive it to +5V.</p>
</li>
</ul>
<p>As you are unlikely to want to provide an extra high side drive the P channel option is preferred. This could be eg:</p>
<ul>
<li>A "jellybean" bipolar transistor or small FET worth a few cents) and a few resistors, or a small N Channel MOSFET and one resistor</li>
</ul>
<p>or</p>
<ul>
<li>An opto isolator.</li>
</ul>
<hr />
<p><strong>Transistor driver:</strong></p>
<p>Bipolar transistor NPN (BC337 / BC817 or similar)(ANYTHING NPN will work).<br />
R1 = 10k resistor Arduino out to base.<br />
R2 = 10k FET gate to +12.</p>
<p>If an N Channel MOSFET is used for Q1 then R1 is not needed.</p>
<p>This could be a <a href="http://www.onsemi.com/pub_link/Collateral/EN6559-D.PDF" rel="nofollow noreferrer">5LN01SP</a> IF you can get them - no stock Digikey.These have a very low Vgsth (turn on voltage)</p>
<p>Otherwise you can use a 2n2222, VN2222, BS108 or similar logic-gate N channel MOSFET.<br />
eg <a href="http://www.onsemi.com/pub_link/Collateral/VN2222LL-D.PDF" rel="nofollow noreferrer">VN2222</a>. Many variants of these are widely available and low cost.</p>
<p><img src="https://i.stack.imgur.com/OQdAa.png" alt="schematic" /></p>
<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fOQdAa.png">simulate this circuit</a> – Schematic created using <a href="https://www.circuitlab.com/" rel="nofollow">CircuitLab</a></sup></p>
|
8511 | |voltage-level| | How to identify Arduino Mini Pro 5v vs 3.3v | 2015-02-08T21:56:31.960 | <p>I have many Arduino Mini Pro, every from different seller.
Few are 3.3v and most 5v.</p>
<p>I had to clean table for Xmas and now I do not have any idea how to identify 3.3v Arduinos.</p>
<p>They do not have any marks. I bought them on ebay.</p>
<p>I know 3.3v has 8mhz clock but only one my arduino has big crystal with 16.000-30.</p>
| <p>Some clones on ebay labeled "the simple" come with 4B2X. They are 3.3v but the maximum voltage is 10v instead of 12v so beware to not burn it out.</p>
|
8519 | |arduino-uno|ethernet|sketch|web-server| | Arduino Ethernet and Uno R3 as a firewall | 2015-02-09T05:16:59.990 | <p>Is there a way to program the Ethernet Shield and Uno R3 to act as a firewall without using a huge chunk of the allowed bytes on the R3? I plan on using a DC adapter to plug the R3 into a wall, and use the mini-SD card to keep logs while having the ethernet shield plugged into my router.</p>
<p>I know that it is possible to program it to do this but I want to know if there is a simple modification I can make to the web-client library or if I should use the web-server library and modify that?</p>
| <p>As an entry level board, I wouldn't suggest trying this on the R3. You can do it to an extent on the Yun which comes with both a network port and wifi. </p>
<p>Now that said, your internet speed will be severely hampered by the lack of resources on the yun. In which case, you might want to steer closer to the Intel Edison, which you can use with the arduino IDE. It is considerably more powerful. </p>
|
8524 | |power| | Will the 3.3V regulator on an Arduino Leonardo work when powered from USB? | 2015-02-09T10:40:07.617 | <p>Will the 3.3V regulator produce 3.3v when the Arduino is powered from the USB port?</p>
| <blockquote>
<p>Will the 3.3V regulator on an Arduino Leonardo work when powered from USB?</p>
</blockquote>
<p>Yes, provided that </p>
<ul>
<li><p>it is an "official" Leonardo or a competent clone and </p></li>
<li><p>as long as you do not load the power supply excessively with external loads.</p></li>
</ul>
<p><a href="http://arduino.cc/en/uploads/Main/arduino-leonardo-schematic_3b.pdf" rel="nofollow noreferrer"><strong>Official circuit diagram here</strong></a></p>
<p>The USB supply feeds the 3V3 regulator via MOSFET T1 at the bottom of the sheet and U3, an LP2985 LDO regulator. If your board has the same circuitry as this it should provide 3V3 from USB.</p>
<hr>
<p><img src="https://i.stack.imgur.com/2EACG.jpg" alt="enter image description here"></p>
|
8532 | |arduino-uno|led|power|servo|battery| | project not working when switching to battery power | 2015-02-09T19:29:57.133 | <p><img src="https://i.stack.imgur.com/arOYe.png" alt="enter image description here"></p>
<p>I have a project which involves a photocell, an led, a push button, and a small hobby servo (<a href="http://www.adafruit.com/product/155" rel="nofollow noreferrer">tower pro sg5010</a>) - the project works as expected when the arduino is powered by usb, but when I switch to battery power (4 AA batteries) - it doesn't work.</p>
<p>When powered by batteries, the servo actually starts right up and moves to the correct angle, so I feel like it should be getting enough power, but when I push the push button, it doesn't move to the new angle. I can hear a clicking noise of the servo on a regular interval, like a clock, and my LED flickers on and off at about the same interval.</p>
<p>If I'm doing something wrong, can anyone point it out? If it's just that the servo is not getting enough power, is there a way to add a transistor or something so that I don't have to add a separate power supply for the servo (I'm not sure there's room in my project's enclosure). </p>
<p>I've attached a fritzing diagram as well as my project code.</p>
<p>CODE:</p>
<pre><code>#include <Servo.h>
const int buttonPin = 2; // the number of the pushbutton pin
boolean buttonPushed = false;
const int ledPin = 13; // the number of the LED pin
const int servoPin = 9;
Servo servo;
int angle = 0;
int servoStartAngle = 90;
int servoEndAngle = 10;
boolean servoActivated = false;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int photoCellPin = 2;
int photoCellThreshold = 500;
int photoCellActivated = false;
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
servo.attach(servoPin);
servo.write(servoStartAngle);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
int photoCellVal = analogRead(photoCellPin);
if (photoCellVal > photoCellThreshold){
photoCellActivated = true;
} else {
photoCellActivated = false;
}
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW && buttonPushed == false) {
// turn LED on:
buttonPushed = true;
Serial.println("button pushed");
} else if (buttonState == LOW && buttonPushed == true){
buttonPushed = false;
Serial.println('deactivate');
}
if (buttonPushed == true){
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
if (buttonPushed && servoActivated == false && photoCellActivated == true){
servoActivated = true;
Serial.println("activate motor");
for(angle = servoStartAngle; angle > servoEndAngle; angle--){
servo.write(angle);
Serial.println(angle);
delay(15);
}
} else if (buttonPushed == false && servoActivated == true){ //deactivate
for(angle = servoEndAngle; angle < servoStartAngle; angle++){
servo.write(angle);
Serial.println(angle);
delay(15);
}
delay(200);
servoActivated = false;
}
delay(200);
}
</code></pre>
| <p>I had an even simpler project only involving a TMP sensor and 433 MHz RF module. On a 9V (150 mAh) block battery it lasted only about 2,5 hours.
The Arduino is great for prototyping this sort of stuff, but when you want to build something for battery operation I found that it draws 56 mA just looping without RF or motor!</p>
<p>Counting 2 digital outputs, 1 digital input and 1 analog input in your project, you can run that of an ATTiny85 or ATTiny45. It's the same family and after setup can be programmed with the Arduino environment. You can also opt for a lower speed bootloader 1 MHz or 8 MHz instead of 16 MHz for the Arduino to save energy, you don't seem to calculate that much. The ATTiny will draw about 10 mA looping this way. </p>
<p>Next you'll find also that you can disable the brown out detection in the bootloader, so it just drains the battery until completion. </p>
<p>Saving space in you enclosure by swapping Arduino board for ATTiny chip will allow you to put in more batteries, say 8 AA in two parallel packs of 6V each.</p>
<p>When that doesn't help you'll discover about the sleep modes and disabling ADC when not in use, where you go to sleep for specific intervals and allow the chip to be woken up by interrupts. In sleep mode I found the ATTiny to consume only 0.03 mA.</p>
<p><strong>Some more information</strong></p>
<p><a href="http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/" rel="nofollow">Program an ATtiny with Arduino</a></p>
<p><a href="https://code.google.com/p/arduino-tiny/" rel="nofollow">ATTiny files for Arduino IDE</a></p>
|
8563 | |arduino-ide|avrdude|arduino-micro| | Cannot program Arduino Micro in OSX without hard resetting the board every time | 2015-02-10T17:05:26.027 | <p>I am experiencing a problem when programming Arduino Micro in OSX Mavericks. I have tried to reproduce this problem in XCode and Arduino IDE and it is persistent. I need to make a hard-reset at the same time as a click the "program" button.</p>
<p>I have tried to use the new Leonardo bootloader to see if it solves my issue, but its still persistent. </p>
<p>I am running avrdude 6.1, what is the problem?</p>
<p>Stacktrace:</p>
<pre><code>---- Size ----
Binary sketch size: 24162 bytes (of a 28672 byte maximum)
Estimated SRAM used: 733 bytes (of a 2560 byte maximum)
Elapsed time: 5.2 s
---- Reset ----
screen -X kill
No screen session found.
make: [reset] Error 1 (ignored)
sleep 1
9.2-RESET: < micro ./ ./
stty -f /dev/tty.usbmodem1411 1200
---- Upload ----
10.6-UPLOAD: < micro ./
/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/bin/avrdude -patmega32u4 -C/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/avr/etc/avrdude.conf -D -cavr109 -b57600 -P/dev/tty.usbmodem1411 -Uflash:w:Builds/embeddedcomputing.hex:i
Connecting to programmer: .avrdude: butterfly_recv(): programmer is not responding
</code></pre>
| <p>This <a href="http://arduino.cc/en/Guide/ArduinoLeonardoMicro" rel="nofollow">Arduino.cc article</a> describes the differences between Leonard & Micro vs. other Arduinos, including the fact that Micro does not have a separate USB processor on board but creates a virtual USB with the main processor. There is no (or a very different) auto-reset mechanism. There is apparently a way for the IDE to open the Mac's USB at 1200 baud to cause the Micro to reset; then the IDE can wait for the virtual USB to re-appear. But it also says you may need to use the reset button suggesting the 1200 baud dance doesn't work all that reliably.</p>
|
8564 | |avr|avrdude|arduino-micro| | Unable to flash bootloader on ATmega32U4 with AVR dragon | 2015-02-10T17:16:28.380 | <p>I am flashing a <em>naked</em> ATmega32U4, but the process fails in the end where it is verifying.</p>
<pre><code>avrdude -c dragon_isp -p m32u4 -P usb -U flash:w:Caterina-Micro.hex -U lfuse:w:0xff:m -U hfuse:w:0xd8:m -U efuse:w:0xcb:m -U lock:w:0x2f:m -v -B 100
avrdude: Version 6.1, compiled on Mar 23 2014 at 04:42:55
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "/usr/local/Cellar/avrdude/6.1/etc/avrdude.conf"
User configuration file is "/Users/SomeUser/.avrduderc"
User configuration file does not exist or is not a regular file, skipping
Using Port : usb
Using Programmer : dragon_isp
Setting bit clk period : 100.0
avrdude: usbdev_open(): Found AVRDRAGON, serno: 00A200050468
JTAG ICE mkII sign-on message:
Communications protocol version: 1
M_MCU:
boot-loader FW version: 255
firmware version: 7.38
hardware version: 1
S_MCU:
boot-loader FW version: 255
firmware version: 7.38
hardware version: 7
Serial number: 00:a2:00:05:04:68
Device ID: AVRDRAGON
AVR Part : ATmega32U4
Chip Erase delay : 9000 us
PAGEL : PD7
BS2 : PA0
RESET disposition : dedicated
RETRY pulse : SCK
serial program mode : yes
parallel program mode : yes
Timeout : 200
StabDelay : 100
CmdexeDelay : 25
SyncLoops : 32
ByteDelay : 0
PollIndex : 3
PollValue : 0x53
Memory Detail :
Block Poll Page Polled
Memory Type Mode Delay Size Indx Paged Size Size #Pages MinW MaxW ReadBack
----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
eeprom 65 20 4 0 no 1024 4 0 9000 9000 0x00 0x00
flash 65 6 128 0 yes 32768 128 256 4500 4500 0x00 0x00
lfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
hfuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
efuse 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
lock 0 0 0 0 no 1 0 0 9000 9000 0x00 0x00
calibration 0 0 0 0 no 1 0 0 0 0 0x00 0x00
signature 0 0 0 0 no 3 0 0 0 0 0x00 0x00
Programmer Type : DRAGON_ISP
Description : Atmel AVR Dragon in ISP mode
Vtarget : 5.0 V
SCK period : 100.37 us
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.16s
avrdude: Device signature = 0x1e9587
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D8
avrdude: safemode: efuse reads as CB
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "Caterina-Micro.hex"
avrdude: input file Caterina-Micro.hex auto detected as Intel Hex
avrdude: writing flash (32730 bytes):
Writing | ################################################## | 100% 62.28s
avrdude: 32730 bytes of flash written
avrdude: verifying flash memory against Caterina-Micro.hex:
avrdude: load data flash data from input file Caterina-Micro.hex:
avrdude: input file Caterina-Micro.hex auto detected as Intel Hex
avrdude: input file Caterina-Micro.hex contains 32730 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 152.35s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0002
0x66 != 0x6e
avrdude: verification error; content mismatch
avrdude: safemode: lfuse reads as FF
avrdude: safemode: Verify error - unable to read hfuse properly. Programmer may not be reliable.
avrdude: safemode: lfuse reads as FF
avrdude: safemode: Verify error - unable to read hfuse properly. Programmer may not be reliable.
avrdude: safemode: Sorry, reading back fuses was unreliable. I have given up and exited programming mode
avrdude done. Thank you.
</code></pre>
<p>I get another verification error when i program without fuses:</p>
<pre><code>avrdude -c dragon_isp -p atmega32u4 -P usb -U flash:w:Caterina-Micro.hex -u
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.16s
avrdude: Device signature = 0x1e9587
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "Caterina-Micro.hex"
avrdude: input file Caterina-Micro.hex auto detected as Intel Hex
avrdude: writing flash (32730 bytes):
Writing | ################################################## | 100% 69.60s
avrdude: 32730 bytes of flash written
avrdude: verifying flash memory against Caterina-Micro.hex:
avrdude: load data flash data from input file Caterina-Micro.hex:
avrdude: input file Caterina-Micro.hex auto detected as Intel Hex
avrdude: input file Caterina-Micro.hex contains 32730 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 178.10s
avrdude: verifying ...
avrdude: verification error, first mismatch at byte 0x0000
0x04 != 0x0c
avrdude: verification error; content mismatch
avrdude done. Thank you.
</code></pre>
| <p>I literally gave up and got myself a Atmel-ICE which solved all my problems.</p>
|
8566 | |arduino-uno|power|battery| | estimating battery run time | 2015-02-10T21:38:02.527 | <p>I have a project which runs a continuous loop and listens for the push of a button to light an led and activate a servo motor on an Arduino Uno (R2). The arduino is powered by 4 AA batteries, and the servo is powered by a 9V. I'm wondering how long I can leave this running off battery power. Does anyone know how to estimate this? As a side note, if anyone spots a way to improve battery life in my sketch / wiring, I'd love to know. </p>
<p>Below is my code and attached is the wiring diagram for the project (minus the batteries).</p>
<pre><code> #include <Servo.h>
const int buttonPin = 2; // the number of the pushbutton pin
boolean buttonPushed = false;
const int ledPin = 13; // the number of the LED pin
const int servoPin = 9;
Servo servo;
int angle = 0;
int servoStartAngle = 90;
int servoEndAngle = 10;
boolean servoActivated = false;
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int photoCellPin = 2;
int photoCellThreshold = 500;
int photoCellActivated = false;
void setup() {
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
servo.attach(servoPin);
servo.write(servoStartAngle);
}
void loop(){
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
int photoCellVal = analogRead(photoCellPin);
if (photoCellVal > photoCellThreshold){
photoCellActivated = true;
} else {
photoCellActivated = false;
}
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == LOW && buttonPushed == false) {
// turn LED on:
buttonPushed = true;
Serial.println("button pushed");
} else if (buttonState == LOW && buttonPushed == true){
buttonPushed = false;
Serial.println('deactivate');
}
if (buttonPushed == true){
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
if (buttonPushed && servoActivated == false && photoCellActivated == true){
servoActivated = true;
Serial.println("activate motor");
for(angle = servoStartAngle; angle > servoEndAngle; angle--){
servo.write(angle);
Serial.println(angle);
delay(15);
}
} else if (buttonPushed == false && servoActivated == true){ //deactivate
for(angle = servoEndAngle; angle < servoStartAngle; angle++){
servo.write(angle);
Serial.println(angle);
delay(15);
}
delay(200);
servoActivated = false;
}
delay(200);
}
</code></pre>
| <blockquote>
<p>I'm wondering how long I can leave this running off battery power. Does anyone know how to estimate this?</p>
</blockquote>
<p>If your circuit draws 1A @ 12V, a 12V 1Ah battery will power it for approximately one hour. A 9V alkaline typically contains about 565mAh. You can use the datasheets to sum all the power consumption, but its probably easier just to measure it with a multimeter.</p>
<blockquote>
<p>As a side note, if anyone spots a way to improve battery life in my
sketch / wiring, I'd love to know.</p>
</blockquote>
<p>-Check out the ATTiny series (<a href="http://www.atmel.com/v2PFResults.aspx#(actives:!(8238,8394,8362,8282,8431,8300,8358,8392,8378,8445,8236,8449,8474,8248,8264,8447,8256,8254,8286,8462,8429,8458,8466,8400,8302,8278),data:(area:'',category:'34864[33180[33086]]',pm:!((i:8238,v:!(1,7)),(i:8394,v:!(0,7)),(i:8362,v:!(5,12)),(i:8282,v:!(5)),(i:8431,v:!(1,8)),(i:8300,v:!(1,5)),(i:8358,v:!(1,19)),(i:8392,v:!(0,1)),(i:8378,v:!n),(i:8445,v:!(5,6,9)),(i:8236,v:!(0,9)),(i:8449,v:!(1,3)),(i:8474,v:!(0)),(i:8248,v:!(0,1)),(i:8264,v:!(1,2)),(i:8447,v:!(0,1)),(i:8256,v:!(1,4)),(i:8254,v:!(3,16)),(i:8286,v:!(0)),(i:8462,v:!(0,2)),(i:8429,v:!(1,2)),(i:8458,v:!(0,1)),(i:8466,v:!(4)),(i:8400,v:!(0,7)),(i:8302,v:!(0)),(i:8278,v:!(0))),view:table),sc:1)" rel="nofollow">parametric</a>); they are tiny, low-power, and Arduino-compatible; perfect when you only need a couple of pins.</p>
<p>-Use an interrupt to monitor the button's pin; the MCU can sleep until the interrupt fires.</p>
<p>Generally:<br>
1) The interrupt will set a flag so main() knows that something happened, then wake the processor.<br>
2) Main() resumes, checks the flag, turns on/off the LED accordingly, tells the servo where to go, waits for the servo to get there (delay()), clears the flag, and then puts the MCU back to sleep.</p>
<p>-As others have pointed out, delay() is bad. delay() tells the MCU to <strong>do nothing</strong> (NO-OP) repeatedly, for a period of time. This is different from having <strong>nothing to do</strong> because it's asleep.</p>
|
8580 | |serial|mpu6050|simulator| | Simulink with arduino : data acquisition | 2015-02-11T12:26:25.183 | <p>I'm working on data acquisition from a sensor attached to the Arduino : MPU6050 using a model in Ssimulink. I have installed the hardware support in Simulink but I don't know how to start building the model. The model must read the data from the Arduino by deploying it into the Arduino.</p>
<p>My connection Arduino <=> MPU6050 is :</p>
<pre><code>Arduino MPU 9150
3.3V VCC
GND GND
A5 SCL
A4 SDA
DIGITAL 2 INT
GND AD0
</code></pre>
<p>update : i have use a s-function but I get the following error:
_The call to realtime_make_rtw_hook, during the after_make hook generated the following error: Could not download the model to the target hardware. Verify the connection between the computer and target hardware.</p>
<p>The build process will terminate as a result.</p>
<p>Caused by: Could not download the model to the target hardware. Verify the connection between the computer and target hardware._</p>
<p>But the target is definitely connected, and downloading others module (like led blinking ) with simulink is working fine. I've also tested this on a different PC with Windows 8 (64bits) with the same result. Can anyone give me a hint please?</p>
| <p>I just made my GY-521(MPU6050) work with Simulink using s-function.
I wish this would be helpful for you.</p>
<p>I am using an Arduino MEGA 2650 board. The sensor data is read in in real time.
Note that currently only Arduino MEGA 2650, Arduino MEGA 2650 ADK, and Arduino DUE support the real time windows target.
If you are using other types of board, this answer may not applied.</p>
<p>Your hardware connection looks correct. But if you have some troubles you can refer to mine for checking:</p>
<pre><code>5v VCC
GND GND
SCL SCL(check the register map of your board)
SDA SDA(check the register map of your board)
</code></pre>
<p>Above four connections are adequate if you just read raw sensor data.
INT is needed if you are going to read fused data. But I did not try that.</p>
<p>Next you may write a small program in Arduino IDE to ensure everything works.
You can refer to the Arduino MPU6050 examples.
The code written here will be used to construct your Simulink s-function later.</p>
<p>Now you can start to build your Simulink block using s-function builder.
If you did not do this before, here is a good tutorial:</p>
<p><a href="https://m.youtube.com/watch?v=_OLctOFjjYQ" rel="nofollow">https://m.youtube.com/watch?v=_OLctOFjjYQ</a></p>
<p>In our case, you need to copy Wire.h, twi.h and their .c counterparts in your current working directory where your s-function resides.</p>
<p>And do not forget to rename generated .c file to .cpp, and add external "C" declaration. All of these are illustrated in above video tutorial.</p>
<p>After all of above are done, you turn your simulation mode to external, and run.
You can view your sensor data in scope if everything goes right.</p>
<hr>
<p>Source code and configuration used in my function:
I include all headers in the <code>Libraries</code> panel of S-Function Builder,</p>
<pre><code>#ifndef MATLAB_MEX_FILE
#define ARDUINO 100
#include <Arduino.h>
#include <Wire.h>
#include <Wire.cpp>
#include <twi.h>
#include <twi.c>
#define MPU 0x68
#endif
</code></pre>
<p>Wire.* and twi.* files are copied from Arduino IDE's directory. I put these files along with my S-Function block file.</p>
<p>The address of I2C is 0x68 here.</p>
<p>Next, the code for sensor outputs are placed in <code>Outputs</code> panel. And do not forget to add ports in <code>Data Properties</code> panel.</p>
<pre><code>#ifndef MATLAB_MEX_FILE
Wire.beginTransmission(MPU);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU, 14, true);
int raw = Wire.read() << 8;
raw = raw | Wire.read();
ax[0] = (float)raw / 8192.0f;
raw = Wire.read() << 8;
raw = raw | Wire.read();
ay[0] = (float)raw / 8192.0f;
raw = Wire.read() << 8;
raw = raw | Wire.read();
az[0] = (float)raw / 8192.0f;
raw = Wire.read() << 8;
raw = raw | Wire.read();
temp[0] = (float)raw / 340.0f + 36.53f;
raw = Wire.read() << 8;
raw = raw | Wire.read();
gx[0] = (float)raw / 131.0f;
raw = Wire.read() << 8;
raw = raw | Wire.read();
gy[0] = (float)raw / 131.0f;
raw = Wire.read() << 8;
raw = raw | Wire.read();
gz[0] = (float)raw / 131.0f;
#endif
</code></pre>
<p>Finally, initialization and configuration are done in <code>Discrete Update</code> panel.</p>
<pre><code>#ifndef MATLAB_MEX_FILE
if (xD[0] != 1) {
Wire.begin();
/* Do not sleep */
Wire.beginTransmission(MPU);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
/* Gyroscope full scale range: 250 degs/s */
Wire.beginTransmission(MPU);
Wire.write(0x1B);
Wire.write(0);
Wire.endTransmission(true);
/* Accelerometer full scale range: 4g */
Wire.beginTransmission(MPU);
Wire.write(0x1C);
Wire.write(8);
Wire.endTransmission(true);
xD[0] = 1;
}
#endif
</code></pre>
<p>Please refer to your board's datasheet for specific address and LSB scales. I am using GY-521 here.</p>
|
8587 | |arduino-nano| | Arduino program wont work properly for some reason | 2015-02-11T15:10:06.680 | <p>I have a arduino program that I wrote with my teammembers. We are working on a project and try to move a RC car. Here is our code.</p>
<pre><code>int forward =12 ; //assign to correlating pin attached to TP06
int backward = 11; //assign to correlating pin attached to TP07
int left = 10; //assign to correlating pin attached to (left steer)
int right = 9; //assign to correlating pin attached to (right steer)
// TP09 & TP02 (don't remember which is left and right)
void setup() {
pinMode(forward, OUTPUT);
pinMode(backward, OUTPUT);
pinMode(left, OUTPUT);
pinMode(right, OUTPUT);
}
void move_Forward() {
digitalWrite(forward, HIGH);
digitalWrite(backward, LOW);
}
void move_Backward() {
digitalWrite(backward, HIGH);
digitalWrite(forward, LOW);
}
void turn_Left() {
digitalWrite(left, HIGH);
digitalWrite(right, LOW);
}
void turn_Right() {
digitalWrite(right, HIGH);
digitalWrite(left, LOW);
}
void stop_Completely() {
digitalWrite(forward, LOW);
digitalWrite(backward, LOW);
digitalWrite(right, LOW);
digitalWrite(left, LOW);
}
// loop will keep going while arduino has power
void loop() {
move_Forward();
turn_Left();
}
</code></pre>
<p>When we run this code, for some reason forward pin and left pins are becoming deactivated, which are the pin numbers 12 and 10. Like it does not supply voltage anymore for some reason. However right pin and backward pins, which are pins 9 and 11, which was not included in loop, works! I can run the RC car with these pins. I dont understand why this is the case. Shouldn't the left and forward pins work? If they are not working, how come? Sorry I am new to arduino programming language and its been very challenging for me and my group. Thanks in advance.</p>
| <p>First: turn off the old direction before turning on the new one. Now you're doing it the other way around.</p>
<p>Then, in your main loop you're repeating forward and left over and over. I guess you want to move forward for some time, then turn left, then move forward again, etc.<br>
But moving forward does deactivate the reverse, but doesn't change left or right. So you're always repeating commands which haven't been changed in the first place: forward will always be active, and so will left be. You'll go in a circle, I don't know if that is the idea. </p>
<p>If you want to go straight, you'll probably want to turn off both left and right? Then add a delay before turning; right now your commands occur within microseconds of each other.</p>
|
8588 | |lcd|ir| | Value of the counter collide on my lcd while decreasing. How can I remove it? | 2015-02-11T15:22:59.293 |
<pre class="lang-cpp prettyprint-override"><code>#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
int visitor=0; //variable for counting visitor number
unsigned long timer_1,timer_2; //variables for recording time for ir_1 and ir_2
void setup() {
lcd.begin(20,4);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
}
void loop(){
lcd.setCursor(0,4);
lcd.print("visitor=");
lcd.setCursor(8, 4);
lcd.print(visitor);
if(digitalRead(A0)==1 && digitalRead(A1)==0)
{
timer_1= millis();
}
if(digitalRead(A0)==0 && digitalRead(A1)==1)
{
timer_2= millis();
}
if(timer_1>timer_2)
{
lcd.setCursor(8,4);
visitor=visitor+1;
lcd.print(visitor);
delay(2000);
timer_1=0;
timer_2=0;
}
else if(timer_1<timer_2)
{
lcd.setCursor(8,4);
visitor=visitor-1;
if (visitor<=0)
{
visitor=0;
}
lcd.print(visitor);
delay(2000);
timer_1=0;
timer_2=0;
}
}
</code></pre>
<p>Two IR sensors are placed in A0 and A1.</p>
<p>While the value of <code>visitor</code> is decreasing from 10 to 9 the LCD is showing 90 because the '0' of previous 10 is here. How can I remove it?</p>
| <p>A simple option would be to call <code>lcd.clear()</code> at the start of <code>loop()</code>. That will clear the entire LCD display. Everything else should work fine because it looks like you're outputting the entire display contents every time round.</p>
<p>Alternatively, you could remove the extra digit by printing a space over it, e.g.:</p>
<pre><code>if (visitor < 10) print(" ");
lcd.print(visitor);
</code></pre>
<p>If <code>visitor</code> is a 1-digit number (i.e. less than 10), it will output a space at the start, getting rid of any underlying digits leftover from a previous iteration. If you want the number to be left-aligned then you could print the space after the number instead.</p>
|
8614 | |arduino-uno|sensors| | Choosing rangefinder for obstacle-avoiding | 2015-02-13T00:37:52.733 | <p>I am looking to buy a range finder module for an obstacle avoidance robot.
Currently, two good options based on available libraries and compatibility with Arduino and rPI are HC-SR04 and parallax ping. </p>
<p>In terms of form factor these seem the same. The only difference I can tell is 4 pins vs 3 pins. Also the price, with parallax being more than x4 the price. As I would rather not buy something cheaper which will need replacing, is anyone aware of further differences, that will make the parallax a better option? </p>
<p>both need 5V
both have max range of 3-4m
Sensor angle HC- 15 degrees, parallax cant find..</p>
| <blockquote>
<p>Odds are pretty good they are real close. I've only used the sr04 with
4 pins (too lazy to mod) and it was ok. cant say if the parallax is
better or not. For 4 times the price you'd expect it to be, but so far
in robotics, price seldom reflect performance in my experience. –
Spiked3</p>
</blockquote>
<p>I've also used the SR (with 4 pins) and it worked great. <2$ on eBay</p>
|
8616 | |serial|bluetooth|arduino-nano|softwareserial| | Send array of Infrared codes | 2015-02-13T10:16:23.407 | <p>I'm having a bit of a problem when sending IR Codes stored in variables. I swear I had this convered up already. I don't actually know the reason why I can't use variables in the first place. I receive data over Bluetooth Serial Com and I'm using an Arduino ProMicro as ISP for the Arduino Nano.</p>
<p>I want to send data over Serial comm and then send an IR code to the end receiver.</p>
<p>Here is some of the code():</p>
<pre><code>#include <IRremote.h> // IR Library - Encode/Decode
void irSerial( char SerChar[] ) // Receive array of characters
char IDChar[]={'s', 'i', 'u'}; // List of Serial Char to identify position
String HRD[]={"Power", "Input", "ChaUp"}; // Action referece
byte CodesIR[]={0x61A0F00F, 0x61A048B7, 0x61A050AF}; // IR Codes
int IRArray = 2; // Size Of The array
if ( SerChar[0] == 's' ) { // Compare Array
for (int CountIR = 0; CountIR <= IRArray; CountIR++){ // Loop through array
if ( SerChar[0] == IDChar[CountIR]) {
bluetooth.println(HRD[CountIR]); // Send String in array - Works
SendIR.sendNEC(CodesIR[CountIR],32); // Send IR in array position
}
}
}
}
</code></pre>
<p>There's not a problem with the current expression as it compiles normally and I can send serial data normally finishing the function. If I replace the array <strong>CodesIR[CountIR]</strong> for example with <strong>0x61A0F00F</strong> then it works perfectly.</p>
<p>How can I use a variable instead? Can anyone help? It is the <strong>byte CodesIR[]</strong> ??</p>
<p>I used a <strong>Switch/Case</strong> and it works but I prefer a variable/array and less useless coding. Thanks for understanding!</p>
| <p>Well as usual it was something stupid (-__-) I changed the <strong>byte</strong> array for <strong>long</strong> and it worked perfectly.</p>
<p>Here is the complete code working(): </p>
<pre><code>#include <IRremote.h> // IR Library - Encode/Decode
void irSerial( char SerChar[] ) { // Receive array of characters
char IDChar[]={'s', 'i', 'u'}; // List of Serial Char to identify position
String HRD[]={"Power", "Input", "ChaUp"}; // Action reference
long CodesIR[]={0x61A0F00F, 0x61A048B7, 0x61A050AF}; // IR Codes
int IRArray = 3; // Size Of The array # Edit
if ( SerChar[0] == 's' ) { // Compare Array
for (int CountIR = 0; CountIR < IRArray; CountIR++){ // Loop through array # Edit
if ( SerChar[0] == IDChar[CountIR]) {
Serial.println(HRD[CountIR]); // Send String in array - Works
SendIR.sendNEC(CodesIR[CountIR],32); // Send IR in array position
}
}
}
}
</code></pre>
|
8620 | |i2c|arduino-leonardo| | Interfacing Arduino Leonardo with PCA8574AN | 2015-02-13T12:53:23.170 | <p>I'm trying to interface my Leonardo with a "Mindsensors Magic Wand" - 8 LEDs connected to a PCA8574AN chip.
On the manufacturer's page, they say it's compatible with Arduino, however no instructions or code are given.
<a href="http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=120" rel="nofollow">http://www.mindsensors.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=120</a></p>
<p>I've connected the SDA, SCL, 5v, and GND connectors on the arduino to the device, but have had no luck in communicating with it. None of the LEDs light up regardless of input.</p>
<p>I can verify that power is being supplied.
The i2c address of the device is 0x70.
Code is below.</p>
<pre><code>#include "Wire.h"
#define TWBR=400000L
void setup() {
// put your setup code here, to run once:
Wire.begin();
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
Wire.beginTransmission(0x70);
Wire.write(32);
Wire.endTransmission();
}
</code></pre>
| <p><strong>tl;dr:</strong> It seems like you need to send a null bit (0) to terminate the communication with this board.</p>
<p>In the downloads section, I found a .nxc file, which I assume is a NXT code file.</p>
<p>In the main loop, they configure the I2C port and a "touch sensor" (I believe this is to figure out how to synchronize the text with the motor). In that, there is a main loop in which they call <code>DispLetter</code>.</p>
<p>This is the <code>DispLetter</code> function:</p>
<pre><code>void DispLetter (const byte & letter[])
{
int nbytes;
// Wait for the end of previously sent data
while(I2CStatus(I2Cport, nbytes)==STAT_COMM_PENDING);
// Write buffer to send to PCF8574
byte WriteBuf[];
ArrayBuild(WriteBuf, I2CAddr8574, letter);
for(int i=1; i<ArrayLen(WriteBuf); i++)
{
WriteBuf[i] ^= 0xff;
}
I2CWrite(I2Cport, 0, WriteBuf);
}
</code></pre>
<p>Let's read this code! First of all, it seems to make sure that the I2C port is connected, which we don't really have to worry about in our case since that's platform-specific.</p>
<p>After that, they create an array called <code>WriteBuf[]</code> that will store the data to be sent to the controller. Then we come across a function called <code>ArrayBuild</code>. Looking that up, it combines <code>I2CAddr8574</code> and <code>letter</code> and places it into the <code>WriteBuf</code> array. (<a href="http://bricxcc.sourceforge.net/nbc/nxcdoc/nxcapi/group___array_functions_gae8d75e08c670f09f01200a897d7ed2ba.html" rel="nofollow">Click here for documentation for that function.</a>) Please note that the <code>I2CAddr8574</code> is just a byte containing 0x70 (the address of the chip), so we will not have to do this step since the Arduino handles the address. So, you will just have to send the <code>letter</code> array to the controller, ignoring the <code>WriteBuf</code> and <code>ArrayBuild</code>!</p>
<p>Let's figure out how <code>letter</code> is passed. In the main loop, they had this code:</p>
<pre><code>DispLetter(L_);
DispLetter(E_);
DispLetter(G_);
DispLetter(O_);
</code></pre>
<p>That must display "LEGO." Let's figure out what <code>L_</code> is defined as. At the beginning of the document, they have this defined:</p>
<pre><code>// Display patterns
// Each byte represents a column of dots
// Bit set to 1 means lit LED.
// Least significant bit is at top of column.
// Last byte must be all 0
// Maximum number of bytes par pattern: 15
byte L_[] = {0xff, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0};
byte E_[] = {0xff, 0x89, 0x89, 0x89, 0x89, 0x81, 0x81, 0};
byte G_[] = {0x7e, 0x00, 0x81, 0x81, 0x81, 0x81, 0x91, 0x90, 0x72, 0};
byte O_[] = {0x7e, 0x00, 0x81, 0x81, 0x81, 0x81, 0x81, 0x00, 0x7e, 0};
byte La_[] = {0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0xff, 0};
byte Ea_[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0};
byte Ga_[] = {0x72, 0x90, 0x91, 0x81, 0x81, 0x81, 0x81, 0x00, 0x7e, 0};
byte Oa_[] = {0x7e, 0x00, 0x81, 0x81, 0x81, 0x81, 0x81, 0x00, 0x7e, 0};
byte N_[] = {0xff, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0xff, 0};
byte X_[] = {0x80, 0x41, 0x22, 0x14, 0x08, 0x14, 0x22, 0x41, 0x80, 0};
byte T_[] = {0x01, 0x01, 0x01, 0x01, 0xff, 0x01, 0x01, 0x01, 0x01, 0};
</code></pre>
<p>As you can see, they listed out how the dots are configured. There's a max of 15 bytes (I assume including the null bit).</p>
<p>There's one more piece of code that we haven't talked about:</p>
<pre><code>for(int i=1; i<ArrayLen(WriteBuf); i++)
{
WriteBuf[i] ^= 0xff;
}
</code></pre>
<p>So it goes through each bit, and does something to it. That is the shorthand for this:</p>
<pre><code>WriteBuf[i] = WriteBuf[i] ^ 0xff;
</code></pre>
<p>No, that is <em>not</em> an exponent. That is an exclusive OR, a <em>bitwise</em> operator. A bitwise operator is basically where it "overlays" the two binary sequences and it does a special computation on them. If the nth bit of each input number is 1 or the nth bit of each input number is 0, the nth output bit is 0. If the nth bit of one input number is 1 and the nth bit of the other input number is 0, then the nth bit of the output is 1.</p>
<p>Since 0xff = B11111111, it will essentially reverse the values of each bit. You can avoid this if you say that a bit set to <em>0</em> is on, instead of a bit set to <em>1</em> (like they do in the example code). A minor adjustment that just makes your life a bit easier :)</p>
<p>After that, you can write that array to the I2C bus and it should display the data!</p>
|
8630 | |arduino-uno|serial|usb|python| | Arduino Raspberry Pi USB Communication | 2015-02-14T02:01:24.867 | <p>I am trying to connect an Arduino and Raspberry Pi over USB. I would like to send serial commands, just like the serial monitor in the Arduino IDE. I know how to do this on the Arduino end but I'm not sure how to send/receive serial communication on the Pi end. Ideally the solution would utilize Python.</p>
| <p>You will need PySerial to accomplish this. A tutorial on interfacing Arduino and the RPi using a usb can be found <a href="http://blog.oscarliang.net/connect-raspberry-pi-and-arduino-usb-cable/" rel="nofollow">here</a></p>
|
8647 | |sketch|variables|code-optimization| | Program button to switch between two values | 2015-02-14T19:58:04.153 | <p>There is a function on one of my programs I want to be switch on and off by pressing a button. The button is unbiased otherwise I would set the function to read the button's status of HIGH or LOW.</p>
<p>So I need to create variable named "switch" with an initial value of 0. Then I would create a function would read if buttonPin is HIGH change the value of "switch" by +1. Next time the buttonPin is HIGH change the value by -1 so that every time the button is pressed the value of "switch" alternates between 1 and 0. Now before my loop calls the function I want on or off it can compare the value of "switch" and run or not run the function.</p>
<p>I don't know how to express this in the Arduino sketch. I'm am also open to alternate ways of achieving the same result. </p>
| <p>It sounds like you are using a number as a boolean (true/false) value.</p>
<p>You might consider using a a boolean instead.</p>
<pre><code>boolean value = false;
if button is pressed {
value=!value
}
if value {
// do something here.
}
</code></pre>
<p>You can set it to <code>true</code> or <code>false</code>, or change it to it's opposite (with <code>value=!value</code> as shown above). You can also do <code>if value</code> or <code>if !value</code> ("if not value") - these are equivalent to <code>if value=true</code> or <code>if value=false</code>. </p>
|
8661 | |programming|c++|sketch|c| | Programming arduino with Objective-C | 2015-02-15T17:48:09.020 | <p>Can you use <code>clang</code>, with <code>--mpu=arm</code>, etc. and <code>avrdude</code> to program an Arduino Due (Arm Cortex M3)?</p>
| <p>It can be done, however, it is inadvisable. In order to implement this, one must implement the Objective-C runtime, which, though not insurmountable, is very near insurmountable as far as difficulty is concerned. Perhaps someday some brave soul will see fit to grace the world with their custom Arduino Objective-C runtime, but until that day, the rest of us mere mortals have naught to do but wait for the coming of the Objective-C prophet.</p>
<p>If there are any brave souls in the audience who wish to take on this ultimate challenge, then let them. But otherwise, keep the code in C and hold your peace.</p>
|
8666 | |library| | How Do I Send An Email WITHOUT An Ethernet or WiFi Shield | 2015-02-16T00:32:24.947 | <p>I can only find info relating to the wifi shield, but I want to send an email without the wifi shield. For now, I just plan on leaving my arduino plugged into a computer, so I just want to use the computer's network connection. Is there a library or something I can grab for this?</p>
| <p>If you mean plugged-in via USB, then no. There's nothing you can do on the Arduino that would let you use the computer's network connection directly.</p>
<p>You would need to have a program running on the computer which would communicate with the Arduino via serial. It would effectively act as an intermediary, sending the email on behalf of the Arduino.</p>
<p>Unfortunately, I suspect you'd have to write the program yourself. It's possible that something similar already exists, but at the very least you'd probably have to modify it to suit your needs.</p>
|
8671 | |arduino-uno|atmega328|timers| | Stable frequency generation | 2015-02-16T07:53:41.223 | <p>I'm trying to work out the best way to generate a stable frequency with my Uno R3</p>
<p>I'm using interrupts to generate an approximately 40KHz frequency which drives some ICs/MOSFETs to effectively generate 40KHz AC which powers a transducer. </p>
<p>I need to receive the frequency at a second transducer and calculate any frequency shifts.</p>
<ul>
<li><p>The problem is that the generated frequency drifts a little bit off of 40KHz. Is there a way to lock it in at 40KHz via software? I'm receiving approximately 40KHz output (as measured using PicoScope software) with this code:</p>
<pre><code>#define LEDPIN 13
void setup()
{
pinMode(LEDPIN, OUTPUT);
// initialize Timer1
cli(); // disable global interrupts
TCCR1A = 0; // set entire TCCR1A register to 0
TCCR1B = 0; // same for TCCR1B
// set compare match register to desired timer count:
OCR1A = 24;
// turn on CTC mode:
TCCR1B |= (1 << WGM12);
// Set CS11 for 8-bit prescaler:
TCCR1B |= (1 << CS11);
// enable timer compare interrupt:
TIMSK1 |= (1 << OCIE1A);
// enable global interrupts:
sei();
}
void loop()
{
// main program
}
ISR(TIMER1_COMPA_vect)
{
digitalWrite(LEDPIN, !digitalRead(LEDPIN));
}
</code></pre></li>
<li><p>If there isn't a way to lock it in, is there atleast a way for the Uno to accurately display/store the frequency of the signal it generated at a given time?</p>
<p>Or is this not plausible because the Uno would "think" it is generating 40KHz?</p></li>
</ul>
<p>Thanks for any hints or suggestions.</p>
<p><strong>EDIT:</strong> @RussellMcMahon pointed me in the right direction for this, so I accepted his answer. However, I wanted to share my final code and my misconceptions I encountered. Hopefully this will assist someone else in the future. I'm obviously by no means an expert, and I will try to not give any misleading information here.</p>
<p>My original goal was, although poorly stated, to generate as clean a 40KHz PWM with 50% duty cycle as possible.</p>
<p>Problems with my original code above were:</p>
<ul>
<li>Using an 8-bit pre-scaler</li>
<li>Using an interrupt</li>
<li>Using digitalWrite()</li>
</ul>
<p><strong>8-Bit Pre-Scaler</strong> <br>
The problem here was that the counter only ticked over once every 8 clock cycles. <em>16MHz clock / 8 (pre-scaler) = 2MHz clock</em> When I asked one of my professors about this he stated something along the lines of "a cycle could be missed due to an interrupt, and would cause it to wait 7 more cycles to 'tick'". Indeed I was originally using interrupts, and when we did the calculations it seemed like it could plausibly cause up to a a 1KHz swing at 40KHz.<br>
To rectify this I took out the pre-scaler, and ran straight at the base clock speed to increase resolution.<br></p>
<p><strong>Using an interrupt</strong><br>
Essentially the interrupt could cause clock cycles to not be counted, further complicated by using an 8-bit pre-scaler. If one clock cycle was missed, with a 2MHz clock (after pre-scale), you add 5E-7 seconds to the counter, changing the output frequency.<br><br></p>
<p><strong>Using digitalWrite()</strong><br>
The digitalWrite function is pretty slow. I'm not a guru, but I read this in multiple places and there seems to be a good comparison of methods here: <a href="http://www.billporter.info/2010/08/18/ready-set-oscillate-the-fastest-way-to-change-arduino-pins/" rel="nofollow noreferrer">Digital Pin Oscillation</a> To get around this problem it had been suggested I toggle a single bit, which is what I set out to do in my final code. (It is worth noting, now that I've completed this project, that the previous link also makes reference to a <a href="http://forum.arduino.cc/index.php/topic,46896.0.html" rel="nofollow noreferrer">library addition</a> for faster digitalWrite/Read/etc....)
<Br><br>
I went through a few variations and scrounged code from all over, and made a couple working examples but they didn't do it the way I wished. I believe part of the project I based this version off of was a melding between a previous version I had working and a class example I found online.<br><br>
Without further ado, I present the code that took me an embarrassing amount of time to write from numerous sources... I really should tinker with this stuff more often:<br><br></p>
<pre><code>#include <avr/io.h>
#include <avr/interrupt.h>
void setup()
{
//Disable interrupts
cli();
// Clear Timer1 registers
TCCR1A = 0;
TCCR1B = 0;
// Set OCR1A (TOP): 16MHz/40KHz /2 = 200 steps.
// Divide 200 by 2 = 100 because waveforms are centered around OCR1A (because toggle)
OCR1A = 100;
// Configure Timer/Counter 1
// Select P & F Correct PWM Mode, and OCR1A as TOP. Use WGM Bits 10 and 13.
// WGM Bits are in TCCR1A and TCCR1B. Any previous settings are cleared.
// Enable COM1A0 to toggle OC1A on compare match
TCCR1A = _BV(WGM10) | _BV(COM1A0);
// CS10 to enable base clock without pre-scale
TCCR1B = _BV(WGM13) | _BV(CS10);
//Set OC1A (Digital Pin 9 / Port B Pin 1) to output
DDRB |= _BV(1);
}
void loop()
{
}
</code></pre>
<p><br> For reference, here is the clock frequency formula. In this instance, I had to divide the result by 2 again since I am toggling.<Br>
<img src="https://i.stack.imgur.com/g1u6n.png" alt="Clock frequency formula"></p>
<p><br></p>
<p>Resultant output verified by PicoScope:
<img src="https://i.stack.imgur.com/NdgbK.png" alt="Picoscope Oscilloscope Trace"></p>
<p><br>
In closing, you will notice that it isn't exactly 40KHz. Research turned up that the Arduino Uno makes use of a less accurate ceramic resonator to clock the ATMEGA328P (although a 16MHz crystal oscillator is onboard to clock the USB). To further increase accuracy in a generated signal will require the Arduino to be driven with an external clock source.</p>
| <p>PWM is the solution.</p>
<p>Russel's answer is proper. My contribution here is a simplification and to relay my observations. I made a <a href="https://arduino.stackexchange.com/questions/68106/set-pwm-by-period-and-have-it-variable">QA about PWM</a> recently and can affirm that "bit banging" and interrupts are not going to be stable. I observed digital writes to be roughly 1 microsecond, so toggling a pin is 2 µsec. This did not affect my project, so no further tests performed about the <code>digitalWrite()</code> function. Writing changes to the port macro as a whole is much faster than using <code>digitalWrite()</code>, however this still will not have the inherent stability setting up the PWM and its output pin will provide. <em>Anecdotally, analogRead() is roughly 100 µsec.</em></p>
<p>I set up my timer with a prescaler and then applied a count to <code>OCRxA</code>. Via my prescaler and <code>WGM</code> bits, it turns out that the <code>OCR</code> registers were 1:1 for microseconds. <code>OCRxB</code> perfectly set the pulse width I was seeking. </p>
<p>Observing the period on an o'scope, it might have been off from the exact integer in <code>OCRxA</code> but did not drift. The error I observed was in the tens of microseconds and the values in <code>OCRxB</code> were between 6300 and 63000. Code examples are in aforementioned link to my QA. From researching my own solution, I learned this error is likely within tolerance of the crystal providing CPU freq.</p>
|
8678 | |arduino-uno|serial|bluetooth| | Bluetooth hc-06 and Standalone Atmega168(possible?) | 2015-02-16T17:32:34.990 | <p>I am making a project that requires bluetooth communication between a Raspberry Pi(equipped with a bluetooth dongle) and a standalone atmega168 circuit. </p>
<p>I want to be able to transfer information serially between the two devices over bluetooth. </p>
<p>I have selected the hc-06 for the arduino and some usb bluetooth dongle for the PI. </p>
<p>I would like to know if connecting the hc-06's TX and RX pins to the RX and TX (respectively) pins of my atmega will work or not. If not, I would like to know how to achieve that (bluetooth on a standalone arduino-powered microcontroller)</p>
| <p>The HC-0x Bluetooth transceivers are a drop-in replacement for a serial connection. Once the transceiver is configured (with baud-rate, device name, and pairing PIN #) you can plug it in in place of a serial line and expect to communicate. The device will take care of pairing and accepting a connection from the master device with no need for any code support from the AVR.</p>
<p>I use a separate program on an Arduino or a breadboarded AVR to configure my HC-06es. They retain their configuration across a power-down, and in fact, there is no hardware support for resetting them to a standard configuration; you need a program that figures out their current baud-rate in order to reconfigure them. It can save a bunch of hassle if you write down their configurations whenever you change them.</p>
|
8679 | |c++|linux| | Compile problem when using keyword 'new' on Raspberry Pi | 2015-02-16T18:19:01.043 | <p>I have the following line of code in my Arduino sketch:</p>
<pre><code>static double *temps = new double[arraySize]; //Declare array to hold tempratures, place the array on the heap where it will not be deleted and keep the pointer as a static
//double temps[arraySize];
</code></pre>
<p>When I compile with the Arduino IDE on Ubuntu it compiles just fine. However, when I compile on the Raspberry Pi, it throws up the following error:</p>
<pre><code>xxx.cpp.o: In function `last Function in file()':
xxx.cpp:[last line in file]: undefined referance to `operator new[] (unsigned int)'
collect2: error: ld returned 1 exit status
</code></pre>
<p>Is this a bug? If so, how do I report it? If not, why is it throwing this error or how else can I declare a static array of doubles (needs to be static, I calculate an average of some incoming data over several function calls)?</p>
| <blockquote>
<p>how else can I declare a static array of doubles (needs to be static,
I calculate an average of some incoming data over several function
calls)</p>
</blockquote>
<p>When you find a bug in the Arduino software, please do report it to the appropriate place -- <a href="http://arduino.cc/en/Main/ContactUs" rel="nofollow">http://arduino.cc/en/Main/ContactUs</a> has the contact details.</p>
<p>One way to declare a static array of doubles is like this:</p>
<pre><code>double boxcar_average(double new_sample) {
const int arraySize = 3;
static double old_sample[ arraySize ] = {0};
double sum = new_sample;
for(int i=0; i<arraySize; i++){
sum += old_sample[i];
}
old_sample[0] = old_sample[1];
old_sample[1] = old_sample[2];
old_sample[2] = new_sample;
return( sum / 4 );
}
</code></pre>
|
8681 | |programming|sketch| | What do these operators do? | 2015-02-16T19:51:56.820 | <p>Going through the "timeouts" example of the elapsedMillis library (<a href="https://github.com/pfeerick/elapsedMillis" rel="nofollow">https://github.com/pfeerick/elapsedMillis</a>) I found the following statement:</p>
<p>digitalWrite(LEDPIN, flashPattern[ledIndex++] ? ledBrightness : !ledBrightness);</p>
<ul>
<li>flashpattern is an array of boolean variables (boolean flashPattern[] = { 1,1,1,1,1,1,1,0,1,1,0 };)</li>
<li>ledBrightness is a boolean as well. </li>
</ul>
<p>What does the "?" and the ":" do there? are these boolean operators? </p>
| <pre><code>A ? B : C;
</code></pre>
<p>is shorthand for</p>
<pre><code>if(A) {
B;
} else {
C;
}
</code></pre>
|
8704 | |arduino-nano| | delay() vs delayMicroseconds() | 2015-02-18T02:40:11.170 | <p>I just started using Arduino and so far I've used both <code>delay()</code> and <code>delayMicroseconds()</code>. I was wondering what the difference between these two is, because it seems to me that they're the same.</p>
| <p>From <a href="http://arduino.cc/en/reference/delay" rel="nofollow">the documentation</a>:</p>
<blockquote>
<h1>delay()</h1>
<h2>Description</h2>
<p>Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.) </p>
</blockquote>
<p>So... milliseconds vs. microseconds.</p>
|
8706 | |arduino-due|library|compile| | Why doesn't the Micro OLED library compile on my DUE? | 2015-02-18T03:13:12.053 | <p>I have an Arduino <code>DUE</code> and just got a <code>Micro OLED</code> display from SparkFun.</p>
<p>Using their library, when I try to compile I get the error below. Other example code works just fine and I've programmed this thing a million times with my code. So it's clearly in the SparkFun code.</p>
<p>Here is the SparkFun tutorial page with a description of the product:</p>
<p><a href="https://learn.sparkfun.com/tutorials/micro-oled-breakout-hookup-guide?_ga=1.19136059.2055231411.1404437767" rel="nofollow">https://learn.sparkfun.com/tutorials/micro-oled-breakout-hookup-guide?_ga=1.19136059.2055231411.1404437767</a></p>
<p>Here is the library I am using:</p>
<p><a href="https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED" rel="nofollow">https://github.com/sparkfun/Micro_OLED_Breakout/tree/master/Firmware/Arduino/libraries/SFE_MicroOLED</a></p>
<p>Here is the error I get:</p>
<pre><code>Build options changed, rebuilding all
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp: In member function 'void MicroOLED::spiSetup()':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:46:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
ssport = portOutputRegister(digitalPinToPort(csPin));
^
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:48:51: error: 'portModeRegister' was not declared in this scope
ssreg = portModeRegister(digitalPinToPort(csPin));
^
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp: In member function 'void MicroOLED::i2cSetup()':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:84:2: error: 'TWBR' was not declared in this scope
TWBR = ((F_CPU / I2C_FREQ) - 16) / 2;
^
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp: In member function 'void MicroOLED::parallelSetup()':
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:109:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
ssport = portOutputRegister(digitalPinToPort(csPin));
^
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:111:51: error: 'portModeRegister' was not declared in this scope
ssreg = portModeRegister(digitalPinToPort(csPin));
^
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:114:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
wrport = portOutputRegister(digitalPinToPort(wrPin));
^
/Applications/Arduino.app/Contents/Resources/Java/libraries/SFE_MicroOLED/hardware.cpp:119:10: error: cannot convert 'RwReg* {aka volatile long unsigned int*}' to 'volatile uint8_t* {aka volatile unsigned char*}' in assignment
rdport = portOutputRegister(digitalPinToPort(rdPin));
^
Error compiling.
</code></pre>
| <p>That library is uses some AVR specific methods, that aren't implemented for the ARM processor in the Due. </p>
<p>I don't see a real easy way to port those methods.</p>
|
8711 | |serial|programming|usb| | Connect Arduino via TX RX Pins to Computer's USB Port | 2015-02-18T08:37:27.117 | <p>I want to avoid using the big USB B connector to program my Arduino Mega. Since there are those RX TX Pins I thought, it would be possible, to connect my USB - Wires from my PC directly to those RX TX Pins. <code>D+ -> TX and D- RX</code>. <a href="https://arduino.stackexchange.com/questions/3772/can-tx-and-rx-pins-on-the-uno-be-used-like-regular-digital-pins">This Post on Arduino Stackexchange</a> says, those wires are just connected, while <a href="https://arduino.stackexchange.com/questions/4652/usb-d-d-to-arduino-mega-rx-tx">this post</a> says the exact opposite. </p>
<p>I'm confused. Is it possible or would I damage my board when connecting USB wireq to RX / TX pins on my Arduino?</p>
| <p>The first answer that you cite that you say says it is possible is in fact not talking about what you are referring to - it is discussing the use of the RX & TX pins directly when they are not being used for USB connection.</p>
<p>The second answer you cite is technically incorrect but "correct enough" in the context.</p>
<p>The answer to your question is "It can be done but it requires a different boot loader, its slower, its technically inferior, it's less standard, it requires a degree of understanding (on someone's part) to get it going, and <strong>it can be done</strong> </p>
<p>It IS possible to access USB directly from digital I/O pins. As TX & RX are also standard digital I/O pins they could be used for this purpose BUT you need dedicated bootloader code to do this and it has inferior performance if a USB to serial converter is available. The eg ADAFruit Arduino Trinket uses this system. </p>
<hr>
<p>Here is how the (or a) <a href="http://www.embedded-creations.com/projects/attiny85-usb-bootloader-overview/details" rel="nofollow noreferrer"><strong>ADAFRUIT Trinket Bootloader</strong></a> works. (The Trinket is not mentioned here but I'm told that this is what it uses. If not, it works in functionally the same manner). </p>
<p>This is in turn based on the <a href="http://www.obdev.at/products/vusb/usbasploader.html" rel="nofollow noreferrer"><strong>USBaspLoader</strong></a></p>
<p>A (very) simple "more or less Arduino compatible" development board which can use this system is <a href="https://metalab.at/wiki/Metaboard" rel="nofollow noreferrer">Metaboard</a>. It's circuit diagram is shown below. As can be seen - it uses an ATMega168 and the USB connection is made to two standard digital I/O pins.</p>
<p><img src="https://i.stack.imgur.com/ScLWt.jpg" alt="enter image description here"></p>
<p><strong>"Metaboard" using ATMega168</strong> </p>
<ul>
<li>note USB connection to pins PD2 & PD4 - NOT via RXD on PD0 and TXD on PD1 via a serial to USB converter, as is more usual. </li>
</ul>
<hr>
<p>AND another version: <a href="http://www.fischl.de/avrusbboot/" rel="nofollow noreferrer"><strong>AVRUSBBOOT</strong></a></p>
<p><img src="https://i.stack.imgur.com/uMRel.png" alt="enter image description here"></p>
<hr>
<p>And <strong>again</strong></p>
<p><a href="http://www.obdev.at/products/vusb/bootloadhid.html" rel="nofollow noreferrer"><strong>BootloadHID</strong></a> They say -</p>
<ul>
<li><p>BootloadHID is a USB boot loader for AVR microcontrollers. The uploader tool requires no kernel level driver on Windows and can therefore be run without installing any DLLs.</p>
<p>BootloadHID is a USB boot loader for AVR microcontrollers. It can be used on all AVRs with at least 2 kB of boot loader section, e.g. the popular ATMega8. The firmware is flashed into the upper 2 kB of the flash memory and takes control immediately after reset. If a certain hardware condition is met (this condition can be configured, e.g. a jumper), the boot loader waits for data on the USB interface and loads it into the remaining part of the flash memory. If the condition is not met, control is passed to the loaded firmware.</p>
<p>This boot loader is similar to Thomas Fischl’s avrusbboot, except that it is built on top of the HID device class. This implementation is more user friendly on Windows, since no kernel level drivers need to be installed.</p></li>
</ul>
|
8719 | |shields|ethernet| | Didn't have MAC address on Wiznet based ethernet shield (cloned) | 2015-02-18T14:04:06.627 | <p>My Ethernet shield dont have any MAC address, please tell me how to find the MAC address, I'm stucked! Here is the link from where I bought the Ethernet shield.<br>
<a href="http://www.amazon.in/gp/product/B00AXVX5D0?ie=UTF8&at=&force-full-site=1&ref_=aw_bottom_links" rel="nofollow">http://www.amazon.in/gp/product/B00AXVX5D0?ie=UTF8&at=&force-full-site=1&ref_=aw_bottom_links</a></p>
| <p>Ethernet will work as long as two different machine in the LAN don't have the same MAC address, as @Nathan wrote in his answer.</p>
<p>The MAC address <a href="http://en.wikipedia.org/wiki/MAC_address#Address_details" rel="nofollow">is built by two parts</a>, a prefix which are given to manufacturers of network devices and is called <em>OUI</em>, and a suffix that is the node part that manufacturers can use as they wish.</p>
<p>If you want to build an MAC address yourself, use a <em>Locally administered</em> address. Universally administered and locally administered addresses are distinguished by <a href="http://en.wikipedia.org/wiki/MAC_address#Address_details" rel="nofollow">setting the second-least-significant bit of the most significant byte of the address</a>.
That will make this address to not use any OUI prefix, as that bit is zero on OUI, which minimize the risk of two or more devices have the same MAC address in same LAN. </p>
<p>If you get the same MAC addresses you will get very strange results if they happen to be in the same LAN, I tell you. Been there, done that, and it wasn't fun to debug.</p>
<p>Here are a <a href="http://www.macvendorlookup.com/" rel="nofollow">site that looks up MAC addresses</a> (and generate random ones). But if you want to see which manufacturer have that MAC address, <a href="http://standards.ieee.org/develop/regauth/oui/public.html" rel="nofollow">you read it from IEEE and their list</a>. </p>
|
8730 | |usb| | USB to TTL with switchable 5v and 3.3v in one | 2015-02-18T18:36:04.007 | <p>are there any USB to TTL with switchable 5v and 3.3v </p>
<p>i need to use it for raspberry pi and arduino</p>
| <p>Many 3.3V FTDI based devices are 5V tolerant and will work with both:</p>
<ul>
<li><a href="https://www.adafruit.com/product/284" rel="nofollow">Adafruit's FTDI friend</a></li>
<li><a href="https://www.sparkfun.com/products/11736" rel="nofollow">Sparkfun FT231X Breakout</a></li>
</ul>
<p>Here is general information about logic levels: <a href="https://learn.sparkfun.com/tutorials/logic-levels" rel="nofollow">https://learn.sparkfun.com/tutorials/logic-levels</a></p>
|
8732 | |arduino-motor-shield|adafruit| | Adafruit motorshield disconnected but getting current from Arduino | 2015-02-18T20:16:32.153 | <p>my Adafruit motorshield is getting current from Arduino board even after disconnected from battery. I was planning to give separate dc power from 6 AA cells to motor shield but not sure if extra current will enter into Arduino and damage it. I have Ultrasonic sensor connected to motorshield which is getting +5v from board (may be Arduino).</p>
<p>Please suggest how to solve this problem.</p>
<p>Thanks</p>
| <p>If all else fails, read <a href="https://learn.adafruit.com/downloads/pdf/adafruit-motor-shield.pdf" rel="nofollow noreferrer"><strong>The Manual</strong></a></p>
<p><strong>The manual indicates that it is intended that the MS electronics may be operated by the Arduino power supply while using a separate external supply for the motor.</strong></p>
<p>Pages 37 to 39 explain about powering options.<br>
The Arduino and the shield interconnect all of : 3V, 5V, Vin.<br>
3V may not be used by the shield. </p>
<p>Arduino Vin to MS V+ is broken by jumper "PWRJMP" - purple rectangle in diagram below.<br>
Arduino 5V to MS Vcc is not interrupted by a jumper - See labels in red squares below.</p>
<p><img src="https://i.stack.imgur.com/LF9QF.jpg" alt="enter image description here"></p>
<hr>
<p>You did not say what version shield you had or which Arduino or what you mean by "disconnected from battery" or supply any links to relevant documents. ALL of these things will help people to help you better. </p>
<p>Assuming latest MS version, </p>
<p><a href="http://www.adafruit.com/product/81" rel="nofollow noreferrer">adafruit motor shield v1.2</a> - discontinued.</p>
<p><a href="https://raw.githubusercontent.com/adafruit/Adafruit-Motor-Shield-for-Arduino/master/mshieldv12schem.png" rel="nofollow noreferrer">github v1.2 schematic</a> this appears to be pre V2 BUT is linked to from a ference in the V2 manual so is probably "more or less correct".</p>
<p><a href="https://learn.adafruit.com/downloads/pdf/adafruit-motor-shield-v2-for-arduino.pdf" rel="nofollow noreferrer"><strong>adafruit motor shield v2 manual</strong></a> - <strong>probably what you have</strong></p>
<p><a href="https://learn.adafruit.com/adafruit-motor-shield/use-it" rel="nofollow noreferrer">adafruit current MS page</a></p>
<p>This probably tells you what you need to know. Manual page 37-38</p>
<ul>
<li><p>How to set up the Arduino + Shield for powering motors</p>
<p>Servos are powered off of the same regulated 5V that the Arduino uses. This
is OK for the small hobby servos suggested. If you want something beefier, cut the trace
going to + on the servo connectors and wire up your own 5-6V supply!</p>
<p><strong>The DC motors are powered off of a 'high voltage supply' and NOT the regulated 5V.</strong><br>
Don't connect the motor power supply to the 5V line. This is a very very very bad idea unless you are sure you know what you're doing!</p>
<p>There are two places you can get your motor 'high voltage supply' from. One is the DC jack on the Arduino board and the other is the 2-terminal block on the shield that is
labeled EXT_PWR. The DC Jack on the Arduino has a protection diode so you won't be able
to mess things up too bad if you plug in the wrong kind of power. However the EXT_PWR
terminals on the shield do not have a protection diode (for a fairly good
reason). Be utterly careful not to plug it in backwards or you will destroy the motor
shield and/or your Arduino!</p></li>
</ul>
|
8733 | |atmega328| | What are the implications of running an ATmega328P at 8 MHz and 3.3 V with the Arduino system? | 2015-02-18T22:58:16.930 | <p>I'm working on a custom arduino that will run at 3.3 V with no regulators or USB chips (for power consumption). I've heard that overclocking the chip at 16 MHz/3.3 V is generally fine, but I'd like to stay within spec anyway.</p>
<p>First: to run at 8 MHz, do I just need to replace the crystal? Or is there anything else I have to do?</p>
<p>Second: Do I need to make any code changes to reflect the new speed? I'm using serial, SPI, and I2C connections in this project, along with the NilRTOS operating system and millis/delay functions. Will any of these be broken? Will the code run noticeably slower?</p>
<p>Third: How can I program the chip? Is it ok to program it in an Arduino Uno at 16 MHz, then transplant it to the custom arduino?</p>
<p>Fourth: Will power consumption change at 8 MHz?</p>
<p>Thanks!</p>
| <blockquote>
<p>First: to run at 8 MHz, do I just need to replace the crystal? Or is there anything else I have to do?</p>
</blockquote>
<p>No, run on the internal oscillator as suggested by AMADANON Inc.</p>
<p>Alternatively, set the "divide clock by 8" fuse (which would run it at 2 MHz from a 16 MHz crystal) and then in code change the division back up to 2. ie.</p>
<pre><code>#include <avr/power.h>
void setup ()
{
// slow clock to divide by 2
clock_prescale_set (clock_div_2);
} // end of setup
</code></pre>
<p>Or for programming in another Uno leave the fuse alone, program at 16 MHz and then drop the clock down in the target chip, hoping it works long enough at 3.3V to execute that first instruction. The safest thing would be to just install an 8 MHz crystal or resonator on the target board. However if timing is not critical run with the internal oscillator.</p>
<blockquote>
<p>Second: Do I need to make any code changes to reflect the new speed? I'm using serial, SPI, and I2C connections in this project, along with the NilRTOS operating system and millis/delay functions. </p>
</blockquote>
<p>If you tell the IDE you have an 8 MHz processor (eg. a Lilypad) then it should adjust delays, baud rate calculations etc. appropriately.</p>
<blockquote>
<p>Will any of these be broken?</p>
</blockquote>
<p>I2C and SPI are self-clocked. They can run at a variety of rates. I doubt there will be any problems with them. As for serial, providing the calculations are done right a wide range of baud rates should still be available.</p>
<blockquote>
<p>Will the code run noticeably slower?</p>
</blockquote>
<p>Well yes, it will run at half speed compared to 16 MHz.</p>
<blockquote>
<p>Third: How can I program the chip? Is it ok to program it in an Arduino Uno at 16 MHz, then transplant it to the custom arduino?</p>
</blockquote>
<p>You can do that. Or you could connect up an ICSP header or an FTDI header and program it in situ.</p>
<p>Examples here: <a href="http://www.gammon.com.au/breadboard" rel="nofollow">http://www.gammon.com.au/breadboard</a></p>
<blockquote>
<p>Fourth: Will power consumption change at 8 MHz?</p>
</blockquote>
<p>Yes, it is reduced somewhat.</p>
<p>You can reduce it considerably more by using other techniques as described at <a href="http://www.gammon.com.au/power" rel="nofollow">http://www.gammon.com.au/power</a>, and referred to by AMADANON Inc.</p>
|
8738 | |arduino-uno|sensors| | Understanding Digital IMU 6DOF sketch | 2015-02-19T02:21:32.660 | <p>I am looking at the following code and getting confused by a few elements in it:</p>
<p>1) Why is there a writeto function being performed to the memory locations x053,0x31,x09 for accelerometer and 0x68,0x16 and 0x1A for gyro? We are only reading incoming values so what is the purpose of these functions?</p>
<p>2) the bitwise operation being performed in the getGyrscopeReadings and getAccelerometerReadings... are these operations to define how many bits data we will be reading?</p>
<pre><code> #include <Wire.h> //The I2C library
int gyroResult[3], accelResult[3];
//Function for writing a byte to an address on an I2C device
void writeTo(byte device, byte toAddress, byte val) {
Wire.beginTransmission(device);
Wire.write(toAddress);
Wire.write(val);
Wire.endTransmission();
}
//Function for reading num bytes from addresses on an I2C device
void readFrom(byte device, byte fromAddress, int num, byte result[]) {
Wire.beginTransmission(device);
Wire.write(fromAddress);
Wire.endTransmission();
Wire.requestFrom((int)device, num);
int i = 0;
while(Wire.available()) {
result[i] = Wire.read();
i++;
}
}
//Function for reading the gyros.
void getGyroscopeReadings(int gyroResult[]) {
byte buffer[6];
readFrom(0x68,0x1D,6,buffer);
gyroResult[0] = (((int)buffer[0]) << 8 ) | buffer[1]; //Combine two bytes into one int
gyroResult[1] = (((int)buffer[2]) << 8 ) | buffer[3];
gyroResult[2] = (((int)buffer[4]) << 8 ) | buffer[5];
}
//Function for reading the accelerometers
void getAccelerometerReadings(int accelResult[]) {
byte buffer[6];
readFrom(0x53,0x32,6,buffer);
accelResult[0] = (((int)buffer[1]) << 8 ) | buffer[0]; //Yes, byte order different from gyros'
accelResult[1] = (((int)buffer[3]) << 8 ) | buffer[2];
accelResult[2] = (((int)buffer[5]) << 8 ) | buffer[4];
}
void setup() {
Wire.begin(); //Open I2C communications as master
Serial.begin(9600); //Open serial communications to the PC to see what's happening
writeTo(0x53,0x31,0x09); //Set accelerometer to 11bit, +/-4g
writeTo(0x53,0x2D,0x08); //Set accelerometer to measure mode
writeTo(0x68,0x16,0x1A); //Set gyro to +/-2000deg/sec and 98Hz low pass filter
writeTo(0x68,0x15,0x09); //Set gyro to 100Hz sample rate
}
void loop() {
getGyroscopeReadings(gyroResult);
getAccelerometerReadings(accelResult);
Serial.print(gyroResult[0]);
Serial.print("\t");
Serial.print(gyroResult[1]);
Serial.print("\t");
Serial.print(gyroResult[2]);
Serial.print("\t\t");
Serial.print(accelResult[0]);
Serial.print("\t");
Serial.print(accelResult[1]);
Serial.print("\t");
Serial.print(accelResult[2]);
Serial.print("\n");
delay(50);
}
</code></pre>
<p>any help would be greatly appreciated! </p>
| <p><strong>The <code>writeTo</code> functions</strong></p>
<p>The accelerometer and gyro both have some memory inside that is used to store the configuration. The specific locations and values can be read from the datasheet, but for now I'll trust the comments. These writeTo functions seem to set the device modes and configure the scale used for the sensors. </p>
<p>Notice that they only happen once, right when the program starts. Maybe the devices have a way of storing persistent settings onboard, but setting them once at each startup is safe and easy.</p>
<p><strong>The Bitwise ops</strong></p>
<p>These don't set the number of bits we are reading <em>per se</em>, They reconstruct larger than 8-bit values. The I2C serial protocol is set up to use 8-bit data segments, so to send any value larger than 8-bits they must be broken down, sent, and then "stitched" back together in chucks.</p>
<p><code>(((int)buffer[0]) << 8 ) | buffer[1];</code></p>
<p>Whats happening here is that <code>buffer[0]</code> is converted to int (a 16 bit value), then shifted over by 8 bits. This means the 8 bits in the original <code>buffer[0]</code> are now located in the top 8-bits of the integer, and the lower 8 bits are zeros. Finally the lower 8 bits are set by the bitwise-or operator <code>|</code>, which will turn on any bits that were set in <code>buffer[1]</code> in the result. Since the bottom 8-bits were 0's from the shift, this just copies <code>buffer[1]</code> in exactly.</p>
<p>The net effect is a 16 bit value that contains the bits of both 8-bit buffer values and can be interpreted as a single number. </p>
|
8743 | |arduino-mega|pins|rfid| | Use RFID-RC522 with other Pins | 2015-02-19T06:58:11.943 | <p>I'm wondering where the pin setting is manifested in the library.
I want to use the RC522 with other digital pins than the default 50-53 pins, because I am using a shield for a display on theese ports. </p>
<p>Where can I change the used ports?
why are two ports user-defineable <code>#define RFID_SS 10 #define RFID_RST 5</code> while the rest is not?</p>
<p>I am with this <a href="http://playground.arduino.cc/Learning/MFRC522" rel="nofollow">Playground-Guide</a> using this <a href="https://github.com/miguelbalboa/rfid" rel="nofollow">library from Github</a> on my Arduino Mega</p>
| <p>Sorry I'm a bit late (5 years late) but hopefully this can help someone who's just now trying to do this!</p>
<p>There's an old obscure Sunfounder library, "rfid1.h" that lets you declare every pin. Like this:</p>
<pre><code>rfid.begin(IRQ,SCK,MOSI,MISO,NSS,RST);
</code></pre>
<p>It's a bit hard to find the library online these days, but at the bottom of this page (<a href="http://wiki.sunfounder.cc/index.php?title=Mifare_RC522_Module_RFID_Reader" rel="nofollow noreferrer">http://wiki.sunfounder.cc/index.php?title=Mifare_RC522_Module_RFID_Reader</a>) if you download the "RFID-RC522_test_experiment" zip file it will have the library in there. The secret is that this library includes a software SPI which is sort of like a software serial for SPI communication. Letting other digital pins be used as MISO etc...</p>
<p>This library also makes it much easier to use multiple RFIDs reliably since they don't have to share all the same pins.</p>
<p>You can find some example code here: <a href="https://www.sunfounder.com/learn/RFID_kit_V1_for_Arduino/lesson-29-rfid-entrance-guard-system-rfid-kit-v1-0-for-arduino.html" rel="nofollow noreferrer">https://www.sunfounder.com/learn/RFID_kit_V1_for_Arduino/lesson-29-rfid-entrance-guard-system-rfid-kit-v1-0-for-arduino.html</a></p>
|
8752 | |arduino-uno| | How to check whether my Arduino is working? And how to fix this? | 2015-02-19T18:24:18.813 | <p>I tried my first project with Arduino Uno. But I can't upload any code. Power green LED is working and orange LED is always on, not blinking, and IC also getting hot. What can I do to fix this problem?</p>
| <p>My suggestion is to find someone else with an arduino, and get them to test (with their computer, known to be working) uploading to your Arduino. That way, you can tell if the problem is with your computer or the Arduino.</p>
<p>You haven't mentioned what your first project was. The most common mistake #1 is to light up an LED without a resistor. If you do that for a split second, you might (OR MIGHT NOT!) get away with it. If you leave it running for a few seconds, you are almost certainly going to burn out your AtMega (the IC on the board). This might very well result in the symptoms you describe. If this has happened, and your chip (IC) is removable (some are, some aren't), you should be able to buy a new chip of the same kind. An Arduino Uno has an AtMega 328, you will want a DIP package (they are the removable ones), and you will want one with an Arduino Bootloader pre-programmed. Replacing the chip may OR MAY NOT fix the problem. Make sure you note down the orientation of the broken chip before you pull it out - it will fit in, but won't work (and could burn out!) if you put it in the wrong way. There should be a little dimple at one end of the chip, right on the end. It should look like this (possibly without the pin labeling sticker): <a href="http://www.jaycar.co.nz/productView.asp?ID=ZZ8726&w=atmega328&form=KEYWORD" rel="nofollow">http://www.jaycar.co.nz/productView.asp?ID=ZZ8726&w=atmega328&form=KEYWORD</a></p>
<p>If your chip is not removable, or replacing the chip doesn't help, then you will need to get a new Arduino.</p>
|
8754 | |arduino-mega|library|compile|adafruit|class| | error: 'CLASS' does not name a type only when creating object inside another object | 2015-02-19T19:05:43.037 | <p>I'm trying to use <a href="https://github.com/adafruit/Adafruit-LED-Backpack-Library" rel="nofollow">Adafruit's LED Backpack library</a> within a custom class. When I use the Adafruit library directly within a sketch, it compiles fine. When I use an example sketch provided with the library, it compiles fine. However when I create an instance of my custom class with the Adafruit object within it, I get the following error:</p>
<blockquote>
<p>In file included from sketch_feb18a.ino:6:
/Users/lawnmowerlatte/Documents/Arduino/libraries/Bargraph/bargraph.h:18: error: 'Adafruit_24bargraph' does not name a type</p>
</blockquote>
<p>All the reasons I've seen for this error stem from the library being missing or otherwise incorrectly installed. However, since I can use it directly, I think something else must be wrong.</p>
<p><strong>Working</strong></p>
<pre><code>#include <Adafruit_LEDBackpack.h>
#include <Adafruit_GFX.h>
Adafruit_24bargraph bar = Adafruit_24bargraph();
void setup() { }
void loop() { }
</code></pre>
<p><strong>Not Working</strong></p>
<pre><code>#include <bargraph.h>
Bargraph bargraph = Bargraph("Test", "api", 0);
void setup() { }
void loop() { }
</code></pre>
<p><strong>bargraph.h</strong></p>
<pre><code>#ifndef Bargraph_h
#define Bargraph_h
#include <Adafruit_GFX.h>
#include <Adafruit_LEDBackpack.h>
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
class Bargraph {
public :
String name;
String api;
Adafruit_24bargraph bar;
Bargraph(String _name, String _api, int _device,
String _type="Default");
void set(String _value);
void setMax(String _max);
void update();
void print();
private :
int display[24];
long max;
long value;
int device;
int size;
String type;
void format();
void write();
};
#endif
</code></pre>
<p><strong>bargraph.cpp</strong></p>
<pre><code>#define OFF 0
#define RED 1
#define YELLOW 2
#define GREEN 3
#include <bargraph.h>
#if (ARDUINO >= 100)
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
Bargraph::Bargraph(String _name, String _api, int _device, String _type) : bar() {
name = _name;
api = _api;
max = _max.toLong();
device = _device;
type = _type;
value = 0;
for (int i=0; i<24; i++) {
display[i] = OFF;
}
bar.begin(0x70+device);
}
**Methods Omitted for Brevity**
</code></pre>
<p>Can anyone explain what's going on here? I'm pretty certain my class syntax is correct as I have other object-in-object relationships working. I can post code to GitHub if anyone would like to see more context.</p>
| <p>If you used the serial port, Arduino sometimes causes confusion.
Close Arduino IDE and
delete files in folder C:/users/[your name]/AppData/Local/Temp/
Its working.
Regards</p>
|
8765 | |arduino-yun|compile| | How can I obtain the .hex of a file | 2015-02-20T07:30:53.807 | <p>I have an Arduino Yún running Openwrt-Yún 1.5.3 (which is the latest version, as I upgraded yesterday), and I am trying to obtain a .hex (compiled sketch), so that I can upload a sketch directly into the Yún. I know about compiled sketches, but there are no build directories in "C:\Documents and Settings\MY_USERNAME\Local Settings\Temp".</p>
<p>Where can I obtain the .hex of any file I have compiled, and how?</p>
| <p>As noted in comments, enable verbose compilation and look at the output to find the temporary-directory location. (Click File, Preferences, verbose compilation.)</p>
<p>Note, after you click File, Preferences and the preferences window appears with its half-dozen items, you should also see a note about directly editing preferences in the preferences.txt file. Edit that file (using a plain-text editor, not a word processor) when the arduino IDE is not running. Change the line </p>
<pre><code>preproc.save_build_files=false
</code></pre>
<p>to </p>
<pre><code>preproc.save_build_files=true
</code></pre>
<p>so the .hex files in the temporary directory have a better chance of sticking around. </p>
<p>(I'm not able to test this suggestion on an MS-Windows system. On my Linux system most build files stick around anyway in /tmp/)</p>
|
8779 | |arduino-uno|ethernet| | Arduino Ethernet Shield vendor is null | 2015-02-20T20:22:22.787 | <p>I bought Ethernet Shield for Arduino Uno! from AliExpress. It is good work but I scanned my network with <a href="https://i.stack.imgur.com/K4G8Y.png" rel="nofollow noreferrer">Fing</a> and device Vendor name is null.</p>
<p>Can I change/set device Vendor?</p>
<pre><code>#include <SPI.h>
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 10, 0, 0, 106 };
void setup()
{
Ethernet.begin(mac, ip);
}
</code></pre>
| <p>The vendor name is not stored on the device, rather it is indicated only by the first three octets or OUI part of the MAC address which is either stored on the device, or in your case set up by software. Turning this back into a name on another computer which sees its traffic is done by the help of a local or network-sourced OUI lookup table.</p>
<p>Apparently the table your computer is consulting doesn't have an entry for the OUI 0xDE, 0xAD, 0xBE. </p>
<p>And that's not surprising as this is clearly a dummy value put in as a placeholder - read all 6 octets as if they were a word and you'll see it says "dead beef feed" - a variation on a classic magic "illegal" value.</p>
<p>Technically, this is actually a legal value for use on a local network as the 2's bit of the leading octet is turned on, indicating that it is a "locally administered" address, rather than one guaranteed to be unique in all the world as you would expect a proper piece of network hardware to have.</p>
<p>If you find the table your computer is doing OUI lookups in, you could add a DE:AD:BE entry to it. </p>
|
8806 | |button| | Hooking up 12v Push button to arduino uno/nano | 2015-02-22T21:04:19.150 | <p>I want to use one an push button with an led in middle, similar to this <a href="http://www.ebay.com/itm/16mm-12V-Blue-LED-Power-Push-Button-Switch-Black-Aluminum-Metal-Latching-/231234288662?pt=LH_DefaultDomain_0&hash=item35d6a33c16" rel="nofollow">one</a> on eBay.
The push button has a 12v input I want to hook it up to an Aduino Uno or Nano. </p>
<p>Is there a way to hook it up and receive the signal?</p>
<p>Specifications from the eBay page:</p>
<blockquote>
<ul>
<li>Latching type, push it—on, push it again — off</li>
<li>Switch Rating: 3A/250VAC</li>
<li>LED voltage: 12V only</li>
<li>Contact Configuration: 1NO1NC</li>
<li>Pin Number: 5</li>
</ul>
</blockquote>
| <p>Most likely, there will be a push button, and on separate wires, there is a light. If this is the case, you can hook the push button part up to the arduino. You can test this - find two random wires, test the resistance with a multimeter, then press the button and see if the resistance changes. Keep trying until you find two wires that change when you press the button.</p>
<p>Once you find the pair, you can hook one of those two to a digil pin on the Arduino, and via a resister (large, anything 10kilo-ohm or larger is fine) to ground (GND). Then, connect the other side of your pushbutton to 5V. See <a href="http://arduino.cc/en/tutorial/button" rel="nofollow">http://arduino.cc/en/tutorial/button</a> for photos and a circuit diagram - their wiring is more complicated than it needs to be, and their button has 4 pins in two pairs (left pair, and right pair in the picture with the breadboard; the left-top and left-bottom are permanently connected, and the right-top and right-bottom are permanently connected). Have a look at the circuit diagram - that's a lot simpler. The zig-zag at the top is the resistor, and the disconnected looking thing is the switch (open). There is sample code there too.</p>
<p>Note that push buttons typically "bounce" - that is, when you push them, they will go (starting off) on-off-on-off-on-off-on, so if you're counting the number of pushes you will get a result which is way too high. If you delay long enough in between (10ms?) then you won't get these. The code I linked to already has debounce built in.</p>
<p>The other part is the light. This is a little more tricky. The light will probably use too much current for the arduino to supply directly. You will need a transistor and a resistor (again, at least 10 kiloOhm is good).</p>
<p>The transistor should be an NPN transistor, and should look like the top one in <a href="http://www.reprise.com/host/circuits/transistor_pinouts.asp" rel="nofollow">http://www.reprise.com/host/circuits/transistor_pinouts.asp</a>. The easiest one is the base - this is the middle one. Connect this via your resistor to another digital pin on your arduino (pin 13 is great for testing this, because it will also light up the led on the Arduino). Next, connect your emitter to ground (GND). Then, IF YOUR POWER SUPPLY IS NO MORE THAN 12 VOLT! you can connect VIN to the + side of the light, and the - side of the light to the collector. </p>
<p>Next, load a sketch - the "blink" sketch is good to test this. Adjust the pin as necessary.</p>
<p>Note that, these switches have a resistor already built in to the light; if you want to do the same with an ordinary led, you will have to add one yourself. Check out <a href="http://ledcalc.com/" rel="nofollow">http://ledcalc.com/</a> to tell you which resistor you need. </p>
|
8811 | |power|voltage-level|battery|current|solar| | How to choose between Lithium-ion vs NiMH batteries to power Arduino on the go. | 2015-02-22T22:44:08.043 | <p>For my next project I'd like to use a battery pack to power my Arduino.
I would also like to get a small solar panel and charging module to charge these batteries when possible (during the day).</p>
<ol>
<li>What is the right type of battery for this kind of application?</li>
<li>What are the differences given this context?</li>
<li>What are the factors I need to consider when choosing a rechargeable battery for this application?</li>
</ol>
| <p>Look at <a href="http://www.batteryuniversity.com/" rel="nofollow"><strong>Battery University</strong></a> for many good ideas.</p>
<p>Both NimH and LiIon are viable for your application.</p>
<p>LiIon are easier to manage well <strong>if</strong> managed well.<br>
ie do it right and they are easy to manage, but cut corners and they are easier to destroy.</p>
<p>NimH can be abused more with a slow degradation in capacity - although complete destruction is possible. </p>
<p>As a LiIOn cell has a ~= 3.0V to 4.2V range you'd probably probably need a step up inverter with 1 cell, or a buck regulator with 2 cells, which is 'annoying'. If you are prepared to use the cell over say a 3.4V to 4.2V range with an LDO regulator for a 3.3V system then you lose a significant amount of available capacity but increase battery cycle life substantially. </p>
<p>Nimh give 1.0 - 1.2 V/cell so eg </p>
<ul>
<li><p>6 cells give 6 - 7.2V for a 5V system, </p></li>
<li><p>5 cells give say 5.25V - 7V if run down to 1.05V for a 5V system with a suitable LDO regulator, and</p></li>
<li><p>4 cells give 4 - 4.8V for a 3V3 system. </p></li>
</ul>
<p>NimH are easier overall to build half well and get half good results. </p>
<p>LiIon are slightly harder to get going with in most cases, work very well if treated well, and are VERY unforgiving of bad treatment past a certain point. </p>
|
8815 | |arduino-uno|serial|mac-os| | /dev/cu port resource always busy on OS X 10.10 | 2015-02-23T05:58:15.833 | <p>Is there any reason why is my <code>/dev/cu</code> port always busy? How can I fix that?</p>
<p>It happened on both Uno clone and Spark Core.</p>
<p>The problem is, I'm having issues doing serial communication. Where (as a programmer) I'm seeing something like dropped packets with <code>/dev/tty</code> port. I did a quick test running it on Win 7 (a loaner PC), it works fine...</p>
<p>The code for now is extremely simple. It waits for a command, and write a response.</p>
<pre><code>String str = String(30);
void setup()
{
Serial.begin(9600);
str = "";
}
void loop()
{
if (Serial.available() > 0) {
char inChar = Serial.read();
if ((inChar == '\n') || (inChar == '\r') || (inChar == 'z')) {
str.trim();
if(str == "READ") {
String x = String(random(27, 45)) + "," + String(random(45, 300)) + "," + String(random(35, 250));
Serial.println(x);
}
str = "";
}
else {
if (str.length() < 30) {
str += inChar;
}
else {
str = "";
str += inChar;
}
}
}
}
</code></pre>
| <p>Finally figured it out. I need to call <a href="http://arduino.cc/en/Serial/Flush" rel="nofollow">Serial.flush()</a>.</p>
<blockquote>
<p>Waits for the transmission of outgoing serial data to complete.</p>
</blockquote>
|
8819 | |serial|timing| | How to wait outside the loop without delay()? | 2015-02-23T11:30:25.433 | <p>Is it possible to delay a task inside a function that is called only once (meaning, it's not inside the loop) without using delay()? </p>
<p><a href="https://github.com/kslstn/cozir" rel="nofollow">This library</a> I'm using, for reading sensor measurements via serial has a delay() in it. I want to get rid of it, but I don't how to do it, because the library's function is not looped. </p>
<p>I guess the simple solution would be to move the library functions inside the loop, so I can do a simple check with millis() and run the delayed part as soon as 250 ms have passed. I would like to improve this library though and do a simple, single call for sensor data that doesn't not hold up the entire program.</p>
<p>This is the function with the delay:</p>
<pre class="lang-cpp prettyprint-override"><code>uint16_t COZIR::Request(char* s)
{
Command(s);
// empty buffer
buffer[0] = '\0';
// read answer; there may be a 100ms delay!
// TODO: PROPER TIMEOUT CODE.
delay(250);
int idx = 0;
while(CZR_Serial.available())
{
buffer[idx++] = CZR_Serial.read();
}
buffer[idx] = '\0';
uint16_t rv = 0;
switch(buffer[1])
{
case 'T' :
rv = atoi(&buffer[5]);
if (buffer[4] == 1) rv += 1000;
break;
default :
rv = atoi(&buffer[2]);
break;
}
return rv;
}
</code></pre>
<p>I've had a look at the SoftTimer library, but it requires sketches to be written very differently (without a loop). I'm also not sure if I can even pass arguments to delayed tasks with that library.</p>
| <p>You can look at the BlinkWithoutDelay example sketch (under Digital). Basically you store the current millis as a variable, then have an if statement to check that it has been more than x milliseconds.</p>
|
8827 | |arduino-uno| | Atmega328 component library for Protel 99 SE | 2015-02-23T17:35:53.150 | <p>Any one know a <strong>component library</strong> for Arduino UNO (<strong>Atmega328</strong>, etc) for <strong>Protel 99 SE</strong> PCB design software? </p>
| <p>Found it here with 94 chips.</p>
<p>The author states, "I have made a little library for Protel 99SE with schematic sybols of AVR chips."</p>
<p><a href="http://www.avrfreaks.net/forum/avr-8bit-microcontrollers-protel-99-library" rel="nofollow">http://www.avrfreaks.net/forum/avr-8bit-microcontrollers-protel-99-library</a></p>
|
8828 | |arduino-uno|c++| | Arduino Uno - What can I make with just the base board | 2015-02-23T19:12:34.417 | <p>So I just bought my first Arduino (an Uno r3), and dove right in.</p>
<p>All I have currently is the base board (I didn't want to invest too heavily and then realize arduinos weren't for me), so I made a quick script that translates input letters to morse via the LED on the top.</p>
<p>Now that I'm done with that, I figured I'd come here to ask: do you guys have any random ideas for things I can make with JUST the uno? I understand that I should probably just start buying kits and shields, but I'm just curious as to what I can make with the most minimal of items. I consider it a test :)</p>
<p>Thanks in advance guys!</p>
| <p>Well,</p>
<p>Your question is very broad. But the Arduino essentially needs controlling gadgteers to make things easy ( and funny ).</p>
<p>However if you know a bit of electronics, then you may be able to use the IN/OUT analog ports and build other interfaces to control, for example the lights of your home, or even better. You can measure and control priate things should be linked. Increasing the power of your home.</p>
<p>If you have interest in cars, then you can perform to connect the on-board computer of your car to the Arduino, like <a href="http://arduinodev.com/connect-arduino-to-a-car-through-obd-ii-port/" rel="nofollow">this</a>.</p>
<p>Well, there are numerous ideas, none of these I'm saying is new and there are even libraries ready to be used in these segments mentioned above.</p>
<p>Regards,
Andrew Paes</p>
|
8831 | |arduino-uno|pwm|mosfet| | Arduino PWM output cannot drive MOSFET 0-12V | 2015-02-23T22:23:30.313 | <p>On an Arduino Uno, the PWM pin 3 is connected to the <code>gate</code> pin of an <a href="http://www.farnell.com/datasheets/1690175.pdf" rel="nofollow noreferrer">N-channel MOSFET STP16NF06L</a>. The source pin is connected to ground of a 12 V power supply and drain pin connected to a multimeter. The other end of the multimeter is connected to the positive terminal of the power supply.</p>
<p><strong>Question:</strong> When Arduino varies its PWM output from 0 to 255, the multimeter reading goes from 11.50 V to 12.10 V. Why isn't it 0 to 12 V?</p>
<p>When the FET gate is connected to the Arduino pin that outputs either 0 V or 5 V, the multimeter reading is as expected at 0 V and 12 V respectively.</p>
| <p>Also put a LED with a resistor connected trough drain, then you read the voltage across the resistor and also have visual feedback with the LED. Resistor should be with 0V when your pin is LOW. It's easier to work with transistor knowing if there is current or not.</p>
|
8857 | |arduino-uno|interrupt| | What could cause interrupts from MCP23017 suddenly stop working? | 2015-02-24T20:28:32.767 | <p>I have 4 rotary encoders connected to an MCP23017 which in turn is connected to interrupt port 0 on the arduino (and to I2C of course). Everything works fine: I get interrupts for all 4 rotary encoders, can read the values for them and even store these values in the EEPROM and load them in setup.</p>
<p><img src="https://i.stack.imgur.com/RVWWC.png" alt="Fritzing schematic of the (initially) working setup"></p>
<p>Now, I connect a WS2812 LED to the arduino (with a resistor and a capacitator in front of it). I connect the UNO and the led lights up. I attach the serial console (resetting the UNO) and it stops working (LED does not light up). This could just be simple wiring mistake and is not my real problem.</p>
<p>I remove the LED (and the capacitor) from the board and start everything up again. I can see via the serial console that the UNO works, however it does not receive any interrupts anymore. I exchange the MCP23017 thinking I fried it somehow but that doesn't change anything either...</p>
<p>Is there some sort of state the UNO has I could have affected?</p>
<p>Or could I have fried the interrupt "sub-system" on the UNO (again: all the other stuff still works)?</p>
<p>EDIT: The code is here: <a href="https://github.com/qollin/Liting/blob/master/src/Liting.cpp" rel="nofollow noreferrer">https://github.com/qollin/Liting/blob/master/src/Liting.cpp</a></p>
| <p>I think I figured out whats wrong: you need to reset the interrupt handling of the MCP in setup() (by reading from both INT pins). Otherwise the MCP may start in a state where it does not generate new interrupts, because it waits for the old ones to be handled...</p>
|
8860 | |sensors|rf| | How to access 315mhz signals from household devices, with an arduino 315mhz kit? | 2015-02-25T02:57:41.330 | <p>Background:</p>
<p>I am looking into automation and I have realized that many of the devices I have around my house transmit 315mhz to their specific controllers. I know this from reading the labels on the back that say 315mhz</p>
<p>Question:</p>
<p>Is there a way I can use a 315mhz receiver with an arduino to view the signals and log the data based on what happens and mimic certain actions with the transmitter? In other words can I program the reciever to display every bit passed through 315mhz that is in range?</p>
<p>I know the virtual wire library parses the data before I receive it, but I don't know to what extent? If I just dedicate the arduino to watch that pin and print results will that tell me what is being sent?</p>
<p>Thanks Very Much,</p>
<p>Joel</p>
| <p><strong>The Short Answer:</strong></p>
<p>In theory it is possible to do what you are asking.
There are examples of using an Arduino to send and receive messages at 315 MHz. Such as <a href="http://www.buildcircuit.com/how-to-use-rf-module-with-arduino/" rel="nofollow noreferrer">this example</a>.</p>
<p>Although these devices might not even be compatible with the ones you are using. They may be modulating their signal differently or framing their data differently or at different baud rates or encoding bits differently or a number of other fundamental differences that would make them incompatible.</p>
<p><strong>The Long Not Quite An Answer:</strong></p>
<p>There is more to the problem than just being able to get bits at 315 MHz.</p>
<p>For one you would need to know how the bits are encoded. See some of the answers on <a href="https://electronics.stackexchange.com/questions/81399/reverse-engeneering-a-home-automation-rf-315mhz-transimtter">this</a> post.</p>
<p>Even if it was a simple high low stream of even width bits. You also need to know what baud rate the bits are being transmitted at so you can sync with it. (Consider 4800 vs 9600 baud, slow I know but just an example. You just got a bit stream, was it 1010 at 4800 baud or 11001100 sent at twice the speed of 9600.)</p>
<p>Not to mention that the lowest level of data is probably not just a stream of bits, but is probably framed in some way and grouped into a byte/bytes. Or has a leader to help lock onto the signal.</p>
<p>Even once you are getting reliable data you would need to know the data structure. Is the data arranged in packets? Do they have a packet header? Does the header contain these packet destination address? Where in the header is this data? How is the data apart from the header structured? What does it mean?.</p>
<p>Knowing the answers to these questions defines, or is defined by, the protocol that is being used by the transmitter (as others are saying in comments.) But these are only a few simple questions that <strong>start</strong> to define a protocol. Often this information is difficult to come by. Often in the case of proprietary protocols it is very very difficult.</p>
|
8872 | |serial|python|float| | Serial, Numbers sent as Floating Point and Characters are different at 1e-8 level | 2015-02-25T13:42:04.910 | <p>I have some code that generates random numbers on the Arduino, it then sends these random numbers firstly, using <code>Serial.print(float data,int lenght)</code> and as a floating point number using the following function</p>
<pre><code>void send_float (float arg)
{
// get access to the float as a byte-array:
byte * data = (byte *) &arg;
// write the data to the serial
Serial.write (data, sizeof (arg));
Serial.println();
}
</code></pre>
<p>I then receive this data using python, take the absolute difference of the two values, discard any differences less than the length with which I send the string and output the rest to the screen.</p>
<p>I observe two things, a) Fluctuations of the order with which I send the data (ie. if I send to 6 decimal places then I see fluctuations of ~1e-6), this is reasonable and b) I see fluctuations of absolute value 1e-8 or lower <strong>independent</strong> of what accuracy I send the string.</p>
<p>Even if I send the string to 11 decimal places, when I compare against the float I see fluctuations up to but not above 1e-8.</p>
<p>Why? This doesn't make any sense. My full code is actually the answer to an old <a href="https://stackoverflow.com/questions/12664826/sending-float-type-data-from-arduino-to-python/28719607#28719607">unanswered stack exchange question</a></p>
| <p>This is a somewhat dumb question but, in case anyone else searches it as pointed out:</p>
<blockquote>
<p>The precision of a float is around 7.2 decimal digits. en.wikipedia.org/wiki/Single-precision_floating-point_format – BrettAM </p>
</blockquote>
<p>So in python the number goes float -> double -> decmial, whereas on the arduino the number goes float -> decimal. The additional step of the double in the case of python causes the discrepancies. But anything after the 7th decimal place is nonesense anyway.</p>
|
8879 | |led| | ws2812b NeoPixel - how to address it? How Arduino knows the correct order of LEDS on the stripe? | 2015-02-25T15:59:26.787 | <p>How to get a One-Wire address of a given WS2812B pixel? I bought several of these, and I cannot make them light. On the other hand, when I connect the addressable LED strip made of these diodes, I have no problem controlling it. </p>
<p>Here is my set-up:</p>
<p><img src="https://i.stack.imgur.com/YtYR3.png" alt="enter image description here"></p>
<p>I tried many programs, e.g. AdaFruit_NeoPixel -> simple, setting number of LEDS to 1, but no effect. No blinks, nothing - as if the diodes were dead.</p>
<p>If every One-Wire device is identifiable by 64 bit ID, how does the Arduino know the correct "order" of the LEDS on the ribbon? How to tell the Arduino the new sequence of the LEDS on the strip that would result if I replace one (broken) LED with another?</p>
| <p>Just one correction. The the first 24 bits of the data are shifted into the first WS2812. That device loads those 24 bits into its PWM registers. If more data is transmitted, the first WS2812 shifts that out to the following WS2812. So the first data sent stays in the first WS2812, the 2nd data stays in the 2nd WS2812, and so on. This is explained in the data sheet.
Data-wise, it's a one-wire device. Power connections don't count.</p>
|
8882 | |arduino-uno| | Decide on baud rate for a project using Arduino Uno R3 | 2015-02-25T19:02:09.827 | <p>I am using an Arduino Uno R3 with the MPU 6050 to get motion data. Different example codes use different baud rates, without any proper explanation as to why.</p>
<p>So how do I know which baud rate is perfect for my project?</p>
| <p>I most cases it doesn't matter!</p>
<p>In some cases the highest possible is preferred, as it prevents delays. That is when the buffer is full (when sending large amounts of data through the serial connection). As <code>Serial.write</code> will block until there is room in the buffer. In most cases this won't be an issue.</p>
<p>When running your arduino at slower speeds, you have to select a lower baudrate, or the micro-controller can't keep up.</p>
<p>When connection to other devices (e.g. GSM shield) using serial, that device may require a specific baudrate.</p>
|
8894 | |arduino-uno|bluetooth|softwareserial| | Anyone have the Maplin N97DG bluetooth shield working? | 2015-02-26T15:09:54.307 | <p>I went & impulse-bought a Maplin <a href="http://www.maplin.co.uk/search?text=Bluetooth+Shield+for+Arduino" rel="nofollow">Bluetooth shield</a> yesterday.</p>
<p>It comes with a little tiny book containing <a href="http://linksprite.com/wiki/index.php5?title=Bluetooth_Shield_for_Arduino" rel="nofollow">examples</a>, and uses the softwareserial library in these; I can load them, and get the Arduino <-> PC communication going OK, however there appears not to be a response from the bluetooth part of the device. The LED lights much as the booklet says it should. I did see it return some odd characters one time, just the once..</p>
<p>Given that the system appears to be alive, I don't want to give up & take it back; however the output from Google is not promising, and my trial to date isn't either - so I'm looking for positive news that this product does actually work for someone somewhere?</p>
<p>I'm using the built-in serial in the IDE to talk to it, not X-CTU as they suggest (as they don't do a Linux version).</p>
| <p>I've just got mine working, in about 3 hours.</p>
<p>The first example I've never got working. The SAT+RESET worked first time... and I was then able to pair.</p>
<p>An easier module is the HC-05. That by default goes straight to discovery mode, and makes things alot easier.</p>
<p>I have more success with the serial monitor in Arduino studio, rather than X-CTU.</p>
<p>The point of the sheild is to prototype, or the shield you have to use in your production project. If you are doing the former, then there is little point in using the shield as you would have to change the code to fit the hardware.</p>
<p>It seems a thorough product, probably too involved.</p>
|
8899 | |button|relay|transistor| | Fog machine Arduino integration | 2015-02-26T22:02:19.373 | <p>I want to control my fog machine with an Arduino. Has a simple button that is used to activate the machine. I want to press this button using an Arduino digital output pin, but the fog machine is operating on its own electrical circuit. How do I use the Arduino to activate this machine?</p>
<p>I a few other machines with buttons that I want to wire into an Arduino, so is there a generic solution?</p>
| <p>Please do not upvote this answer.<br>
This is an expansion of @Krol's answer.
Krol may incorporate this material in his answer if he wishes.</p>
<p>The image below shows a typical relay module which is able to be driven by logic level / GPIO signals from typical microcontrollers.<br>
The relays have 5V coils and there are optocouplers and drive transistors between the input and the relay.<br>
Inputs are active LOW - ground to turn on. </p>
<p>These are available by mail from China for under $2/relay (under $1/relay if you buy 10 modules with several relays in). </p>
<p>They are <strong>NOTIONALLY</strong> opto-isolated as well as having relay isolation between input and contacts. <strong>BUT</strong> the PCB layout and relay design is such that mains to input clearances are poor. They will <strong>PROBABLY NOT</strong> kill you or your controller but they may - as is the case with much other items manufactured afar off at ludicrously low prices. </p>
<p>I have found the seller/manufacturer whose logo appears on that photo to be a reliable supplier of well made products. (Being well made does not overcome "dangerous design" as above.</p>
<p>Note that the above warning applies to most buffered relays you can buy on the hobbyist market and also top consumer products that have not been put through formal testing (UL etc). This relay board would fail UL testing - as would most others. </p>
<p><img src="https://i.stack.imgur.com/HWO2D.jpg" alt="enter image description here"></p>
|
8900 | |power|ir|transistor| | Tv remote connection to an Arduino | 2015-02-26T22:07:34.067 | <p>I have a tv remote that I want to connect to an Arduino so that I can send a series of commands to the TV using the remote. I would like to open the remote and solder transistors or a Transistor Array in place of the buttons. I have never done this before, so what do I need to be aware of? I think that I will need to power the remote using the Arduino's power supply, but I am a bit foggy on the details.</p>
| <p>Using an IR library as mentioned in a previous answer is likely to be about the best approach. However, if you decide to use electronic switches to jumper across the remote's switch contacts, consider using CMOS analog switch chips for the purpose. If each button on the remote connects one contact to a common net, inexpensive chips like 74HC4051 and CD74HCT4067 would serve for 8 or 16 buttons each, respectively.</p>
<p>I don't have a reference for an affordable many-SPST-contacts CMOS switch. Inexpensive chips with a few such contacts are available. The 74HC4053, for example, contains three SPDT CMOS switches. Handling a dozen buttons would use four 4053 chips. A CD4007 probably could provide three SPST switches also.</p>
<p><img src="https://i.stack.imgur.com/hyBNX.jpg" alt="PS4051/52/53 pinouts">
<em>Edit:</em> The figure above shows pinouts of CD4051/52/53 devices. To use a CD4053 as three separate switches, connect V- and GND to Arduino ground, V+ to +5V or +3.3V, and each of COMA,B,C to one circuit contact to be switched. With NCA, NCB, NCC connected to the other contacts of circuits A, B, C, raise ADDA, B, or C and drop INH to close circuit A, B, or C.</p>
<p>If your remote has dozens of buttons, it's likely that they are arranged in rows and columns for multiplexed scanning. In this case, follow the printed circuit tracks to identify which buttons attach to which rows and which columns. Suppose there are eight or fewer of one or the other; eg, suppose there are 5 columns and 8 rows. In this case, you would hook up 5 CD4051 chips: connect V- and GND to Arduino ground, V+ to +5V or +3.3V, and the COM of each 4051 to a different column line. Connect NO0–7 to row lines 0 to 7.</p>
<p>To close circuit <em>j</em> in column <em>k</em>, put <em>j</em> in binary on ADDA,B,C of all 4051s and drop INH on 4051 #<em>k</em>. (Either use one DIO line per INH, or use a DM74LS138 or MM74HC138 (etc.) and put <em>k</em> in binary on the A,B,C select lines of the '138.)</p>
|
8904 | |arduino-uno|serial|usb| | Why is Serial.print working when nobody receives the data? | 2015-02-27T00:59:10.040 | <p>I have a kind of theoretical question. Let's have an Arduino Uno connected through USB that does a lot of Serial.print-ing. Then I disconnect it and I don't see anything on the Serial monitor, but the Arduino is still working. I can judge by the blinking lamps and so on.</p>
<p>Now I see that all printing goes through HardwareSerial::write from the Arduino core. There is this statement:</p>
<pre><code> // If the output buffer is full, there's nothing for it other than to
// wait for the interrupt handler to empty it a bit
// ???: return 0 here instead?
while (i == _tx_buffer->tail)
;
</code></pre>
<p>It means that if the output buffer is full, the Serial.print will hang there eternally. However this doesn't happen. I guess somebody is consuming the data and to be more precise in ISR(USART_UDRE_vect). It seems as the only place where within interrupt _tx_buffer->tail can be changed. Otherwise the code would loop endlessly in HardwareSerial::write. This interrupt USART_UDRE_vect should be raised only when the Data Register is empty.</p>
<p>My question is - who is consuming the sent data? Is that done by some USART_to_USB drivers? Or am I missing some part of the picture?</p>
<p>Regards,
Boyan</p>
| <p>atmega 328p datasheet, section 20.6.3:</p>
<blockquote>
<p>The Data Register Empty (UDREn) Flag indicates whether the transmit
buffer is ready to receive new data. This bit is set when the transmit
buffer is empty, and cleared when the transmit buffer contains data to
be transmitted that has not yet been moved into the Shift Register</p>
<p>...</p>
<p>When interrupt-driven data transmission is used, the Data Register
Empty interrupt routine must either write new data to UDRn in order to
clear UDREn or disable the Data Register Empty interrupt, otherwise a
new interrupt will occur once the interrupt routine terminates.</p>
</blockquote>
<p>the USART Data Register Empty vector is run when the hardware for USART serial has taken the byte in the register and sent it, not when a receiving device has polled and "taken" it. Once copied into the shift register and sent out of the chip nothing knows if there was another device to "hear" it or not. Some systems may have hardware flow control and wait for a CTS (clear to send) signal on a different wire, but the arduino does not.</p>
<p>You may also notice that if interrupts are not currently enabled (preventing USART_UDRE_vect from ever occuring) the HardwareSerial::write routine will manually poll the correct condition and run the interrupt handler when appropriate to cycle data through and prevent a deadlock.</p>
|
8909 | |relay| | Arduino, relays and building code | 2015-02-27T04:53:23.397 | <p>I want to install several Arduino controlled relays which are use to turn on/off some lights, a fog machine and some door locks in a building. What do I need to do to insure that the power relays don't violate building code?</p>
<p>Do components need to be put in a box or can they be mounted to a 2x4?
Are there requirements regarding the points were the bear wire is screwed into the relay?</p>
<p>I am assuming that if anyone as ever wired an Arduino into a garage door opener, these questions may have come up.</p>
| <p><strong>Disclaimer:</strong> IANAL nor US regulations expert. </p>
<p>There are a few standard certifications that will essentially guarantee that a part will meet US regulatory requirements. Usually more of the form "your building burned down and you have no insurance because ..." rather than prosecuting you for non compliance. </p>
<p>Relays with UL rating bought via a reputable US supplier will usually quality.<br>
eg if Digikey sell it it is PROBABLY Kosher.<br>
Also if made by reputable manufacturers the same applies, as long as its genuine. eg (1 of many) Omron - they don't make no junk largely and even their junk is certified :-). </p>
<p><strong>HOWEVER</strong> if you are building something using such parts the whole unit will need to be certified. For small volume applications it may be easier and cheaper to buy comething COTS (commercial off the shelf) which has the relevant certifications. That said,be sure these are legitimate. </p>
<h2>As a guide:</h2>
<p><a href="http://www.sensorcentral.com/worldsupport/standards03.php" rel="nofollow"><strong>US standards</strong></a> a useful introduction</p>
<p><a href="http://www.technick.net/public/code/cp_dpage.php?aiocp_dp=guide_safetymarks" rel="nofollow"><strong>Extensive international standards summary</strong></a></p>
<p><a href="http://en.wikipedia.org/wiki/UL_(safety_organization)" rel="nofollow"><strong>Wikipedia on UL</strong></a></p>
<p><a href="http://www.metlabs.com/Services/Product-Safety-Testing.aspx" rel="nofollow"><strong>MET Labs strut their stuff</strong></a> comparison with UL.</p>
<p><a href="http://www.intertek.com/marks/etl/" rel="nofollow"><strong>Intertek test labs bow in</strong></a></p>
<p><a href="http://www.watertechonline.com/articles/understanding-electrical-certification" rel="nofollow"><strong>Useful - Understanding electrical certification</strong></a></p>
<p><a href="http://www.med.govt.nz/energysafety/forms/certification/electrical-certification-templates" rel="nofollow"><strong>Possibly useful templates</strong></a></p>
|
8913 | |sensors| | Is there a thermal sensor with a distance of 10 meters for Arduino | 2015-02-27T08:14:47.200 | <p>I am looking for a thermal sensor with a distance of 10 meters . In my plan , I would like to recognize objects based on the heat. for example car.</p>
| <p>How about <a href="https://www.sparkfun.com/products/9570" rel="nofollow">this one</a> at £20?</p>
<p>The range depends on what lens you put in front of it - this has to be plastic as IR doesn't penetrate glass, but you can set your own range, like a focus adjustment. Commercial IR remote thermometers generally have aiming dots (laser) so you can see the optimum range - there's a fixed lens.</p>
<p>The actual sensor won't have a defined range, because of this.</p>
|
8916 | |power|arduino-pro-mini| | Powering fans and arduino pro mini from single 12v supply | 2015-02-27T10:31:39.400 | <p>So, I have a 5V Arduino Pro Mini, which is running the logic behind a multi-DHT22 sensor array, and using that input to control a 12v 24mm fan (12v, 0.16 A).</p>
<p>This is currently a working board on an Arduino Nano with two separate power supplies (1 to USB, 1 to fan). I want to simplify it and make a more permanent installation.</p>
<p>What I'm keen to do is something like the following:</p>
<pre><code>Wall Wart (12v, 500mA) ------------------------> Relay -> Fan
\ (1) -> Arduino Pro Mini @5V -> /
</code></pre>
<p>In order to power the Arduino efficiently at 5V, and avoid drawing power all the time (i.e. when the Arduino is asleep), is the best way to apply a Linear (or Switching) Regulator with minimal burn when idle at <code>(1)</code> in the diagram, and power the Pro via its VCC line, or is it better to just run via the internal regulators and RAW?</p>
<p>Will this actually just generate a high burn whenever the arduino is on to convert the 12v-5v? What is the most power efficient approach here?</p>
| <p>If you want to minimize power usage, the best thing would be to start with <strong>devices that use more power!</strong> :D</p>
<p>It's time for math! I'm going to use the <a href="http://www.mouser.com/ProductDetail/STMicroelectronics/L7805CV/?qs=9NrABl3fj%2FqplZAHiYUxWg%3D%3D" rel="nofollow noreferrer">generic L7805CV</a> 5V, 1A linear regulator. Poking in the <a href="http://www.st.com/web/en/resource/technical/document/datasheet/CD00000444.pdf" rel="nofollow noreferrer">datasheet</a>, we find that the quiescent (standby) current is max of 6 mA. I'm assuming this power drawn is 12V, not 5V.</p>
<p>Since a linear regulator is basically a variable resistor, we can figure out that the efficiency is:</p>
<pre><code>Vout / Vin
</code></pre>
<p>...thus, our efficiency in this application is...</p>
<pre><code>5V / 12V = 0.416666667% efficiency
</code></pre>
<p>... <a href="https://electronics.stackexchange.com/a/21135/18442">Read more here.</a></p>
<p>So, we can use the inverse of the efficiency function (<code>Vout / Vin</code> → <code>Vin / Vout</code>) to establish the amount of power it'll use. Final equation:</p>
<pre><code>Power Used (W) = (12V / 5V) * Current Draw + (0.006A * 12V)
</code></pre>
<p>...which simplifies to:</p>
<pre><code>Power Used (W) = 2.4 * Current Draw + 0.072 W
</code></pre>
<p>So, all we need to find is the power consumption of the Arduino. <a href="http://www.gammon.com.au/forum/?id=11497" rel="nofollow noreferrer">This forum post</a> states the power consumption of different sleep modes:</p>
<ul>
<li>SLEEP_MODE_IDLE: 15 mA</li>
<li>SLEEP_MODE_ADC: 6.5 mA</li>
<li>SLEEP_MODE_PWR_SAVE: 1.62 mA</li>
<li>SLEEP_MODE_EXT_STANDBY: 1.62 mA</li>
<li>SLEEP_MODE_STANDBY : 0.84 mA</li>
<li>SLEEP_MODE_PWR_DOWN : 0.36 mA</li>
</ul>
<p>Let's give the Arduino a generous 15mA to sleep:</p>
<pre><code>Power Used (W) = 2.4 * 0.025 + 0.072 W = 0.132 W
</code></pre>
<p>So, 132 milliwatts, idle. A bit further, we can calculate that, if your wall wart has an efficiency of 10%, it will actually draw 1.32 W from your wall socket. Using a general cost per killawatt hour ($0.125), we can calculate that it will cost you about $1.45 a year for that Arduino to be ran in sleep mode 24/7 (given that we used the maximums for everything).</p>
<p>It's pretty cheap, so I wouldn't worry about that power. A good switching regulator will cost more than to run it for a few years with a linear regulator. I'd use the onboard one.</p>
<p>If you still want to optimize things, the wall wart or the fan should be looked at first. Consider getting a switching wall wart instead; this will give you a higher return on your investment since both the fan and the logic use this.</p>
|
8920 | |arduino-uno|xbee| | Can ZigBee API and ZigBee AT work together in the same network? | 2015-02-27T12:49:22.910 | <p>I'm currently trying to make 3 arduinos talking to each other with ZigBee, and it's kinda working.
But I currently use AT mode on the Bees and it's a little bit harsh when I have to switch the destination address in the Coordinator of the network (1 Coordinator and 2 Routers)</p>
<p>Can I put the Coordinator in API mode (to make it easier to switch addresses with xbee-api for Arduino) but still be able to communicate with the AT routers and be able to send/receive data from them?</p>
<p>Thanks for your answer :)</p>
| <p>My question has been answered on Stack Overflow, if you ask</p>
<p><a href="https://stackoverflow.com/questions/28765288/can-zigbee-api-and-zigbee-at-modules-work-together-in-the-same-network">https://stackoverflow.com/questions/28765288/can-zigbee-api-and-zigbee-at-modules-work-together-in-the-same-network</a></p>
|
8921 | |power|arduino-nano| | Does Nano not get sufficient power via USB? | 2015-02-27T14:21:13.893 | <p>I have an Uno, and I can play all I want with it, just using a USB cable. </p>
<p>Then I got two Nano clones, and they both show the same behavior:</p>
<p>When I connect it to the USB cable (which leads to my PC) it blinks a few times, then seemingly does nothing. I am also not able to connect to it via the Arduino IDE. </p>
<p>If I then connect an external power source to Vin and Gnd, it wakes up and blinks forever, and I am able to connect to it. </p>
<p>Is this just because I got a cheap clone? Or is this really the accepted / expected behavior?</p>
<p><img src="https://i.stack.imgur.com/7UBfE.gif" alt="enter image description here"></p>
| <p>To answer your title question, My Nanos run at significantly less than the 500 mA you can draw from a normal USB port, so unless you have a cable problem it should be getting enough, yes.</p>
<p>One thing I have learned about cables is that your mileage may vary. For the Pi, it is nice enough to show me a lightning bolt on-screen when it isn't getting enough, and swapping the cable fixes it 99.9% of the time.</p>
<p>Arduinos simply display odd behavior like this one. </p>
<p><strong>I always suspect power supply first.</strong> </p>
<p>So first, try changing cables. Then if that doesn't help try changing Arduinos and see if the problem follows the Arduino.</p>
<p>Good luck!</p>
|
8928 | |system-design| | Arduino Based Solid State Drive | 2015-02-27T16:08:26.173 | <p>I've searched high and low for something to get me on the right track, it's making me think it might not be possible.</p>
<p>Basically, I want to create a cheap SSD using Arduino (or another microcontroller if it is too weak). I know I would have to implement the SATA protocol on the device and an OS driver for the disk drive. Assuming I could jump those two hurdles, what else would bar me from implementing a rudimentary SSD? I'm not even talking about full production quality, just a SATA wire coming from a mother board plugged into a socket on a breadboard. Do I need flash storage or would I need another kind of chip to handle the data needs?</p>
| <p>The good news is that SATA drivers are fairly generic so you don't have to write the OS side. The bad news is everything else.</p>
<p><em>just a SATA wire coming from a mother board plugged into a socket on a breadboard</em></p>
<p>Let me stop you there. The minimum data rate for SATA is sufficiently high that you need a PCB. If you try and do this with wires or breadboards it will simply not get through; it will be lost to parasitic capacitance.</p>
<p>(Many years ago as a student I tried to do something vaguely similar with a wire-wrap board. At just 20MHz you could see a clean signal go in one side and a noisy unreadable mess come out the other side. Actually seeing it on a scope drove home the importance of shielding.)</p>
<p><em>Do I need flash storage or would I need another kind of chip to handle the data needs</em></p>
<p>Where would you put the data otherwise? It might be an entertaining first step to create a read-only drive with constant contents, but it's not very useful.</p>
<p>You need a chip with a SATA interface. This will almost certainly be an ARM and almost certainly <em>not</em> in DIP. I can't remember at the moment whether SATA master and slave "PHY" interfaces are different or whether it's all defined in software, someone else can answer that.</p>
|
8930 | |arduino-uno|power| | Powering Arduino Uno R3 with battery packs | 2015-02-28T02:36:04.017 | <p>I am using Arduino Uno R3 with MPU 6050 for a personal project. MPU 6050 is being powered by the 3.3V supply pin in the Arduino board.</p>
<p>In order to make the sensor mobile, I ordered <a href="http://www.amazon.ca/gp/product/B00MEC4NP0?psc=1&redirect=true&ref_=oh_aui_detailpage_o00_s00" rel="nofollow">this battery</a>, which has one power output of 5V 1Amp that I plan on plugging into the Uno's USB Power/Data Outlet.</p>
<p>I know that when plugged into the computer via the same USB port, around 5V 500 mA is supplied. I was wondering if someone could tell me, <strong>whether the 1A battery that I ordered would burn my board or not</strong>. </p>
<p><strong>Also, is there a built in fuse inside this board?</strong></p>
| <p>Power sources like batteries and wall warts are <strong>voltage sources</strong>: they will deliver a fixed voltage, more or less. The current that they supply will be determined by the load you attach to them.</p>
<p>The "Amps" listed on a power supply is not how much current it <strong>will</strong> put out, it is the <strong>maximum</strong> current that the manufacturer has decided it <strong>can</strong> put out safely, without acting funny or overheating. So when you read that the USB port on a computer supplies 5V and 500mA, that means that it will supply 5V and <strong>up to</strong> 500mA. If you draw more than a 500mA current from your USB port, you would exceed the max current rating of the USB port. USB ports usually have an emergency shut-off mechanism built in, so they would just turn off if you drew more than 500mA out of them. I wouldn't try it though :). Your battery seems to have pretty similar safety features: "Super protection: overshoot, over-discharge, short circuit, over voltage, leakage, and many other protective functions".</p>
<p>If you had a 5V 20 Amp power supply, it will act the same as the USB port power supply, except it will be able to handle putting out much more current. As long as you don't exceed a voltage source's max current rating, <strong>the amount of current that a voltage source puts out depends on how much current the load draws, not on the voltage source.</strong> For example, a resistor will draw a current in Amps equal to the voltage supplied to it divided by the resistance (I=V/R), via Ohm's Law. For microcontrollers, you can often find their current draw on their datasheet: your MPU 6050 with the Gyro + Accel running has an operating current of <a href="http://www.invensense.com/mems/gyro/mpu6050.html" rel="nofollow">3.8mA</a> when you give it ~3.3V. An Arduino Uno draws about <a href="http://forum.arduino.cc/index.php?topic=135872.0" rel="nofollow">80mA</a> by itself, though I don't think this includes the 3.3V power regulator on the 3V3 pin. So you're looking at somewhere a little over 84mA (=0.084A) in total. Your battery can supply 2.5A or 1A depending on which of its ports you use, so you are nowhere near exceeding the battery's max current rating, which is a good thing.</p>
<p>There are no fuses built in to the Arduino Uno R3. If you exceed its <a href="http://playground.arduino.cc/Main/ArduinoPinCurrentLimitations" rel="nofollow">maximum current limitations</a>, you will mess it up. There's a <a href="http://www.ruggedcircuits.com/ruggeduino/" rel="nofollow">ruggedino</a> available with more safety features if you're worried about frying your arduino. But as long as you're careful you should be fine with a standard R3.</p>
|
8938 | |sensors|hardware| | Do Water sensors Rust? | 2015-02-28T22:16:58.440 | <p>I'm new to Arduino and still learning the basics.
I tried reading water level by using <a href="http://www.emartee.com/Images/websites/emartee.com/Water%20Sensor.jpg" rel="nofollow">this sensor</a> I left it in the water for about 5 minutes then I noticed it changing color (some parts darker than other)like the water is still over it .
So my question is do Water sensors really rust ? or is it my own imagination?</p>
| <p>The color change you observed is probably caused a galvanic reaction between metals in the sensor and other metals that are present, such as the tank, piping, or dissolved metals in the water. Do not modify the parallel strips of metal on the sensor. This will render the sensor useless. To reduce the effects of galvanic corrosion, you can:
1) Reduce the current passing through the sensor. To do this, sample the sensor less frequently. For, example, sample it once every second.
2) If possible, remove sources of metal from the water. For example, replace metal pipes with PVC, and replace screws with plastic zip-ties.
3) Move the sensor further away from sources of metal.
4) Place a grounded sacrificial zinc in the water, close any other metal sources. If the water is circulating, place the zinc near the inflow opening.
5) Remove stray or electrical currents from the water. Connect the "-" pin (GND) and the water to the same ground.</p>
|
8940 | |arduino-uno|wires| | Can I mix 22awg and 26awg hookup wire in the same circuit? | 2015-03-01T04:16:43.627 | <p>I'm still fairly new to Arduino projects, and am only just now getting into building circuits where I want to cut and place my own hookup wire instead of using the precut jumper wires. I inherited some supplies from a friend who abandoned the hobby, and about half of the wire he gave me is 22awg and the other half is 26awg. All of it is solid core copper. Is it ok to mix wire gauges like this in the same circuit/project?</p>
| <p>Assuming you won't ever put more current through it than the 26AWG wire can handle, you'll be safe.</p>
|
8945 | |ethernet|datalogging| | POST request not working | 2015-03-01T07:27:11.347 | <p>I'm following a guide on storing sensor data to MySQL:</p>
<p><a href="http://www.instructables.com/id/PART-1-Send-Arduino-data-to-the-Web-PHP-MySQL-D3js/#step1" rel="nofollow noreferrer">Guide</a></p>
<p>My POST request isn't getting any results to my server. For now, I'm only storing temperature.</p>
<p>Here is my code for saving data:</p>
<pre class="lang-cpp prettyprint-override"><code>void sendData(double input) {
String data = "sensorid=3000000&temp=" + doubleToString(input, 2) + "&hum=1.2";
if (client.connect("192.168.1.50", 80)) {
client.println("POST /arduino/add.php HTTP/1.1");
client.println("Host: 192.168.1.50");
// client.println("User-Agent: Arduino/1.0");
// client.println("Connection: close");
client.println("Content-Type: application/x-www-form-urlencoded");
client.print("Content-Length: ");
client.print(data.length());
client.println();
client.print(data);
Serial.println("Sent data: " + data);
}
if (client.connected()) {
client.stop();
}
delay(300000);
}
</code></pre>
<p>I've commented out two headers since it did not give any other results. My <code>Serial.println</code> gives: Sent data: sensorid=3000000&temp=24.00&hum=1.2, which means that the Arduino is connected to the given IP-adress and that my request data is as I want. They are also working perfectly when I'm testing with <a href="http://requestmaker.com/" rel="nofollow noreferrer">Requestmaker</a>, so I'm pretty sure my error comes from the way I'm doing the request here.</p>
<p>Do you have any idea how I can solve or debug this?</p>
| <p><em>Answered by Edgar Bonet</em></p>
<p>There needs to be an empty line between the headers and the body of the request. Therefore you have to <code>println()</code> (not <code>print()</code>) the end of the last header.</p>
|
8946 | |arduino-uno|bluetooth| | Arduino weird bluetooth module | 2015-03-01T13:43:57.623 | <p>Recently I bought a BT module from eBay which was very cheap. I didn't really noticed the image and I just bought it. When it came I couldn't find any holes to solder the headers. Also the specific module is pretty rare and I couldn't find anything.</p>
<p>Here is an image:</p>
<p><a href="https://i.stack.imgur.com/Dz4RR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dz4RR.jpg" alt="BlueTooth Module"></a></p>
<p>How do I wire up this chip?</p>
| <p>These Bluetooth modules are typically mounted onto another substrate, either the product board or a small PCB backplane which provides the pinouts and any additional circuitry like the pairing LED, and power- & signal-level management.
They are readily available as HC-05 (master/slave) or HC-06 (slave only) with signals brought to through-holes or pins at the edge of the backplane.</p>
|
8949 | |wifi|arduino-yun|remote-control|h-bridge| | External access to Yun - request not recognised as HTML | 2015-03-01T17:01:45.800 | <p>I am trying to access my Yun externally.</p>
<p>My router recognises traffic on Port XXXXX and forwards it to my Arduino Yun.</p>
<p>I have the below code working internally and now trying to adapt this to work for external (adapted from <a href="http://arduino.cc/en/Tutorial/TemperatureWebPanel" rel="nofollow noreferrer">http://arduino.cc/en/Tutorial/TemperatureWebPanel</a>). </p>
<p>To access the Arduino Yun over the network I type:</p>
<pre class="lang-none prettyprint-override"><code>http://XXX.XXX.XXX.XXX:XXXXX/arduino/on
</code></pre>
<p>When using this script locally, i.e. <code>myArduinoName.local/arduino/on</code>, the onboard light turns on (and off if URL changed accordingly).</p>
<p>Adapting this working code, I have changed to "<code>noListenOnLocalhost</code>" and put in my port number (XXXXX). </p>
<p>The code is reached (see below for the response).</p>
<pre class="lang-cpp prettyprint-override"><code>#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
// Listen on default port 5555, the webserver on the Yun
// will forward there all the HTTP requests for us.
YunServer server(XXXXX);
String startString;
long hits = 0;
void setup() {
//Serial.begin(9600);
// Bridge startup
pinMode(13,OUTPUT);
digitalWrite(13, LOW);
digitalWrite(13, HIGH);
Bridge.begin();
Console.begin();
// Listen for incoming connection only from localhost
// (no one from the external network could connect)
//server.listenOnLocalhost();
server.noListenOnLocalhost();
server.begin();
}
void loop() {
// Get clients coming from server
YunClient client = server.accept();
client.println("hello");
// There is a new client?
if (client) {
// read the command
String command = client.readString();
command.trim(); //kill whitespace
client.println(command); // why does this return a full GET request instead of "on"?
if (command == "on") {
digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000);
}
if (command == "off") {
digitalWrite(13, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
// Close connection and free resources.
client.stop();
hits++;
}
delay(50); // Poll every 50ms
}
</code></pre>
<p>The response I get is (I have replaced my IP and port with X's):</p>
<blockquote>
<p>hello</p>
<p>GET /arduino/off HTTP/1.1 Host: XXX.XXX.XXX.XXX:XXXXX
Connection: keep-alive Pragma: no-cache Cache-Control: no-cache
Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,<em>/</em>;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/40.0.2214.115 Safari/537.36
Accept-Encoding: gzip, deflate, sdch Accept-Language:
en-GB,en-US;q=0.8,en;q=0.6</p>
</blockquote>
<p>I expected</p>
<blockquote>
<p>hello </p>
<p>on</p>
</blockquote>
<p>So it would seem that because I'm using a different port (other than 80 or 5555) the response is no longer being interpreted as an HTTP request.</p>
<p>I have also tried to edit the uhttpd file via SSH to provide a specific address and port for both my external IP address and my fixed internal IP address.</p>
<p>Then tried to restart the device and also a uhttpd restart i.e.:</p>
<pre class="lang-none prettyprint-override"><code>/etc/init.d/uhttpd restart
</code></pre>
<p>I have attempted to access the URL using my mobile phone (i.e. not on the same network).</p>
<p>Any ideas why my request is not being treated as HTTP?</p>
| <p>It works!</p>
<p>The changes to the uhttpd must have done the trick to listen for http traffic on a given IP/port (other than 0.0.0.0:80).</p>
<p>Instead of supplying a port number for the server in the code, I would surmise that the change to the config takes care of it so this, so the port number in code is no longer needed:</p>
<p>YunServer server(XXXXX);</p>
<p>should be changed back to </p>
<p>YunServer server;</p>
|
8950 | |pins|uploading|arduino-pro-mini| | Having difficulty uploading sketch to an Arduino Pro Mini | 2015-03-01T17:05:40.853 | <p>Having developed and tested a project using an Arduino Uno, I would now like to upload it to an <a href="http://www.amazon.co.uk/dp/B007YQZUEE" rel="noreferrer">Arduino Pro Mini</a> (5V, 328, 16MHz) for semi-permanent, long-term use, but I can't get any sign of life from the Pro Mini.</p>
<p>I'm using the latest Arduino IDE (v1.6.0 with Java 6, on Mac OS X Mavericks), and I've got a <a href="http://www.amazon.co.uk/gp/product/B00AFRXKFU" rel="noreferrer">USB 2.0 to TTL UART 6PIN CP2102 Module Serial Converter</a> to connect the Pro Mini to the Mac, and I've selected Tools —> Board —> Arduino Pro or Pro Mini (5V, 16MHz) w/ ATmega328.</p>
<p>The problem is that I don't see a suitable serial port in the list. When I plug in the Arduino Uno, "/dev/tty.usbmodem1421" immediately pops up in the Tools —> Serial Port menu, but I don't see anything similar with the Mini Pro.</p>
<p>The problem is probably in the connection between the USB/TTL converter and the Mini Pro, so my question is: which pins should connect to which?</p>
<p><img src="https://i.stack.imgur.com/nAxLG.jpg" alt="USB/TTL converter face to face with Arduino Pro Mini"></p>
<p>FWIW the USB/TTL converter was supplied with a 5-core (not 6-core) cable to connect its 6 pins.</p>
<p>So do I connect Tx—>Tx and Rx->Rx, or should they be crossed over? It's fairly clear that "5V" connects to "Vcc" and "GND" goes to "GND", but what about CTS and DTR?</p>
<p>Also FWIW, I have googled this, and I have read a number of other posts and answers on StackExchange, but the fact that I'm here writing my question means that I'm still stuck. Any and all constructive suggestions will be appreciated. Thanks!</p>
| <p>If you still have any issues, try connecting the vcc and gnd to raw and gnd near the pins. Mine worked this way</p>
|
8956 | |programming|voltage-level|attiny| | How to program ATTiny85 running 3.3V | 2015-03-01T19:26:23.130 | <p>I have a working project built around ATTiny85 on a breadboard running at 5V. Now I want to move this prototype on a PCB where it will be powered from batteries. All components used are capable of running 3.3V so I want to run the ATTiny85 at 3.3V as well.</p>
<p>I don't have a programmer so I use ArduinoISP to program the ATTiny. If I change the fuses on Tiny to run it at 3.3V can I still use the 5V Arduino to program the tiny?</p>
<p>Since the ATTiny can easily run at 5V I don't see any problem with programming it at 5V levels and then run it at 3.3V. Is that correct?</p>
| <p>Most ideal would be to use a buffer chip (like there is on the <a href="https://www.sparkfun.com/products/9825" rel="nofollow">AVR Pocket Programmer</a>). </p>
<p>But in your case you could get away with just placing some resistors (1k or something) on the ISP lines. This is because if the chip is powered by 3v and you put a 5v signal on one of the pins it's clamping diodes will redirect the higher voltage to VCC, raising VCC to 5v. In your case the 5v is not necessarily a problem. But if you circuit is using e.g. 100mA, that means 100mA will go through the clamping diode. It's not designed for that.</p>
|
8957 | |networking|esp8266| | Arduino and ESP8266 Web server | 2015-03-01T19:36:33.453 | <p>First things first, if there was an ESP8266 StackExchange, I would post this there.</p>
<p>I am setting up a web server that will programmaticly be controlled from an external Python script, and I am currently able to send this server data using this script, but I don't receive an HTTP response back when I do, so the external script crashes.</p>
<p>I have googled around and not found much on this, so the question is How do I, From the Arduino, using an ESP8266 send an HTML response code?</p>
| <p>After countless Trial/error attempts, I was able to put together the proper sequence. </p>
<pre><code>AT+CIPSEND=0,40 \\Set this for your current connection ID and payload length.
HTTP/1.1 200 OK\r\nConnection: close\r\n\r\n
AT+CIPCLOSE=0 \\Set this for your current connection ID
</code></pre>
<p>Send these commands with the arduino, and it should exit successfully. You can also flush out the HTTP line with any other information you would like to include, as defined in the <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.html#sec6" rel="noreferrer">rfc2616 (HTTP/1.1) standard</a></p>
|
8962 | |serial|arduino-mega| | Can you query the current serial port's speed? | 2015-03-02T00:23:24.347 | <p>Is there some code I can use to find out what the a chosen serial port's speed is running at ?</p>
| <p>There is not a top level, easy to use way. Sorry. It is probably easier to just store your chosen baud rate in a variable when you setup the serial port.</p>
<p>Anyway, What you can try to do for the AVR-based, hardware UARTs is undo what <code>Serial.begin</code> does to set up a particular baud rate, but its a bit of a pain. This is the code for setting the baud rate:</p>
<pre><code> // Try u2x mode first
uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
*_ucsra = 1 << U2X0;
// hardcoded exception for 57600 for compatibility with the bootloader
// shipped with the Duemilanove and previous boards and the firmware
// on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot
// be > 4095, so switch back to non-u2x mode if the baud rate is too
// low.
if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
{
*_ucsra = 0;
baud_setting = (F_CPU / 8 / baud - 1) / 2;
}
// assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
*_ubrrh = baud_setting >> 8;
*_ubrrl = baud_setting;
</code></pre>
<p>You can find the results of this by reading the right UCSRA, UBRRH, and UBRRL registers. On an uno those are the correct register names, on an mega its UCSR0A, UBRR0H, UBRR0L for Serial, UCRS1A ... for serial1 and so on. Non-avr boards (and <code>Serial</code> on a leonardo) will be totally different.</p>
<p>There will be a single state for those three registers on an AVR hardware serial port for a particular board (and frequency of that board) at each baud rate. You can try and make an equation to get the original baud rate out, but I recommend just comparing the direct values with a lookup of some kind because the integer arithmetic rounding errors will make it a huge mess.</p>
<p>For example, on my mega UBBR0H, UBBR0L, and UCSR0A are 0, 207, 2 at 9600 baud, but they are 0, 51, 2 at 38400 baud and 0, 16, 0 at 57600 baud.</p>
|
8965 | |motor|arduino-leonardo|arduino-pro-micro| | STEPPER MOTOR CONTROLLER Using LEONARDO PRO MICRO | 2015-03-02T02:42:36.453 | <p>I want to Use LEONARDO PRO MICRO and A4988 Stepper Motor DRIVER to control Nema 17 Stepper Motor.</p>
<p><img src="https://i.stack.imgur.com/43w75.jpg" alt="enter image description here">
<img src="https://i.stack.imgur.com/pklWd.png" alt="enter image description here"></p>
<p>Please let me know how to hookup these together. </p>
<p>Please give me a circuit for this type of assembly with Arduino code.</p>
| <p>You can simply make a google search;
<img src="https://i.stack.imgur.com/7W4Th.png" alt="Wiring instructions"></p>
<p>Here is some code to get you started</p>
<pre><code>// Declaration of variables
#define Step 7 // Pin that transmits the "step" order to the board
#define Dir 6 // Pin that indicates the direction of the rotation
int vit = 10 ; // Speed of the rotation (smaller means faster rotation)
int sens = 1 ; // Rotation direction (0 or 1)
void setup()
{
pinMode( Step , OUTPUT );
pinMode( Dir , OUTPUT );
}
void loop()
{
digitalWrite( Dir , sens);
digitalWrite( Step , LOW);
// Fabrication d'un "Pas"
digitalWrite( Step, HIGH );
delay(vit);
digitalWrite( Step, LOW );
delay(vit);
}
</code></pre>
<p>Just a google search and I got on [this site][2] which had the code I gave you.
I think you can also find some libraries that can do the work for you.</p>
<p>in case that you need to wait less than a millisecond, <code>millis()</code> won't be useful for you; instead, use <code>delayMicroseconds()</code> which will make you wait a thousandth (at minimum) of a millisecond.</p>
<p><strong>EDIT</strong></p>
<p>For what you asked you have to first get the voltage: </p>
<pre><code>float voltage = analogRead ( 0 ) * (3.0 / 1023.0);
</code></pre>
<p>You just have to adapt your speed relatively to the voltage.
To do this, I suggest you the <a href="http://arduino.cc/en/reference/map" rel="nofollow noreferrer">map function</a> directly from Arduino site.</p>
<p>Be careful just because whatever you are doing, analogRead takes <strong>100 microseconds</strong> to get the voltage, so if you need to go very fast you can't. I suggest you to work with a different type of communication, like Serial, SPI or I2c. </p>
|
8972 | |arduino-pro-micro| | Problems with (somewhat) large boolean arrays | 2015-03-02T15:52:58.197 | <p>I am writing a simple Conway's Game of Life implementation just to get to grips with the "Nokia 3310" LCD and I am having problems with boolean arrays. I am using an (unofficial) Arduino Pro Micro 5V/16MHz</p>
<p>Here's the code that is causing me trouble:</p>
<pre><code>boolean buffer[84][48];
void setup(){
for(int i = 0; i < 84; i++){
for(int j = 0; j < 48; j++){
buffer[i][j] = true;
}
}
}
void loop(){}
</code></pre>
<p>When I upload this to the Arduino, it seemingly freezes up with the RX led on and its COM port stops working. If I want to upload any other sketch, I have to manually pull the RST pin LOW (since the Pro Micro doesn't have a reset button).</p>
<p>I've been playing around with the code and found out that the source of problems is this line:</p>
<pre><code>buffer[i][j] = true;
</code></pre>
<p>It also doesn't matter if I use <code>true</code> or <code>false</code>.</p>
<p>I have tried debugging with Serial to the computer, but the Serial communication doesn't work at all, so I tried using an LED to find out where the problem is. I don't have any "regular" LEDs on me, so I had to try with an Adafruit NeoPixel. The outcome was quite interesting. When I comment out the problematic line, everything runs just fine, the led goes red for 500ms then it blinks white every time the problematic line would run and then it goes green and stays that way. With the problematic line in place, the LED won't do anything, even turn red, which I put much earlier in the code than the source of the problem.</p>
<p>Does anybody have any insights that might be useful? (Also, I really hope it is not some stupid typo, I swear I read it through about twenty times) </p>
| <p>Well, if each boolean takes a full byte, as fuenfundachtzig says, then you might try some bitwise hacking to fit 8 bools per byte on your own. Maybe something like this:</p>
<pre><code>unsigned int16 buffer[84][3]; //16 bits * 3 = 48 bits, per the original example
void init_buffer()
{
for(int i = 0; i < 84; i++)
{
for(int j = 0; j < 3; j++)
{
buffer[i][j] = 0xFFFF; //all TRUE: each F is hexadecimal for 0b1111 in binary
}
}
}
bool get_buffer(unsigned int8 i, unsigned int8 j)
{
unsigned int16 k = 0;
while(j >= 16)
{
j -= 16; //I can do this because i and j are passed by value and are therefore separate copies inside this function
k++;
}
//now k is the array index and j is the bit position inside that element
if(buffer[i][k] & (1 << j)) //(bitwise AND with 1 shifted left by j positions, so we only care about that bit)
{
return TRUE;
}
else
{
return FALSE;
}
//or, if your compiler supports it, you might replace the if/else with:
return (buffer[i][k] & (1 << j));
}
</code></pre>
<p>As for the stylistic differences between my example and yours:</p>
<ul>
<li>I like to completely specify my datatypes if I can. Don't rely on the compiler to do what you expect because it may have options to that effect that are set differently than you think.</li>
<li>I like to use brackets for everything, even single statements, and make them obvious. That way, there's no confusion later or additional bugs because a second statement was added to what used to be a bracketless single without adding the brackets.
<ul>
<li>The only exception to that is when I'm writing a series of almost-identical if's and I put both the if and the action on the same line, all aligned so that the subtle differences line up and become obvious.</li>
</ul></li>
</ul>
|
8979 | |led|display| | 7 segment LEDs on wood face | 2015-03-02T18:24:57.273 | <p>I'm not sure this is right place for this question, but does anyone have any idea how a 7 segment display is projected or embedded in wood for products like this?</p>
<p><img src="https://i.stack.imgur.com/neWtv.jpg" alt="amazon wood clock"></p>
<p>Full product info at <a href="http://rads.stackoverflow.com/amzn/click/B00D6DI0LE" rel="noreferrer">http://www.amazon.com/Cube-Wood-LED-Alarm-Clock/dp/B00D6DI0LE</a></p>
<p>Another example:</p>
<p><img src="https://i.stack.imgur.com/x3VBV.jpg" alt="enter image description here"></p>
<p>From: <a href="http://www.selectism.com/2013/11/27/a-wooden-led-alarm-clock-and-wireless-bluetooth-speaker-from-gogroove/" rel="noreferrer">http://www.selectism.com/2013/11/27/a-wooden-led-alarm-clock-and-wireless-bluetooth-speaker-from-gogroove/</a></p>
| <p>This is done by carefully placing a layer of wood veneer over the 7-segment displays. The veneer is thin enough to let the light pass through. I wouldn't be surprised if some manufacturers use brighter than normal LEDs to make the display easier to see. <a href="https://www.youtube.com/watch?v=2P-8-zd7sXg">Here is a video detailing an example.</a></p>
<p>It is also possible to simply drill out the wood to make it very thin where the 7-segment displays go. <a href="http://www.instructables.com/id/Solid-Wood-Digital-Clock/">Here is an example of drilling the solid wood to be very thin.</a> </p>
|
8998 | |battery|sleep| | How best to power down an Arduino for ~5 minutes at a time? | 2015-02-24T18:48:48.107 | <p>Reading over the datasheet it appears the longest it can shutdown for is 8s so should I just keep a counter in the loop method that checks if it's run 38 times and then execute the code I want? Would this wakeup every 8s hurt battery life much if it's doing nothing but incrementing a counter?</p>
| <p>Looks like you've got some great answers already. For a great deal more info and details on the matter, check out what Nick Gammon has written here too: <a href="http://www.gammon.com.au/forum/?id=11497" rel="nofollow">http://www.gammon.com.au/forum/?id=11497</a> - Power saving techniques for microprocessors</p>
|
9015 | |sensors|shields| | Integrating Freescale Multi Sensor board with Arduino | 2015-03-04T15:59:03.240 | <p>I recently bought Freescale's <a href="http://uk.farnell.com/freescale-semiconductor/frdm-fxs-multi-b/dev-board-xtrinsic-sensor-kinetis/dp/2443150" rel="nofollow">FRDM-FXS-MULTI-B</a>, and have been trying to integrate it with an Arduino UNO. The board descriptions say that it has the shield layout that matches that of an Arduino shield. So in theory, I should be able to integrate it fine.</p>
<p>The problem comes when I plug it in and try to program the Arduino. As soon as I plug it in, the board resets and hangs. If I try to upload a simple code (just reading the analogue signal from the light sensor), the IDE hangs when uploading. Sometimes, I can fix it by removing the shield and pressing the reset button, but sometimes that doesn't work: the computer doesn't recognise the Arduino on the port, and the IDE removes the port from the Port Selection option. When I do remove it and it resumes functioning normally, and I re-attach the shield, the board resets and hangs again, until I go into the Serial Monitor.</p>
<p>With this board, I realised the Bluetooth module is connected to the Serial Receive pin, which explains the hang in the IDE, but I cannot understand why it resets and hangs when I plug it in.</p>
<p>Does anyone have any experience with this board, and can help me out? Why can I not find any tutorials online? With the multitude of sensors on this shield, I'm guessing you can access them via normal I2C and SPI communications, right? How do you use the Bluetooth module on the board?</p>
| <p>So... 20 months later I stumbled upon this question, only to find out I wrote it. Awkward! Anyway, for anyone who stumbles across this question in the future, here is the answer.</p>
<p>The Rx pin is connected to the Bluetooth module, and as such the module will keep the pin in an idle state (either idle-high or idle-low). The Rx pin of the Arduino UNO (or the Rx0 pin on the Mega/Due) requires to be free of anything that may interfere with the upload. The Arduinos rely on the Rx pin for the sketch upload. If anything is connected to it, the IDE will freeze and nothing will be uploaded. Simply disconnect the FRDM board, upload the code, and put the board back in place. Then it should work. </p>
|
9018 | |arduino-uno|programming|motor|analogwrite|digital| | How to make the motor car move left-forward / left-backward/ right-forward/ right-backward | 2015-03-04T18:03:40.177 | <p>I'm using an Arduino Uno to make a motor car. And I successfully made it move forward / backward / left / right.</p>
<pre><code>void forward(void) {
analogWrite(EA, 254); //speed 0 - 255
analogWrite(EB, 255); //speed 0 - 255
digitalWrite(EN2, LOW);
digitalWrite(EN3, HIGH);
digitalWrite(EN4, LOW);
digitalWrite(EN5, HIGH);
}
void backward(void) {
analogWrite(EA, 255); //speed 0 - 255
analogWrite(EB, 255); //speed 0 - 255
digitalWrite(EN2, HIGH);
digitalWrite(EN3, LOW);
digitalWrite(EN4, HIGH);
digitalWrite(EN5, LOW);
}
void left(void) {
analogWrite(EA, 180); //speed 0 - 255
analogWrite(EB, 180); //speed 0 - 255
digitalWrite(EN2, LOW);
digitalWrite(EN3, HIGH);
digitalWrite(EN4, HIGH);
digitalWrite(EN5, LOW);
}
void right(void) {
analogWrite(EA, 180); //speed 0 - 255
analogWrite(EB, 180); //speed 0 - 255
digitalWrite(EN2, HIGH);
digitalWrite(EN3, LOW);
digitalWrite(EN4, LOW);
digitalWrite(EN5, HIGH);
}
</code></pre>
<p>The problem is, I found it is quite strange if I need to first press left/ right and press forward to turn around. I would like to make 4 extra buttons for left-forward / left-backward/ right-forward/ right-backward. Any ideas to create 4 extra functions for that?</p>
<p>Thanks for helping.</p>
<p><strong>Update: Connection</strong></p>
<pre><code>int EN2 = 14;
int EN3 = 15;
int EN4 = 16;
int EN5 = 17;
int EA = 3;
int EB = 5;
</code></pre>
<p><strong>Update: Attempted code and hardware connection</strong></p>
<pre><code>void left_top(void) {
analogWrite(EA, 128); //speed 0 - 255
analogWrite(EB, 255); //speed 0 - 255
digitalWrite(EN2, LOW);
digitalWrite(EN3, HIGH);
digitalWrite(EN4, LOW);
digitalWrite(EN5, HIGH);
}
void right_top(void) {
analogWrite(EA, 255); //speed 0 - 255
analogWrite(EB, 128); //speed 0 - 255
digitalWrite(EN2, LOW);
digitalWrite(EN3, HIGH);
digitalWrite(EN4, LOW);
digitalWrite(EN5, HIGH);
}
void left_down(void) {
analogWrite(EA, 128); //speed 0 - 255
analogWrite(EB, 255); //speed 0 - 255
digitalWrite(EN2, HIGH);
digitalWrite(EN3, LOW);
digitalWrite(EN4, HIGH);
digitalWrite(EN5, LOW);
}
void right_down(void) {
analogWrite(EA, 255); //speed 0 - 255
analogWrite(EB, 128); //speed 0 - 255
digitalWrite(EN2, HIGH);
digitalWrite(EN3, LOW);
digitalWrite(EN4, HIGH);
digitalWrite(EN5, LOW);
}
</code></pre>
<p>Left top / right top seem not to move at all, and right top / down is just similar to right / left.</p>
<p><strong>And for hardware, I am using</strong></p>
<p>Arduino AR 293d</p>
<p><img src="https://i.stack.imgur.com/6TtmL.png" alt="enter image description here"></p>
<p>For the motor connection, it's like this:</p>
<p><img src="https://i.stack.imgur.com/V397E.jpg" alt="enter image description here"></p>
| <p>just go to this link.
Visit to
<a href="https://www.arduino.cc/en/Tutorial/PWM" rel="nofollow">https://www.arduino.cc/en/Tutorial/PWM</a></p>
<p>At first use PWM to both right side and left side motor.
When right side motor spin/rotate at 255 value make leftside motor rotation speed at about 100 then you will see that it goes left-forward like wise you do rest of other.</p>
<p>Eg.</p>
<pre class="lang-cpp prettyprint-override"><code>void setup()
{
//LEFT MOTOR
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); // connect pwm pin of left motor at pin9
//right motor
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
pinMode(12, OUTPUT); motor // connect pwm pin of right motor at pin12
}
void loop()
{
digitalWrite(7, HIGH);
digitalWrite(8, LOW);
analogWrite(9, 100);
delay(1000);
digitalWrite(10, HIGH);
digitalWrite(11, LOW);
analogWrite(12, 255);
delay(1000);
}
</code></pre>
|
9019 | |arduino-uno|programming|string|networking|tcpip| | How to return a message when calling by a TCP connection? | 2015-03-04T18:12:43.590 | <p>I am working on a communication between Android and Arduino board.</p>
<p>The Android makes a TCP connection with the board and successfully sends some strings to the board. </p>
<p>The problem is, there is an int in my Arduino code (e.g. <code>int distance</code>) and I would like to pass that back to my Android device.</p>
<p>I have handled the Android side already, but I do not know how to return a message from Arduino.</p>
<pre><code>in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
//in this while the client listens for the messages sent by the server
while (mRun) {
serverMessage = in.readLine();
if (serverMessage != null && mMessageListener != null) {
//call the method messageReceived from MyActivity class
mMessageListener.messageReceived(serverMessage);
}
serverMessage = null;
}
</code></pre>
<p>This is the Android side code but I think that it is not a specific Android problem, there should be some way for Arduino to make a response of an integer variable (without concern what is the source device)?</p>
<p>What I should do in Arduino for making that response?</p>
| <p>I'm assuming that you are using an Ethernet shield, as nothing about this is stated. But solution is really similar between many network solution.</p>
<p>Once a TCP connection has been established, it can be used like you would use the Serial;</p>
<p>you'll probably end up having something similar to:</p>
<pre><code>EthernetClient client = server.available(); //accept a new connection
if (client) { //if valid connection
client.print(distanceValue);
client.close(); //close connection
}
</code></pre>
<p>look at the <a href="http://arduino.cc/en/reference/ethernet" rel="nofollow">official API reference</a> for a more detailed list of available command.</p>
|
9030 | |sensors|pins|wires| | What type of connector does the GROVE system use? | 2015-03-04T23:12:29.703 | <p>What type of connector does <a href="http://wiki.seeed.cc/Grove_System/" rel="noreferrer">GROVE</a> use?</p>
<p>I'm interested in wiring some old sensors so they're compatible with GROVE, so I first need to identify the connector so I can buy the housing and pins to crimp. It looks to be some type of JST connector, but there are <a href="http://en.wikipedia.org/wiki/JST_connector" rel="noreferrer">many different sizes</a>, each with incompatible pitches and a lot of retailers often advertise them incorrectly. Unfortunately, I can't find any documentation of the connector on Seeedstudio's site.</p>
| <p>I might have found at least one of the many possible manufacturers that make these types of connector. The manufacturer is Boom Precision Electronics and you can buy the connectors through <a href="https://www.lcsc.com/" rel="nofollow noreferrer">LCSC</a>.</p>
<p>Here are the links to four of the connectors on LCSC.</p>
<p><a href="https://www.lcsc.com/product-detail/Wire-To-Board-Wire-To-Wire-Connector_BOOMELE-Boom-Precision-Elec-HY-4A_C146064.html" rel="nofollow noreferrer">Vert. THT 4-Pin 2.00mm</a>
<a href="https://www.lcsc.com/product-detail/Wire-To-Board-Wire-To-Wire-Connector_BOOMELE-Boom-Precision-Elec-HY-4AW_C146068.html" rel="nofollow noreferrer">RA THT 4-Pin 2.00mm</a>
<a href="https://www.lcsc.com/product-detail/Wire-To-Board-Wire-To-Wire-Connector_BOOMELE-Boom-Precision-Elec-C161188_C161188.html" rel="nofollow noreferrer">Vert. SMD 4-Pin 2.00mm</a>
<a href="https://www.lcsc.com/product-detail/Wire-To-Board-Wire-To-Wire-Connector_BOOMELE-Boom-Precision-Elec-C146060_C146060.html" rel="nofollow noreferrer">RA SMD 4-Pin 2.00mm</a></p>
<p>Disclaimer: I never bought these connectors listed above so I never got the chance to try and mate the grove cable housing with it. It however does seem to fit the dimension and shape based on the drawings.</p>
|
9044 | |voltage-level|analogread|battery| | Arduino ADC read bad value | 2015-02-20T01:42:14.743 | <p>I have an Arduino device and I'm trying to read two voltages. The first one is the Arduino Vcc by using the bandgap value 1.1V (this requires raw access to registers since it's not implemented in analogRead). The other one is checking the battery voltage using the badgap as a reference. I want both of them because I'm doing a study on the battery life when using a step-up converter.</p>
<p>I'm using these pieces of code:</p>
<pre><code>// Read bandgap with Vcc as reference - this will give use the Vcc
ADMUX = DEFAULT << 6 | 14;
delayMicroseconds(250);
bitSet(ADCSRA, ADSC);
while(bit_is_set(ADCSRA, ADSC))
;
word x = ADC;
Serial.println(x);
// Read A1 with 1.1V bandgap as reference - this will give battery voltage
ADMUX = INTERNAL << 6 | 1;
delayMicroseconds(250);
bitSet(ADCSRA, ADSC);
while(bit_is_set(ADCSRA, ADSC))
;
word x = ADC;
Serial.println(x);
</code></pre>
<p>The problem that I have is that separately they seem to work well, however when using them together the first piece of code ruins the reading for the second one. The culprit is the line <code>ADMUX = DEFAULT << 6 | 14</code>. This sets up the default reference (chip voltage) and reads channel 14 (which is the 1.1V). I can't figure out why after using this line changing back with <code>ADMUX = INTERNAL << 6 | 1</code> doesn't work.</p>
| <p>The datasheet says:</p>
<blockquote>
<p>The first ADC conversion result after switching reference voltage
source may be inaccurate, and the user is advised to discard this
result.</p>
</blockquote>
<p>Then you could try to take each reading twice, looping over four ADC
readings:</p>
<ol>
<li>Read bandgap with Vcc as reference, discard the value.</li>
<li>Re-take the same, keep the value.</li>
<li>Read A1 with 1.1V bandgap as reference, discard the value.</li>
<li>Re-take the same, keep the value.</li>
</ol>
|
9051 | |debugging|gcc| | How to fix error line number offset in Sublime Text when compiling for Arduino | 2015-03-05T19:07:32.147 | <p>When compiling for Arduino via the Stino plugin line numbers are not represented correctly in the output. For example, I have an error on line 117 however the output is: <code>sketch_name.ino.cpp:136:1: error:</code></p>
| <p>The <a href="https://gcc.gnu.org/onlinedocs/cpp/Line-Control.html" rel="nofollow"><code>#line</code> preprocessor directive</a> is used to tell GCC both what the next line should be numbered as and what filename should be reported, and the plugin is not generating them properly. This is therefore a Stino bug.</p>
|
9055 | |millis|data-type| | arduino - millis() | 2015-03-05T20:35:21.740 | <p>Copied from the <a href="http://arduino.cc/en/Reference/Millis" rel="noreferrer">Arduino reference - millis()</a></p>
<blockquote>
<p><strong><em>Tip</strong>: Note that the parameter for millis is an unsigned long, errors may be generated if a programmer tries to do math with other
datatypes such as ints.</em></p>
</blockquote>
<p>What kind of math? What kind of other type of processing is excluded while working with millis? </p>
<p>Could someone clarify this statement and/or give some example? </p>
| <p>Whenever you write an equation in C/C++, the data types being operated on have a very real effect on the equation's output. </p>
<p>Each type like <code>int</code>, <code>float</code>, and <code>unsigned long</code> have different behaviors, and take a certain amount of space in memory to store. </p>
<p><code>int</code> (on arduino) is store in 16 bits, with half of its values being given to negative numbers, half-1 given to positive values, and one value given to 0. That gives it a range of -2^15 (-32,768) to +2^15-1 (32,767).</p>
<p><code>unsigned long</code> (on arduino) is 32 bits, but none are designated as negative. its range is then 0 to 2^32-1 (4294967295).</p>
<blockquote>
<p>What kind of math? What kind of other type of processing is excluded
while working with millis?</p>
</blockquote>
<p>The crux of the issue is that it the time millis returns ever got past 32767 and you tried to store it in an int, the arduino couldn't do it, because an <code>int</code> can't hold that big of a number. The type of math this is off limits is math happening to smaller data types, not any specific operations. Maybe these examples will help:</p>
<pre><code> int i = 32767;
Serial.println(i);
//No problems here; it fits just fine
</code></pre>
<blockquote>
<p>32767</p>
</blockquote>
<pre><code> i = 32767 + 1;
Serial.println(i);
//Oh no, the value didn't fit
</code></pre>
<blockquote>
<p>-32768</p>
</blockquote>
<pre><code> unsigned long fake_millis = 42000;
i = fake_millis;
Serial.println(i);
//This is an example of millis going past an int
</code></pre>
<blockquote>
<p>-23536</p>
</blockquote>
<pre><code> i = -10;
unsigned int j = i;
Serial.println(j);
//no way to put a negative number in an unsigned value
</code></pre>
<blockquote>
<p>65526</p>
</blockquote>
<pre><code> uint32_t k = fake_millis;
Serial.println(k);
//unsigned long is a uint32_t on arduino; this works great!
</code></pre>
<blockquote>
<p>42000</p>
</blockquote>
<p>The way this is implemented is really quite genius; If you are interested in where these numbers come from and why they spill over in the way they do you should look into same explanations of two's complement number representations.</p>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.