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
|
---|---|---|---|---|---|
5137 | |arduino-uno|led|resistor| | Lighting 5 leds...the last one lit is always dim | 2014-11-22T18:18:13.543 | <p>I have a simple project with a close deadline.</p>
<p>I am trying to light up 5 LEDs as part of the project. The first 4 light up in sequence fine, and if I light up just the last one it lights up fine, but if all 5 are lit at once the very last LED is very dim. I swapped out cables, the pin on the Arduino, resistor, LED.</p>
<p>What would explain that? Input amperage? Too strong a resistor?</p>
<p>I have a 330 ohm resistor in between each LED and ground. I am using one of the neat resistors from SparkFun that packages up the 5 330 ohm resistors together, with a common ground wire. I bought two and tried swapping it out with no change.</p>
<p><a href="https://i.stack.imgur.com/QZ4qU.jpg" rel="nofollow noreferrer">https://i.stack.imgur.com/QZ4qU.jpg</a></p>
<p>Here is my code:</p>
<pre><code>/* Blink without Delay
http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
const int startButtonPin = 6;
const int reedSwitchPin = 7;
const int ledPins[] = {8,9,10,11,13};
const int numLeds = 5;
const long interval = 1000; // interval at which to blink (milliseconds)
const int revolutionsPerStage = 15;
int debounceDelay = 500; // for switches--interval to ignore short button presses/reed switch open/close
long lastDebounce = 0;
int buttonState = LOW;
int mapStage = 0;
unsigned long previousMillis = 0; // will store last time LED was updated
void setup() {
// set pin modes
for (int thisPin = 0; thisPin < (sizeof(ledPins)/sizeof(int)) - 1; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
pinMode(startButtonPin, INPUT);
pinMode(reedSwitchPin,INPUT);
digitalWrite(reedSwitchPin,HIGH); // activate the pull-up resistor
}
// Main program loop
void loop()
{
buttonState = digitalRead(startButtonPin);
//digitalWrite(8,HIGH);
// wait for button press to begin program proper. we won't get back to this state except on first boot or if program finishes
if (buttonState == HIGH) {
digitalWrite(8,HIGH);
chasingLEDs();
//trackProgress();
}
}
void trackProgress() {
int blinkState = LOW;
unsigned long currentMillis = millis();
unsigned int numRevolutions = 0;
do {
digitalWrite(ledPins[mapStage], HIGH);
// blink the current goal LED at constant interval specified earlier
if(currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
blinkState = !blinkState;
digitalWrite(ledPins[mapStage], blinkState);
}
} while (mapStage < numLeds);
}
// perform a simple welcome sequence to indicate we are ready to start pedalling
void chasingLEDs() {
// turn LEDs on in sequence, then back off
for (int i = 0; i < numLeds; i++){
digitalWrite(ledPins[i], HIGH);
delay(333);
}
for (int j = numLeds; j > 0; j--) {
digitalWrite(ledPins[j], LOW);
delay(333);
}
// flash the LEDs twice
for (int k = 0; k < 2; k++) {
for (int l = 0; l < numLeds; l++) {
digitalWrite(ledPins[l], HIGH);
}
delay(500);
for (int m = 0; m < numLeds; m++) {
digitalWrite(ledPins[m], LOW);
}
}
}
</code></pre>
| <p>I found the problem, it was a bug in my code. I had found code to read the array size online but it was off by 1.</p>
<p>Instead of: </p>
<pre><code>for (int thisPin = 0; thisPin < (sizeof(ledPins)/sizeof(int)) - 1; thisPin++) {
pinMode(ledPins[thisPin], OUTPUT);
}
</code></pre>
<p>When I changed it to thisPin < numLeds, it worked correctly. The last pin was simply set to be an input pin instead of an output pin.</p>
|
5140 | |led| | Infrared sensor has a frequency to activate it? | 2014-11-22T20:43:48.510 | <p>I am trying to understand 2 sensors that I have here. One says that is "infrared sensor of 38kHz" and the other is "infrared optical reflexive sensor -> <a href="http://www.robosoftsystems.co.in/wikidocs/index.php?title=TCRT_5000_Reflective_Optical_Sensor" rel="nofollow">http://www.robosoftsystems.co.in/wikidocs/index.php?title=TCRT_5000_Reflective_Optical_Sensor</a>"</p>
<p>I thought that infrared sensor would tell me if an infrared light is passing on it. Infrared light has a wavelenght, right? Can infrared light be emited in different frequencies? Or the frequency of infrared light is the same to all infrared lights?</p>
| <p>38Khz is not the frequency of the IR light but the frequency it is pulsed on and off at, the receiver is designed to accept that frequency and reject others so as to avoid interference from sunlight etc. I see you have asked the question again in a slightly different way and received a similar answer.
<a href="https://arduino.stackexchange.com/questions/5152/infrared-led-and-sensor-how-it-work">Infrared led and sensor: how it work</a></p>
|
5141 | |current| | How does an analog input pin work? | 2014-11-22T21:37:13.623 | <p>I have a potentiometer of 10k and I connected it this way:</p>
<p>5v -> potentiometer -> analog input pin of Arduino</p>
<p>When I turn the potentiometer I change the resistance of the circuit but in the Arduino documentation they say that an analog pin in INPUT mode will have 1 megaohm resistance. So, for example, if I turn the potentiometer to the middle it will generate 5k of resistance + 1 megaohm of the analog pin it will result in a tiny, very tiny current. If I use U = R x I across the potentiometer it will be:</p>
<p>U = 5000 x 0.0000001</p>
<p>U ~ 0 across the potentiometer. So U will be 5 V at the analog input because there was no drop of voltage in the circuit. If turn the potentiometer all way up to 10k resistance the voltage in the analog input will also be 5 V because the voltage drop across the potentiometer is still really small.</p>
<p>I know that an analog pin in INPUT mode will read 0 V as 0 and 5 V as 1023. But as I showed you it should always read 5 V even when I turn the potentiometer all way up because the voltage is not being changed. I know I am wrong cause when I log the input pin it shows different values as I turn the potentiometer. So how does this work?</p>
| <p>The potentiometer and the internal resistance form a voltage divider. The voltage created by this voltage divider is essentially indistinguishable from 5V regardless of what the pot is set to because the internal resistance is so high.</p>
<p>What you want to do is to create an <em>external</em> voltage divider that will cause the voltage to vary full scale between 5V and 0V. You do so by connecting one end of the pot to 5V and the other end to 0V, and drawing the voltage from the wiper.</p>
|
5148 | |ir| | Blue LED not switching off | 2014-11-23T10:32:12.403 | <p>I have a circuit with a blue led, 470ohm resistor and one IR led. I want the led to be switched off when the IR led has a digitalRead value of LOW(i move my hand over it). So I wrote the code:-</p>
<pre><code>void setup() {
// initialize digital pin 13 as an output.
pinMode(13, OUTPUT); // this is the blue led
pinMode(10, INPUT); // this is the IR sensor's O/P
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(13, HIGH); // first I give HIGH voltage to the blue LED
if(digitalRead(10) == LOW){ // when the voltage of the IR sensor decreases
digitalWrite(13, LOW); // the blue LED should switch off or have 0 Voltage
}
}
</code></pre>
<p>But the blue LED just dims and doesn't switch off. Thanks in advance</p>
| <p>Every time through your loop, the LED is being set to HIGH voltage. This may or may not be followed by setting it to LOW voltage, but since the loop runs again immediately, it's immediately set back to high voltage. This happens so fast that the LED essentially "feels" half voltage and it will dim. Your code needs to be more like this...</p>
<pre><code>void loop() {
if(digitalRead(10) == LOW) {
digitalWrite(13, LOW);
} else {
digitalWrite(13, HIGH);
}
}
</code></pre>
<p>OR... even like this...</p>
<pre><code>void loop() {
digitalWrite(13, digitalRead(10));
}
</code></pre>
|
5152 | |current| | Infrared led and sensor: how it work | 2014-11-23T15:13:08.303 | <p>I am having a difficult time to understand how an infrared sensor and led work. I have an infrared LED (like the ones you buy anywhere), does it mean that the infrared LED has the frequency os 38khz?</p>
<p>I know that infrared light has a wavelegnth, but does it also have a frequency?</p>
| <p>An infrared LED just emits its light (primarily) in the infrared range as described by this <a href="https://en.wikipedia.org/wiki/Infrared" rel="nofollow">Wikipedia article</a>. Any emitted radiated signal (including sound) has both a frequency and a wavelength. The frequency = the velocity of the signal through space divided by its wavelength (F = V / W), or vice-versa: (W = V / F). The natural frequency of light, infrared or visible is far, far higher than 38 KHz; around 4 x 10^14 Hz.</p>
<p>38 KHz is simply a convenient chopping frequency for switching the LED on and off so the sensor can distinguish between infrared in sunlight, for instance, which is relatively constant - from that emitted by the LED. Your circuitry would have to create the 38KHz chopping signal.</p>
|
5163 | |c++|library| | Include my header files | 2014-11-24T11:38:04.123 | <p>let's suppose I have folder called AES, in this folder is file "AES.ino" where is code and folder "AESLib" what is library. In "AESLib" is file called "AESLib.h", </p>
<p>now when I try to include AESLib.h with</p>
<pre><code>#include "AESLib/AESLib.h"
</code></pre>
<p>in my AES.ino, then Arduino command line tool complain that its not able to find "AESLib.h"</p>
<p>Where could be the catch?</p>
<p>Thanks</p>
| <p>Maybe this similar post is what you are looking for. In your case, you should use the path to the sketch folder as 'PROJECT_ROOT'.</p>
<p>Here's the link:
<a href="https://arduino.stackexchange.com/a/9575/7741">https://arduino.stackexchange.com/a/9575/7741</a></p>
<p>Hope it helps.</p>
|
5168 | |arduino-uno|serial|c++| | serial char read first letter if it is ";" print char without fists letter | 2014-11-25T00:57:00.283 | <p>I'm working on a project and I need to print serial to a LCD but only if the first letter of the serial is ":"</p>
<p>I have the serial being stored in a char and a if statement reading the first letter of the char to see if it is ":" From there I can't get it to print to the LCD without the first letter. I also don't know how to clear the char.</p>
<pre><code>#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
char inData[20];
char inChar;
byte index = 0;
void setup(){
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
while(Serial.available() > 0)
{
if(index < 19)
{
inChar = Serial.read();
inData[index] = inChar;
index++;
inData[index] = '\0';
}
if(inData[0] == ':') {
lcd.print(inData);
}
}
}
</code></pre>
| <p>Tell it to print starting from the second character.</p>
<pre><code>lcd.print(inData + 1);
</code></pre>
|
5173 | |arduino-uno| | Extremely cheap "Arduino" for single tasks? | 2014-11-25T03:39:07.400 | <p>I have been thinking of a million things to do with my Arduino, but those things are extremely simple and it would leave my Arduino as a $25 waste. </p>
<p>For example, programming Arduino to control my living room lights with my smartphone ... I was thinking of connecting the Arduino in the wall, onto the light switch wires. I am looking for a "permanent" solution, but I figure this would leave me with a $25 waste of circuitry inside my wall.</p>
<p>Are there any "Arduino" types of electronics that perhaps have many less ports, JUST enough to get a single task done?</p>
| <p>You can embed a bootloaded ATMega328 (or any of the other compatible ATMega processors) <a href="http://arduino.cc/en/pmwiki.php?n=Main/Standalone" rel="nofollow noreferrer">http://arduino.cc/en/pmwiki.php?n=Main/Standalone</a> in your project. That way, you will only need the processor and a couple of components, setting you back only a couple of dollars <em>and</em> saving quite a lot of space:</p>
<p><a href="http://arduino.cc/en/pmwiki.php?n=Main/Standalone" rel="nofollow noreferrer">http://arduino.cc/en/pmwiki.php?n=Main/Standalone</a></p>
<p>If that is one bridge to far, you can have a look at the Arduino Pro or <a href="http://arduino.cc/en/Main/ArduinoBoardProMini" rel="nofollow noreferrer">Arduino Pro Mini</a>. Those boards are complete boards, only smaller and cheaper, and specifically designed for a more definitive use in projects.</p>
<p>If you need even more space and cost reduction, you can switch to a stand-alone ATTiny processor. The better models of those can also contain an Arduino program. <em>Instructables</em> has this <a href="http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/" rel="nofollow noreferrer">great tutorial</a> that shows you how to use an ATTiny85 or ATTiny45 as a lightweight 'Arduino'. </p>
<p>Recently, I have <a href="https://electronics.stackexchange.com/questions/136919/attiny-project-resets-when-plugging-in-phone">tried to use an ATTiny13A</a> for a project, but that one only has 1KB of flash memory, which leaves you with hardly any space for the Arduino bootloader, let alone your program, so therefor I chose to program it directly using AVR Studio, at which point I think you cannot in any way call it an Arduino project anymore. :) Still, it's not that different. You only miss out on some of the library functions, and the implied application loop.</p>
|
5175 | |motor|analogread|arduino-uno-smd|eclipse|pid| | Trouble reading from multiple analog ports | 2014-11-25T05:05:16.617 | <p>So I'm trying to read 4 different analog values and store each one to a variable. I imagine doing this by first initializing the ADC registers and each time it enters the ADC ISR checking which port it read from and saving it to the corresponding variable. Then setting the ADMUX to the next ADC port and repeating the whole process. Unfortunately something goes wonky and I just can't figure out what it is. If I get rid of the switch case and just read from one port it all works fine, but if I put the switch case back in and try to cycle through them it stops working. Please ignore the rest of code as this is not complete. I just included everything I could. Eventually this will take in 4 values. Then use them for error checking and a PID loop.</p>
<p>Thanks for any help!</p>
<pre><code>/*
* Throttle_by_Wire.c
*
* Basic throttle by wire controller
* for the 2015 Formula Hybrid car
*
* Created on: Nov 24, 2014
* Author: Austin R. Bartz
*
* Pin Connections:
* PB2 - Motor Speed (Enable pin) (PWM)
* PB4 - Direction control (Counter-Clockwise)
* PB5 - Direction control (Clockwise)
* PC0 - Throttle Pedal Sensor A (TPA) (Shallower Slope)
* PC1 - Throttle Pedal Sensor B (TPB) (Steeper Slope)
* PC2 - Throttle Valve Sensor A (TPSA) (Negative Slope)
* PC3 - Throttle Valve Sensor B (TPSB) (Positive Slope)
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <inttypes.h>
#include <stdlib.h>
uint16_t TPA = 0;
uint16_t TPB = 0;
uint16_t TPSA = 0;
uint16_t TPSB = 0;
uint16_t analogpin = 0;
long map(long x, long in_min, long in_max, long out_min, long out_max);
int main(void)
{
//Configure ADC for single shot conversion
ADMUX |= (1<<REFS0);
ADCSRA = (1<<ADEN)|(1<<ADSC)|(1<<ADIE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);
DIDR0 = (1<<ADC4D)|(1<<ADC3D)|(1<<ADC2D)|(1<<ADC1D)|(1<<ADC0D);
//Configure timer/counter1 for FastPWM
TCCR1A = (1<<COM1B1)|(1<<WGM11)|(1<<WGM10);
TCCR1B = (1<<WGM13)|(1<<WGM12)|(1<<CS10);
OCR1A = 800; //20kHz
//Set motor control pins as outputs
DDRB = (1<<PB2)|(1<<PB4)|(1<<PB5);
PORTB |= (1<<PB5);
//Enable global variables and interrupts
sei();
while(1)
{
//Control PWM % to motor
OCR1B = map(TPA, 0, 1023, 0, OCR1A);
}
}
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
ISR(ADC_vect)
{
//Save current conversion's ADC value
analogpin = ADMUX & 0b00001111;
switch (analogpin)
{
case 0:
TPA = ADCW;
//Increment ADC port to ADC1
ADMUX |= (1<<MUX0);
break;
case 1:
TPB = ADCW;
//Increment ADC port ADC2
ADMUX &= ~0b00001111;
ADMUX |= (1<<MUX1);
break;
case 2:
TPSA = ADCW;
//Increment ADC port to ADC3
ADMUX &= 0b00001111;
ADMUX = (1<<MUX0)|(1<<MUX1);
break;
case 3:
TPSB = ADCW;
//Reset ADC Port to ADC0
ADMUX &= ~0b00001111;
break;
}
//Start next conversion
ADCSRA |= (1<<ADSC);
}
</code></pre>
| <p>Case 2 is missing the ~ and does not clear off the low 4 bits</p>
<blockquote>
<p>ADMUX &= 0b00001111;</p>
</blockquote>
<p>should be this to clear off the MUX selection bits:</p>
<pre><code>ADMUX &= ~0b00001111;
</code></pre>
<p>Also, you have no default case. I would agree that by design the bits can only contain the values 0-3, but what happens if it ends up 4?</p>
<p>The bit manipulation is hard to follow. I would implement like this:</p>
<pre><code>ISR(ADC_vect) {
uint8_t nextMux;
//Save current conversion's ADC value
analogpin = ADMUX & 0b00001111;
switch (analogpin) {
case 0:
TPA = ADCW;
nextMux = (1<<MUX0);
break;
case 1:
TPB = ADCW;
nextMux = (1<<MUX1);
break;
case 2:
TPSA = ADCW;
nextMux = (1<<MUX0)|(1<<MUX1);
break;
case 3:
TPSB = ADCW;
default:
nextMux = 0;
}
// set mux for next conversion
ADMUX &= 0b11110000;
ADMUX |= nextMux;
//Start next conversion
ADCSRA |= (1<<ADSC);
return;
}
</code></pre>
<p>I like the consistent pattern of this because it makes errors easy to see. With respect to code space, a few bytes should be saved. Execution time wise, it adds one |= to the case 3. </p>
|
5189 | |motor| | Can a DC motor use more current than its datasheet? | 2014-11-25T16:39:37.210 | <p>I am using small dc motors connected to the 5V of the arduino which is known to provide 200mA without damaging it.</p>
<p>The motor I am using is a very common one found in toys -> <a href="https://www.sparkfun.com/datasheets/Robotics/ROB-09608.jpg" rel="nofollow">https://www.sparkfun.com/datasheets/Robotics/ROB-09608.jpg</a></p>
<p>As I see the maximum current of this motor is 170mA. Does it mean that the motor will not drain more current than that or it means that I need to use a resistor in series with my 5V in order to make sure the current will not pass 170mA?</p>
| <p>YES (typically resulting in melting the coils). The current used by standard or brushless motors is related to the voltage applied and the load applied. As you approach the load limit, current rises over the limit. There are many ways to control this but controlling the load is the easiest way. DO NOT run the motor through the Arduino even if you think it will be under the 200mA limit. Motors produce a lot of spikes and back-flow. </p>
<p>Here's a tutorial on safely running a motor and controlling the speed: <a href="https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/overview" rel="nofollow noreferrer">https://learn.adafruit.com/adafruit-arduino-lesson-13-dc-motors/overview</a></p>
<p><img src="https://i.stack.imgur.com/z7O3z.png" alt="enter image description here"></p>
|
5196 | |serial|arduino-mega|float| | Saving data in a globally declared float array | 2014-11-25T20:26:11.050 | <p>I'm trying to send 60 float values via serial. Numbers are provided by an accelerometer and saved in a 240 bytes-long array. The array is sent to a function and these values are then copied in a structure.</p>
<p><strong>The problem</strong>
The content of the array is still correct when the function is called. Then, when I copy it in the structure, something wrong happens and data are modified after the 26th float. </p>
<p>Where does the modification of an array of floats take place?</p>
<pre><code>void sendBuffAcc(float a[])
{
int stepCont = 1;
// Prints the content of the globally defined array buffXAccToSend
Serial.println();
for (int i=0;i<sizeBuffAcc;i++)
{
Serial.print("val: ");
Serial.print(i);
Serial.print(" ");
Serial.println(buffXAccToSend[i]);
}
Serial.println();
MyShortCommand * pMyCmdShort = (MyShortCommand *)(&bufferAcc[sizeof(MyControlHdr)]);
for (int i=0;i<sizeBuffAcc;i++)
{
Serial.print("val: ");
Serial.print(i);
Serial.print("| Global Array:");
Serial.println(buffXAccToSend[i]);
numFilterValuesToSend++;
pMyCmdShort->cmd = accValuesID;
pMyCmdShort->param1 = a[i];
pMyCmdShort->param2 = 0;
pMyCmdShort->param3 = 0;
pMyCmdShort->param4 = 0;
Serial.print("| Param: ");
Serial.print(pMyCmdShort->param1);
Serial.print("| Array:");
Serial.println(a[i]);
// Move the pointer to save data in next positions
pMyCmdShort++;
}
stepCont++;
}
storeAccData = false;
contBuffAcc=1;
}
</code></pre>
<p>First, the content of the global array <code>buffXAccToSend</code> is printed via serial, then the i-th elements of a[i] and the value assigned to the pMyCmdShort->param1. This is the output:</p>
<pre><code>val: 0 -0.00
val: 1 -0.00
val: 2 0.01
val: 3 -0.01
val: 4 0.04
val: 5 0.00
val: 6 0.01
val: 7 0.03
val: 8 0.01
val: 9 -0.00
val: 10 0.00
val: 11 -0.01
val: 12 -0.00
val: 13 0.01
val: 14 -0.02
val: 15 0.03
val: 16 0.00
val: 17 0.02
val: 18 -0.01
val: 19 0.00
val: 20 0.00
val: 21 -0.00
val: 22 -0.01
val: 23 -0.01
val: 24 0.01
val: 25 0.01
val: 26 -0.00
val: 27 0.03
val: 28 -0.01
val: 29 -0.00
val: 30 0.04
val: 31 -0.01
val: 32 0.01
val: 0| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 1| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 2| Global Array: -0.01| Param: -0.01| Array: -0.01
val: 3| Global Array: -0.02| Param: -0.02| Array: -0.02
val: 4| Global Array: 0.02| Param: 0.02| Array: 0.02
val: 5| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 6| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 7| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 8| Global Array: 0.04| Param: 0.04| Array: 0.04
val: 9| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 10| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 11| Global Array: -0.00| Param: -0.00| Array: -0.00
val: 12| Global Array: -0.01| Param: -0.01| Array: -0.01
val: 13| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 14| Global Array: -0.02| Param: -0.02| Array: -0.02
val: 15| Global Array: -0.02| Param: -0.02| Array: -0.02
val: 16| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 17| Global Array: -0.02| Param: -0.02| Array: -0.02
val: 18| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 19| Global Array: 0.03| Param: 0.03| Array: 0.03
val: 20| Global Array: -0.01| Param: -0.01| Array: -0.01
val: 21| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 22| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 23| Global Array: 0.01| Param: 0.01| Array: 0.01
val: 24| Global Array: -0.01| Param: -0.01| Array: -0.01
val: 25| Global Array: -0.02| Param: -0.02| Array: -0.02
val: 26| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 27| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 28| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 29| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 30| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 31| Global Array: 0.00| Param: 0.00| Array: 0.00
val: 32| Global Array: 0.00| Param: 0.00| Array: 0.00
</code></pre>
<p>This is the output of avr-size:</p>
<pre><code> text data bss dec hex
55828 3906 2978 62712 f4f8
</code></pre>
<p>Is it a memory related problem? </p>
| <p>The ATmega328P has 2kiB of SRAM. Your program uses almost 3kiB. Move strings and constant values <a href="http://www.arduino.cc/en/Reference/PROGMEM" rel="nofollow">into flash</a>.</p>
|
5198 | |arduino-uno|motor|transistor| | Why is my transistor getting very hot when controlling a 12V peristalic pump? | 2014-11-25T21:43:20.960 | <p>I have followed this tutorial:</p>
<p><a href="http://www.instructables.com/id/Automatically-water-your-small-indoor-plant-using-/?ALLSTEPS" rel="nofollow">http://www.instructables.com/id/Automatically-water-your-small-indoor-plant-using-/?ALLSTEPS</a></p>
<p>Every time i try to run my circuit, My transistor gets very hot and breaks. </p>
<p>I have exactly the same parts as the tutorial. I have also tested the circuit with 3.3V Power supply and a diode instead of an engine, this works. </p>
<p>I am super thankfull for any answers.</p>
| <p>Measure the Current through the motor, the PN2222 can pass a maximum of 600mA.
I would guess that just over half an amp would be enough for the motor but you can check what you motor is trying to pull by connecting it to 12 V direct and measure the supply current.
The only thing that will make the transistor hot is excess current</p>
|
5199 | |arduino-uno|serial|bluetooth|communication| | Arduino to Arduino Communication using HC05 | 2014-11-25T22:16:49.890 | <p>I have been working on a project for work ( I'm a waiter :/ ) I was tasked to build a food wait time display that receives input from the kitchen and echoes the time via bluetooth to another display.
So that we are all on the same page I will describe what I have built and where I am stuck.</p>
<p><strong>Before I do, I would like to state that I have:</strong> </p>
<ul>
<li>been planning and prototyping this thing for over a month</li>
<li>googled/crawled all over the web looking for answers</li>
<li>read the entire manual on the HC05 module</li>
<li>Bound both of the bluetooth modules via AT commands One as Master the other as Slave</li>
</ul>
<p>Now with that out out the way here is what I have so far:</p>
<ul>
<li>2x Arduino uno R3</li>
<li>2x 16x2 LCD Display</li>
<li>2x HC05 Bluetooth Modules (1 set as Master the other as Slave & bound using AT Commands)</li>
<li>2x 10K Potentiometers for adjusting the contrast</li>
<li>3x Momentary push Button switches on Master with pull-up resistors (timeUp, timeDown, sendButton)</li>
</ul>
<p>Here is where I am stuck. <strong>UPDATE</strong></p>
<p>I was able to get the master and slave to communicate. RX and TX on master were crossed... SMH! However now the issue is that the slave is <em>writing</em> both digits it receives on top of itself. First writing one digit then clearing it and then the second digit... </p>
<p>Enough with the prologue here is the a code:</p>
<p><strong>Master</strong></p>
<pre><code>#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets up LCD pins
int waitTime = 10; //if food comes quicker than there is no need for a display ;)
const int timeUp = 6;
const int timeDown = 7;
const int sendButton = 8;
int timeUpState = 0;
int timeDownState = 0;
int sendButtonState = 0;
void setup() {
Serial.begin(115200);
pinMode(timeUp, INPUT);
pinMode(timeDown, INPUT);
pinMode(sendButton, INPUT);
lcd.begin(16, 2);
lcd.print(" Sam Kullman's"); //Splash screen on start up
lcd.setCursor(0,1);
lcd.print(" Diner"); //Splash Screen
delay(2000); // Delay intended to allow the device to pair prior to use.
lcd.clear();
lcd.print("Essen Dauert:"); //German for "Food takes":
lcd.setCursor(0,1);
lcd.print(" Minuten"); // xx minutes
}
void loop(){
lcd.setCursor(0,1);
timeUpState = digitalRead(timeUp);
timeDownState = digitalRead(timeDown);
sendButtonState = digitalRead(sendButton);
if (timeUpState == LOW) {
waitTime += 5;
delay(500); //debounce button
lcd.print(waitTime);
}
if(waitTime > 90){ // Max limit for wait time
waitTime = 10; //default wait time
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Essen Dauert:");
lcd.setCursor(0,1);
lcd.print(" Minuten");
}
if (timeDownState == LOW){
waitTime -= 5;
delay(500);
lcd.print(waitTime);
}
if(waitTime < 10){ //Min value waiting time
waitTime = 10;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Essen Dauert:");
lcd.setCursor(0,1);
lcd.print(" Minuten");
}
if(Serial.available()){ // **This is where I am stuck**
if(sendButtonState == LOW){
Serial.write(waitTime);
delay(500);
}
}
}
</code></pre>
<p><strong>Slave</strong></p>
<pre><code>#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup() {
Serial.begin(9600);
Serial.flush();
lcd.begin(16, 2);
lcd.print(" Sam Kullman's");
lcd.setCursor(0,1);
lcd.print(" Diner");
}
void loop(){
if (Serial.available()) {
int waitTime = Serial.read();
delay(200);
lcd.clear();
lcd.print("Essen Dauert:");
lcd.setCursor(0,1);
lcd.write(waitTime);
lcd.print(" Minuten");
}
}
</code></pre>
<p>Thanks in advance,
Jonathan</p>
| <p>The problem was how I was reading the incoming serial data. </p>
<p>After changing <code>int waitTime = Serial.read()</code></p>
<p>to <code>int waitTime = Serial.parseInt()</code>
the code works. </p>
<p><strong>Thanks to everyone for all your help and tips!</strong></p>
|
5210 | |arduino-uno|programming|library|lcd| | lcd.print and 2D arrays | 2014-11-26T23:00:58.797 | <p><a href="https://www.dropbox.com/sc/ur5f8b10ifdtuhz/AADK7fM8EeLWgxXQ0I42VrGoa" rel="nofollow">Click here to see my program running</a> </p>
<p>I have created a 2D array (see my full code below), and each row contains one state of a battery here is a schematic :</p>
<pre><code>row [0] : "▯▢▢▷" // this row represents an empty AAA battery
row [1] : "▮▩▢▷"
row [2] : "▮▩▩▷"
row [3] : "▮▩▩ ▶" // this row represents a Full AAA battery
</code></pre>
<p>Each "▩" character is a custom made character with this function:</p>
<pre><code>lcd.createChar(0, customLcdfont_squareONE);
</code></pre>
<p>As you saw in my video it works at the end, but it's absolutely not the way I want it to work. The code that works is a mess!</p>
<p><strong>I think the problem is that the Raw n°1 ([0]) starts with a 0, (try it out it's very strange). If we replace</strong> </p>
<pre><code>char batteryFonts [10][5] = {
{ 0, 1, 1, 2 }, // you see { this "0", 1, 1, 2 }, is a problem I think
{ 3, 1, 1, 2 },
{etc}, }
lcd.print( batteryFonts[0]); // this sentence does not work
</code></pre>
<p><strong>with</strong> </p>
<pre><code>"char batteryFonts [10][5]={{ 4, 1, 1, 2 }, // 4 or what ever you want
{etc},
{etc}, }
lcd.print( batteryFonts[0]); // this sentence behind does work, but only with a row that does not start with a 0. Why?
</code></pre>
<p>It works!</p>
<p>Here is my full code. Just connect the pins 12, 13, 7, 4, 3, 2 to the LCD.</p>
<pre><code>//This is a simple program that charges alkaline batteries
//Copyleft
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 13, 7, 4, 3, 2); // why pin 13 and not 12 ? because I love the led attached to it <3
// the empty battery - end
byte customLcdfont_A [8] = { // B stand for "Binary" and then the pixel ...
B01111,
B11000,
B10101,
B10100,
B10100,
B10100,
B11000,
B01111
// the empty battery body with fancy graphics enabled
};
byte customLcdfont_B [8] = { // B stand for "Binary" and then the pixel ...
B11111,
B00000,
B11001,
B00000,
B00000,
B00000,
B00000,
B11111
};
// the empty battery + end
byte customLcdfont_C [8] = { // B stand for "Binary" and then the pixel ...
B11100,
B00100,
B10111,
B00101,
B00111,
B00111,
B00100,
B11100
};
// the full battery - end
byte customLcdfont_D [8] = { // B stand for "Binary" and then the pixel ...
B1111,
B11111,
B10110,
B10111,
B10111,
B10111,
B11111,
B1111
};
// the FULL battery + end
byte customLcdfont_E [8] = { // B stand for "Binary" and then the pixel ...
B11100,
B11100,
B01111,
B11101,
B11111,
B11111,
B11100,
B11100
};
// the full battery body
byte customLcdfont_F [8] = {
B11111,
B11111,
B00110,
B11111,
B11111,
B11111,
B11111,
B11111
};
// the 1/3 battery body
byte customLcdfont_G [8] = {
B11111,
B11000,
B00001,
B11000,
B11000,
B11000,
B11000,
B11111
};
// the 2/3 battery body
byte customLcdfont_H [8] = {
B11111,
B11110,
B00111,
B11110,
B11110,
B11110,
B11110,
B11111
};
/**************************************************************************/
void setup() {
int i = 0 ;
// initialize serial communications at 9600 bps:
lcd.createChar(0, customLcdfont_A);
lcd.createChar(1, customLcdfont_B);
lcd.createChar(2, customLcdfont_C);
lcd.createChar(3, customLcdfont_D);
lcd.createChar(4, customLcdfont_E);
lcd.createChar(5, customLcdfont_F);
lcd.createChar(6, customLcdfont_G);
lcd.createChar(7, customLcdfont_H);
lcd.begin(16, 2);
// WATCH HERE IS THE PROBLEM !!!!
//the char table behind creates my different battery states as shown in the video ;)
char batteryFonts [10][5]={
{ 0, 1, 1, 2 }, // this is an empty one f%*# this does not work !!!
{ 3, 1, 1, 2 },
{ 3, 6, 1, 2 },
{ 3, 7, 1, 2 },// this is a 50 % full charged battery !
{ 3, 5, 1, 2 },
{ 3, 5, 6, 2 },
{ 3, 5, 7, 2 },
{ 3, 5, 5, 2 },
{ 3, 5, 5, 4 },// this is nice full one
};
// this sentence behind does not work !!! but only with the raw [0]
lcd.print( batteryFonts[0]); // I F***ing want this to display the first raw !!!!
lcd.setCursor(0,1 );
lcd.print(" not working ");
lcd.setCursor(0,0 );
delay(9300); // this make a short pause for us so that we can see the result
lcd.setCursor(0,1 );
lcd.print(" working ");
lcd.setCursor(0,0 );
for (i=0; i=10 ; i+=1 ){
delay(300);
lcd.setCursor(6,0 );
lcd.write(byte(0)); lcd.write(byte(1)); lcd.write(byte(1)); lcd.write(byte(2));
delay(700); // batterry 0/8 empty aka discharged
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(1)); lcd.write(byte(1)); lcd.write(byte(2));
delay(1000); //batterry 1 /8
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(6)); lcd.write(byte(1)); lcd.write(byte(2));
delay(1000);//batterry 2 /8
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(7)); lcd.write(byte(1)); lcd.write(byte(2)); //batery 3 /8
delay(1000);
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(5)); lcd.write(byte(1)); lcd.write(byte(2));
delay(1000); //batery 4 /8
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(5)); lcd.write(byte(6)); lcd.write(byte(2));
delay(1000); //batery 5 /8
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(5)); lcd.write(byte(7)); lcd.write(byte(2));
delay(1000); //batery 6 /8
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(5)); lcd.write(byte(5)); lcd.write(byte(2));
delay(1000); //batery 7 /8
lcd.setCursor(6,0 );
lcd.write(byte(3)); lcd.write(byte(5)); lcd.write(byte(5)); lcd.write(byte(4)); //batery 8 /8
delay(1000);
}
lcd.setCursor(15, 1);
delay(115000);
}
/**************************************************************************/
void loop() {
//This is not interesting here
lcd.print(" ~ The end of the code ... thank you for reading ;) ~ ");
}
</code></pre>
| <p>You are correct; in C a NUL (0x00) is used to indicate the end of a <code>char*</code>. You will need to use <code>LiquidCrystal::write()</code> in order to send the character data byte by byte instead of depending on <code>LiquidCrystal::print()</code> to handle it.</p>
<p>Also, consider moving all of that static data <a href="http://www.arduino.cc/en/Reference/PROGMEM" rel="nofollow">into flash</a>; you're going to need to handle it manually so you may as well do it right in the first place.</p>
|
5213 | |c++|arduino-ide|class| | How to prepare data structures and classes? | 2014-11-27T06:53:15.400 | <p>How can I port these structures to arduino ide, I also get error when I define pointers</p>
<pre><code>// pointer to classes example
#include <iostream>
using namespace std;
class Rectangle {
int width, height;
public:
Rectangle(int x, int y) : width(x), height(y) {}
int area(void) { return width * height; }
};
int main() {
Rectangle obj (3, 4);
Rectangle * foo, * bar, * baz;
foo = &obj;
bar = new Rectangle (5, 6);
baz = new Rectangle[2] { {2,5}, {3,6} };
cout << "obj's area: " << obj.area() << '\n';
cout << "*foo's area: " << foo->area() << '\n';
cout << "*bar's area: " << bar->area() << '\n';
cout << "baz[0]'s area:" << baz[0].area() << '\n';
cout << "baz[1]'s area:" << baz[1].area() << '\n';
delete bar;
delete[] baz;
return 0;
}
</code></pre>
<p>In <a href="http://www.cplusplus.com/doc/tutorial/classes/" rel="nofollow">CPP shell</a> it works</p>
<p>I try to put it like this</p>
<pre><code>class Rectangle {
int width, height;
public:
Rectangle(int x, int y) : width(x), height(y) {}
int area(void) { return width * height; }
};
Rectangle obj (3, 4);
Rectangle * foo, * bar, * baz;
foo = &obj;
bar = new Rectangle (5, 6);
baz = new Rectangle[2] { {2,5}, {3,6} };
void setup() {
// put your setup code here, to run once:
}
void loop() {
// put your main code here, to run repeatedly:
}
</code></pre>
<p>I get an error</p>
<pre><code>sketch_nov27a.ino:10:3: error: 'foo' does not name a type
sketch_nov27a.ino:11:3: error: 'bar' does not name a type
sketch_nov27a.ino:12:3: error: 'baz' does not name a type
Error compiling.
</code></pre>
| <p>The problem is that the lines saying <code>foo = ...</code> etc. are assignment operations. C++ lets you declare and immediately initialise variables at global scope, but after that you can only assign to them inside a function. In your original program, all your declarations/assignments were inside <code>main()</code>, which is why it worked there.</p>
<p>For your Arduino program, you could change the assignments to initialisations instead (in global scope):</p>
<pre><code>Rectangle obj (3, 4);
Rectangle * foo = &obj;
Rectangle * bar = new Rectangle (5, 6);
Rectangle * baz = new Rectangle[2] { {2,5}, {3,6} };
</code></pre>
<p>Alternatively, you could leave the declarations in global scope and move the assignments into <code>setup()</code>:</p>
<pre><code>Rectangle obj (3, 4);
Rectangle * foo, * bar, * baz;
void setup() {
foo = &obj;
bar = new Rectangle (5, 6);
baz = new Rectangle[2] { {2,5}, {3,6} };
}
</code></pre>
|
5228 | |serial|arduino-yun| | Cannot communicate with Serial Monitor - Arduino Yun | 2014-11-28T08:25:29.243 | <p>I connect Arduino Yun to my Computer with WiFi. I was able to get the IP address of my Arduino Yun. However, when I try to print something. It seems to not work at all. The following code is the one that I try:</p>
<pre class="lang-cpp prettyprint-override"><code>void setup() {
Serial.begin(9600);
}
void loop() {
// print labels
Serial.print("NO FORMAT");
delay(100);
}
</code></pre>
<p>I did not get any kind of error. However, when I open the Serial Monitor, it shows nothing at all. I try to use the same code with Arduino Uno. It works fine. </p>
| <p>When using the Yun over wifi, you cannot user Serial, you need to use Bridge <a href="http://arduino.cc/en/Reference/YunConsoleConstructor" rel="nofollow">Console</a> object. Serial is bound to the usb cable.</p>
<p>Give a spin to <a href="http://arduino.cc/en/Tutorial/ConsoleRead" rel="nofollow">ConsoleRead</a> example.</p>
|
5240 | |library|ide|debugging| | Issue with adding a library: No such file or directory | 2014-11-28T20:49:30.183 | <p>I downloaded a Library called "Morse" which I got from the Arduino website:</p>
<p><a href="http://arduino.cc/en/Hacking/LibraryTutorial" rel="nofollow noreferrer">http://arduino.cc/en/Hacking/LibraryTutorial</a></p>
<p>(all the way at the bottom of the page there is a link called Morse.zip)
And basically added the library. Then when I import the library, it is included to the sketch. However when I try verifying it, the following error message appears:</p>
<p><img src="https://i.stack.imgur.com/FnDKq.png" alt="enter image description here"></p>
<p><em>to see the image clearer you can right click it and click on "Open image in new tab"</em></p>
<p>Basically it says:</p>
<p>In file included from sketch_nov28a.ino:1:
C:\Users\Marko\Documents\Arduino\libraries\Morse/Morse.h:10:22: error: WProgram.h: No such file or directory</p>
<p>Now I tried reinstalling the Arduino IDE, I tried adding the library again as well as using the manual method that was stated in that first link above, and the error persists.</p>
<p>What I did notice was that in that second line of the error message, something caught my eye: "...\Morse/Morse.h:10:22:..."
There is a forward slash!(/) Now it seems weird to me that with would happen, especially given that all the other examples I saw of this error online have a backslash (\). This could be the problem.... but even if it is, how do I fix it? I tried going to preferences... does anyone know?</p>
| <p>That library is for the older version of the Arduino ide. To fix this you need to open <code>Morse.h</code> and change <code>WProgram.h</code> to <code>Arduino.h</code>.</p>
|
5242 | |uploading|bootloader|sketch| | Unable to load sketch: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x41 | 2014-11-29T08:48:24.317 | <p>I've stumbled upon what I've later found it's quite common error, but there seems not to be simple troubleshooting way and solution (people often try various things, sometimes they succeed, sometimes not).</p>
<p>I am using <a href="http://www.dawnrobotics.co.uk/dagu-arduino-mini-driver-board/" rel="nofollow">DAGU mini driver</a>, I was able to load sketch as described <a href="http://blog.dawnrobotics.co.uk/2013/11/getting-started-with-the-dagu-arduino-mini-driver-board/" rel="nofollow">here</a> - chose Arduino NG ATMega8 as board, connect to my PC via USB (with the driver listed on the <a href="http://www.dawnrobotics.co.uk/dagu-arduino-mini-driver-board/" rel="nofollow">product page</a>).</p>
<p>Later on I've plugged RedBot wheel encoders sensor and write some simplistic program to check whether it works at all. I've summarized the steps in a github <a href="https://github.com/BartAdv/rowboat/issues/1" rel="nofollow">issue</a>, so that it's easy to reference it.</p>
<p>When I tried to upload the sketch I've receiced <code>stk500_initialize(): (a) protocol error, expect=0x14, resp=0x42</code>, <code>stk500_getparm(): (a) protocol error, expect=0x14, resp=0x41</code>. The full log is included in comment on that github issue.</p>
<p>The D13 diode is making series of 3-blink bursts - 8 bursts after start. More diagnostic I did in the github issue as well.</p>
<p>My question (apart from obvious 'how to fix it!?!' ;) ) is whether there is some kind of documentation for this protocol? On the various topics I've found people seem to have somewhat different problems (the numbers and messages were different). I just want to know why the first few messages are exchanged OK (avrdude receives some basic info from the chip), but later ones (namely <code>Send: A [41] . [81] [20]</code>) are producing protocol errors.</p>
| <p>AVR programmer helped.</p>
<p>Meaning the bootloader somewhat got corrupted and I had to burn new one.</p>
|
5243 | |programming|arduino-yun| | How to make Arduino communicate with MySQL? | 2014-11-29T14:53:14.670 | <p>I am trying to send data from my Arduino to my database but it seems that the process is not successfully beginning. Here is my code for Arduino:</p>
<pre><code>#include <Process.h>
#include <Bridge.h>
int temperature;
void setup() {
Bridge.begin(); // Initialize Bridge
}
void loop() {
int temperature = random(0, 100);
Process p;
p.begin("143.248.181.36/db.php");// 143.248.181.36 address of localhost.
p.addParameter(String(temperature));
p.run();
delay(5000);
}
</code></pre>
<p>I am using xampp and I put db.php inside the htcocs folder. Can anyone point out why it does not work?</p>
| <p>I'm not familiar with those libraries, but a quick look gives me the impression that Bridge and Process are used together to make system calls over serial connection on the host system. Based on that..</p>
<p>First, looking at <a href="http://arduino.cc/en/Tutorial/Process" rel="nofollow">Arduino Process Tutorial</a> Process.begin() should call the process that you want to call. Maybe something like this:</p>
<pre><code>p.begin("curl"); // Assuming you have curl installed on your host system
p.addParameter("http://143.248.181.36/db.php?temperature=SOMEVALUE");
</code></pre>
<p>Second, your PHP script is broken. </p>
<pre><code>/ check connection
</code></pre>
<p>^ That comment is missing a second slash /</p>
<p>You should definitely get the PHP/MySQL part working standalone before attempting to integrate Arduino in the process. I'm a bit doubtful that $argv gets populated unless you're running the script from command line. If you're making a GET HTTP request (as you would with curl) you might wanna try instead</p>
<pre><code>$temperature = $_GET['temperature'];
</code></pre>
<p>If the above works as a workaround, you should get an entry into your MySQL table if you visit the URL below with your browser. </p>
<pre><code>"http://143.248.181.36/db.php?temperature=100"
</code></pre>
<p>In any case, get the PHP script working first in your browser. One step at a time.</p>
|
5246 | |arduino-uno|i2c| | Is there a pullup on I2C? | 2014-11-29T22:18:21.047 | <p>I am using an Arduino Uno R3.</p>
<p>It is not clear on the schematic whether there are pullups on the A4 and A5 I2C pins.</p>
<p>Are there hardwired pullups or do I have to add them myself?</p>
| <p>No. There are potential internal pullups, but not AFIK activated.</p>
<p>You can quite safely connect I²C to Raspberry P1 (3.3V).</p>
|
5249 | |serial|arduino-mega| | Serial Communication over Desktop to Arduino | 2014-11-30T04:22:06.570 | <p>I have a USB 2 Serial adapter and the device is working fine. I see the device perfectly configured in my System.</p>
<p>I have connected the TX0 pin of Arduino to DB 2 pin (read pin) of the adapter. Below is my Arduino code:</p>
<pre><code>int i = 0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
for(i=0;i<6;i++)
{
Serial.write('H');
delay(100);
}
}
</code></pre>
<p>But when I try to read thru terminal software of data received at my COM port I see some junk character incoming. I am pretty sure that I am using same baud rate / flow setting both side. Why am I facing this issue - do I need to connect any other pins also as I just need to receive data at system side?</p>
| <blockquote>
<p>I have a USB 2 Serial adapter...I have connected the TX0 pin of Arduino to DB 2 pin (read pin) of the adapter.</p>
</blockquote>
<p>You <strong>must not</strong> connect Arduino pins directly to a D-SUB connector of a USB-Serial adapter, as those connectors traditionally carry higher voltage, opposite sense RS232 signals.</p>
<ul>
<li>The voltage is too high, and likely to cause damage to your Arduino's processor</li>
<li>The signal is inverted in sense from the logic-level signaling used by your Arduino's processor.</li>
</ul>
<p>If you actually needed to make this connection, you would need to either use a "logic level" USB serial adapter (sometimes informally called a USB-TTL adapter). These terminate in various types of connections such as bare wires or header pins/sockets - but basically <em>never</em> in an D-SUB connector. Or you can use an inverting line driver and receiver such as the MAX2232 type devices, or even an old 1488/1489 pair.</p>
<p>But it's not clear that you should be doing this at all - <strong>an Arduino Mega already has a USB-serial converter onboard</strong> - that is the interface you use to program it, and it would ordinarily be simplest to use that for runtime communication as well.</p>
|
5251 | |arduino-galileo| | Can I use an Arduino Uno-style Shield with the Arduino Mega, Tre, or Zero? How about the Intel Edison? | 2014-11-30T05:40:51.367 | <p>Can I use an Arduino Uno-style Shield with the Arduino Mega, Tre, or Zero? How about the Intel Edison?</p>
| <p>Zero, Mega and Tre all have the same basic pinout layout as Uno, which provides at least physical compatibility for the pins. <a href="https://www.sparkfun.com/products/13097" rel="nofollow">Sparkfun has a breakout board for the Intel Edison</a>. </p>
<p>Mini, Micro & Nano obviously have a different pin layout. I would consider them mainly for projects that have challenging space requirements, since their main advantage is their small size. The Micro should be the easiest to plug'n'play (native USB COM serial). Nano is still stuck with FTDI drivers, so it's going to require separate drivers from the Uno/Mega family. And finally Mini doesn't have USB at all. </p>
<p>Maybe take a look at Wikipedia <a href="http://en.wikipedia.org/wiki/List_of_Arduino_boards_and_compatible_systems" rel="nofollow">list of Arduino boards and compatible systems</a> to evaluate better what suits your needs best.</p>
|
5253 | |ethernet|usb|arduino-uno-smd| | USB mouse/keyboard passthrough feasible? | 2014-11-30T09:25:15.087 | <p>I'm looking to achieve the following:</p>
<pre><code>USB HID Mouse (or Keyboard) -> [ Arduino device ] -> PC
|
`-> Internet
</code></pre>
<p>Basically, I want to connect a keyboard or mouse to an Arduino device, do some processing, send some data over the internet and then pass-through the USB data to the PC as if the Arduino wasn't even there.</p>
<p>My question is twofold: what hardware should I use? Right now I'm looking at the following peripherals:</p>
<ul>
<li><a href="https://www.sparkfun.com/products/11224" rel="nofollow">Arduino Uno R3 SMD</a></li>
<li><a href="https://www.sparkfun.com/products/9026" rel="nofollow">Arduino Ethernet Shield</a></li>
<li><a href="https://www.sparkfun.com/products/9947" rel="nofollow">SparkFun USB Host Shield</a></li>
</ul>
<p>Since I'm a complete neophyte when it comes to Arduino, I wanted to double-check and make sure my parts will fit together as well as work towards my goal. I was also contemplating the Arduino Leonardo (since it seems to provide mouse/keyboard out-of-the-box without reflashing the firmware), but I'm not sure I understand what that decision might entail.</p>
<p>Which brings me to my second question: is this feasible software-wise? I found <a href="http://hunt.net.nz/users/darran/blog/?tag=mouse" rel="nofollow">this blog</a> which has some information about pass-through connections, but the mouse library seems to be unfinished. I'd hate to invest 150+ dollars into a project that is doomed from the start.</p>
<p>Thank you!</p>
| <p>To connect an external USB device to AVR you need <strong>USB Host</strong> supported on AVR side. Overhelming majority of AVR chips supports <strong>USB device only</strong>. There is e.g. AT90USB1287 chip exception. It even exists an <strong>AVR USB Key 2</strong> device which can be used instead of normal Arduino unless you want make own PCBs.</p>
<p><strong>Arduino UNO Mouse HID</strong> emulates USB mouse internally in Arduino. Implementing is easy when you have USB device AVR chip using LUFA library. But it's not case using external mouse. On the other side you can use legacy serial mouse or PS/2 keyboard as workaround.</p>
|
5258 | |led| | Arduino Uno PWM | 2014-11-30T13:49:08.537 | <p>My scheme is very basic: I use RGB LED with Arduino Uno. 5v is connected to anode, and pins 9-11 are connected to cathodes. </p>
<p>When using following sketch, my LED is producing white colour, which red, green and blue components are on:</p>
<pre><code>int redPin = 9;
int greenPin = 10;
int bluePin = 11;
void setup(){}
void loop(){
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);
}
</code></pre>
<p>But when I refer to <a href="http://arduino.cc/en/Tutorial/PWM" rel="nofollow">docs</a> for PWM:</p>
<pre><code>A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on)
</code></pre>
<p>When I write <code>0</code> to all pins, I expect led to be off. What am I missing?</p>
| <p>When you set the pin value to 0 you are making that pin act as ground. Since the LED had a single anode that receives 5V. When the difference between the anode and cathode is high (Anode - 5V & Cathode - 0V) the LED turns on. When the difference between the anode and cathode is low (Anode - 5V & Cathode - 5V) the LED is off. The larger the difference between the two the brighter the LED. In your code use <code>analogWrite(redPin, ~0);</code> then everything should work. Change 0 above to whatever value you want, less than 255, and it should work. Also do the same for the green and plus pins too.</p>
|
5268 | |bootloader| | Burn Arduino Bootloader - Atmega8L | 2014-12-01T15:47:19.443 | <p>I am making an RGB LED project right now using the Arduino UNO board.</p>
<p>At this point everything is working fine so I would like to transfer this onto a small microcontroller circuit to be put inside the enclosure. Since the enclosure is small, I cannot fit the UNO board inside it, hence I want to make a small circuit on perfboard with minimal components.</p>
<p>I read that you can burn the arduino bootloader on a standalone AVR (hooked up to power, filter caps and 16Mhz crystal) which can then execute Arduino code.</p>
<p>Any idea how can I do this? Also can I do this on an ATmega8l AVR, since my code is small enough to fit in one? No point wasting a 328 if 8L can do the job.</p>
<p>Thanks!</p>
| <p>Problem with Atmega8A-pu </p>
<p>Make sure the correct com port is selected then on the tools menu select Arduino NG or Older as the board type then choose the ATmega8 as the processor from the tools menu and upload any example Program probably i prefer blink to test (courtesy-PARC-India).</p>
<p>All the best</p>
|
5276 | |sensors| | How to continuously calibrate sensor | 2014-12-01T22:56:20.787 | <p>I have a problem in calibration an LDR sensor. I want to let the sensor goes all day long and I'm using the LDR sensor as a presence sensor. The calibration values (min and max) changes all the day, and I need to detect only the peaks, or continuously change the min and the max values. Are there some defined pattern or algorithms to use?</p>
| <p>In this situation, it may be useful to look at the differential of the signal.</p>
<p>One way to do this is to store the value, wait some time and read another value. You can then do:</p>
<p><code>dv = current_value - last_value</code></p>
<p>Or if you have some time metric (Perhaps clock ticks, or a rtc):</p>
<p><code>dv = (current_value - last_value) / (current_time - last_time)</code></p>
<p>You would then want to only count significantly large changes in <code>dv</code>. As the day progresses the light value will only change at a small rate but if someone were to block the light then there will be a large difference between <code>current_value</code> and <code>last_value</code>, causing <code>dv</code> to be largely negative (Indicating a loss of a lot of light) and when they no longer block the light you will get the opposite, indicating there is no longer an obstruction. (Or rather, less of an obstruction.)</p>
|
5278 | |arduino-micro| | Are the Arduino Micro, Mini, etc plug'n play? | 2014-12-02T04:36:37.713 | <p>Also, what about the micro/nano/mini arduinos? Are they easily plug'n'play like the uno?
(This is an edit from another of my questions)</p>
| <p>The ones that have a USB connector are plug-and-play with a USB host. The ones that don't need a USB-to-UART bridge.</p>
|
5286 | |bluetooth|rfid|adafruit| | Arduino: The program exited the loop early and execute setup() repeatedly | 2014-12-01T21:28:27.547 | <p>I'm working with Arduino Uno, Adafruit PN532 NFC/RFID Shield and along with other modules. I'm posting this test program because I found there's conflict with the serial output while writing code to integrate all the modules together. I tried troubleshooting by running this code. The result wasn't what I'd expected. </p>
<p>In Arduino, as far as I know, setup() only runs once after starting the program and then loop() will be executed repeatedly. I ran the example sketch called <em>readMiFare</em> provided by Adafruit alone and it was fine. This code can be found at <a href="https://github.com/adafruit/Adafruit_NFCShield_I2C/blob/master/examples/readMifare/readMifare.pde" rel="nofollow noreferrer">https://github.com/adafruit/Adafruit_NFCShield_I2C/blob/master/examples/readMifare/readMifare.pde</a>. However, when I did the following in main,</p>
<pre><code>void setup()
{
Serial.begin(115200);
nfctestsetup();
}
void loop(void)
{
nfctestloop();
}
</code></pre>
<p>the following conflict showed up. When happened was that whenever I scanned a card to the reader it executed the loop() partially and exited the loop. Even worse, it executed the setup() again and again whenever I scanned a card. </p>
<p><img src="https://i.stack.imgur.com/lIVAG.png" alt="Serial output"></p>
<p>In nfctestsetup(), I just commented out <code>Serial.begin(115200);</code> from readMiFare.</p>
<p>My hardware setup was a no brainer since I'm using I2C.
<img src="https://i.stack.imgur.com/KS2jd.jpg" alt="Uno and PN532 Shield"></p>
<p>Appreciate the help. </p>
<p>After spending a good amount of hours on troubleshooting, I found something interesting. When I commented out all other files except NFC and main, it worked like a charm. So I suspect there could be redefinitions on the pins that the NFC shield uses on other files. I suspect the following code in the other file gave me the problem because I commented out the rest of the code in this file and ran this block of code together with NFC and main. In fact, it's the last line of code in this block that gave me the problem. </p>
<p>Also, I probed on the RESET pin (see the readMiFare link above). It generated a high-low-high pulse whenever I scanned a card. Is this related to the problem? </p>
<pre><code>#include <SPI.h>
#include "Adafruit_BLE_UART.h"
// Connect CLK/MISO/MOSI to hardware SPI
// e.g. On UNO & compatible: CLK = 13, MISO = 12, MOSI = 11
#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 3 // This should be an interrupt pin, on Uno thats #2 or #3
#define ADAFRUITBLE_RST 9
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
</code></pre>
<p>Any thought is appreciated. </p>
| <p>This can happen when your sketch uses too much memory - the board can no longer assign addresses so it resets leading to an endless loop. Try reducing the amount of memory you are allocating.</p>
|
5287 | |arduino-mega|c++|pins|digital| | Arduino Digital Input Causing Output Problems | 2014-12-02T19:07:57.090 | <p>I am working on a simple project using an Arduino Mega 2560 that involves reading a 12-bit binary encoder signal and which is used to cycle a digital pin high and low (depending on the angular location of the encoder).</p>
<p>My problem is that when the digital output pin is told to go low, it only goes down to about 4V. I also noticed that it would occasionally dip down to ground, instead of just 4V. Much to my surprise, when I unplug the Arduino, the digital output pin is still reading 4V. When I turned off power to my encoder which is connected up the the Arduino through 12 digital input pins, the output pin dropped down to 0V. When I turn the encoder back on it goes back up to about 4V.</p>
<p>I have tried connecting the output pin to ground and obviously the voltage goes to 0, but as soon as I remove the connection to ground the voltage springs back up to around 4V. It appears as though somehow the voltage being fed to the digital input pins (in the form of a ~5V digital input signal) is preventing the digital output pin from going to ground. I have no idea why this is the case, I have searched all over and could not find any similar complaints. My code is posted below, any help is greatly appreciated!</p>
<pre><code>unsigned long CamAngle = 0; // Variable to store encoder value
unsigned long PrevCamAngle = 0; // Variable to store previous encoder value
int i = 0; // Cycle index
int BDC[] = {683,2048,3413}; // BDC angle (12-bit encoder value)
int TDC[] = {0,1365,2731}; // TDC angle (12-bit encoder value)
boolean TDCycle = false; // TDC Cycle
boolean BDCycle = false; // BDC Cycle
boolean Cycle = true; // Encoder rollover cycle (replaces TDC cycle 0)
void setup()
{
pinMode(37, INPUT); // Encoder bit 0 (PORTC-0)
pinMode(36, INPUT); // Encoder bit 1 (PORTC-1)
pinMode(35, INPUT); // Encoder bit 2 (PORTC-2)
pinMode(34, INPUT); // Encoder bit 3 (PORTC-3)
pinMode(22, INPUT); // Encoder bit 4 (PORTA-0)
pinMode(23, INPUT); // Encoder bit 5 (PORTA-1)
pinMode(24, INPUT); // Encoder bit 6 (PORTA-2)
pinMode(25, INPUT); // Encoder bit 7 (PORTA-3)
pinMode(26, INPUT); // Encoder bit 8 (PORTA-4)
pinMode(27, INPUT); // Encoder bit 9 (PORTA-5)
pinMode(28, INPUT); // Encoder bit 10 (PORTA-6)
pinMode(29, INPUT); // Encoder bit 11 (PORTA-7)
pinMode(30, OUTPUT); // Set PORTC pin 8 to output (stop pin float)
pinMode(31, OUTPUT); // Set PORTC pin 7 to output (stop pin float)
pinMode(32, OUTPUT); // Set PORTC pin 6 to output (stop pin float)
pinMode(33, OUTPUT); // Set PORTC pin 5 to output (stop pin float)
digitalWrite(30, LOW); // Set PORTC pin 8 low (stop pin float)
digitalWrite(31, LOW); // Set PORTC pin 7 low (stop pin float)
digitalWrite(32, LOW); // Set PORTC pin 6 low (stop pin float)
digitalWrite(33, LOW); // Set PORTC pin 5 low (stop pin float)
pinMode(53, OUTPUT); // Set pin 53 (PORTB-0) as digital output
digitalWrite(53, LOW); // Set pin 53 (PORTB-0) LOW
}
void loop()
{
// Cam Angle Update
PrevCamAngle = CamAngle; // Set variable to previous encoder value
CamAngle = (PINA << 4) + PINC; // Read encoder, set variable to value
if (TDCycle == true && CamAngle >= TDC[i]) // Wait for encoder to reach angle if cycle active
{
PORTB = 0; // Set digital pin 53 LOW
TDCycle = false;
BDCycle = true;
}
if (BDCycle == true && CamAngle >= BDC[i]) // Wait for encoder to reach angle if cycle active
{
PORTB = 1; // Set digital pin 53 HIGH
TDCycle = false;
BDCycle = true;
i++;
if (i > 2) // Reset every 3 cycles (3 cycles per revolution)
{
i = 0;
BDCycle = false;
Cycle = true;
}
}
if (Cycle == true && CamAngle < (PrevCamAngle + 1)) // Wait for encoder to cycle back to 0
{
PORTB = 0; // Set digital pin 53 LOW
BDCycle = true;
Cycle = false;
}
}
</code></pre>
<p>As you can see I am utilizing direct port manipulation, however I have the same issues when I use the Arduino library commands as well. I'm fairly certain this is some sort of hardware issue, however I could be wrong.</p>
| <p>I think you have two issues here. </p>
<p>First:</p>
<blockquote>
<p>Much to my surprise, when I unplug the Arduino, the digital output pin is still reading 4V. </p>
</blockquote>
<p>With a powered device connected to the input pins, the overvoltage protection diodes power your 5V line with what is called "parasitic power". Those diodes are supposed to clamp an input pin to not exceed 5V, but if the power is off, they actually <strong>supply</strong> 5V (assuming at least some of the pins are high), hence powering up the processor. It is not designed to do this, and you should not power off the processor in this way.</p>
<hr>
<p>Second:</p>
<blockquote>
<p>My problem is that when the digital output pin is told to go low, it only goes down to about 4V.</p>
</blockquote>
<p>I tried out your code, but without the encoder to hand, I just comment out the three "if" tests:</p>
<pre><code>// if (TDCycle == true && CamAngle >= TDC[i])
...
// if (BDCycle == true && CamAngle >= BDC[i])
...
// if (Cycle == true && CamAngle < (PrevCamAngle + 1))
</code></pre>
<p>A multimeter on pin 53 reads 0.98V, however this is because the pin is being turned on and off quickly. I can't work out for sure whether some or all of these conditions would be satisfied in sequence (they don't seem directly related). One thing you could do, since you seem to want pin 53 either on or off is use "else", eg.</p>
<pre><code>if (TDCycle == true && CamAngle >= TDC[i])
{
...
} else if (BDCycle == true && CamAngle >= BDC[i])
{
...
}
else if (Cycle == true && CamAngle < (PrevCamAngle + 1))
{
...
}
</code></pre>
<p>Now you won't have multiple attempts to turn the pin on <strong>and</strong> off through one turn through the loop.</p>
|
5290 | |arduino-uno| | Simple IR sensor | 2014-12-02T23:22:51.313 | <p>I had an infrared 38khz sensor that I used to read my TV remote control commands. It worked fine but I burned it. I had not another 38khz IR sensor so I tried to use my infrared reflective optic sensor like the one below:</p>
<p><img src="https://i.stack.imgur.com/HnGi6.jpg" alt="enter image description here"></p>
<p>I press my TV remote control button and when I try to read the HIGHs and LOWs it does not work. The sensor shows in my Serial that it received the infrared light but it does not sense the lows/high.</p>
<p>As far as I know, this sensor is not 38khz, it listens in all frequencies that are infrared. So why it does not work? It should work cause it listens in all frequencies. Why it can detect the HIGHs/LOWs that the remote control sends?</p>
| <p>You didn't post the code that used to work with the standard 38Khz IR sensor, but I believe you used <strong>digitalRead</strong> to determine a HIGH or LOW value, by thus determine if there is an IR emitting in place. </p>
<p>The reflective optic sensor works differently, the output is analog, and changes according to the amount of IR light it sens. In addition, it has a built-in IR led next to the IR sensor, so if you want to use this as the IR detection sensor you had, first you need to disable the IR led to prevent interference.</p>
<p>The second step would be to use <strong>analogRead</strong>, and compare the result to a pre-defined threshold. For example, since analogRead returns result in the range of 0...1023, you can treat everything from, say, 512 and above as logic 'HIGH'. If you are working with libraries that detects the IR signal, you will need to alter them accordingly. </p>
|
5291 | |sketch|c|attiny|prototype| | ATtiny85 minimum setup to blink led | 2014-12-03T05:11:20.130 | <p>What would be the (very) minimum <em>schematic</em> to make a ATtiny85 blink a led?</p>
<p>Restrictions are:</p>
<ul>
<li>There must be a C program compiled and uploaded to it, just like an Arduino board would have. The code would use a simple "delay" to wait a little bit before changing the LED state.</li>
<li>The LED must be controlled by a "digital output port" just like an Arduino board would be.</li>
</ul>
<p>This is the main question. Although I thought to ask a similar question with the restriction of "blinking exactly once per second", that would change completely the schema (not being a MINIMAL after all). So lets restrain to the main question. Maybe some day we can discuss the version 2.0!</p>
| <p>My setup would be:</p>
<ul>
<li>a 10k resistor between Vcc and reset pin (pull-up) </li>
<li>a 330k put in serial with a led, connected between, e. g. PB0 and gnd. </li>
</ul>
<p>That's all. </p>
<p>For programming, I use an ISP programmer. I use a cheap Arduino Nano clone board for that.</p>
<p>I can run my ATtiny85 at 16Mhz internal oscillator, but important: I remarked that I had better results after having burnt the bootloader onto the ATtiny85, even if it is not needed because there is no USB serial chip besides the MCU. </p>
<p>But perhaps using avrdude to program the ATtiny85 fuses bits could avoid to burn this useless bootloader (taking 1/4 of flash memory). If someone has a solution, he is welcome.</p>
|
5293 | |arduino-uno|ethernet|web-server| | Using a web server with Arduino | 2014-12-03T05:23:46.933 | <p>So I am not new to arduino, however, I am new with web servers. I am working on a project that can control a robotic arm that is at one location and I can be at my house. I know basic HTML, Basic CSS, Basic JavaScript, and a tiny bit of JQuery. Only reason I say basic is because I self taught all these languages to myself using codeacademy. So I have a few questions since I done research on the matter.</p>
<p>Can a project like this be done with just the languages I know? All the tutorials I have looked at say you have to know AJAX and JSON. I have no idea what these are.</p>
<p>Also, for the interface, I need to be able to take the value of the encoders on the robot and view them. I also need a button that will record the value at that point in time of the encoders so I can configure the points and maybe even name them. A box where I can see the points and their coordinates, and finally a box where i can place points in and then execute a sequence. </p>
<p>How tough should this be?</p>
| <p>There is an example of using the ethernet shield as a simple web server on the arduino website:
<a href="http://arduino.cc/en/Tutorial/WebServer" rel="nofollow">http://arduino.cc/en/Tutorial/WebServer</a></p>
<p>Adafruit has another tutorial using an SDCard to hold the web application's files:
<a href="http://www.ladyada.net/learn/arduino/ethfiles.html" rel="nofollow">http://www.ladyada.net/learn/arduino/ethfiles.html</a></p>
<p>It would be possible to use the aforementioned techniques to host a simple web application.
Since the browser only understands HTML, CSS and JavaScript (browser plugins not withstanding), the application will have to be written using these languages.
The HTML file will describe the structure of the UI (text, buttons, etc.), the CSS will apply styles if necessary and the JavaScript will add the interaction code (e.g. what happens when you press a button). The JavaScript could request data from the arduino+ethernet shield using AJAX request and should be able to send data back the same way. Using jQuery, this should be pretty straightforward.</p>
<p>That said, it might be easier to use a full fledged network stack such as the one you can find on Linux (using a raspberry pi for example) and to communicate using the serial port with Linux. I have an example on GitHub (the documentation is lacking but I could update it if need be): <a href="https://github.com/ddm/arduino-express" rel="nofollow">https://github.com/ddm/arduino-express</a></p>
<p>But in that case you don't get to use the ethernet shield which you may have already bought...</p>
|
5308 | |arduino-uno| | What is this PIND command | 2014-12-03T19:14:00.157 | <p>I have a code that reads the value of a sensor and because it needs to be very fast it does not use digitalRead but a strange form of reading. In the top of the code it shows:</p>
<pre><code>#define IRSENSOR PIND
int irpin = 2;
</code></pre>
<p>I have no idea why this PIND referes to my arduino pin 2, but it only work if my sensor is in pin 2. If I want to change to pin 9 and only change the irpin varialbe it does not work. Why?</p>
<p>To read the sensor I use this code:</p>
<pre><code>while (IRSENSOR & (1 << irpin )) {
</code></pre>
<p>Have no idea why this work. Does anyone know this kind of programming with arduino?</p>
| <p>Reason explained by @BrettM. To be more perfect use macros everywhere, e.g.:</p>
<pre><code>#define IRSENSOR PIND
#define IRSENSOR_PIN PD2
while (IRSENSOR & _BV(IRSENSOR_PIN)) {
</code></pre>
<p>Arduino's <em>digitalWrite(),digitalRead(),pinMode()</em> functions are useless for more serious coding because they are 1) slow 2) you cannot address pins not connected to headers (e.g. at <em>Arduino2560</em>).</p>
|
5314 | |arduino-mega|pins|digital| | Arduino Mega: which Digital pins are already used for something? | 2014-12-04T04:10:49.383 | <p>I got an Ethermega, and learned that Pin 13 already has a LED. </p>
<p>Are there other digital pins with special circuitry or already allocated to a specific function? (like usb,serial,ethernet,sd, etc)</p>
<p>I need about 30 inputs so I can skip some if that would avoid headaches.</p>
| <p>D4: ChipSelect for the SD card reader (can be used if no SD is present)</p>
<p>D0 and D1 are Serial RX and TX (just like any other arduino)</p>
<p>D10: Ethernet enable line</p>
<p>D13: led. Led is connected via a mosfet, so it doesn't interfer (like on the uno)</p>
<p>D50, D51, D52: SPI for the ethernet chip and SD card</p>
<p>All this was found in the <a href="https://github.com/freetronics/EtherMega/raw/master/EtherMega.pdf" rel="nofollow">schematic</a></p>
|
5329 | |arduino-uno|attiny| | Shift register on Attiny85 programmed by Arduino | 2014-12-05T04:13:50.430 | <p>Shift registers need 3 digital pins in order to work (data, clock and latch), but Attiny45/85 chips provides 2 digital and 2 analog pins.</p>
<p>Would I use 1 analog pin as digital pin? How?</p>
| <p>As <em>Ingnacio has already pointed out</em>, <strong>PB0</strong> to <strong>PB4</strong> can be used as digital IO ports <strong>without problems</strong>. It night be a good idea though not to touch <strong>PB6</strong>, the <code>RESET</code> pin. </p>
<p>Btw, this isn't different from an Arduino, where all so-called <em>analog pins</em> can be used for digital output as well.</p>
<p>If you want to drive shift registers from an ATtiny85 using SPI, you might want to have a look at the <a href="https://github.com/JChristensen/tinySPI" rel="nofollow">tinySPI</a> library written by <strong>Jack Christensen</strong>. <em>Please note that I haven't used this library personally!</em></p>
|
5333 | |led|remote-control|audio|signal-processing| | Using Arduino audio to control an LED light | 2014-12-05T07:35:16.087 | <p>I am looking for a way to control an LED on a circuit board using audio input for learning purposes. </p>
<p>I have written my own speech recognition system using dynamic time warping in Python, but I would like to know if (and maybe what models if not all can do) Arduino can possibly handle the processing of a 70 by 70 O(n^2) matrix traversal with <strong>fft</strong> or <strong>dct</strong> operations on audio input divided into 10ms frames.</p>
<p>Any advice will be appreciated.</p>
| <p>The Due or Tre may have enough power for this. The Yún may be able to offload it to the more powerful CPU. Every other Arduino will struggle with it.</p>
|
5345 | |pins|bluetooth|arduino-leonardo|sd-card| | Blend with SD Shield | 2014-12-05T23:12:48.683 | <p>Building a data logging and transmission system here. I've a RedBearLab Blend with built-in BLE capabilities and a (cheap) SD / Data logging shield that looks very suspiciously like it's copied from the Adafruit one. </p>
<p>Using a Stock Arduino Uno board, the Data logging shield works out of the box - both RTC TimeSet and cardinfo come back successfully.</p>
<p>Stacking the shield on the Blend, both examples lead nowhere. The TimeSet states that no connection could be made, and the cardinfo says it can't find the card.</p>
<p>I assume it's a pin conflict of some sort, but I'm really unsure what I should do to debug/fix it.</p>
<p>[edit] As I found out below, the SD Module works now - but I still face the problem of not getting the RTC to work. Neither on the shield nor a Tiny RTC module. Again, both work fine on the Arduino Uno.</p>
<p>[edit2] I had basically the same problem for the RTC module as well - see the answer below.</p>
| <p>Sometimes it helps just adding the tags.....</p>
<p>The Blend is a Arduino Leonardo Chip -
and as Lady Ada helpfully points out, you need a special SD Library to use this. The advice on <a href="https://learn.adafruit.com/adafruit-data-logger-shield/for-the-mega-and-leonardo" rel="nofollow">https://learn.adafruit.com/adafruit-data-logger-shield/for-the-mega-and-leonardo</a> is everything I needed to get the cardinfo working, especially the <code>while (!card.init(SPI_HALF_SPEED, 10, 11, 12, 13)) {</code>
part.</p>
<p>Also, the I2C Pins for the RTC Clock are not the "standard" Analog Pins 4 and 5, but D2 and D3 (see <a href="http://arduino.cc/en/Reference/Wire" rel="nofollow">http://arduino.cc/en/Reference/Wire</a>)</p>
|
5349 | |sensors|robotics| | Which reflectance sensor array for a line following robot? | 2014-12-06T04:23:45.317 | <p>I'm working on a line-following robot with my son. We've found a sensor array on Robot Shop that will help us but .. there's two and I'm not sure which will be the best for us.</p>
<p>The difference between them, as described in <a href="https://secure.robotshop.com/media/files/pdf/pololu-qtr-8x-reflectance-sensor-array-user-guide.pdf" rel="noreferrer">this PDF</a> is "The QTR-8A uses a voltage divider for each sensor’s output while the QTR-8RC uses an RC circuit."</p>
<p>What I want to do is detect which sensor the followed line is triggering. All I need is a yes/no. But I'm too new to this to decide which of these two sensors would be best for me.</p>
| <p>The main difference between the two models, as stated in the PDF you provided, is the output they provide to the MCU. </p>
<p>The QTR-8A will provide an <strong>Analog</strong> output, requiring a corresponding analog pin on the microcontroller. The QTR-8RC will provide a <strong>Digital</strong> output, but will allow the same accuracy of the QTA-8A by measuring the discharge time of the capacitor (HIGH to LOW time), with the advantage of higher accuracy due to the use of RC circuit instead of a voltage divider. </p>
<p>Both seems pretty straight forward, but for your needs, the QTR-8RC might seem more compatible, considering the Arduino Uno has 6 analog I/O pins (you didn't mention which Arduino is going to be used, the Arduino Nano has 8 and the Arduino Mega has 16), and that the QTR sensor provides 8 outputs. The way you could accomplish that with QTR-8RC and 8 <strong>digital</strong> I/O pins is described in the PDF:</p>
<blockquote>
<ol>
<li>Turn on IR LEDs (optional)</li>
<li>Set the I/O line to an output and drive it high</li>
<li>Allow at least 10 us for the 10 nF capacitor to charge</li>
<li>Make the I/O line an input (high impedance)</li>
<li>Measure the time for the capacitor to discharge by waiting for the I/O line to go low</li>
<li>Turn off IR LEDs (optional)</li>
</ol>
</blockquote>
|
5351 | |arduino-mega|wifi|nrf24l01+| | NRF24L01+ scanning and connecting to wifi hotspots or creating one | 2014-12-06T07:53:35.010 | <p>I've seen this <a href="https://www.youtube.com/watch?v=issW8aeM5tY" rel="nofollow">video</a> so I think I can connect it through my wifi router to any device. How can I scan for and discover wifi hotspots and then connect to it? Or is there a way to create wifi hotspot of it's own?</p>
| <p>It does seem possible, check out <a href="http://forum.arduino.cc/index.php?topic=54795.0">this thread</a> on Arduino forums, where cpixip worked directly with the NRF24 SPI interface to accomplish that.</p>
<p>Here is the code he published, in case the link won't be available:</p>
<pre><code>#include <SPI.h>
// Poor Man's Wireless 2.4GHz Scanner
//
// uses an nRF24L01p connected to an Arduino
//
// Cables are:
// SS -> 10
// MOSI -> 11
// MISO -> 12
// SCK -> 13
//
// and CE -> 9
//
// created March 2011 by Rolf Henkel
//
#define CE 9
// Array to hold Channel data
#define CHANNELS 64
int channel[CHANNELS];
// greyscale mapping
int line;
char grey[] = " .:-=+*aRW";
// nRF24L01P registers we need
#define _NRF24_CONFIG 0x00
#define _NRF24_EN_AA 0x01
#define _NRF24_RF_CH 0x05
#define _NRF24_RF_SETUP 0x06
#define _NRF24_RPD 0x09
// get the value of a nRF24L01p register
byte getRegister(byte r)
{
byte c;
PORTB &=~_BV(2);
c = SPI.transfer(r&0x1F);
c = SPI.transfer(0);
PORTB |= _BV(2);
return(c);
}
// set the value of a nRF24L01p register
void setRegister(byte r, byte v)
{
PORTB &=~_BV(2);
SPI.transfer((r&0x1F)|0x20);
SPI.transfer(v);
PORTB |= _BV(2);
}
// power up the nRF24L01p chip
void powerUp(void)
{
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x02);
delayMicroseconds(130);
}
// switch nRF24L01p off
void powerDown(void)
{
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)&~0x02);
}
// enable RX
void enable(void)
{
PORTB |= _BV(1);
}
// disable RX
void disable(void)
{
PORTB &=~_BV(1);
}
// setup RX-Mode of nRF24L01p
void setRX(void)
{
setRegister(_NRF24_CONFIG,getRegister(_NRF24_CONFIG)|0x01);
enable();
// this is slightly shorter than
// the recommended delay of 130 usec
// - but it works for me and speeds things up a little...
delayMicroseconds(100);
}
// scanning all channels in the 2.4GHz band
void scanChannels(void)
{
disable();
for( int j=0 ; j<200 ; j++)
{
for( int i=0 ; i<CHANNELS ; i++)
{
// select a new channel
setRegister(_NRF24_RF_CH,(128*i)/CHANNELS);
// switch on RX
setRX();
// wait enough for RX-things to settle
delayMicroseconds(40);
// this is actually the point where the RPD-flag
// is set, when CE goes low
disable();
// read out RPD flag; set to 1 if
// received power > -64dBm
if( getRegister(_NRF24_RPD)>0 ) channel[i]++;
}
}
}
// outputs channel data as a simple grey map
void outputChannels(void)
{
int norm = 0;
// find the maximal count in channel array
for( int i=0 ; i<CHANNELS ; i++)
if( channel[i]>norm ) norm = channel[i];
// now output the data
Serial.print('|');
for( int i=0 ; i<CHANNELS ; i++)
{
int pos;
// calculate grey value position
if( norm!=0 ) pos = (channel[i]*10)/norm;
else pos = 0;
// boost low values
if( pos==0 && channel[i]>0 ) pos++;
// clamp large values
if( pos>9 ) pos = 9;
// print it out
Serial.print(grey[pos]);
channel[i] = 0;
}
// indicate overall power
Serial.print("| ");
Serial.println(norm);
}
// give a visual reference between WLAN-channels and displayed data
void printChannels(void)
{
// output approximate positions of WLAN-channels
Serial.println("> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 <");
}
void setup()
{
Serial.begin(57600);
Serial.println("Starting Poor Man's Wireless 2.4GHz Scanner ...");
Serial.println();
// Channel Layout
// 0 1 2 3 4 5 6
// 0123456789012345678901234567890123456789012345678901234567890123
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
//
Serial.println("Channel Layout");
printChannels();
// Setup SPI
SPI.begin();
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV2);
SPI.setBitOrder(MSBFIRST);
// Activate Chip Enable
pinMode(CE,OUTPUT);
disable();
// now start receiver
powerUp();
// switch off Shockburst
setRegister(_NRF24_EN_AA,0x0);
// make sure RF-section is set properly
// - just write default value...
setRegister(_NRF24_RF_SETUP,0x0F);
// reset line counter
line = 0;
}
void loop()
{
// do the scan
scanChannels();
// output the result
outputChannels();
// output WLAN-channel reference every 12th line
if( line++>12 )
{
printChannels();
line = 0;
}
}
</code></pre>
<p>The pinout seems to match the NRF24 library pinout.
Please note that it seems this project does not implement the WiFi stack, but only check a high enough signal ( > -64dBm) for a given channel. </p>
<p>In order to create a WiFi hotspot, implementing the 802.11 stack is inevitable, and it seems like the Arduino core chip (atmega328) is not suitable for implementing it using software and bit-banging, so a dedicated hardware will be necessary. </p>
|
5360 | |gsm| | Using Arduino's hardware serial to control SIM900 | 2014-12-06T15:22:50.793 | <p>I have a SIM900 board which has a serial interface. I'm trying to control it using Arduino Uno. I've tried using SoftwareSerial on pins 10 (RX) and 11 (TX) to talk to my board. It works OK with different baud rates (SIM900 has auto-bauding). I'm connecting pin 10 directly to my board, but pin 11 is connected through a voltage divider in order to lower voltage from 5 V to 2.8 V (SIM900 uses 2.8 V CMOS logic levels).</p>
<p>But now I want to use Arduino's hardware UART to talk to SIM900. I'm using pins 0 and 1 with similar design as above (also using voltage divider). I just can't get it to work. No matter what I do I can't see any communication. I've tried different baud rates, but it just doesn't work. Here is my code:</p>
<pre class="lang-cpp prettyprint-override"><code>void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
delay(10000);
Serial.write("AT\r");
delay(1000);
if (Serial.available())
{
digitalWrite(13, HIGH);
}
}
void loop()
{
}
</code></pre>
<p>So I should see a LED light up but nothing happens (SIM900 responds with "\r\nOK\r\n" to "AT\r"). What am I doing wrong?</p>
| <p>Arduino with sim900 module is disabled after a day or course sim900 module is completely safe and always receives sms but the Arduino module led after one or more days is no longer able to enable or disable.</p>
<pre><code>#include <SoftwareSerial.h>
SoftwareSerial SIM900 (7, 8);
char incoming_char = 0; // Will hold the incoming character from the Serial Port.
int led_status = 0;
int led1 = 10;
int led2 = 13;
void setup () {
pinMode (led1, OUTPUT);
pinMode (led2, OUTPUT);
SIM900power ();
Serial.begin (19200); // Set the baud rate
SIM900.begin (19200); // For GSM shield
delay (20000); // Give time to log on to network.
SIM900.print ( "AT + CMGF = 1 \ r"); // Set SMS mode to text
delay (100);
SIM900.println ( "AT + CNMI = 2,2,0,0,0 \ r");
//SIM900.print("AT+CLIP=1\r "); // Turn on caller ID notification
digitalWrite (led1, LOW); // Set led to LOW
digitalWrite (led2, LOW);
// Serial.println ( "AT + CMGD = 1,4"); // Delete all SMS in box
}
void sendSMS (char led_status) {// SEND SMS
SIM900.print ( "AT + CMGF = 1 \ r"); // AT command to send SMS message
delay (1000);
SIM900.println ( "AT + CMGS = \" + 9xxxxxxxx \ "\ r"); // Recipient's mobile number, in international format
delay (1000);
if (led_status == 0)
{
SIM900.println ( "ALARM ON");
}
else
{
SIM900.println ( "ALARM OFF");
}
delay (1000);
SIM900.println ();
delay (5000); // Give module time to send SMS
}
void SIM900power ()
// Software equivalent of pressing the GSM shield "power" button
{
digitalWrite (9, HIGH);
delay (1000);
digitalWrite (9, LOW);
delay (7000);
}
void loop () {
// # A1s on & # a0s off
if (SIM900.available ()> 0)
{
incoming_char = SIM900.read ();
if (incoming_char == '#')
{
delay (10);
incoming_char = SIM900.read ();
if (incoming_char == 'a')
{
delay (10);
incoming_char = SIM900.read ();
if (incoming_char == '0')
{
digitalWrite (led1, LOW);
digitalWrite (led2, LOW);
}
else if (incoming_char == '1')
{
digitalWrite (led1, HIGH);
digitalWrite (led2, HIGH);
}
else if (incoming_char == 'S')
{
digitalRead (led1);
led_status = digitalRead (led1);
led_status = digitalRead (led2);
Serial.print (led_status); // Prints status on serial terminal
sendSMS (led_status);
}
delay (10);
}
// End AT command with a ^ Z, ASCII code 26
delay (5000);
led_status = digitalRead (led1);
led_status = digitalRead (led2);
Serial.print (led_status); // Prints status on serial terminal
sendSMS (led_status);
SIM900.println ((char) 26);
}
}
}
</code></pre>
|
5362 | |programming|sketch| | How to use bitset/read on 16bit numbers (Arduino) | 2014-12-06T18:54:44.893 | <p>I'm working on an Arduino powered Tetris game. To keep track of the pieces that have fallen and become fixed I have an array of bytes </p>
<pre><code>byte theGrid[] = {
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
...
</code></pre>
<p>This works great when the well is only 8 LEDs wide, but I need it to be 16 wide. Is there a way to perform bitwise operations on a 16 bit number, like a short? I tried just declaring theGrid as a short, but I'm getting this error no matter what I do.</p>
<pre><code>tetris:62: error: 'B0000000000000000' was not declared in this scope
</code></pre>
<p>The reason I was using byte is so I could use bitread and bitset. So if an L piece comes down and lands, I can bitset the appropriate bits like this </p>
<pre><code>bitSet(theGrid[pixelY], 15-pixelX);
</code></pre>
<p>and end up with</p>
<pre><code>B1000000000000000, B1110000000000000
</code></pre>
| <p>The main problem that you're having is that <em>binary literals don't exist in C</em>; the Arduino libraries get around this by having <strong>every single binary value</strong> from <a href="http://www.asic-world.com/verilog/syntax1.html#Integer_Numbers" rel="nofollow">1'b0</a> to 8'b1111_1111 defined as a macro in <a href="https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/binary.h" rel="nofollow"><code>cores/arduino/binary.h</code></a>. The obvious workaround is to use octal, decimal, or hexadecimal literals instead.</p>
<pre><code>unsigned short theGrid[] = {
00,
0,
0x0,
...
};
</code></pre>
<p>Bitwise operations work as normal.</p>
<pre><code>theGrid[pixelY] |= _BV(15 - pixelX);
</code></pre>
|
5378 | |arduino-uno|serial| | Garbled serial on custom arduino UNO | 2014-12-07T19:59:33.423 | <p>I built my own Arduino UNO for a project at school. I think I have got the USB bootloader and Windows drivers all situated as the UNO shows up as an UNO in the device manager. When I try to load a sketch I get the error: avrdude: stk500_getsync(): not in sync: resp=0x10. (previously I received the same message with the message ending with resp=0x00)</p>
<p>I loaded a serial echo program using the ICSP and sent the message "serial test" to the UNO. I received this message back: {u{m}o¿wu{w</p>
<p>Can anyone help me troubleshoot this problem as I have ran out of things to test or look into. </p>
<p>Thanks in advance.</p>
<p>Edit: Added requested pictures of TX and RX. These were taken at Pin 0 and 1 of the headers. The scope showed the same results at the pins of the 328P but I couldn't operate the scope and hold the probe at the same time. </p>
<p><img src="https://i.stack.imgur.com/vvzet.jpg" alt="Pin 0"></p>
<p><img src="https://i.stack.imgur.com/PyJS5.jpg" alt="Pin 1"></p>
| <p>From the scope picture it appears you have a ground problem. All the grounds must be connected together even the scope. It appears like you have a pseudo phantom ground via the mains power system. Did you set the baud in the uno with Serial.begin(your baud rate);? The baud must be the same on both ends. For a check you should get a UNO and see if it works with that the problem is your board. Also be sure Tx on the UNO goes to RX on the receiving end and visa versa.</p>
|
5381 | |audio| | Arduino to Home Speakers | 2014-12-08T04:38:32.513 | <p>I know little about electronics in general. I wanted to connect Arduino, and play a tone using tone() through my home speakers.</p>
<p>I've used a 1/8'' audio jack and connect ground to ground and left/right to pin 2. Run it and it was too loud.</p>
<p>Then I read the specification and it says,</p>
<p>Input impedance = 20 kOhm </p>
<p>Input sensibility = 400mV +/- 50mV</p>
<p>Arduino sends 5V so that should be a lot. Did I damage my speaker? They still work.</p>
| <p>It's probably not damaged, but you shouldn't do it again.</p>
<p>To get the 5V signal down to 400mV you need to create a voltage divider. As such you will need a:</p>
<p>5V / (400mV / 20kohm) − 20kohm = 230kohm</p>
<p>resistor between the pin and the input. 220kohm should be close enough.</p>
|
5386 | |arduino-uno|accelerometer|gyroscope| | Calculating Angles from MPU6050 | 2014-12-08T11:48:00.287 | <p>I've been playing with a GY521 breakout recently with the MPU6050 chip on it, though i've hit a bit of a problem that I can't quite work out</p>
<p>I know when I rotated the board I rotated ~90 degrees about the Y axis, and using the sensitivity numbers from the datasheet (131) and integrating i've managed to get something that looks believable from the gyroscope, but am having problems with the accelerometer.</p>
<p>From a number of sources, <a href="http://www.geekmomprojects.com/gyroscopes-and-accelerometers-on-a-chip/" rel="nofollow noreferrer">this being one of them</a>, I've managed to get the three equations seen on here, however when I apply them to either the raw or scaled data (as they're scalers is shouldn't make a difference?) I get a set of data that varies from 0 to 90, but only on the X and Z axes, while nothing happens to the Y.</p>
<p>Updated to include code:</p>
<pre><code>#include "I2Cdev.h"
#include "MPU6050.h"
#include "Wire.h"
MPU6050 accelgyro;
int16_t ax, ay, az, gx, gy, gz;
double timeStep, time, timePrev;
double arx, ary, arz, grx, gry, grz, gsx, gsy, gsz, rx, ry, rz;
int i;
double gyroScale = 131;
void setup() {
Wire.begin();
Serial.begin(9600);
accelgyro.initialize();
time = millis();
i = 1;
}
void loop() {
// set up time for integration
timePrev = time;
time = millis();
timeStep = (time - timePrev) / 1000; // time-step in s
// collect readings
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
// apply gyro scale from datasheet
gsx = gx/gyroScale; gsy = gy/gyroScale; gsz = gz/gyroScale;
// calculate accelerometer angles
arx = (180/3.141592) * atan(ax / sqrt(square(ay) + square(az)));
ary = (180/3.141592) * atan(ay / sqrt(square(ax) + square(az)));
arz = (180/3.141592) * atan(sqrt(square(ay) + square(ax)) / az);
// set initial values equal to accel values
if (i == 1) {
grx = arx;
gry = ary;
grz = arz;
}
// integrate to find the gyro angle
else{
grx = grx + (timeStep * gsx);
gry = gry + (timeStep * gsy);
grz = grz + (timeStep * gsz);
}
// apply filter
rx = (0.1 * arx) + (0.9 * grx);
ry = (0.1 * ary) + (0.9 * gry);
rz = (0.1 * arz) + (0.9 * grz);
// print result
Serial.print(i); Serial.print("\t");
Serial.print(timePrev); Serial.print("\t");
Serial.print(time); Serial.print("\t");
Serial.print(timeStep, 5); Serial.print("\t\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.print(gz); Serial.print("\t\t");
Serial.print(arx); Serial.print("\t");
Serial.print(ary); Serial.print("\t");
Serial.print(arz); Serial.print("\t\t");
Serial.print(grx); Serial.print("\t");
Serial.print(gry); Serial.print("\t");
Serial.print(grz); Serial.print("\t\t");
Serial.print(rx); Serial.print("\t");
Serial.print(ry); Serial.print("\t");
Serial.println(rz);
i = i + 1;
delay(50);
}
</code></pre>
<p>Results:</p>
<p><img src="https://i.stack.imgur.com/Jssg5.png" alt="plottedResults"></p>
<p>Strikes me as a little odd, as I was expecting only a rotational change in Y. Any suggestions? </p>
| <p>If I understand your question, the main issues are that the axis don't match up, and z from the accel is not accurate?</p>
<p>with respect to the axis: just swap the values. Rotation math is self-consistent and "correct" in many different permutations. What makes it correct is the set of equations, not any single equation; So, copying equations from one reference frame to another will yield incorrect results even if they were correct originally.</p>
<p>your link addresses this difference:</p>
<blockquote>
<p>"Interpreting the diagram at left is a little tricky, since the tilt
of the X-axis actually shows rotation around the Y-axis, and the
angling of the Y-axis shows (negative) rotation around the X-axis."</p>
</blockquote>
<pre><code> ary = -(180/3.141592) * atan(ax / sqrt(square(ay) + square(az)));
arx = (180/3.141592) * atan(ay / sqrt(square(ax) + square(az)));
</code></pre>
<p>should work better for you</p>
<p>On the second point: accelerometers can't measure yaw, the "z" equation can safely be ignored. that isn't yaw it calculates. Calculating z from the gyro alone should fix your second issue.</p>
<p>Other considerations:</p>
<ul>
<li>The gyroscope tracking can be made more accurate by using the midpoint rule in your integration</li>
<li>Your code is not integrating the gyroscope's signal with the best estimate of its last position (rx, ry, rz), instead it integrates the gyro with separate numbers (grx, gry, grz). In effect information from the accelerometer is discarded each loop and gyro drift is not corrected for.</li>
<li>Thanks for including those graphs with your code samples =] rotation math is extremely tricky, and graphs help a lot</li>
</ul>
|
5396 | |arduino-mega|timers|compile|avr-gcc| | Setting timer3 in CTC mode - conflict with servo library | 2014-12-09T02:20:08.713 | <p>I would like to set up a timer in order to call a function 800 times per second. I'm using the Arduino Mega and Timer3 with a prescaler of 1024. To choose the prescaler factor I've considered the following steps:</p>
<ul>
<li>CPU freq: 16MHz</li>
<li>Timer resolution: 65536 (16 bits)</li>
<li>Divide CPU freq by the chosen prescaler:
16x10^6/<strong>1024</strong>=15625</li>
<li>Divide the rest through the desired freq
62500/800=<strong>19</strong>. </li>
<li>Put the result + 1 in OCR3 register.</li>
</ul>
<p>I've used the following table to set registers of TCCR3B:</p>
<p><img src="https://i.stack.imgur.com/Z3H7p.png" alt="enter image description here"></p>
<p><strong>The error</strong></p>
<p>It is impossible to compile the code. This is the error returned by the compiler:</p>
<blockquote>
<p>Servo\Servo.cpp.o: In function '__vector_32': C:\Program Files
(x86)\Arduino\libraries\Servo/Servo.cpp:110: multiple definition of
'__vector_32' AccelPart1_35.cpp.o:C:\Program Files
(x86)\Arduino/AccelPart1_35.ino:457: first defined here c:/program
files
(x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe:
Disabling relaxation: it will not work with multiple definitions</p>
</blockquote>
<p><strong>The code</strong></p>
<pre><code>volatile int cont = 0;
unsigned long aCont = 0;
void setup()
{
[...]
// initialize Timer3
cli(); // disable global interrupts
TCCR3A = 0; // set entire TCCR3A register to 0
TCCR3B = 0; // same for TCCR3B
// set compare match register to desired timer count: 800 Hz
OCR3A = 20;
// turn on CTC mode:
TCCR3B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30) | (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3A);
// enable global interrupts:
sei();
}
void loop()
{
// Print every second the number of ISR invoked -> should be 100
if ( millis() % 1000 == 0)
{
Serial.println();
Serial.print(" tick: ");
Serial.println(contatore);
contatore = 0;
}
}
[...]
// This is the 457-th line
ISR(TIMER3_COMPA_vect)
{
accRoutine();
contatore++;
}
void accRoutine()
{
// reads analog values
}
</code></pre>
<p>How to solve the conflict with the servo library?</p>
<p><strong>SOLUTION</strong></p>
<p>Conflict solved using the following code. It compiles but the counter associated with the 800Hz timer doesn't increment its value.</p>
<pre><code>volatile int cont = 0;
void setup()
{
Serial.begin(9600);
// Initialize Timer
cli(); // disable global interrupts
TCCR3A = 0; // set entire TCCR3A register to 0
TCCR3B = 0; // same for TCCR3B
// set compare match register to desired timer count: 800 Hz
OCR3B = 20;
// turn on CTC mode:
TCCR3B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30) | (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3B);
// enable global interrupts:
sei();
Serial.println("Setup completed");
}
void loop()
{
if (millis() % 1000 == 0)
{
Serial.print(" tick: ");
Serial.println(cont);
cont = 0;
}
}
ISR(TIMER3_COMPB_vect)
{
cont++;
}
</code></pre>
<p>Since the main problem has been solved, I've created another question <a href="https://arduino.stackexchange.com/questions/5431/how-to-update-a-variable-in-an-isr-using-timers">here</a> related to the problem of the counter incrementation.</p>
| <p>Unfortunately, The Servo library reserves output compare A (OCR*A) on timers 1,3,4, and 5 when loaded on an arduino mega. Each can only have one ISR, so you will not be able to define your own TIMER*_COMPA_vect while you use Servo without modifying the library. </p>
<p>However, each hardware timer is equipped with 2 output compare registers. Servo does not claim any TIMER*_COMPB_vect interrupts, so those are free to use, and work exactly the same.</p>
<p>You should watch out for the Servo libraries activities, it could change the configuration of your timer. The default order is on megas is 5,1,3,4 and to give each 12 servos. It only configures the timer once it needs it, so you should be fine using timer 3 until you add that 25th servo.</p>
<p>To change your code, use OCR3B instead of OCR3A (the Output Compare Registers) and set bit OCIE3B instead of OCIE3A in TIMSK3 (the Output Compare Interrupt Enable bits). Then you to change your ISR function to <code>ISR(TIMER3_COMPB_vect){}</code></p>
<p>CTC mode only works with OCR3A, but if you set TCNT3 to 0 in your interrupt function you can get similar behavior. Remember to remove the line that turns CTC mode on using WGM12.</p>
|
5397 | |serial|arduino-leonardo|usb|mac-os| | Mac won't detect Serial Port for Leonardo | 2014-12-09T04:41:04.553 | <p><strong><em>EDIT:</em></strong> <em>The problem was the cable I was using (see answer below).</em></p>
<hr>
<p>I have a MacBook Pro running OS X Yosemite (10.10.1). I connected my Arduino Leonardo to my computer for the first time today (using a Micro USB to USB cable), but my computer isn't detecting it.</p>
<p>When I opened the Arduino IDE I selected Tools > Board > "Arduino Leonardo", but when I try to choose a Serial Port the only options are:</p>
<ul>
<li>/dev/tty.Bluetooth-Incoming-Port</li>
<li>/dev/cu.Bluetooth-Incoming-Port</li>
<li>/dev/tty.Bluetooth-Modem</li>
<li>/dev/cu.Bluetooth-Modem</li>
</ul>
<p><img src="https://i.stack.imgur.com/r8DwE.png" alt="screenshot of available serial ports"></p>
<p>I have tried closing and relaunching the Arduino IDE, disconnecting and reconnecting my Arduino Leonardo, and restarting my computer, but I still only see the four Bluetooth ports.</p>
<p>System Information (aka System Profiler) doesn't show anything connected to any of my USB ports.</p>
<p>Thanks in advance!</p>
| <p>@IgnacioVazquez-Abrams's comment made me realize that the problem was the Micro USB cable I was using. It gave the Arduino 5V power from my computer, but didn't support any data connection. I'm buying a new cable.</p>
|
5400 | |power|usb| | How to stop Arduino from drawing power through USB | 2014-12-09T09:22:58.347 | <p>I'm working on an embedded project, where I use arduinos as a "sensor shield" for RaspberryPi (I have model B).</p>
<p>The problem is, that the RaspberryPi's USB port is not powerfull enough to drive WiFi adapter and arduino with sensors. The solution is easy, I will power the sensors externally, not through the RPi. </p>
<p>But I was wondering, <strong>is it possible to power whole Arduino externally (through Vin) and use the USB only for serial communication.</strong></p>
<p>To clarify, I know how to solve my problem - use some other mean of communication, than USB - GPIO serial, I2C, wireless, etc... I'm just interested if the whole thing will work, with USB cable which has 5V lead cut, for example.</p>
<p>The main issue I can see with this is, that the USB<->Serial chip is powered through USB only, then it will now work.</p>
| <p><strong>Just cut the <em><code>VCC</code></em> line (usually <em>red</em>) in the USB cable.</strong></p>
<hr>
<p>There are four wires in a USB cable:</p>
<ul>
<li>Ground</li>
<li>VCC</li>
<li>Data +</li>
<li>Data -</li>
</ul>
<p>You cannot send data along without a reference ground as you need a potential difference. Hence you must keep the ground connected and just snip the power line (red <em><code>VCC</code></em>). </p>
<hr>
<p>Note that this is <strong>not</strong> usually necessary as <strong><em><code>VIN</code></em> is favoured over <em>USB</em> power</strong>.</p>
|
5401 | |led| | Problem with fading LEDs | 2014-12-09T09:26:10.440 | <p>I got a breadboard with 10 LEDs, 4 of them fade, to be specific:
3, 5, 6 and 9 are working. 0, 1, 2, 4, 7, 8 are not working.</p>
<p>I'm using LEDs and resistors on all spots, they're all the same. Tried changing things around but the problem doesn't seem to be the resistors or the LEDs.</p>
<p>I'm using the following code (I'll highlight the parts for the fading, by marking it between <code>//**</code> comments).</p>
<p>Does anyone know a way to fix this? Or see any problem?</p>
<pre><code>const int inButton = 13;
int buttonPushCounter = 0;
int buttonState = 0;
int lastButtonState = 0;
int delayTime = 100;
int brightness = 0;
int fadeAmount = 5;
void setup() {
//**
pinMode(inButton, INPUT);
for (int out = 0; out < 10; out++){
pinMode(out, OUTPUT);
}
//**
pinMode(testLed, OUTPUT);
}
void loop() {
buttonState = digitalRead(inButton);
if (buttonState != lastButtonState){
if (buttonState == 1){
buttonPushCounter++;
}
}
lastButtonState = buttonState;
if (buttonPushCounter % 5 == 0){
for (int i = 0; i < 10; i++){
digitalWrite(i, 1);
delay(delayTime / 2);
digitalWrite(i, 0);
}
}
else if (buttonPushCounter % 5 == 1){
for (int i = 0, j = 9; i < 10, j >= 0; i++, j--){
digitalWrite (i, 1);
digitalWrite (j, 1);
delay(delayTime / 2);
digitalWrite (i, 0);
digitalWrite (j, 0);
}
}
else if (buttonPushCounter % 5 == 2){
for (int i = 0; i < 10; i+=2){
digitalWrite(i, 1);
}
delay(delayTime);
for (int i = 0; i < 10; i+=2){
digitalWrite(i, 0);
}
delay(delayTime);
for (int i = 1; i < 10; i+=2){
digitalWrite(i, 1);
}
delay(delayTime);
for (int i = 1; i < 10; i+=2){
digitalWrite(i, 0);
}
}
else if (buttonPushCounter % 5 == 3){
for (int i = 0 ; i < 10 ; i++){
analogWrite(i, brightness);
}
brightness = brightness + fadeAmount;
if (brightness == 0 || brightness == 255){
fadeAmount = -fadeAmount;
}
delay(25);
}
else {
int R1 = random(10);
int R2 = random(10);
int R3 = random(10);
int R4 = random(10);
digitalWrite(R1, 1);
digitalWrite(R2, 1);
digitalWrite(R3, 1);
digitalWrite(R4, 1);
delay(delayTime);
digitalWrite(R1, 0);
digitalWrite(R2, 0);
digitalWrite(R3, 0);
digitalWrite(R4, 0);
}
}
</code></pre>
| <p>To add to @ignacio-vazquez-abrams answer, the pins that support <code>analogWrite()</code> have <code>~</code> sign next to their number (on my Uno board they are <code>9~</code>, <code>10~</code>, <code>11~</code> e.g.);</p>
|
5416 | |programming|variables| | Convert long to char array and back | 2014-12-10T01:31:43.440 | <p>I'm trying to store a state in my data logger. I can read/write fine to SD, but I can't wrap my head around reading/writing a <code>long</code> value correctly - I've build it down to converting it to char array and back.</p>
<p>My best try so far has been </p>
<pre><code>long temp = 1418172669L;
unsigned char buf[4];
buf[0] = temp & 0xFF;
buf[1] = (temp >> 8) & 0xFF;
buf[2] = (temp >> 16) & 0xFF;
buf[3] = (temp >> 24) & 0xFF;
long l = buf[0] | (buf[1] << 8) | (buf[2] << 16) | (buf[3] << 24);
</code></pre>
<p>But <code>l</code> is very different from <code>temp</code> - currently the output is <code>-26371</code>. Am I making an obvious mistake?</p>
| <p>Just for completeness, after posting this, I've found another way around it, but @Phataas solution is much more elegant.
Using the <code>ltoa</code> and <code>atol</code> functions, long to char array and vice-verse can be done like this:</p>
<pre><code>char temp[10];
ltoa(669L,temp,10);
long result = atol(temp);
</code></pre>
|
5430 | |arduino-uno|rf|signal-processing| | Sniffing RF signals | 2014-12-10T22:35:20.863 | <p>I am using an Arduino UNO and an <a href="http://i.ebayimg.com/00/s/NzUwWDc1MA==/z/wucAAOxy0x1TRKey/$_57.JPG" rel="nofollow noreferrer">RXb6</a> (I would link to the data sheet if I could find one) to try to decode a RF Signal that controls a remote outlet. I have the devices connected as you would assume 5V+ to 5v, Gnd to Gnd, Antenna is not connected as I think it would only exacerbate my problem, and data is connected to the A0 pin on my UNO. </p>
<p>The problem I am having is with all the noise that I am getting with my signal.I hooked it up to my o-scope to give a better idea of whats happening. When no signal is being transmitted this is the noise I am seeing:
<img src="https://i.stack.imgur.com/1Qvs8.png" alt="enter image description here"></p>
<p>Just lots of static. When I press the remote button I can see a clean signal come through (note that it is cutoff):<img src="https://i.stack.imgur.com/u3V1n.png" alt="enter image description here"></p>
<p>I was able to export a CSV of the wave and manually clean it up but it was just such a pain trying to translate it back to highs and lows for the arduino to send.</p>
<p><strong>How can I reduce signal noise on my 433MHz receiver so the arduino can read the actual signal instead of noise?</strong> </p>
| <p>I'm adding another answer, because I don't think the core thing to grasp is mentioned, and others might benefit :)</p>
<p>The noise you are seeing, is actually the result of a feature of the RXB6, KSA6, and similar modules. When they see no signal, they increase gain/sensitivity until they do see a signal. The upside of this is they are very sensitive, and can operate well over quite long ranges. The downside is that if there really is no signal, they will start picking up anything that remotely looks like a signal, the noise you see :)</p>
<p>Dealing with this noise is the job of the software/protocol and other electronics built around the receiver.
A common way to solve it, which the VirtualWire library also uses, is to send some unimportant 'data' first, which makes the receiver decrease it's sensitivity, and then send the important data.
Another common way is to just repeat the data several times, this is also what your wall sockets most likely do.</p>
<p>In software you can usually find the 'important' parts by looking at pulse lengths, the noise is usually short high pulses, most protocols use far longer pulses, which also have a predictable/defined length.</p>
<p>What I did in exactly your case was to dump the sound recording as a raw signed pcm 16 bit file, which I could then easily read into a bit of software I wrote, which find's the high/low transitions, filters out any short pulses, and then writes out the output (like a csv) you want :)</p>
|
5431 | |arduino-mega|interrupt|timers|variables|isr| | How to update a variable in an ISR using Timers | 2014-12-11T00:03:14.787 | <p>I'm trying to check the frequency of Timer3 using a counter. The value of the counter, declared as volatile, is incremented in the ISR and every second the sum is shown in the main loop and the value reset to zero. </p>
<p>The timer has been set up correctly. (If I choose a 3Hz timer I can see the led blinking)</p>
<p><strong>The problem</strong></p>
<p>The counter isn't incremented. Here is the output:</p>
<pre><code>Setup Completed
tick: 1
tick: 0
tick: 0
tick: 0
</code></pre>
<p><strong>CODE</strong></p>
<pre><code>volatile int cont = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
// Initialize Timer
cli(); // disable global interrupts
TCCR3A = 0; // set entire TCCR3A register to 0
TCCR3B = 0; // same for TCCR3B
// set compare match register to desired timer count: 800 Hz
OCR3B = 20; // 800Hz 5; // 3 Hz
// turn on CTC mode:
TCCR3B |= (1 << WGM12);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30) | (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3B);
// enable global interrupts:
sei();
Serial.println("Setup completed");
}
void loop()
{
if (millis() % 1000 == 0)
{
Serial.print(" tick: ");
Serial.println(cont);
cont = 0;
}
}
ISR(TIMER3_COMPB_vect)
{
//digitalWrite(13, digitalRead(13) ^ 1);
cont++;
}
</code></pre>
<p><strong>EDIT</strong>
This timer is used to read an anlog value from an accelerometer and store it in an array of float. But at the moment I'm stuck on this update issue.</p>
<p><strong>SOLUTION 1</strong>
Thanks to Gerben</p>
<pre><code>volatile int cont = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
// Initialize Timer
cli(); // disable global interrupts
TCCR3A = 0; // set entire TCCR3A register to 0
TCCR3B = 0; // same for TCCR3B
// set compare match register to desired timer count: 800 Hz
OCR3A = 20; // 20; //800Hz 5; // 3 Hz
// turn on CTC mode:
TCCR3B |= (1 << WGM32);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30) | (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3B);
// enable global interrupts:
sei();
Serial.println("Setup completed");
}
void loop()
{
delay(1000);
Serial.println(cont);
cont = 0;
}
ISR(TIMER3_COMPB_vect)
{
cont++;
}
</code></pre>
<p><strong>SOLUTION 2</strong>
Thanks to BrettM</p>
<pre><code>volatile int cont = 0;
void setup()
{
Serial.begin(9600);
pinMode(13, OUTPUT);
// Initialize Timer
cli(); // disable global interrupts
TCCR3A = 0; // set entire TCCR3A register to 0
TCCR3B = 0; // same for TCCR3B
// set compare match register to desired timer count: 800 Hz
OCR3B = 20; //800Hz 5; // 3 Hz
// turn on CTC mode:
//TCCR3B |= (1 << WGM32);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30) | (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3B);
// enable global interrupts:
sei();
Serial.println("Setup completed");
}
void loop()
{
Serial.println(cont);
cont = 0;
delay(1000);
}
ISR(TIMER3_COMPB_vect)
{
TCNT3 = 0;
cont++;
}
</code></pre>
| <p>It seems my answer to <a href="https://arduino.stackexchange.com/questions/5396/setting-timer3-in-ctc-mode-conflict-with-servo-library/5432#5432">this question</a> was previously incomplete, thanks for pointing out that CTC mode only works with OCR3A Gerben. I apologize for not testing an answer before I post it.</p>
<p>Given the information only in this question Gerben's answer is complete, but since your other question implies that you cannot use OCR3A due to the Servo library I'll add a bit. (I've also edited that answer)</p>
<p>you can emulate the behavior of CTC mode by setting TCNT3 to 0 in your interrupt routine. Remember to remove the line that turns on CTC mode in your code.</p>
<p>I've tested your code with this ISR:</p>
<pre><code>ISR(TIMER3_COMPB_vect)
{
TCNT3 = 0;
cont++;
}
</code></pre>
<p>and this configuration of the timer registers </p>
<pre><code>OCR3B = 5208; // 800Hz 5; // 3 Hz
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR3B |= (1 << CS30) | (1 << CS32);
// enable timer compare interrupt:
TIMSK3 |= (1 << OCIE3B);
</code></pre>
<p>This might be a bit less accurate at high frequencies than CTC, I'm not sure, but at 3Hz it worked perfectly. Notice that 5208 was the correct OCR value, not 20 (again thanks to Gerben). </p>
|
5433 | |arduino-mega|sensors| | Why can this color sensor not recognize green? | 2014-12-11T01:12:39.730 | <p>I got this <a href="http://www.icstation.com/product_info.php?products_id=1503" rel="nofollow noreferrer">color sensor</a> last week, I've been able to get the sensor to recognize blue and red, but not green. still working on this.
I use the code in the product page.</p>
<p>so anybody have any idea about this issue? Pretty thanks.
<img src="https://i.stack.imgur.com/f69jM.jpg" alt="enter image description here"></p>
| <p>Check that you've connected all the Arduino pins correctly to the sensor. In particular, make sure pin 4 on the Arduino is connected to S2 on the sensor.</p>
<p>It's the combination of signals on S2 and S3 which determines which colour is being detected:</p>
<pre><code>S2 S3 Colour
---- ---- ------
Low Low Red
Low High Blue
High Low Clear
High High Green
</code></pre>
<p>If S2 is always low then you can only detect red and blue.</p>
<p>If the connections are definitely correct, then ensure you haven't made any code modifications which could interfere with it. You may also want to test pin 4 on your Arduino (e.g. using a multimeter) to make sure it's working properly. If necessary, you could use a different pin instead. However, you'll need to modify the <code>#define S2</code> line in the code to match.</p>
|
6434 | |arduino-uno|johnny-five| | How to delay so that LED stays on a bit longer? | 2014-12-11T05:44:29.527 | <p>I have a circuit with a shift register which controls 8 LEDs: <a href="http://node-ardx.org/exercises/5" rel="nofollow">http://node-ardx.org/exercises/5</a>. In code, I created a function <code>cycle()</code> cycle through each LED one at a time, but this occurs too quickly on the board. How can I add a delay inside the loop so that each LED stays on for 500ms?</p>
<p>Here's my code:</p>
<pre><code>var five = require("johnny-five"), board, shiftRegister;
board = new five.Board();
board.on("ready", function() {
shiftRegister = new five.ShiftRegister({
pins: {
data: 2,
clock: 3,
latch: 4
}
});
var bytes = [
00000001,
00000010,
00000100,
00001000,
00010000,
00100000,
01000000,
10000000,
00000000
];
function cycle() {
for ( var i = 0; i < bytes.length; i++ ) {
console.log(bytes[i]);
shiftRegister.send(bytes[i]);
}
}
this.repl.inject({
sr: shiftRegister
});
cycle();
});
</code></pre>
| <p>The answer is already provided in the article.</p>
<pre><code> var i = 0;
function cycle() {
console.log(bytes[i]);
sr.send(bits[i]);
i++;
if( i<bytes.length )
setTimeout(cycle, 300);
}
</code></pre>
|
6442 | |arduino-uno|c++|memory-usage|sram| | Are my arrays stored in sram or in Flash? | 2014-12-11T13:05:41.360 | <p>I have the following memory allocation: </p>
<pre><code>unsigned char g1[]={
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ....0x00 ,0x00 ,0x00 ,0x00 ,0x00 };
g2[]={
0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ....0x00 ,0x00 ,0x00 ,0x00 ,0x00 };
...
unsigned char* index[10] = {g1,g2,g3,g4,g5,g6,g7,g8,g9,g0};
</code></pre>
<p>This is accessed in the following way:</p>
<pre><code>unsigned char* getMatch(int input){
return index[input];
}
</code></pre>
<p>This is then futher acces using the method of </p>
<pre><code>unsigned char store[1024]
unsigned char* temp = getMatch(n);
for(int i=0;i <50;i++){
store[i]=temp[i];
}
</code></pre>
<p>and store is then modified and send to an external device.</p>
<p>As my program is randomly failing I think it might be running low on SRAM and was wondering if there is any way to force this memory to be placed in flash. Anybody got an idea?</p>
| <p>It's stored in both the FLASH and SRAM because it's initialized array. To store in FLASH only you need use PROGMEM attribute.</p>
<pre><code>const unsigned PROGMEM char g1[]= ...
</code></pre>
<p>You cannot access directly but using <em>memcpy_P()</em> function.</p>
|
6450 | |serial|debugging| | Arduino - Progamming issue | 2014-12-11T13:44:13.547 | <p>my first post here.</p>
<p>Anyway I'm working on a Simon Says game.
I have a weird bug with the function that reads button input.</p>
<p>This is the code:</p>
<pre><code>int deBounce(int count){
int pressed=-1;
int laastButtons[3]; // save the previous deBounce read.
for(int x; x<4; x++)
{
laastButtons[x] = lastButtons[x];
lastButtons[x] = !digitalRead(button[x]);
if(lastButtons[x] == true)
{
delay(50);
lastButtons[x] = !digitalRead(button[x]);
if(lastButtons[x] == 1){ pressed = x;}
nt("Pressed!, Button ID: ");nt(x); nt(" pressed: ");nt(pressed); nt(" state "); ntln(lastButtons[x]);
}
}
if((lastButtons[0] + lastButtons[1] + lastButtons[2] + lastButtons[3]) > 1)
{
ntln("ERROR: dont press more than one button at a time. ");
}
if( ((lastButtons[0] + lastButtons[1] + lastButtons[2] + lastButtons[3]) == 1 ) && !laastButtons[pressed] && (pressed != -1) ) {
pressButtons[count] = pressed;
nt("Pressed!, ID: ");nt(count); nt(" Button ID ");ntln(pressed);
return count++;
}else return count;
}
</code></pre>
<p>This is what I recieve in the Serial Monitor if I press one of the buttons.</p>
<blockquote>
<p>Pressed!, Button ID: 3 pressed: -1 state 1</p>
</blockquote>
<p>How is that possible? Note the lines where that line is printed and the line above it.
Seems like that if should run, but the line pressed = x; doesn't function.
Note that, nt and ntln are just a short for Serial.print.
I have this weird bug and sometimes it seems like the chip is glitching!</p>
<p>Another question is- I tried attaching interrupt and it didn't worked,
Is it possible that my board is not compatiable with them? (It's not original).</p>
<p>Thanks.</p>
<p>EDIT:</p>
<p>After Majenko helped me figure it out,
The thing that created the bug was that I expected a x==0, but I didn't define it in the for loop.</p>
<p>Before:</p>
<pre><code>for(int x; x<4; x++)
</code></pre>
<p>After:</p>
<pre><code>for(int x=0; x<4; x++)
</code></pre>
<p>Thanks again Majenko!</p>
| <pre><code>int laastButtons[3]; // save the previous deBounce read.
for(int x; x<4; x++)
{
laastButtons[x] = lastButtons[x];
</code></pre>
<p>Well, there's a common bug right away. An array with three slices, numbered 0, 1 and 2, and you're accessing them with a loop that counts from 0 to 3.</p>
<p>Spot the error.</p>
<p>Also, in the for loop, what number does it start counting from?</p>
<p>And now for your "bug". This block of code:</p>
<pre><code>if(lastButtons[x] == true)
{
delay(50);
lastButtons[x] = !digitalRead(button[x]);
if(lastButtons[x] == 1){ pressed = x;}
nt("Pressed!, Button ID: ");nt(x); nt(" pressed: ");nt(pressed); nt(" state "); ntln(lastButtons[x]);
}
</code></pre>
<p>I think you have it slightly wrong. Let's convert it into plain english:</p>
<ul>
<li>If button is pressed:
<ul>
<li>Delay 50 ms</li>
<li>Read button again</li>
<li>If button is pressed:
<ul>
<li>Set <em>pressed</em> to the button number</li>
</ul></li>
<li>Print the button message</li>
</ul></li>
</ul>
<p>Note the indenting, which highlights what gets executed for what IF statement. The print is going to happen regardless of the setting of the <em>pressed</em> variable.</p>
<p>I think the structure you wanted is:</p>
<ul>
<li>If button is pressed:
<ul>
<li>Delay 50 ms</li>
<li>Read button again</li>
<li>If button is pressed:
<ul>
<li>Set <em>pressed</em> to the button number</li>
<li>Print the button message</li>
</ul></li>
</ul></li>
</ul>
<p>In that layout the second If is controlling both the setting of the <em>pressed</em> variable as well as whether or not to print the Pressed! message.</p>
<pre><code>if(lastButtons[x] == 1){ pressed = x;}
</code></pre>
<p>That line is saying "If last buttons X is 1, then set pressed to X. That is all it is doing. Nothing more, nothing less.</p>
|
6457 | |c| | How to prevent Arduino compiler from merging changing of port pin outputs into a single operation | 2014-12-11T22:49:45.790 | <p>I want to set one pin's output value, and then set a different pin's output value so that the two pins change value one after the other.
However, the compiler optimises the two calls to change both pins in one go.</p>
<p><code>
PORTD |= _BV(0); //set pd0 to high
PORTD |= _BV(1); //set pd1 to high
PORTD &= ~(_BV(1)); //set pd1 to low
</code></p>
<p>The two pins go high simultaneously. I tried inserting a NOP between these but it doesn't change behaviour.</p>
<p>(I originally intended to include an oscilloscope screengrab to show what was happening - that's how I knew (or got the wrong impression) that the two pins were changing at the same time. But the photo wasn't shifting from my Nexus 7 for me to access it from my laptop.)</p>
| <p>I certainly can't duplicate what you are saying. The small code snippet:</p>
<pre><code>void setup() {
PORTD |= _BV(0);
PORTD |= _BV(1);
PORTD &= ~(_BV(1));
}
void loop() {
}
</code></pre>
<p>compiles into:</p>
<pre><code>000000a6 <setup>:
a6: 58 9a sbi 0x0b, 0 ; 11
a8: 59 9a sbi 0x0b, 1 ; 11
aa: 59 98 cbi 0x0b, 1 ; 11
ac: 08 95 ret
000000ae <loop>:
ae: 08 95 ret
</code></pre>
<p>That is clearly two separate bit sets followed by a bit clear.</p>
<p>I am using UECIDE that is set to use GCC 4.3.2</p>
<p>If I switch to GCC 4.8.1 instead, the code generated is identical.</p>
<p>Even turning on full -O3 optimization I still get the same results.</p>
<p>So how are you determining that it's happening at the same time?</p>
|
6460 | |programming|c++| | Difference between void setup() and void setup(void) | 2014-12-12T03:51:09.900 | <p>As it says in the title. I have been searching but I cant seem to find the answer.</p>
<p>What is the difference between void setup() and void setup(void) as well as void loop() and void loop(void)?</p>
| <p>Absolutely nothing, in modern versions of C and C++. Specifying no arguments is the same as specifying <code>void</code>.</p>
<p>In old versions of C a function with no arguments took a single implicit <code>int</code> argument or allowed you to specify the arguments on a separate line, but no one uses anything like that nowadays.</p>
|
6463 | |arduino-ide|mac-os| | Arduino software won't open in Mac OSX 10.10.1 | 2014-12-12T07:07:34.213 | <p>I am having trouble opening the Arduino software on my mac, since I have updated Java to version 8 the Arduino software won't open. It does not give an error just closes instantly.</p>
<p>I have tried getting the newest version of the Arduino.cc site but no change.</p>
<p>Can anyone tell me how to open Arduino using an older version of Java?</p>
| <p>I just clicked on the apple icon => about this Mac => software update => Mac Sierra update. </p>
<p>now to get the USB port to work</p>
<p>numbatmark</p>
|
6467 | |avr|arduino-micro| | AVR ATmega328p-pu operating circuit? | 2014-12-12T12:42:56.277 | <p>I used to work with PIC micro-controller so i know what it needs to work from operating circuit to crystal oscillators needed and other components to power it up , my question here where can i find the operating circuit for ATmega32p-pu and other AVR models . or all i need to do is to give it +5v and gnd and it will work ? </p>
| <p>You're looking for <a href="http://arduino.cc/en/main/standalone" rel="nofollow">this</a> I think? How to set up an Arduino on a breadboard.</p>
|
6481 | |c| | Comparing a char with the symbols '.-' | 2014-12-13T09:15:52.180 | <p>I'm using the Arduino software to create a Morse code decoder using the serial monitor.</p>
<p>I enter a Morse code such as <code>.-</code> as a text string and it's displayed in the LCD as a alphanumeric text. So if I enter <code>.-</code> into the serial Monitor, <code>A</code> is displayed on the LCD. But it only works for single symbols, not the dot and dash together.</p>
<p>Is there a way to make the if statement as seen below accept both the dots and dashes together?</p>
<pre><code>#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
void setup()
{
lcd.begin(16, 2);
Serial.begin(9600);
}
void loop()
{
char schar;
if (Serial.available())
{
schar = Serial.read();
Serial.write(schar);
if (schar== '.-' ){
Serial.write('A');
lcd.print('a');
}
}
}
</code></pre>
| <p>You could use C strings, (type <code>char*</code>) or C++ String objects (type <code>String</code>). Both would work.</p>
<p>If you use C strings, you'll need to use functions like <code>strcmp()</code> from the C library to see if your input string matches a particular morse sequence.</p>
<p>If you use C++ String objects, you'll need to use the methods of that class. I'm less familiar with that class.</p>
<p>If you have single Morse characters, matching them up is pretty easy. If you have a continuous stream of dots and dashes, though, it's a much thornier problem. You need a way to figure out the boundary between characters. Morse characters can be sequences of between 1 and 5 dots and dashes.</p>
<p>Unless there are extra delays between the dots/dashes for a character, I'm not sure how you figure out where the boundaries are. There are already computer Morse code readers, though, so this must be a "solved problem". I'd do some googling.</p>
|
6483 | |arduino-uno|programming|c|code-optimization| | Sweep with two shift registers | 2014-12-13T12:20:37.900 | <p>I am working with 8 dual color LED's and 2 shift registers. My connections are in place. But I do not understand how to work with 2 shift registers.</p>
<p>So I am trying to make this: turn the first led on, turn the first led of, go to the next led, turn it on, turn in off, etc...</p>
<p>I do not know how to jump from the first shift register to the second shift register when the last LED of the first shift register is turned off.</p>
| <p>Exactly the same as when you're trying to keep them dark when lighting an LED with the first register: shift two bytes.</p>
<p>The first byte shifts into the first register to begin with, and then <em>out</em> of the first register and <em>into</em> the second register when you shift the second byte into the first register. Just make sure only the appropriate bits are set in both bytes and you're good to go.</p>
|
6487 | |sensors| | Oil Pressure / Water Pressure / Boost Pressure ( Turbo Engine ) | 2014-12-14T03:44:14.020 | <p>I'm an automotive enthusiast and I want to build some gauges by myself using Arduino.</p>
<p>I was taking a look at this <a href="http://www.ebay.com/itm/Pressure-transducer-or-sender-100-psi-stainless-steel-for-oil-fuel-air-water-/271576977896?pt=Motors_Car_Truck_Parts_Accessories&hash=item3f3b3fd1e8&vxp=mtr" rel="nofollow noreferrer">pressure transducer or sender, 100 psi, stainless steel, for oil, fuel, air, water</a> and I was thinking if I can use this sensor to do all of the these tasks: Water, Boost and Oil Pressure.</p>
<p>Look at the Signal output vs read PSI chart of the sensor</p>
<p><img src="https://i.stack.imgur.com/6Yy1T.png" alt=" Signal output vs read PSI chart of the sensor"></p>
<p>I came out with this equation for the PSI calculation:</p>
<p>Since it is a <code>Y = bx + a</code>, where: </p>
<pre><code>a = 0.5
b = y2 - y1 / x2 - x1 = (4.5 - 0.5 ) / (100 - 0) = 4/100 = 0.04
x = PSI
y = Signal's Voltage
</code></pre>
<p>This means that</p>
<p>Voltage Reading = 0.04PSI + 0.5</p>
<p>So we have :</p>
<p>PSI = (Voltage Reading - 0.5 ) / 0.04 </p>
<p>Am I correct? Can I use this sensor?</p>
| <p>I'd add code to test for voltage between 0.0 to less than or near 0.5 volts. Disconnected pressure transducer won't present 0.5v, 0 PSI transducer voltage; not output 0.5 v @0 PSI shows a lower voltage indicated a fault or open circuit in transducer wiring. My experiences, too many times other engineers "borrowed" hardware and I wound up troubleshooting a non-fault but theft ;} Only a few lines of code to ensure connections are correct.
The floating point vs integer arithmetic compute time is outweighed by settling time of A/D converter and transducer. The auto part was my solution to show HOA board stats for my wildly varying water pressure at Condo Assn, very cost effective too.</p>
|
6491 | |arduino-uno|led|button| | Button reading not going off | 2014-12-14T09:03:41.843 | <p>I made a circuit which in my intentions would allow me to toggle a LED dimming loop.</p>
<p>Problem is that once I push the button the first time pushing it a second time doesn't toggle the LED loop off.</p>
<p>Here is the code:</p>
<pre><code>const int LED = 9; // the pin for the LED
const int BUTTON = 7;
int val = LOW;
int old_val = LOW;
int state = 0;
int i = 0;
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop()
{
val = digitalRead(BUTTON);
if ((val == HIGH) && (old_val==LOW))
{
state = 1 - state;
delay(10);
}
old_val = val;
if (state == 1)
{
for (i = 0; i < 255; i++) // loop from 0 to 254 (fade in)
{
analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
for (i = 255; i > 0; i--) // loop from 255 to 1 (fade out)
{
analogWrite(LED, i); // set the LED brightness
delay(10); // Wait 10ms
}
} else
{
analogWrite(LED, 0);
}
if ((val == LOW) && (old_val == HIGH))
{
delay(10);
}
}
</code></pre>
<p>Here is the circuit scheme:</p>
<p><img src="https://i.stack.imgur.com/ap6j4.png" alt="circuit schematics"></p>
<p>I would be interested both in learning what the problem is AND learning any mental methods I can apply to debug in such situations.</p>
| <p>While the led is fading in and out (which takes 5 seconds), the state of the button is never checked. So you'd need to have the button released for at least 5 seconds (so old_val becomes LOW), and then pressed exactly we the led is faded out (again, 5 seconds later). So try keeping the button pressed for at least 5 seconds.</p>
<p>You probably want to rewrite your code, so the button is more 'responsive'. Below I added an example of how to do this.</p>
<pre><code>const int LED = 9; // the pin for the LED
const int BUTTON = 7;
int val = LOW;
int old_val = LOW;
bool fadeLed = false;
int brightness = 0;//current pwm value
int direction = 1;// 1 is brightness is increasing, -1 if brightness is decreasing
void setup()
{
pinMode(LED, OUTPUT);
pinMode(BUTTON, INPUT);
}
void loop()
{
/* check the button */
val = digitalRead(BUTTON);
if ((val == HIGH) && (old_val==LOW))
{
// button pressed ( called only once per press )
fadeLed = !fadeLed;// invert boolean
}
old_val = val;
/* update the leds brightness */
if( fadeLed )
{
// fade led in and out
if( brightness==0 )
direction = 1;//change direction is minimum value reached
if( brightness==255 )
direction = -1;//change direction is maximum value reached
brightness += direction;// increase/decrease brightness
}
else
{
// fadeLed is disabled, so only decrease brightness till it reaches zero
if( brightness>0 )
brightness--;
}
analogWrite(LED, brightness); // set the LED brightness
delay(10); // Wait 10ms because analogWrite
// is instantaneous and we would
// not see any change
}
</code></pre>
<p>Any questions about the code; just let me know.</p>
|
6500 | |arduino-uno|arduino-mega|pins|shields| | How can I tell which pins I will have left available by looking at a shield? | 2014-12-15T12:37:03.877 | <p>I'm very new to Arduino and came to a point where I'm interested in playing with shields, such as LCDs.</p>
<p>For example, I really like the looks of "LCD 1602 with keypad" module, but it seems to be using a lot of pins.</p>
<ul>
<li>By looking at a module / shield, how can I tell (or at least estimate) which pins will be used and which ones I will have left if I stack them with my Uno or Mega without printed schematics?</li>
</ul>
| <p>why dont you use an i2c adapter for this type of display?
search for i2c display module.
i2c only needs 2 wires for data and clock and 2 for power.
you can also easily locate the SDA and SCL pins on your arduino</p>
|
6502 | |arduino-uno|c| | Where can I see the output of printf? | 2014-12-15T14:02:55.873 | <p>I would like to know where I can see the output when I use the command <code>printf</code>. I am programming using the Arduino interface.</p>
<h2>Update</h2>
<p>I'll add a few lines of code for better understanding:</p>
<pre><code>#include <stdio.h>
int main(void)
{
printf("Hello World");
return 0;
}
</code></pre>
| <p>If you're working with the standard Arduino environment and libraries then <code>printf()</code> won't display anything anywhere. The reason is that microcontrollers could be connected to any number of different output/communication devices in any way. <code>stdio</code> would have no idea how or where to send the data.</p>
<p>The most common approach to outputting text from an Arduino (particularly during development) is to send it to the primary UART port using <a href="http://arduino.cc/en/Serial/Begin"><code>Serial.begin()</code></a> and <a href="http://arduino.cc/en/Serial/Print"><code>Serial.print()</code></a>. If the Arduino is connected to your computer via USB then the Arduino IDE's serial monitor should display the result.</p>
<p>If you <em>really</em> want to use <code>printf()</code> though then it is possible to make it work (or implement similar functionality). A full explanation is on this page:</p>
<ul>
<li><a href="http://playground.arduino.cc/Main/Printf">http://playground.arduino.cc/Main/Printf</a></li>
</ul>
|
6517 | |arduino-uno|i2c| | RTC MCP7940M not counting up | 2014-12-15T23:50:23.323 | <p>I'm able to set a time and to read it back without any problems but it doesn’t tick up. It stays the same. Even if I restart the serial monitor and thereby resets the buffer(?). So it seems to me that I'm able to set the registers but somehow the oscillator isn't working, do I have to tell it to use the external oscillator? <a href="http://ww1.microchip.com/downloads/en/DeviceDoc/20002292B.pdf" rel="nofollow noreferrer">Datasheet</a>.
Using Uno Rev3.</p>
<p>I've connected it like this:<img src="https://i.stack.imgur.com/VbAhL.png" alt="Schematic"></p>
<p>Never mind the BAT54 diode and the "RTC+MCU_VCC" node, its all just backup power from a capacitor. The supply voltage is alright.</p>
<p>The code I've been using is a modified version of <a href="http://www.instructables.com/id/Setting-the-DS1307-Real-Time-Clock-using-the-Seria/" rel="nofollow noreferrer">this</a>. </p>
<pre><code>// SDA analog pin 4
// SCL analog pin 5
#include <Wire.h>
const int MCP7940 = 0x6F; // Address of MCP7940 see data sheets
const char* days[] =
{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
const char* months[] =
{"January", "February", "March", "April", "May", "June", "July", "August","September", "October", "November", "December"};
// Initializes all values:
byte second = 0;
byte minute = 0;
byte hour = 0;
byte weekday = 0;
byte monthday = 0;
byte month = 0;
byte year = 0;
void setup() {
Wire.begin();
Serial.begin(9600);
delay(2000); // This delay allows the MCU to read the current date and time.
Serial.print("The current date and time is: ");
printTime();
Serial.println("Please change to newline ending the settings on the lower right of the Serial Monitor");
Serial.println("Would you like to set the date and time now? Y/N");
while (!Serial.available()) delay(10);
if (Serial.read() == 'y' || Serial.read() == 'Y')
// This set of functions allows the user to change the date and time
{
Serial.read();
setTime();
Serial.print("The current date and time is now: ");
printTime();
}
Serial.println("Thank you.");
}
// Continuous function for converting bytes to decimals and vice versa
void loop() {
}
byte decToBcd(byte val) {
return ((val/10*16) + (val%10));
}
byte bcdToDec(byte val) {
return ((val/16*10) + (val%16));
}
// This set of codes is allows input of data
void setTime() {
Serial.print("Please enter the current year, 00-99. - ");
year = readByte();
Serial.println(year);
Serial.print("Please enter the current month, 1-12. - ");
month = readByte();
Serial.println(months[month-1]);
Serial.print("Please enter the current day of the month, 1-31. - ");
monthday = readByte();
Serial.println(monthday);
Serial.println("Please enter the current day of the week, 1-7.");
Serial.print("1 Sun | 2 Mon | 3 Tues | 4 Weds | 5 Thu | 6 Fri | 7 Sat - ");
weekday = readByte();
Serial.println(days[weekday-1]);
Serial.print("Please enter the current hour in 24hr format, 0-23. - ");
hour = readByte();
Serial.println(hour);
Serial.print("Please enter the current minute, 0-59. - ");
minute = readByte();
Serial.println(minute);
second = 0;
Serial.println("The data has been entered.");
// The following codes transmits the data to the RTC
Wire.beginTransmission(MCP7940);
Wire.write(byte(0));
Wire.write(decToBcd(second));
Wire.write(decToBcd(minute));
Wire.write(decToBcd(hour));
Wire.write(decToBcd(weekday));
Wire.write(decToBcd(monthday));
Wire.write(decToBcd(month));
Wire.write(decToBcd(year));
Wire.write(byte(0));
Wire.endTransmission();
// Ends transmission of data
}
byte readByte() {
while (!Serial.available()) delay(10);
byte reading = 0;
byte incomingByte = Serial.read();
while (incomingByte != '\n') {
if (incomingByte >= '0' && incomingByte <= '9')
reading = reading * 10 + (incomingByte - '0');
else;
incomingByte = Serial.read();
}
Serial.flush();
return reading;
}
void printTime() {
char buffer[3];
const char* AMPM = 0;
readTime();
Serial.print(days[weekday-1]);
Serial.print(" ");
Serial.print(months[month-1]);
Serial.print(" ");
Serial.print(monthday);
Serial.print(", 20");
Serial.print(year);
Serial.print(" ");
Serial.print(hour);
Serial.print(":");
Serial.print(minute);
Serial.println();
}
void readTime() {
Wire.beginTransmission(MCP7940);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(MCP7940, 7);
second = bcdToDec(Wire.read());
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
</code></pre>
| <p>you have a small flaw in your readTime function. If you don't want very strange seconds from the device you should combine the two nibbles packed into the seconds byte. Like this:</p>
<pre><code>void readTime() {
Wire.beginTransmission(MCP7940);
Wire.write(byte(0));
Wire.endTransmission();
Wire.requestFrom(MCP7940, 7);
int rawsecond = Wire.read();
second = bcdToDec( rawsecond & 112) + bcdToDec(rawsecond & 15);
minute = bcdToDec(Wire.read());
hour = bcdToDec(Wire.read());
weekday = bcdToDec(Wire.read());
monthday = bcdToDec(Wire.read());
month = bcdToDec(Wire.read());
year = bcdToDec(Wire.read());
}
</code></pre>
<p>Thanks for the sample - helped me quite a bit.</p>
|
6519 | |arduino-uno|pwm| | Arduino PWM malfunctioning | 2014-12-16T01:09:18.523 | <p>I am controlling 4 motors using the PWM ports on an Arduino Uno (3,9,10,11). For some reason, the motor hooked up to port 11 doesn't move with my current code. I know it's a code issue because I can create a new basic code that just moves the motor and it works fine, but for some reason it doesn't in this code.</p>
<pre><code>#include <SPI.h>
#include <Pixy.h>
Pixy pixy;
int personX = 0;
int offCount = 0;
void setup()
{
pinMode(3, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
while (! Serial);
pixy.init();
}
void loop()
{
static int i = 0;
int j;
uint16_t blocks;
char buf[32];
blocks = pixy.getBlocks();
if (blocks)
{
personX = pixy.blocks[0].x;
}
if (blocks){
Serial.println(personX);
if (personX < 110){
analogWrite(11, 130);
analogWrite(3, 130);
analogWrite(9, 250);
analogWrite(10, 250);
} else if (personX > 190){
analogWrite(11, 250);
analogWrite(3, 250);
analogWrite(9, 130);
analogWrite(10, 130);
} else {
analogWrite(11, 190);
analogWrite(3, 190);
analogWrite(9, 190);
analogWrite(10, 190);
}
offCount = 0;
} else {
if (offCount < 1000){
offCount = offCount + 1;
} else {
analogWrite(11, 190);
analogWrite(3, 190);
analogWrite(9, 190);
analogWrite(10, 190);
}
}
}
</code></pre>
<p>Also, when I take the motor and swap it with another, the old one works in the new PWM port, but the new one stops working once I put it in port 11.</p>
| <p>Pin 11 is shared between both PWM and SPI. By activating SPI you've disabled PWM from working on that pin. Either use another PWM pin instead, or switch to software SPI on different pins.</p>
|
6525 | |arduino-due|usb| | Is this set up appropriate? | 2014-12-16T04:16:34.243 | <p>Hello Internet Arduino enthusiasts!</p>
<p>I'm totally new to Arduino and as my first project, I'd like to make a controller connected to computer A (the master) and computers B and C as 'slaves'.</p>
<p>The master would simply send commands as USB mouse and USB keyboard inputs to slave computers through an Arduino controller. Think of it as a hardware KVM switch (without the V(ideo)).</p>
<p>Now, I'm planning to work on that during the Christmas vacations, so I need to order the parts now to receive them in time. </p>
<p>I was thinking I could use these parts:</p>
<ol>
<li>Arduino Due (because it has the capability to send keyboard and mouse input) </li>
<li>2 SparkFun FTDI Basic Breakout - 5V, one for the mouse, one for the keyboard (per target computer) (<a href="https://www.sparkfun.com/products/9716" rel="nofollow">https://www.sparkfun.com/products/9716</a>) (because I can convert it to a 3.3v, what the Due is using)</li>
</ol>
<p>Please consider:</p>
<ul>
<li>The price is not really an issue for now. </li>
<li>I'm not worried to much about the programming. </li>
<li>I'll figure out how to make it work once I have the time and the items. </li>
<li>I know someone who has a starter kit from SparkFun, and there is an electronic store closeby, so I'm not worried about the wires.</li>
</ul>
<p>Will I be able to make what I'd like with those basic parts, or am I missing something?</p>
<p>Thanks!</p>
| <p>You need:</p>
<ul>
<li><p>two MCUs that can act as USB devices (one per slave),</p></li>
<li><p>some way of getting the commands from the master to the MCUs</p></li>
</ul>
<p>That means two Arduino Dues (or Arduino Leonardos, or SparkFun ATmega32U4 breakout boards, etc.) and one USB device of some sort that you can talk to and have send commands to the MCUs.</p>
<p>And perhaps something to transport the commands from the master to the slaves, but you need to think about the programming for that first since the transport and the programming will be very closely connected.</p>
|
6539 | |c++| | Creating arduino library linking question | 2014-12-17T07:41:19.377 | <p>I know how to create my own arduino library and use it. I am using Xcode to create a c++ project. I have the arduino library files(Servo, Wire, Keypad, etc). If I want to include the Servo.h library file in my created library, how do I go about linking that? For some reason, I can't just add the Servo.h/.cpp files in my project because then I get other linking file problems that Servo.h references and are not linked in my project. Has anyone done this before?</p>
| <p>I can't speak for Xcode, but in general with Arduino IDEs (UECIDE excepting) if you use a library within another library, that library also has to be #included in the main sketch. That is the only way most IDEs determine which libraries need to be compiled into the finished program.</p>
<p>That's one of the first targets I had for UECIDE - to enable fully recursive library compilation. Any libraries found within the master header of a library will also be included for compilation - and any found in those libraries, etc. It took a lot of work (and it's by no means 100% perfect), which is why so few others do it and leave it up to the programmer to ensure the inclusion of the right sub-libraries in their sketch.</p>
|
6541 | |arduino-uno|arduino-mega|bluetooth|communication| | What are the fundemental differences of different Bluetooth modules for beginners? | 2014-12-17T11:01:28.533 | <p>I'm a beginner to microcontrollers and electronics, albeit not really to computers and programming.</p>
<p>Starting out with the Arduino, I came to a point whereby I'm really interested in getting my prototype to talk to a mobile device or a computer to send and receive data (for example, send sensor data or receive commands).</p>
<p>Looking out, I've found out that there are different bluetooth modules with varying pricing points. Further research into differences did not reveal much to me as being a beginner, I am struggling to understand what to look out for or how to choose.</p>
<p><strong>My question here is:</strong></p>
<p>What are the fundemental differences of different Bluetooth modules for beginners, such as:</p>
<ul>
<li>HC-05</li>
<li>HC-06</li>
<li>HC-07</li>
</ul>
<p>And what should one look for when buying a simple Bluetooth module for Arduino?</p>
| <p>As far as simplicity is concerned, HC05 would be the way to go. It is by far the most popular and there are a tonne of tutorials on using it (just a quick google search).
As for the differences:</p>
<ul>
<li><p>The HC-05 module can build a connection to other modules. E.g. a Robot being a master and connecting to slave bluetooth module. Or in slave mode to make a wireless bridge to a notebook.</p></li>
<li><p>The HC-06 module only can be a slave. This makes it only useful for say connecting a notebook as a master to a robot with a slave module e.g. for a wireless serial bridge.</p></li>
<li><p>As for the HC07, support seems low so I would recommend sticking with HC05 or HC06</p></li>
</ul>
<p>At the end of the day it comes down to your requirements. If you are only wanting to talk between the phone and your arduino than the HC06 would work fine, however if at some point in time you want to talk to another arduino, than hc05 would be the way to go.</p>
|
6542 | |arduino-due|voltage-level|relay| | Arduino DUE and optocoupler 4N25 | 2014-12-17T12:47:13.387 | <p>I'm using an Arduino Due board with an optocoupler 4N25 to simulate a button pressed.
I have to open and close a circuit that drive an actuator. In that circuit, when connected, with the tester I'm measuring 6V. </p>
<p>I connect the anode to the pin 12 and the cathode in series with a 150-ohm resistor to ground, and Collector and Emitter from optocopupler to the circuit (and a normal Blink example with the pin 12).</p>
<p>When optocoupler is fired on and off respectively with a tester I measure 0V and 1.7V in the arduino part, and 4V and 6V.</p>
<p>This is not enough and the actuator is always run. I'd like to read 0-6V instad of 4V-6V. Does this depends on how much current goes to the anode/cathode of the optocoupler? Do I have to change the resistor in the arduino part? Any kind of advice? What can I do?</p>
<p>I don't want to use relay because I have read that in respect to a relay they are faster, smaller, longer-lived and quieter.</p>
<p><img src="https://i.stack.imgur.com/tMwJq.png" alt="enter image description here"></p>
| <p>It sounds like the 4N25 opto-coupler on its own can't do what you need because it's not designed to directly make/break a connection between a power source and its load (i.e. it isn't functionally equivalent to a relay).</p>
<p>Internally, the switching functionality is provided by an NPN photo-transistor. A typical open collector usage would be something like this:</p>
<p><img src="https://i.stack.imgur.com/WYr1d.png" alt="Example of an opto-coupler circuit"></p>
<p><sub><em>(Image copyright Lewis Loflin: <a href="http://www.bristolwatch.com/ele/opto_isolated.htm" rel="nofollow noreferrer">http://www.bristolwatch.com/ele/opto_isolated.htm</a>)</em></sub></p>
<p>The switch (<code>S1</code>) and the power source (<code>Vi</code>) on the left would be your Arduino. All the connections on the right would be part of your device (the actuator).</p>
<p>As you can see, you need 3 connections on the right: voltage source (<code>Vcc</code>), ground, and the output (<code>Vo</code>, which goes to your device). The circuit basically works by pulling the output (<code>Vo</code>) either up to <code>Vcc</code> to turn it on, or down to ground to turn it off.</p>
<p>It looks like all you have is <code>Vcc</code> and <code>Vo</code>, so this kind of configuration won't work. (Don't try to use the ground from your Arduino instead. That could cause various other problems.)</p>
<p>It should be possible to setup additional circuitry to act more like a Solid State Relay, but without a ground reference point it can be harder than it sounds. A mechanical relay might be the easiest option.</p>
|
6543 | |arduino-uno|arduino-mega|sensors|temperature-sensor| | How to choose between AM230x and DHT22 temperature and humidity sensors? | 2014-12-17T16:05:54.857 | <p>I'm looking forward to getting an accurate humidity and temperature sensor.</p>
<p>Right when I decided to go with a DHT22 module, I saw AM230x (AM2301, for example).</p>
<ul>
<li>How do I choose between DHT22 and AM2301?</li>
</ul>
| <p>The AM2302 has a built-in pull-up resistor, whereas the DHT22 does not. Apart of that and de different housing they should be technically identical.</p>
|
6545 | |bluetooth|xbee| | What is differences in usage between a HC-05 bluetooth module and a Zigbee HC-05 module? | 2014-12-17T16:43:21.947 | <p>I have seen commercial Xbee / Zigbee clones using HC-05 integrated inside.
Are they any different than regular HC-05 bluetooth modules?</p>
<ul>
<li>What is differences in usage between a HC-05 bluetooth module and a Zigbee HC-05 module?</li>
</ul>
| <p>Bluetooth and Zigbee are two different communication protocols. The Xbee clones you are talking about a called <a href="http://www.elecfreaks.com/store/bluetooth-bee-hc05-btbeehc05-p-171.html" rel="nofollow">BTbee</a>. </p>
<p>As far as im aware the BTbee modules are the same hardware/firmware wise as the hc05/hc06 modules. The only difference being the BTbee modules are in the Xbee footprint, allowing you to plug them into Xbee/Zigbee sockets.</p>
|
6551 | |arduino-uno| | Did I accidentally short something? My Arduino UNO board does not communicate with the computer anymore | 2014-12-17T23:42:34.857 | <p>I had my sketch uplaoded and everything was working fine when I tried connecting one of the input pins(pre-configured as digital INPUT) to 12V, just to see if this was being read as a HIGH as well.
It seems to have done something and the board stopped working. Moreover, all pins seem to be stuck at HIGH! </p>
<p>So far Ive tried the following:</p>
<ul>
<li>reset button: doesnt help</li>
<li>re-upload: doesn't work - it says not in sync</li>
</ul>
<p>Physically nothing seems to be burnt/blown. What am I missing? Have I fried my board? I hope not. PS: It was connected to a 12V external power source</p>
<p>Any thoughts?</p>
| <p>Unfortunately, the arduino's input pins are not tolerant of 12 volts, You have likely caused permanent damage to the chip =(. There is a regulator that makes it capable of being <em>powered</em> by 12 volts, but the input pins are different.</p>
<p>If you look at table 30-1 on the datasheet for the Uno's controller <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">here</a> you can see the input characteristics. The arduino is powered at 5v, so the max digital input voltage is 5.5v</p>
|
6553 | |arduino-mega| | Which Arduino board to buy? | 2014-12-18T03:51:41.783 | <p>I need an Arduino Mega 2560 (that is the one that has more pins). I went to eBay and there are a lot of different boards. I'm thinking of buying an <a href="http://www.ebay.com/itm/201197139954" rel="nofollow noreferrer">ATmega2560-16AU CH340G MEGA 2560 R3 Board + Free USB Cable for Arduino
</a>. Is this one good? I mean, does it do the work? Is it compatible with the Arduino IDE? Anything I need to know?</p>
| <p>I bought some of those boards and have had no problems with them. They are not as some claim, counterfeit boards. If they were, that would mean that the 'arduino' boards are not open source. I have also never seen any boards claiming to be built from italy. They are specifically labeled "Made In China". </p>
|
6557 | |arduino-uno|motor|shields| | Arduino Uno to drive 2 unipolar stepper motors | 2014-12-18T11:23:36.557 | <p>I need to use two stepper motors to move microscope positioning knobs in the X/Y direction. The stepper motors I have are unipolar and are 6V rated (I think).</p>
<p>I know it's possible to drive a unipolar stepper motor via a ULN2003 using an Arduino Uno. I know I can wire it using the 2-wire or 4-wire method.</p>
<p>But my questions are:</p>
<p>Is it possible to drive 2 of them? What are the modifications I will need to make to the circuit? Will this harm my Arduino? Do I need a stepper motor shield?</p>
| <p>No problem. Just use two ULN2003 chips, one for each stepper. </p>
<p>No need for a motor/stepper shield on these unipolar steppers. </p>
<p>It will not harm the arduino (if wired correctly).</p>
|
6567 | |serial|analogread| | analog serial read values are not equal | 2014-12-18T21:27:33.720 | <p>I have not used the Arduino in over 2 years and have forgotten a bunch of stuff I was wondering if someone could help me out. I have two analog sensors both the same connected to the appropriate analog pins. I am getting a read on the serial monitor and when i test the sensors the values are changing so i know the circuit is correct and everything is in the right place. I just have an issue with my code. </p>
<pre><code>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 sensorValue1 = analogRead(A0);
// print out the value you read:
Serial.println(sensorValue1);
//Serial.print("val1 = " );
Serial.print(sensorValue1);
Serial.print(" ");
delay(1000); // delay in between reads for stability
// read the input on analog pin 1:
int sensorValue2 = analogRead(A1);
// print out the value you read:
Serial.println(sensorValue2);
//Serial.print("val2 = " );
Serial.print(sensorValue2);
Serial.print(" ");
delay(1000); // delay in between reads for stability
}
</code></pre>
<p>once i view this in the serial monitor it is not organized and the sensorvalue1 is skipping over to the next line. I would appreciate the help. </p>
<p><img src="https://i.stack.imgur.com/u5ipi.png" alt="This is the serial output on the serial monitor"></p>
<p>There are two sensors so there should be two values but in the picture the values are all messed up i would ideally like it to give me a two seperate values one for each sensor</p>
<p>val1= sensorvalue1
val2= sensorvalue2</p>
| <p>The problem here seems like you are writing the value with a println(), and then again the value without new line but space. Then you write value2 with an ending newline and again value2 without newline. In your output there is also a string that does not match up anywhere in the code you posted. Double check what you are uploading and check if it has error.</p>
|
6568 | |uploading| | Can I set the Arduino board type in code | 2014-12-18T22:15:01.290 | <p>When I've come back to Arduino programming after a spell doing other things, I keep forgetting that I last experimented with a different type of board and get a "avrdude: stk500_getsync(): not in sync: resp=0x00" error. </p>
<p>I have one sketch which will always be compiled and uploaded against a specific piece of hardware. Therefore, I would like to specify the board type and preferably COM port as well, in my sketch. </p>
<p>Can it be done?</p>
| <p>No, it cannot. Neither the compiler invocation nor the subsequent upload examine the code for the hardware in use, so there is no way of doing what you are asking.</p>
<p>What you can do is to create entries in a new <code>boards.txt</code> and <code>programmers.txt</code> using an existing core that specify all the parameters, and all you would have to do is select them in the IDE for everything to be set at once. See <a href="https://code.google.com/p/arduino/wiki/Platforms" rel="nofollow">Google Code/Arduino/Platforms</a> for more information.</p>
|
6570 | |wifi|esp8266|networking| | Is it possible to use ESP8266 modules interchangeably? | 2014-12-18T22:37:08.723 | <p>I discovered that there are multiple types & versions of <code>ESP8266</code> modules.</p>
<p>I'm wondering:</p>
<ul>
<li>Build my application around one type (eg ESP-03) and in future swap the module with another (ESP-07), continuing to use the same library and code?</li>
</ul>
<p>Given the lack of information online, I couldn't find an answer for this online.</p>
| <p>Well...<br>
Yes, but... <strong>mostly</strong> only if you are using the simple serial lines(rx and tx) to communicate with it and only using the AT flash image.</p>
<p>Just as a for-instance:<br>
The ESP8266-01 and ESP8266-02 have three and two IO pins (respectively) that are reprogrammable.<br>
The ESP8266-03 has seven IO pins.<br>
The others have different amounts of pins found on this page:<br>
<a href="http://hackerspace.pbworks.com/w/page/88183850/ESP8266" rel="nofollow">http://hackerspace.pbworks.com/w/page/88183850/ESP8266</a></p>
<p>So if the program you use to flash the module uses more pins then you have to use the module that has the proper amount of IO pins or rewrite the flash image. </p>
<p>Instructions for compiling a toolchain to write and flash your own flash images to the ESP8266-XX module are found on this page:<br>
<a href="https://github.com/esp8266/esp8266-wiki/wiki/Hardware_versions" rel="nofollow">https://github.com/esp8266/esp8266-wiki/wiki/Hardware_versions</a></p>
|
6571 | |arduino-uno|power| | Is the supply voltage made available anywhere on the Arduino Uno Board? | 2014-12-18T22:46:20.867 | <p>I need to power an OpAmp based circuit that will be connected to my Arduino Uno input. Since I have a 12V adapter for the Arduino board, I want to draw power from it for this opamp(LM358).</p>
<p>Does anybody know if there is any way I can do this from the Arduino board(pins?)is as opposed to having to solder wires directly to the bottom of the DC jack?</p>
| <p>The <code>Vin</code> pin is available (next to <code>Gnd</code>) pins.</p>
|
6572 | |spi| | What should the frequency reading of the SPI clock be with this code? | 2014-12-19T01:12:34.610 | <p>My Extech EX330 multimeter is reading 3.439Mhz on the pin 13 on my Arduino Uno running the following code. Is the reading correct? If the divider is 2, shouldn't I get 8 Mhz (16Mhz / 2)? </p>
<pre><code> #include <SPI.h>
void setup()
{
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV2);
}
void loop()
{
byte pot = B0;
SPI.transfer(pot); // Do SPI transfer of variable pot
}
</code></pre>
| <p>Yes, the clock speed should be (and most probably is) 8 MHz. However, you're not generating an 8 MHz clock.</p>
<p>What you are in fact generating is 8 clock pulses of 8 MHz, then you have a delay while it deals with the rest of your code, and then it generates another 8 clock cycles of 8MHz.</p>
<p>The overall frequency is evidently sensed as 3.439 MHz.</p>
<p>To generate a pure 8 MHz clock you would have to use a different transfer method. I don't know if the 328P has DMA available, but if it does, that would give you much faster transfers. Also, you could write a more non-blocking version of SPI.transfer().</p>
<p>The normal SPI.transfer() first starts the transfer, then waits for the transfer to finish, and returns the results of the transfer. If you're only interested in transmitting, and not receiving, or the transmitted and received data don't need to c correlate completely, you can instead change the order of how it works:</p>
<ol>
<li>Wait for there to be no transfer in operation</li>
<li>Store the result of the last transfer</li>
<li>Start the new transfer</li>
<li>Return the results of the last transfer.</li>
</ol>
<p>That way it runs much smoother as it's doing the current transfer at the same time as running your other code.</p>
|
6587 | |arduino-mega|led|pins| | 4 bit to Decimal Converter IC | 2014-12-19T20:15:40.317 | <p>im using arduino and im out of pins.</p>
<p>I need something like a decoder but the problem is that the decoders only change one output pin I.E. for 0011 the output will be 0001000000000000 what i need is to have the first outputs on I.E for 1000 the output will be 111111111000000000 i basically need to light up to 16leds and im out of pins so i was wondering is there is any IC that does this for me if i have 1111 it will output 16 ones.</p>
| <p>You could use the MCP23017 an i2c 16 input/output port expander. (<a href="http://www.adafruit.com/datasheets/mcp23017.pdf" rel="nofollow">datasheet</a>)</p>
<p>It allows you to control 16 I/O pins via a simple I2C interface (only 2 pins needed). And an <a href="https://github.com/adafruit/Adafruit-MCP23017-Arduino-Library" rel="nofollow">Arduino library</a> exists for it.</p>
|
6591 | |arduino-uno|display| | Using displays with Arduino Uno | 2014-12-20T00:08:14.640 | <p>Does anybody know if there is any documentation available online on basic information about using displays with Arduino Uno? I've never used displays before and would very much appreciate some basic information on the different types etc.. </p>
<p>Any information that can help me choose what display I want to buy for my next project will be helpful. </p>
<p>for ex: Right now I don't even know what a shield is in context to a display and whether or not I should look for one in my purchasing my display.</p>
| <p>The Arduino website has a <a href="http://playground.arduino.cc/Code/LCD" rel="nofollow">list of LCD displays</a> and link with more information about each one. For controlling the display you may want to look at Arduino's <a href="http://www.arduino.cc/en/Reference/LiquidCrystal" rel="nofollow">LiquidCrystal Library</a>.</p>
<p>If you are looking for a step by step guide for using a lcd display with the Arduino, there is a <a href="https://learn.adafruit.com/adafruit-arduino-lesson-11-lcd-displays-1/" rel="nofollow">nice guide on Adafruit</a>.</p>
|
6600 | |arduino-uno|arduino-mega|pwm|current|signal-processing| | PWM signaling with Arduinos: What is the reason for the ground connection? | 2014-12-20T16:59:23.877 | <p><em>This may sound like a very dumb question and I apologise in advance.</em></p>
<p>I've gone through reading about PWM and working on some example sketches to control PC fan speeds using PWM and Arduino.</p>
<p>In all documents I read, it is mentioned that "PWM is a signal".</p>
<p><strong>My questions:</strong></p>
<ol>
<li><p>Is PWM <strong>really</strong> a signal? To me, it looks like an electric current turned on and kept on for a certain time, then off for a while repeatedly. What makes this a "signal"?</p></li>
<li><p>If PWM is a signal, why do we need to connect the Ground from Arduino to the ground of the device to which "PWM signal" is being sent to?</p></li>
</ol>
<p>This is confusing me because in my mind, for example, radio signals do not need a ground connection. The signal comes and gets read.</p>
| <blockquote>
<p>Is PWM <strong>really</strong> a signal? To me, it looks like an electric current turned on and kept on for a certain time, then off for a while repeatedly. What makes this a "signal"?</p>
</blockquote>
<p>At the most basic, it is a signal because we call it such. Even a constant voltage can be a signal, signalling that e.g. a window has not been broken. A PWM signal indicates that we want to apply a certain fraction of full power to a load.</p>
<blockquote>
<p>If PWM is a signal, why do we need to connect the Ground from Arduino to the ground of the device to which "PWM signal" is being sent to?</p>
</blockquote>
<p>Because it is a voltage-based signal, and ground serves as the reference for this voltage. Voltage only exists <em>between</em> two points.</p>
<blockquote>
<p>This is confusing me because in my mind, for example, radio signals do not need a ground connection. The signal comes and gets read.</p>
</blockquote>
<p>Radio signals are photon-based; the oscillation of photons at a given frequency being broadcast from a location are what define the signal. Since frequencies are absolute, they can be discriminated without a (relative) reference.</p>
|
6601 | |arduino-uno|ethernet|tlc5940| | Using an Ethernet Shield and a tlc5940 together | 2014-12-20T17:07:03.730 | <p>I have am using an Arduino Uno R2 and <a href="http://playground.arduino.cc/Learning/TLC5940" rel="nofollow">TLC5940</a> to control a bunch of RGB LEDs. I want to add an Ethernet Shield R3 so that I can control the LEDs over a web-interface. However, the ethernet shield and TLC5940 use many of the same pins. Can I use them together? How?</p>
| <p>You can do this with out any additional hardware by putting the TLC5940 to BITBANG mode instead of SPI mode and making the Ethernet Shield use D8 pin instead of D10 pin.</p>
<h2>Software Changes</h2>
<ol>
<li><p>On line 61 of <code>sketchbook/libraries/Tlc5940/tlc_config.h</code> replace</p>
<pre><code>#define DATA_TRANSFER_MODE TLC_SPI
</code></pre>
<p>with</p>
<pre><code>#define DATA_TRANSFER_MODE TLC_BITBANG
</code></pre></li>
<li><p>On lines 339 - 341 of <code>arduino/libraries/Ethernet/utility/w5100.h</code> replace</p>
<pre><code> inline static void initSS() { DDRB |= _BV(2); };
inline static void setSS() { PORTB &= ~_BV(2); };
inline static void resetSS() { PORTB |= _BV(2); };
</code></pre>
<p>with</p>
<pre><code> inline static void initSS() { DDRB |= _BV(0); };
inline static void setSS() { PORTB &= ~_BV(0); };
inline static void resetSS() { PORTB |= _BV(0); };
</code></pre></li>
</ol>
<h2>Hardware Changes</h2>
<ol>
<li><p>Bend leg of the D10 pin on the Ethernet Shield so it doesn’t connect to the D10 pin on the Arduino.</p></li>
<li><p>Connect D10 pin of Ethernet Shield to D8 pin on the Ethernet Shield
<img src="https://i.stack.imgur.com/QnHfh.jpg" alt="D10 pin connected to D8 pin"></p></li>
<li><p>Connect the TLC5940 using the following pins:</p>
<pre><code>------------- ---u----
Ethernet 13| OUT1 |1 28| OUT channel 0
Shield 12| OUT2 |2 27|-> GND (VPRG)
11| OUT3 |3 26|-> SIN (pin 7)
10,underneath|-> BLANK (pin 23) OUT4 |4 25|-> SCLK (pin 4)
9|-> XLAT (pin 24) . |5 24|-> XLAT (pin 9)
8|-> to pin 10 on shield . |6 23|-> BLANK (pin 10 underneath shield)
7|-> SIN (pin 26) . |7 22|-> GND
6| . |8 21|-> VCC (+5V)
5| . |9 20|-> 2K Resistor -> GND
4|-> SCLK (pin 25) . |10 19|-> +5V (DCPRG)
3|-> GSCLK (pin 18) . |11 18|-> GSCLK (pin 3)
2| . |12 17|-> SOUT
1| . |13 16|-> XERR
0| OUT14|14 15| OUT channel 15
------------- --------
</code></pre></li>
</ol>
<p>Tested with Arduino 1.0.5 on Linux Mint 17 with r14 of the <a href="https://code.google.com/p/tlc5940arduino/" rel="nofollow noreferrer">tlc5940arduino</a> library.</p>
<p>References:<br>
<a href="http://blog.andrewwei.mu/?p=19" rel="nofollow noreferrer">http://blog.andrewwei.mu/?p=19</a><br>
<a href="http://forum.arduino.cc/index.php/topic,22111.0.html" rel="nofollow noreferrer">http://forum.arduino.cc/index.php/topic,22111.0.html</a><br>
<a href="http://forum.arduino.cc/index.php/topic,142977.0.html" rel="nofollow noreferrer">http://forum.arduino.cc/index.php/topic,142977.0.html</a><br>
<a href="http://forum.arduino.cc/index.php/topic,118265.0.html" rel="nofollow noreferrer">http://forum.arduino.cc/index.php/topic,118265.0.html</a></p>
|
6607 | |arduino-uno|power| | Powering 5V Accesories | 2014-12-21T00:42:10.453 | <p>I'm using an Uno to control NeoPixels LED strips (60 per metre). These are powered with a 5V DC supply. Now, when using USB to power the Arduino it works lovely. However I want to move the Arduino into a standalone "installation" where I'll only want one power supply. </p>
<p>I've already got a 5V DC supply which outputs about 5.2V. What is the best way to power both the Arduino and the LEDs? I understand the need for at least 7V at the Arduino's voltage regulator input. Would my best bet be to get a 12V supply (or similar) and use a buck converter to power the LEDs? The total current draw <em>could</em> reach 3.6A but will be 400mA for the majority of the time.</p>
| <p>If your supply is regulated (put a 47ohm resistor across it and measure the AC voltage with a DMM; it should be almost nothing if properly regulated) then you can use it for both the Uno and the NeoPixels. The ATmega328P has a maximum input voltage of 5.5V, and the WS2812B has a maximum voltage of 5.3V, putting the supply within the proper range to run them.</p>
|
6614 | |c++|sketch|interrupt|avr| | Interrupts don't work | 2014-12-21T08:41:53.130 | <p>I tried to run a sketch that tests my AVR's interrupts,
I have an UNoriginal Arduino Uno, and I've checked pins 2 and 3 like the following:</p>
<pre><code>- at void setup()
attachInterrupt(2, inter, CHANGE);
- at void inter()
Serial.println("Interrupt pin 2");
</code></pre>
<p>I did the same on pin 3, I checked them by attaching the pins to a button with a Pull-Up,
When I click the button it goes from HIGH to LOW.
But yet, the arduino doesn't run the 'inter'.
Is it possible that because my Arduino is not original it won't work?
And this type of interrupts are software not hardware right?</p>
| <p>On all Arduino boards except the DUE, <code>attachInterrupt()</code> does not use the pin number as first argument but the interrupt number, which is different:</p>
<pre><code>void attachInterrupt(uint8_t interrupt, void (*ISR)(void), int mode);
</code></pre>
<p>As documented on <a href="http://arduino.cc/en/Reference/AttachInterrupt" rel="nofollow">Arduino reference</a>, for an Arduino UNO, the mapping is as follows:</p>
<ul>
<li>Interrupt 0 -> Pin 2</li>
<li>Interrupt 1 -> Pin 3</li>
</ul>
<p>So just change the code in <code>setup()</code> to:</p>
<pre><code>attachInterrupt(0, inter, CHANGE);
</code></pre>
<p>And that should work for pin 2.</p>
|
6617 | |arduino-nano|ch340| | Setting serial number on CH340 USB-Serial device | 2014-12-21T12:22:13.607 | <p>Reading <a href="http://playground.arduino.cc/Linux/Udev" rel="noreferrer">http://playground.arduino.cc/Linux/Udev</a> there appears to be a way to write out to a FTDI USB-Serial EEPROM to set a given SerialNumber, allowing you to identify a given nano/other arduino to handle it specifically in UDEV.</p>
<p>I have a nano-style boad with a QinHeng Electronics HL-340 USB-Serial adapter, which clearly isn't an FTDI chip, and the FTDI programmer therefore doesn't work. Does anyone know of an alternative utility/where I can find information to do the same with this chip?</p>
<p>Currently the device identifies itself with:</p>
<pre><code>[ 6850.608080] usb 2-1.2: new full-speed USB device number 7 using ehci-pci
[ 6850.701496] usb 2-1.2: New USB device found, idVendor=1a86, idProduct=7523
[ 6850.701505] usb 2-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 6850.701510] usb 2-1.2: Product: USB2.0-Serial
[ 6850.702201] ch341 2-1.2:1.0: ch341-uart converter detected
[ 6850.704210] usb 2-1.2: ch341-uart converter now attached to ttyUSB0
</code></pre>
<p>Which is essentially useless, as I can't identify the given board attached (when I attach two, their details are the same).</p>
| <p>Here is a software tool that I wrote which can be used to update serial number of WinChip Head CH340B. This will be useful for some one who wants to connect multiple CH340B Virtual COM Port devices to their Windows PC.</p>
<p>You can get the source code of this tool from the following github repository.</p>
<p><a href="https://github.com/senthilnathant/tools-ch340b-configuration" rel="nofollow noreferrer">https://github.com/senthilnathant/tools-ch340b-configuration</a></p>
|
6618 | |arduino-uno|sensors|wires| | How to move from arduino to physical prototype | 2014-12-21T17:55:19.963 | <p>I've been reading a bit about moving from Arduino to PCB and it seems a bit daunting. For now, all I really want to do is take something I've built, and make a few changes so that I can actually create a casing for it and make sure everything stays connected.</p>
<p>I've attached a photo of my project. What I am trying to do is create a box, where 4 pushbuttons sit in a box, with LEDs next to them. I will probably create foamboard cutouts for the spaces where the pushbuttons and leds sit. The wiring for the push buttons and the LEDs need to be hidden below the foam board, along with the arduino itself and the servo motor - which is where I get stuck. </p>
<p>What do I need to do to essentially "lengthen" the wires for the pushbuttons and LEDs, and make sure all the components stay secure in the breadboard (the push buttons in particular like to pop out)? Is there a way to do this without making a PCB? I understand the concept of soldering components into protoboard, but as far as cutting / printing the circuits or whatever, it is really confusing to me. </p>
<p>I'd appreciate any guidance. If you see anything wrong with my wiring setup too, I'd love a learning experience on that as well. Thanks!</p>
<p><img src="https://i.stack.imgur.com/zuw5E.jpg" alt="enter image description here"></p>
<p><img src="https://i.stack.imgur.com/ZfWWo.png" alt="enter image description here"></p>
| <p>You can use Arduino proto shield. It's a prototyping board shaped the way it can be plugged into the Arduino. There are over 9000 of them from different manufacturers. Then just solder the stuff you need on the proto shield.</p>
<p><img src="https://i.stack.imgur.com/Tzgva.jpg" alt="enter image description here"></p>
|
6623 | |shields|arduino-due|relay| | Can I drive this relay shield with an Arduino Due? | 2014-12-22T13:26:28.287 | <p>Sorry I'm new to electronics while I've some experience in coding. This let me very curious about the Arduino Due board: it is super powerful and I can run some C++ code that I can not with the normal Arduino Uno. But I lack in electronic theory, sorry if the question is a little bit dumb.</p>
<p>Can I drive <a href="http://www.ebay.com/itm/8-Channel-5V-Relay-Module-Board-Shield-for-Arduino-PIC-AVR-MCU-DSP-ARM-US-Stock-/360717697832" rel="nofollow">this shield</a> with an Arduino Due? The Due board is at 3.3V while <a href="https://www.ghielectronics.com/downloads/man/20084141716341001RelayX1.pdf" rel="nofollow">the relays</a> in the shield are at 5V.</p>
<p>What do I need to make them run smoothly?</p>
<p>Actually I'd like to run 5 of those shield with only one Arduino Due board. Do I have some problem with power supply?</p>
| <p>You'd have to remove the yellow jumper. Connect 3.3v to the VCC and 5v to the JDVCC. But please double check that JDVCC is connected to one side of all the relays.</p>
<p>This way the opto-couplers are activated by 3.3v signals, which in turn activate the transistor (5v) used to engage the relay.</p>
|
6646 | |temperature-sensor| | Temperature sensors TMP36 and LM35 have temperature diff. (offset) in the same circuit | 2014-12-23T16:39:30.463 | <p>I am trying to use the two temperature sensors TMP36 (from Sparkfun Inventor's kit) and KEYES LM35.</p>
<p>In read TMP36 Sensor and I convert the result to Celsius using the following code:</p>
<pre><code>// TMP36 input sensor -> degrees Celsius calculation
TM36reading = analogRead(TM36sensor);
TM36voltage = (TM36reading/1024.0)*5.0;
//converting from 10mv per degree with 500 mV offset
// (TMP36 voltage - 500mV) times 100)
TM36degreesC = (TM36voltage - 0.5) * 100;
</code></pre>
<p>In read LM35 Sensor and I convert the result to Celsius using the following code:</p>
<pre><code>// LM35 input sensor -> degrees Celsius calculation
LM35reading=analogRead(LM35sensor); // reads the LM35 output
LM35voltage = (LM35reading/1024.0)*5.0;
LM35degreesC=LM35voltage*100.0;
</code></pre>
<p>I have connected also a LCD display to monitor visually the values of these two sensors. Here is my <a href="http://pastebin.com/0W7hn9rg" rel="noreferrer">full code</a>. I use also a serial log. Here is a sample from this serial log (as you can see there is a difference/offset between 0.5 to 0.9 Celsius).</p>
<pre><code>TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.89, LM35: 16.11 diff -> 0.78
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.87, LM35: 16.60 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 17.09 diff -> 0.20
TM36: 17.38, LM35: 17.09 diff -> 0.29
mean difference between sensors: 0.48
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.41, LM35: 17.58 diff -> 1.17
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 17.09 diff -> 0.20
mean difference between sensors: 0.71
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 17.09 diff -> 0.29
TM36: 16.89, LM35: 16.11 diff -> 0.78
mean difference between sensors: 0.93
</code></pre>
<p>I power the Arduino from the computer using the USB cable. When the computer is ON we have the offset that I already demonstrated above. When the computer is turned off (after computer shutdown), immediately the sensor of TMP36 falls around 1 Celsius.. And then both sensors have similar temperature.
<img src="https://i.stack.imgur.com/LyDT6.jpg" alt="Arduino powered by USB and Computer ON versus Computer off (LM35 and TMP36 temperature sensors)"></p>
<p>Why there is this temperature difference between TMP36 and LM35 sensors? How can we "fine tune" these sensors to monitor the real temperature?</p>
| <p>The sensors have different accuracy, according to their datasheets.
The <a href="http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Temp/TMP35_36_37.pdf" rel="noreferrer">TMP36</a> has <strong>±2°C typical accuracy</strong>, while the the <a href="http://www.biltek.tubitak.gov.tr/gelisim/elektronik/dosyalar/5/LM35.pdf" rel="noreferrer">LM35</a> has <strong>0.5°C typical accuracy</strong> (over 25°C).
Read the datasheet carefully and pay attention to the characteristics, more specifically to the accuracy error graphs for each sensor. At your measured temperature (~17°C), you should expect the following error (the red line is not super accurate, but should give a general clue):</p>
<p><strong>LM35:</strong></p>
<p><img src="https://i.stack.imgur.com/yt0rY.png" alt="LM35 Accuracy Error characteristics as per datasheet"></p>
<p><strong>TMP36:</strong></p>
<p><img src="https://i.stack.imgur.com/bzWWw.png" alt="TMP36 Accuracy Error characteristics as per datasheet"></p>
<p>In addition, as <strong>Michal</strong> stated, you might have noise in your circuit, and you are not connecting the TMP36 as per the datasheet suggests (note the capacitor between +V and Ground):</p>
<p><img src="https://i.stack.imgur.com/EzVTX.png" alt="TMP36 typical application as per datasheet"></p>
|
6647 | |arduino-uno|arduino-mega| | ov7670 + Sd Card + arduino | 2014-12-23T16:42:27.397 | <p>I have three devices for making a motion activated security camera system:</p>
<ul>
<li>this is the camera : <a href="http://urun.gittigidiyor.com/ev-elektronigi/arduino-pic-kamera-modulu-ov7660-134509055" rel="nofollow">LINK</a> OV 7670 </li>
<li>this is the SD Card module: <a href="http://urun.gittigidiyor.com/ev-elektronigi/arduino-sd-kart-modulu-140174113?opi=132220334" rel="nofollow">LINK</a></li>
<li>and a basic motion Sensor: PIR with 3 pin </li>
</ul>
<p>I have an Arduino UNO and an Arduino Mega 2560.</p>
<p>I can connect the SD card and sensor, they work fine but I cannot connect the camera as there are not enough pins for it on UNO. </p>
<p>Is there a chance to connect all of them without any additional device? </p>
<p>I saw some working project with additional device (arducam) but I do not have much money to spend on this project.</p>
| <p>This camera module requires the use of additional hardware, as the camera and Arduino operating frequencies differ, which can result in loss of synchronization and changes to the image, and other connection problems.</p>
<p>Thus, we must use an integrated circuit intermediary, making the connection between the camera and the Arduino. The function of this chip is to receive the camera information, store them and then send them to the Arduino using the digital doors, much faster than if we used the serial communication.</p>
<p>An example of an integrated circuit that could be used is AL422, suitable for treating a video signal, which also is embedded in <strong>some</strong> OV7670 modules.</p>
<p>Looking like the connection pins behave in 7670, your module should be equal to it. So spare pins to be able to make other necessary connections.</p>
<p><img src="https://i.stack.imgur.com/c40y9.jpg" alt="7670 with AL422 pin"></p>
<p>Would better check the connection through the datasheets:</p>
<p><a href="https://www.openimpulse.com/blog/document-viewer/?pdf_file=OV7670-CMOS-VGA-Camera-Datasheet.pdf" rel="noreferrer">7670 datasheet</a></p>
<p><a href="https://www.openimpulse.com/blog/document-viewer/?pdf_file=AL422-FIFO-Datasheet.pdf" rel="noreferrer">AL422 datasheet</a></p>
<p><a href="http://nicolasfley.fast-page.org/?page_id=35" rel="noreferrer">An example of project</a></p>
<p>But to answer your question; You'll need to purchase a piece more if you don't have AL442.</p>
<p>Regards,</p>
|
6652 | |arduino-uno|serial| | Read all Digital input in arduino once time and sent theme to serial | 2014-12-23T21:18:03.333 | <p>i need to read all Read all Digital input in arduino once time; example:</p>
<pre><code>Serial.write(digitalRead(0),digitalRead(1),...,digitalRead(13));
</code></pre>
<p>to receive state of all digital pin in one times from my app build with delphi</p>
| <pre><code>void setup()
{
Serial.begin(115200);
}
void loop()
{
Serial.print("<");
for (int p = 0; p < 14; p++)
{
Serial.print(digitalRead(p));
}
Serial.println(">");
}
</code></pre>
|
6653 | |ide|arduino-micro| | IDE support for Arduino micro | 2014-12-23T21:34:47.287 | <p>I have an Arduino micro <a href="http://arduino.cc/en/Main/arduinoBoardMicro" rel="nofollow">http://arduino.cc/en/Main/arduinoBoardMicro</a> I was looking to know which is the lowest version of the IDE that support it. Actually on the IDE 0023 is not present in <code>Tools > Board</code>.</p>
| <p>According to the <a href="http://arduino.cc/en/Main/ReleaseNotes" rel="nofollow">Arduino Software Release Notes</a>, support for the Arduino Micro was added in 1.0.2.</p>
|
6660 | |programming|display|string| | Program got so many errors about expected ) or ; before either | 2014-12-24T03:46:44.240 | <p>This is my first time to try program arduino, and I am clueless. I have a friend who told me about things work, and he told me the programming language is C (or similar to C) which we have learned in our class. I just program as my friend examples, but it doesn't work and return error codes about expected ; before ( or ) before ; etc.</p>
<p>I'm not sure why this wont work. This is the hardware (simulated) I going to make.
<img src="https://i.stack.imgur.com/HnyKf.jpg" alt="hw-planned"></p>
<p>here's the code:</p>
<pre><code>#define dw 8; //buttons down
#define ri 9; //buttons right
#define le 10; //buttons left
#define up 11; //buttons up
#define ok 12; //buttons ok
#define mn 13; //buttons menu
#include <LiquidCrystal.h>
LiquidCrystal lcd(6,5,4,3,2,1);
int i=0;
char input[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void setup()
{
pinMode(dw, INPUT);
pinMode(ri, INPUT);
pinMode(le, INPUT);
pinMode(up, INPUT);
pinMode(ok, INPUT);
pinMode(mn, INPUT);
}
void intext()
{
int c=0, lim=16;
for(i=0;i<lim;)
{
lcd.setCursor(c,1);
input[i]=97;
if(dw=HIGH)
{
if(input[i]>122)
input[i]=97;
input[i]=input[i]+1;
lcd.print(input[i]);
}
if(up=HIGH)
{
if(input[i]>97)
input[i]=122;
input[i]=input[i]-1;
lcd.print(input[i]);
}
if(ri=HIGH)
{
c=c+1;
lcd.setCursor(c,1);
lcd.print(input[i]);
}
if(le=HIGH)
{
c=c-1;
lcd.setCursor(c,1);
lcd.print(input[i]);
}
if(ok=HIGH)
{
lim=i+1;
}
}
}
void loop()
{
lcd.begin(16,2);
lcd.setCursor(0,0);
lcd.print("Masukan kata:");
intext();
}
</code></pre>
<p>I have no idea why it wouldn't work. I'm sorry if I'm too stupid to understand.
Thank you!</p>
<p>Edit: oh yeah, the errors, here:</p>
<pre><code> This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.
Arduino: 1.0.6 (Windows NT (unknown)), Board: "Arduino Uno"
programyuhu.ino: In function 'void setup()':
programyuhu:14: error: expected `)' before ';' token
programyuhu:14: error: expected primary-expression before ',' token
programyuhu:14: error: expected `;' before ')' token
programyuhu:15: error: expected `)' before ';' token
programyuhu:15: error: expected primary-expression before ',' token
programyuhu:15: error: expected `;' before ')' token
programyuhu:16: error: expected `)' before ';' token
programyuhu:16: error: expected primary-expression before ',' token
programyuhu:16: error: expected `;' before ')' token
programyuhu:17: error: expected `)' before ';' token
programyuhu:17: error: expected primary-expression before ',' token
programyuhu:17: error: expected `;' before ')' token
programyuhu:18: error: expected `)' before ';' token
programyuhu:18: error: expected primary-expression before ',' token
programyuhu:18: error: expected `;' before ')' token
programyuhu:19: error: expected `)' before ';' token
programyuhu:19: error: expected primary-expression before ',' token
programyuhu:19: error: expected `;' before ')' token
programyuhu.ino: In function 'void intext()':
programyuhu:28: error: expected `)' before ';' token
programyuhu:28: error: expected primary-expression before '=' token
programyuhu:28: error: expected `;' before ')' token
programyuhu:35: error: expected `)' before ';' token
programyuhu:35: error: expected primary-expression before '=' token
programyuhu:35: error: expected `;' before ')' token
programyuhu:42: error: expected `)' before ';' token
programyuhu:42: error: expected primary-expression before '=' token
programyuhu:42: error: expected `;' before ')' token
programyuhu:48: error: expected `)' before ';' token
programyuhu:48: error: expected primary-expression before '=' token
programyuhu:48: error: expected `;' before ')' token
programyuhu:54: error: expected `)' before ';' token
programyuhu:54: error: expected primary-expression before '=' token
programyuhu:54: error: expected `;' before ')' token
</code></pre>
| <p>In C and in C++, <code>#define</code> is not an instruction of the language, but a directive of the <strong>pre-processor</strong>.</p>
<p>What it does is define a "macro" which will be replaced everywhere it appears later on in the source file.</p>
<p>For instance:</p>
<pre><code>#define DUMMY 152
int x = x + DUMMY;
myfunction(DUMMY);
</code></pre>
<p>will be changed, before compilation, into:</p>
<pre><code>int x = x + 152;
myfuntion(152);
</code></pre>
<p>In the example above, <code>DUMMY</code> is replaced everywhere by what follows it in the <code>#define</code> line, i.e. 152.</p>
<p>As pre-processor directive is not an instruction, it shall not be ended by <code>;</code>. If you add <code>;</code> at the end of a <code>#define</code>, then it will be part of the replacement:</p>
<pre><code>#define DUMMY 152;
int x = x + 152;;
myfuntion(152;);
</code></pre>
<p>As you can see now, <code>DUMMY</code> is replaced by <code>152;</code>, not just <code>152</code>.</p>
<p>So the solution in you example is to remove all <code>;</code> that are at the end of <code>#define</code> lines:</p>
<pre><code>//buttons down
#define dw 8
//buttons right
#define ri 9
//buttons left
#define le 10
//buttons up
#define up 11
//buttons ok
#define ok 12
//buttons menu
#define mn 13
</code></pre>
<p>Note that comments should also be removed from the <code>#define</code> otherwise they would also appear everywhere the replacements are done.</p>
|
6671 | |sensors| | Is there a radar - like sensor that can tell me the distances of multiple things around the sensor? | 2014-12-24T17:39:12.230 | <p>I'm trying to develop something that requires accurate distance measurement of objects around the center of the contraption. However, I cannot find any way to achieve this other than using a bunch of infrared distance sensors. Really, I'm looking for something that costs at most $200 and is compatible either with arduino, PC, or raspberry pi.</p>
<p>This may not be the place for this, if not, please inform me.</p>
<p>Thanks in advance!</p>
| <p>What you're looking for is called <a href="http://en.wikipedia.org/wiki/Lidar" rel="nofollow"><strong>lidar</strong></a> - but it's not cheap. <a href="http://rplidar.robopeak.com/" rel="nofollow">RPLIDAR</a> is the current price leader for non-hacky solutions, and I haven't seen it for much less than $400 anywhere.</p>
|
6675 | |serial|i2c|usb|communication| | Can an Arduino Micro receive commands from another microcontroller when hardwired together? | 2014-12-24T20:50:15.200 | <p>I plan to build functioning reaction wheels, controlled by an Arduino Micro. Ideally, I'd like to have the reaction wheels, and the micro, be a single unit which would receive external commands from another microcontroller.</p>
<p>I know you can link Arduino microcontrollers, and every time I've seen it done it has been with a RC module such as XBee. Is it possible to link units using something like the micro-usb on the Arduino Micro?</p>
<p>If this is possible, is it as simple as connecting the micro-usb ports on my microcontrollers, and then working out the programming?</p>
| <p>You can use a USB <strong><a href="http://www.digikey.com/product-detail/en/87520-0010BLF/609-1045-ND/1001359" rel="nofollow">connector</a></strong> (<a href="http://www.digikey.com/product-detail/en/0475890001/WM17143TR-ND/1832253" rel="nofollow">micro</a>) (mounted on a custom PCB) for whatever you want and route the connector's pins to whichever Arduino pins you want. It will not be USB, but you could, at least, use USB cables for ease-of-connection.</p>
<p>This is <em>un-wise</em>, at best, because someone is, eventually, going to plug in a real USB cable.</p>
|
6681 | |attiny|virtualwire| | RCSwitch on Attiny85 | 2014-12-25T01:16:00.593 | <p>I would like to use my Attiny85 as an remote controlled relay switch.
I have already tested the sketch on my Atmega328 and it worked.
Now I wanted to burn the sketch on my Attiny85 using ArduinoISP but I get the following error in the ArduinoIDE:</p>
<pre><code>sketch_dec25a.ino: In function ‘void setup()’:
sketch_dec25a:13: error: ‘class RCSwitch’ has no member named ‘enableReceive’
sketch_dec25a.ino: In function ‘void loop()’:
sketch_dec25a:20: error: ‘class RCSwitch’ has no member named ‘available’
sketch_dec25a:21: error: ‘class RCSwitch’ has no member named ‘getReceivedValue’
sketch_dec25a:22: error: ‘class RCSwitch’ has no member named ‘getReceivedValue’
sketch_dec25a:25: error: ‘class RCSwitch’ has no member named ‘resetAvailable’
</code></pre>
<p>That's my code:</p>
<pre><code>#include <SoftwareSerial.h>
#include <RCSwitch.h>
int RELAY_PIN = 2;
RCSwitch mySwitch = RCSwitch();
SoftwareSerial mySerial(1, 3); // RX, TX
void setup()
{
pinMode(RELAY_PIN, OUTPUT);
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
mySerial.begin(9600);
mySerial.println("Hello, world?");
}
void loop() // run over and over
{
if (mySwitch.available()) {
Serial.println(mySwitch.getReceivedValue());
if(mySwitch.getReceivedValue() == 1234567){
digitalWrite(RELAY_PIN, HIGH);
}
mySwitch.resetAvailable();
}
}
</code></pre>
<p>I am using these cores: <a href="https://code.google.com/p/arduino-tiny/" rel="nofollow">https://code.google.com/p/arduino-tiny/</a></p>
<p>I am using the SoftwareSerial just for debugging.
Sorry for my bad english and thanks for your help!</p>
| <p>I have tested with Digispark ATtiny85 and <a href="https://github.com/sui77/rc-switch" rel="nofollow noreferrer">https://github.com/sui77/rc-switch</a> work perfect</p>
<p>just comment <code>#define RCSwitchDisableReceiving</code>
than use in setup code <code>enableReceive(0);</code> and external pin 7 PB2(int0) as RF source</p>
<p>Or you can use other software pin interrupt</p>
<p>in setup:<code>
PCMSK |= (1<<PCINT0);//here pin number
GIMSK |= (1<<PCIE);</code></p>
<p>interrupt function
<code>
ISR(PCINT0_vect) {
rd.handleInterrupt(); // you need also put handleInterrupt() in public section in RCSwitch.h
}</code></p>
|
6683 | |serial|arduino-mega| | Serial debug output looking messy | 2014-12-25T08:21:06.967 | <p>I've got this quite basic code running on an Arduino Mega 2560, and the output is looking like I have the serial settings wrong, though I can't work out what to change.</p>
<pre><code>void setup()
{
Serial.begin(9600);
Serial.println("test123");
}
void loop()
{
Serial.println("test" + millis());
}
</code></pre>
<p>The output looks like this:</p>
<pre><code>ð¦·Z©÷
×ï¾üÿ7ß^|ïüûÿVÏuØëo~ìÿÓûzëýÿ{ßþ©×xñפ¿ïßûÏûýoÏ¿îãõI
õfwi÷`p¬½Ïª»QáÀª»¦·ð¦·Z©÷
test123
D
4ñjü¯÷~µÞMz¹Ý~¼
Ûþ}iû}Ò֦ǿ÷ÿÂï½Õ¾;îö
</code></pre>
<p>I'm using the inbuilt "Serial Monitor" in the Arduino suite with settings 9600 baud and no line endings.</p>
<p>I see that the first println in <code>setup()</code> is sending the data as expected but all other comms are coming through as nonsense.</p>
<p>Any suggestions of what to do?</p>
| <p>Just as a minor addition to Peter's excellent answer and comments on concatenation and implicit typecasting with <code>String</code> objects: </p>
<p>Alternatives to construct the message (as a <code>char[]</code>) to be send might be: </p>
<ol>
<li>use <code>sprintf()</code></li>
</ol>
<p></p>
<pre><code>char buffer[80]; // for the complete output
char value[4]; // for millis(), which returns an unsigned long
sprintf(buffer, "I'm running for %u ms now", millis());
Serial.println(buffer);
</code></pre>
<p><em>Note that <code>sprintf()</code> uses quite some memory!</em></p>
<ol start="2">
<li>build the message 'manually':</li>
</ol>
<p></p>
<pre><code> char buffer[80] = "I'm running for ";
itoa(millis(), value, 10);
strcat(buffer, value);
strcat(buffer, " ms");
Serial.println(buffer);
</code></pre>
|
6686 | |usb| | Why does Arduino use USB A-B plug, instead of A to micro USB plug? | 2014-12-25T11:38:54.017 | <p>I understand that A-B plug used to be common but they could have switched to micro without issues.</p>
<p>My questions:</p>
<ul>
<li>Why does Arduino use USB A-B plug, instead of A to micro USB plug?</li>
<li>What are the challenged Arduino would be facing if they switched to micro USB?</li>
</ul>
<p>Note:
By "Arduino" I'm referring to Arduino models that do not come with a micro USB port such as the most common Uno & Mega.</p>
| <p><em>Please note that this answer is based on speculation and some common sense rather than on insider information</em>:</p>
<p>If you take look at the <a href="http://arduino.cc/en/Main/Boards" rel="nofollow">hardware index</a>, you'll notice that significant parts of the layout (drill holes, pin spacing, and position and <strong>type of the USB jack</strong>) haven't changed between the <em>Arduino Extreme</em> and the current <em>Arduino UNO R3</em>), while other improvements have been made. For changes between the UNO R2 and R3, please see <a href="https://learn.adafruit.com/arduino-tips-tricks-and-techniques/arduino-uno-faq" rel="nofollow">Arduino UNO FAQ at adafruit</a> (link provided by <strong>jfpoilpret</strong>).</p>
<p>It is thus reasonable to me that keeping the USB jack was a deliberate design decision: Improve if possible, but keep the layout changes to a minimum and allow for maximum backwards compaptibility.</p>
<p><em>But again, this is just the guess of a user!</em></p>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.