texts: Replacing several pinMode() and digitalWrite() pins with an array

texts:
I'd like to 'clean up' some code that involves several pinMode() and digitalWrite() lines by using a single line of an array. I'm very new to both arrays so I'm a bit confused. The following examples are sections from code that controls a 4 digit, 7 segment LED.

// Define display pins
// Digit pins (common cathode)
int digit1 = 13; //Display pin 1
int digit2 = 12; //Display pin 2
int digit3 = 11; //Display pin 6
int digit4 = 10; //Display pin 8
// Segment pins
int segA = 2; //Display pin 14
int segB = 3; //Display pin 16
int segC = 4; //Display pin 13
int segD = 5; //Display pin 3
int segE = 6; //Display pin 5
int segF = 7; //Display pin 11
int segG = 8; //Display pin 15

void setup() {
  pinMode(segA, OUTPUT);
  pinMode(segB, OUTPUT);
  pinMode(segC, OUTPUT);
  pinMode(segD, OUTPUT);
  pinMode(segE, OUTPUT);
  pinMode(segF, OUTPUT);
  pinMode(segG, OUTPUT);

  pinMode(digit1, OUTPUT);
  pinMode(digit2, OUTPUT);
  pinMode(digit3, OUTPUT);
  pinMode(digit4, OUTPUT);
}

#define SEGMENT_ON  LOW
#define SEGMENT_OFF HIGH

  switch (numberToDisplay){

  case 0:
    digitalWrite(segA, SEGMENT_ON);
    digitalWrite(segB, SEGMENT_ON);
    digitalWrite(segC, SEGMENT_ON);
    digitalWrite(segD, SEGMENT_ON);
    digitalWrite(segE, SEGMENT_ON);
    digitalWrite(segF, SEGMENT_ON);
    digitalWrite(segG, SEGMENT_OFF);
    break;

Defining pins:

I'm pretty sure the code below is the correct way to store the pins as an array (but please correct me  if I'm wrong).

digitPins[] = {13 12 11 10};
segPins[] = {2 3 4 5 6 7 8};

pinMode():

I understand I could use a for loop to set the pin modes but is there an even simpler way? Would something like this work?

pinMode(digitPins[], OUTPUT);
pinMode(segPins[], OUTPUT);

digitalWrite():

I could access the appropriate pin from the array to use in digitalWrite() like the code below but that would result in the same number of lines of code (and be even more confusing). Is there another option?

digitalWrite(segPins[1], HIGH);


texts: dot matrix arduino turn off the intermittent led

texts:
I made a dot matrix that contain 10 row and 12 column , total 120 led.
I want to turn on the leds like this picture but when I open ground 1 , 2 and pin 0 , 1 , 2
6 leds light together.what kind of structure should I build?
Sheme :

I tried row by row like this:
 clear_cube();
 regWrite(cube[0][0], HIGH);
 set_array(4);
 //delay(10);

clear_cube();
regWrite(cube[1][0], HIGH);
set_array(3);
//delay(10);

clear_cube();
regWrite(cube[0][0], HIGH);
set_array(2);
//delay(10);                                                                                When I decrease the delay 5 leds blinking.

100  50  10  0 delay   Youtube


texts:
I want an I/O pin to return current in a circuit, similarly to the function of ground.

Which of these will achieve what I require?

pinMode(pinnumber, OUTPUT)
digitalWrite(pinnumber, LOW)

or

pinMode(pinnumber, input)


texts:
I want to run multiple sketches on one sketch. I use the method of multiple void loops. It works but esp8266 take a lot of time to execute commands.

void Setup()
 {
  setup1();
  setup2();
 }
void loop()
 {
  loop1();
  loop2();
 }

Is there any method to avoid that ?


texts:
I am working with an Arduino on a project for which timing is very important. I use TimerOne to trigger timer interrupts and use micros() for delays (delayMicroseconds() was causing problems worse than the one explained below). The program is sending a manual PWM signal to an LED and it is very important that the signal is sent with an error that is less than 8 microseconds (ideally, the signal is sent at the same time in each period). My test code is shown below:

#include <TimerOne.h>
#include <SPI.h>

const int LED_PIN = 3;
const int CHIP_SELECT = 12;

const int PERIOD = 4000;
const double DUTY_CYCLE = .5;
const int HIGH_TIME = PERIOD * DUTY_CYCLE;
const int LOW_TIME = PERIOD - HIGH_TIME;
const int INITIAL_SIGNAL_DELAY = LOW_TIME / 2;
const int HIGH_TIME_TOTAL_DELAY = INITIAL_SIGNAL_DELAY + HIGH_TIME;

const int RESISTOR_VALUE = 255;

boolean triggered = false;
boolean data = false;

unsigned long triggeredTime;
unsigned long s;
unsigned long e;

boolean found;
int i = 0;

void setup()
{
  s = micros();

  Timer1.initialize(PERIOD);
  Timer1.attachInterrupt(trigger);

  pinMode(LED_PIN, 3);
  pinMode(CHIP_SELECT, OUTPUT);

  SPI.begin();

  digitalWrite(CHIP_SELECT, LOW);
  SPI.transfer(B00010001);
  SPI.transfer(RESISTOR_VALUE);
  digitalWrite(CHIP_SELECT, HIGH);

  e = micros();

  Serial.begin(115200);
  Serial.print("s: ");
  Serial.println(s);
  Serial.print("e: ");
  Serial.println(e);
}

void loop()
{
  if(triggered)
  {
    while(micros() - triggeredTime < INITIAL_SIGNAL_DELAY)
    { }
    s = micros();
    digitalWrite(LED_PIN, data);
    while(micros() - triggeredTime < HIGH_TIME_TOTAL_DELAY)
    { }
    digitalWrite(LED_PIN, LOW);

    data = !data;
    triggered = false;

    e = micros();
    //micros();

    if(s % 100 > 28 || s % 100 < 12)
    {
     found = true;
    }

    if(!found)
    {
      Serial.print("s: ");
      Serial.println(s);
    }
    else
    {
      Serial.print("ERROR: ");
      Serial.println(s);
    }
    //Serial.print("e: ");
    //Serial.println(e);
  }
}

void trigger()
{
  triggeredTime = micros();
  triggered = true;
}

(it should be noted that the first signal sent is always xx20, usually 5020).

So, with this code, I eventually get an error. I am not sure why, but this error occurs at the same point every single time:

.
.
.
s: 1141020
s: 1145020
s: 1149020
ERROR: 1153032
ERROR: 1157020
ERROR: 1161020
.
.
.

Now, the really weird part is if I remove the comments before micros() (the micros() right after e = micros()), there is no error (or at least there is not an error within the first 30 seconds). I was wondering if anybody could provide an explanation for why this happens. I have dedicated many hours trying to get the timing working properly and everything was working well until I encountered this error. Any help would be very much appreciated. Thank you!


texts: How to get interrupt while in sleep mode?

texts:
I am using Arduino-uno, attached ESP-01 module

I want to give interrupt when I send some wifi-signal to arduino,
which is in sleep mode.

so I write this code:

SoftwareSerial esp(2, 3); // RX, TX

void setup() {
  // put your setup code here, to run once:
 Serial.begin(9600);

  esp.begin(9600);

  attachInterrupt(digitalPinToInterrupt(2),work,RISING);

  delay(1000);

  init_sleep(); // go to sleep
}

void work(){
    light = ! light;

    digitalWrite(12,light);

}

when I don't write down the init_sleep, this interrupt is able to work.

but when the arduino is in sleep mode, because of writing 'init_sleep'
It does not react signal by interrupt.

Is it impossible to wake up sleeping arduino by attachInterrupt() ?
please give me some solution.


texts: How to access multiple SPI interfaces on Arduino

texts: I have worked on SPI devices connected with an Arduino one at a time. How do I work with two different SPI devices at the same time?


texts: How many Infrared sensor modules can be added to a single Arduino (eg;Uno)

texts:
I am looking to add block detection to my model railroad. I need approx. 40 infrared sensors to power 40 LED's on my control panel. No signals or other logic required yet, just the LED indications -LED- on=occupied  off=vacant.
How many Uno boards would I need to do this? I may, in the future, look at integrating several two (or three) aspect signals down the track. I am an absolute novice here, never having used an Arduino, nor done any coding of any sort.


texts: How to have an Arduino communicate with 3 other Arduinos?

texts:
I was wondering how I can get 4 Arduinos in total to communicate with each-other through a wired connection. The goal is to have the master Arduino send a number 0-100 to each of the other Arduinos.

The master unit will be an Arduino Uno and the other 3 Arduinos will be Arduino Pro Minis.


texts: restart counter of elapsed millis willingly with read

texts:
When I trigger high it will count for as long as I ask it while I am high then shut off. I am able to start counting again whenever I want by triggering low and going back to high and it starts from the beginning as long as the time in low is not within the time I asked it to be high. The problem is I go low mid count then quickly back to high the count picks up where millis left off without starting from the beginning. Is there a way to make this better.

unsigned long induceTime = 0;
unsigned long elapseTime;
long setTime = 10000;
int openClose;
int openClosePin = 2;
int writeToPin = 3;
void setup() {
Serial.begin(9600);
}

void loop() {
  int openClose = digitalRead(openClosePin);
  elapseTime = millis();
  if (openClose == HIGH && elapseTime < induceTime + setTime){
    digitalWrite(writeToPin, HIGH);
    Serial.println(' ');
    Serial.println(elapseTime);
    Serial.println(' ');
    Serial.println(induceTime);
    Serial.println(' ');
}
  if (openClose == LOW && elapseTime > induceTime + setTime){
    induceTime = elapseTime;
    Serial.println(elapseTime);
    Serial.println(induceTime);
}

delay(500);
}


texts: stepper motor always stops in a fixed position in each rotation

texts: I am trying to run my stepper motor freely. but the stepper motor always stops in a same position in each rotation. but when i am rotating it a bit by my hand then it is rotating for one turn then again it stops in a same position. Someone help me please.


texts: Float arithmetic vs. int arithmetic - is there any power penalty?

texts:
It is widely known that float arithmetic takes longer (that is, eats more cycles) than fixed-point (or integer, or bitwise arithmetic), and that surely is something to consider for speed- and time-critical applications.

My question is: supposing I don't have any time-critical need (and I have enough program and RAM memory), should I be worried by any other disadvantage of using float?

Specifically, I wonder if the processor would be more power-hungry because of those extra CPU cycles.

UPDATE:   What will my application do meanwhile?

The only goal of the application is to turn lights on and off (lots of them) based on push-button input. I am using float to apply filtering to button inputs, in order to debounce the buttons simulating a RC filter + schmitt-trigger. So the loop in pseudo-code would be:

Read all inputs (digitalRead or direct port access);
Filter the readings and decide if a button action has been detected;
Set some control flags that determine which part of the cycle the lights are in;
Check for elapsed time to actually turn blinkers on and off.

So, since I plan to react to button input as realtime as possible, most time would be spent filtering (that is, performing floating point operations), since direct port access and flag-setting are supposed to be nearly instantaneous, right?


texts: Arduino Mega 2560 R3 with Shield Model Wireless SD R3 not working

texts:
Recently I've bought an Arduino Mega 2560 R3 and a Shield Model Wireless SD R3 from http://www.amazon.de/Arduino-A000065-Netzwerkkarte-Wireless-SD-Shield/dp/B00L1FO860. I try to run the example from https://www.arduino.cc/en/Tutorial/ConnectWithWPA

Before running the sketch I turn the DIP switch to the position USB.
It seems like the WIfi Shield is correct connected to the Arduino since the LEDs TX and RX are blinking during upload the Sketch.

Sadly as output I got only:
    WiFi shield not present

Currently I'm not sure if the hardware itself provide Wifi functionality. Does somebody know if it should work with this hardware?


texts: Standalone chipset, power regulation & pinout

texts:
I have succesfully (or so the ide says) burned a bootloader on an ATMega328P-PU chipset, and uploaded my sketch on it.

It appears a voltage regulation is absolutely needed, if I want to solder a pcb with the standalone chip, rather than an arduino. Is that correct? Can I build one out of my starter kits parts (assortment of transistors, diodes, zeners, resistors and capacitors)?

In the meantime, I would like to make sure the chispet is functional. Can I power it from GND/5V of an arduino? Will it take care of that power regulation?

If I can, what is the correspondance between the arduino pins, and the ATMega328P-PU pins? I have this page here : http://www.learningaboutelectronics.com/Articles/Atmega328-pinout.php
referencing the chipset pinout. Am I correct in assuming there is a correspondance with the arduino pinout in the reading order of this chart, ie. :

PD0 to PD7 are Rx, Tx, digital pins 2 to 7 on the arduino, PB0 to PB5 are digital pins 8 to 13, and PC0 to PC5 are A0 to A5 on the arduino?

Thanks for reading.


texts: What's wrong with my undetected, unresponsive Arduino Robot?

texts:
I was wondering if someone could try and solve a major problem I've been having with a brand new Arduino Robot (similar to an Arduino Leonardo). Any input would be very much appreciated!

I've been working with an Arduino Robot on a summer internship for the last week with no major problems. However, a couple of days ago, it stopped running programs and couldn't be detected when being plugged into the computer.

When plugged in or turned on, the LCD turns on with nothing displayed on the screen and the power LED also switches on. However, no program is run (I had a working program involving the LCD uploaded at the time it stopped functioning, which would normally run). Also when plugged in, the Arduino is completely undetected by the computer, with the 'Serial Port' option under Tools grayed out, the device not showing up in device manager, and no signs that a device has been plugged-in. I've tried 3 different USB cables - one of which I tested on another device - and 3 different computers (with Windows 7, 8.1 and Linux Ubuntu installed). On the Linux computer, I ran lsusb before and after plugging in the device and saw no change. I've also tried various solutions such as re-installing the drivers and the Arduino software, using MProg and various rebooting/unplugging-replugging variations.

So I think the problem is almost definitely with the Arduino Robot itself. I'll give a little information about the problems I encountered previously, to see whether something I did affected it or not.

Problem 1:

The first problem I had with the robot was entirely by my own fault and was pretty foolish of me (I'm new to electronics - this being my first project involving it). I ran code from this website (the first set of coding on the page) to try and see whether I could get the LCD to work - not realizing that it wouldn't work for a different type of LCD. After uploading the code, the speaker made a loud constant buzzing noise. Fortunately after uploading a different code, the problem was resolved. I'm doubtful that this could have affected the robot, but since I'm so new to this I'll leave it to one of you to decide.

Problem 2:

The next problem was one to do with uploading. The robot worked fine for a couple of days after the first problem until I came across this one:

When uploading programs, there would be a 'device disconnecting' sound from the computer and the program would fail to upload (I can give details on the error messages if you need them). I managed to solve the issue using an odd solution involving hitting the reset button at just the right time while a program was uploading.

After this, the robot worked for a few hours. In this time I tried to play with the 'turn' function, which didn't seem to work very well at all (the robot would turn angles very different to the ones given) and started creating programs playing around with the LCD. It was at this point the robot stopped functioning properly.

So does anyone have any idea what might be wrong? I have no idea how to fix this problem and I've been trying to find a solution for almost 2 full days now. Any input at all would be greatly appreciated.


texts: Uploading Temperature data (DHT22) to Thingspeak with an ENC28J60

texts:
So, I've gotten my module working pretty well. It logs data from the DHT22 and sends it to a 192 address on my LAN. However, I'd like to log and graph the data.

I figured thingspeak is a decent platform for that. However, I have no experience doing so, and I'm not sure where to start. All the examples use the "official" arduino shield. I've only found ONE example bit of code, but it uses the Dallas One Wire temp module. Link

I'm in over my head, and have no idea how to switch from the One wire to the DHT22. Thanks for the help!

I'm using a clone arduino pro mini, 5V 16mhz, 328.

If there's a better platform than thingspeak, I'm open. All I want to do is graph and visualize the DHT22 sensor readings.


texts: How can I switch a 1.5V buzzer with my Arduino?

texts:
I want to make my alarm clock “smart”. I'm very new to this stuff, that is, the hardware side. The programming shouldn't present too many problems.

I’m currently experimenting with a simulator (http://circuits.io) and want to start with controlling the alarm’s buzzer with my Arduino.

I did some reading on transistors and this is what I came up with:

I’ve turned pin D3 to high and hooked it up to the base of a NPN transistor. I’m trying to run 1.5V through the transistor, but nothing happens. Any thoughts?


texts: Mapping segments and memory allocation on a segment LCD driver

texts:
I've just configured a segment LCD and driver, everything works fine, but because I decided to not use vias on the PCB, the connections between the two are mixed.

To be more precise, in order to display the number 12, both memory addresses should be accessed.

So right now it's impossible to display a single digit without mapping all the segments.

In static mode, this is how RAM memory is allocated to SEG0-SEG7 and SEG8-SEG15 respectively:

What I've tried was to create two multidimensional arrays and map possible combinations of the two digits, like this:

// 01 to 09
const byte map1[10][2] = {
  {B01110111, B111111 },
  {B01110001, B100111},
  {B01111011, B011111},
  {B01111011, B110111},
  {B01111101, B100111},
  {B01111110, B110111},
  {B01111110, B111111},
  {B01110011, B100111},
  {B01111111, B111111},
  {B01111111, B110111}
};

// 10 to 19
const byte map2[10][2] {
  {B00010111, B111100},
  {B00010001, B100100},
  {B00011011, B011100},
  {B00011011, B110100},
  {B00011101, B100100},
  {B00011110, B110100},
  {B00011110, B111100},
  {B00010011, B100100},
  {B00011111, B111100},
  {B00011111, B110100}
};

If there is no way to mix or map them in a dynamic way so any possible combination between 00 and 99 can be achieved, the only solution is to add vias on the PCB and rewire everything as explained in the datasheet.

Any ideas?

Thanks


texts: Dual OLED displays showing the same image via SPI?

texts:
Is it possible to connect two oled displays via SPI to my Uno and send a single image to both displays, with each refreshing at an identical rate?

I have gotten a single oled display (SSD1306) to work using the U8g2 library, however i am not sure which pins can be shared in a dual display setup. There are no CS pin on my displays, only GND, VCC, SCL, SDA, D/C, and RST.

thanks!


texts: Converting live vocals to discrete signals

texts:
I would like to augment a live music performance by displaying an specific LED for any given musical note.

For vocals:
Rather than attempt to process the audio using the Arduino board, I'd like to use something like an auto-tune box to do the heavy lifting.

For digital instruments: Would like to drive the Arduino board with some kind of digital signal (for example midi)

I'm having trouble finding out which (if any) consumer audio device can provide the pre-processing. Are there any comparable projects or insights?


texts: Binary addressing and coding to control a 96 input mux matrix

texts:
I’m trying to wrap my head around using binary addresses in a mux. Failing miserably.
For the circuit I have six 16 channel analog multiplexers CD74HC4067 as slaves to an eight channel multiplexor CD54HC4051 master.
They are bringing in 96 sensor readings (IR receiver diodes through Op Amps) into an array
that, in turn,  is used to constantly update lotsa LEDs through a series of shift registers (TLC5940) using the Arduino TLC5940 Library.

I’ve included the possible wiring scheme that the code is trying to control.
It probably needs work too.

Question: I’ve seen, and SEMI-understand matrixes that address 32 inputs
(4 x 8 bits) but not quite understanding how I can address the six mux chips
with 96 inputs. Or if I can even do it this way. Example from this forum: How to code for cascading multiplexers?
Is it possible with this matrix of 96 inputs, and how? Am I barking up the wrong tree?

Code so far:

    #include <Tlc5940.h> //Arduino TLC5940 Library controls the individual LEDs - "Pixels"

int ledCount = 96; //change  LED "PIXEL" count in matrix...also number of IR sensor inputs

int thresh = 10; //value for usable distance reading from IR

// main structures to hold LED Pixel array on/off state, IR reciever readings
byte dsply_state[ledCount];    //pixel on-off grid, need for tlc5940
uint_16  recv_state[ledCount];           // IR Readings - FROM mux set-up

// Master IR -mux sensor pins for Arduino Pro MINI
#define  M_S0 2
#define  M_S1 4
#define  M_S2 5
// Slave IR mux sensor pins
#define  S_S0 6
#define  S_S1 7
#define  S_S2 8
#define  S_S3 12

//  ANALOG PIN :
#define  InputFromMux A0

void setup() {
    //Serial.begin(9600);

    //tlc5940 Arduino library
    Tlc.init(0);

    // CONFIGURE ADDRESS PINS
    pinMode(M_S0, OUTPUT);
    pinMode(M_S1, OUTPUT);
    pinMode(M_S2, OUTPUT);

    pinMode(S_S0, OUTPUT);
    pinMode(S_S1, OUTPUT);
    pinMode(S_S2, OUTPUT);
    pinMode(S_S3, OUTPUT);
    pinMode(InputFromMux, INPUT);

}

void loop() {
    // LOOP THROUGH ALL THE ADDRESSES OF THE MASTER and SLAVES.

  for (int i = 0; i < ledCount; i++) {

    digitalWrite(M_S2, i & 0b1000000);
    digitalWrite(M_S1, i & 0b0100000);
    digitalWrite(M_S0, i & 0b0010000);
    digitalWrite(S_S3, i & 0b0001000);
    digitalWrite(S_S2, i & 0b0000100);
    digitalWrite(S_S1, i & 0b0000010);
    digitalWrite(S_S0, i & 0b0000001);

    delay(2);

    //edited as per @Gerben. thanks so much

    //get an individual sensor reading from IR receiver/opAmp mux, store it in a variable
     int IRstate = analogRead(InputFromMux);

    //populate receiving array with a reading
     recv_state[i] = IRstate;

    //populate display array for tlc5940 to push out
     dsply_state[i] = recv_state[i];

} //end for(i...) loop

      //run through display state array to check if the stored reading is greater than a threshold number
      //if yes, then turn on the "pixel". If not, set it to zero
      //

       for (int x = 0; x < ledCount; x++)
          if (dsply_state[x] >= thresh ) {

               Tlc.set(dsply_state[x], 4000);

             //or if reading from mux is zero
          } else if (dsply_state[x] < thresh) {

              Tlc.set(dsply_state[x], 0);
              }

            //tlc5940 Arduino library - update() clocks the chips
            // move update(); outside the for(x...) loop for speed?
        Tlc.update();
        delay(10);

      } //end For(x..) Loop

}//endMainLoop


texts: When is following code is dumped into Arduino NANO the output is not as expected after few trials

texts:
I'm a beginner of Arduino programming,  when I dumped the following code into Arduino NANO board, at the first the output is as expected. But After few trials the 16*2 LCD display is getting off and DC motor pump is running continuously.
      #include <Wire.h>
      #include <Adafruit_MLX90614.h>
      #include <LiquidCrystal_I2C.h>
      LiquidCrystal_I2C lcd(0x27, 16,2);

      char *typeName[]={"Object","Ambient"};

      Adafruit_MLX90614 mlx = Adafruit_MLX90614();

      const int trigPin = 13;
      const int echoPin = 12;
      #define DCwater_pump 11

      long duration;
      int distance;

     void setup()
     {
          Serial.begin(9600);
          Serial.println("S.O.A.P. DISPENS");

          Serial.print("Ambient = ");
          Serial.print(mlx.readAmbientTempF());
          Serial.print("*F\tObject = ");
          Serial.print(mlx.readObjectTempF());
          Serial.print("*F");

          Serial.println();

          delay(500);

          if (!mlx.begin())
          {
              lcd.print("MLX90614 Failed");
              lcd.setCursor(0,1);
              lcd.print("check wiring!");
              while (1)
              ;
          }
          Wire.begin();
          lcd.begin(16,2);
          lcd.backlight();
          lcd.print("S.O.A.P.D. Temp");
          lcd.setCursor(0,1);
          lcd.print("S.O.A.P.D. Temp");
          delay(500);
          clearCharacters(2-1,0, 16-1);

          pinMode(trigPin, OUTPUT);
          pinMode(echoPin, INPUT);
          pinMode(DCwater_pump, OUTPUT);

    }

void loop()
{

        printTemp('C');
        delay(1000);

        printTemp('D');
        delay(1500);

}

float getTemp(char type)
{

  float value;
    float tempObjec = mlx.readObjectTempC();
    float tempAmbient = mlx.readAmbientTempC();

   if(type =='C')
   {
    value = tempObjec;
   }
   else if(type =='D')
   {
    value = tempAmbient;
   }
   return value;

}

            void printTemp(char type)
  {
            clearCharacters(1,0, 16-1 );
            float TmpC =getTemp(type);
            float TemF;
            TemF = (TmpC*1.8)+32;
            lcd.setCursor(0,1);
            if(type =='C')

              {
                lcd.print(typeName[0]);
                lcd.print(" ");
                lcd.print(TemF);
                lcd.print((char)223);
                lcd.print("F");
               }

                  else if(type =='D')
                  {
                    lcd.print(typeName[1]);
                    lcd.print(" ");
                    lcd.print(TemF);
                    lcd.print((char)223);
                    lcd.print("F");
                  }

  }

void clearCharacters(uint8_t row,uint8_t start, uint8_t stop )
{
    for (int i=start; i<=stop; i++)
    {
    lcd.setCursor (i,row);
    lcd.write(254);
    }

    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);

    distance= duration*0.034/2;

    Serial.print("Distance: ");
    Serial.println(distance);

           if (distance < 30)
          {
           digitalWrite(DCwater_pump,HIGH);
           Serial.println("DC Pump is ON Now!!");
           delay(500);
          }
          else
          {
           digitalWrite(DCwater_pump,LOW);
           Serial.println("DC Pump is OFF Now!!");
           delay(500);
          }

}


texts: Problem connecting 10W led + Led driver Directly Arduino Uno

texts: can anyone give me an advice on connecting an 10W led + 12 volt drive to an Arduino Uno? it works without the board but when i tried to connect to Uno it doesn't work anymore. Thankyou


texts:
I have a stepper motor, and a Uln2003a stepper driver, which is connected to an ESP8266.

The ESP8266 is powered via USB, and the stepper motor is powered via the driver, which is then powered by an external power source, providing it a bit more than 12 volt. When powered on the LED D1 and D2 lights red.

Pins D0, D1, D2, D3 are used for input signal for the drive, the stepper board.

Everything should be connected correctly, but for some reason I am not able to make my stepper motor move. It doesn't react on any of my commands - why?

I suspect that the logic level might have to be 5v instead of 3v. But I've seen stepper motors being driven by an ESP before. So why does this not work? Any suggestions?

Any ways to debug?

Code:

esphome:
  name: steppermotor
  platform: ESP8266
  board: d1_mini

wifi:
  ssid: "ssid"
  password: "password"

# Enable logging
logger:

# ESPHome configuration
api:
  services:
    - service: control_stepper
      variables:
        target: int
      then:
        - stepper.set_target:
            id: my_stepper
            target: !lambda 'return target;'

# Example configuration entry
stepper:
  - platform: uln2003
    id: my_stepper
    pin_a: D0
    pin_b: D1
    pin_c: D2
    pin_d: D3
    max_speed: 250 steps/s

    acceleration: inf
    deceleration: inf


texts: Does Arduino Tian/LininoOS support Python 3?

texts:
I'm using an Arduino Yun running OpenWRT and it only runs Python 2.7.

I need to find a microcontroller+processor+WiFi board that supports Python 3. Does the Arduino Tian work for this, or are there any others?


texts:
So, I made this code (I'm rather new to this). The only thing that the Arduino should do, is when I press the button on pin 2, turn on the LED on pin 4 and emulate CTRL + R on the keyboard for the computer. Then, if the LED is on and I hit the button again, turn it off and hit the spacebar on my computer. But as soon as I hit the button for the first time, it does indeed press CTRL + R and the LED turns on, but after the delay, it immediately skips checking if I am pressing the button and assumes that I am pressing the button. Thereby it only sees that the LED is on and it turns it off while hitting the spacebar. Any suggestions?

#include <Keyboard.h>

int buttonPin = 2;
int ledPin    = 4;
int val = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  val = digitalRead(buttonPin);
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if ((val == LOW) && (digitalRead(ledPin) == LOW)) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
    Keyboard.press(KEY_LEFT_CTRL);
    Keyboard.press('r');
    delay(100);
    Keyboard.release(KEY_LEFT_CTRL);
    Keyboard.release('r');
    delay(500);
  }
  if ((val == LOW) && (digitalRead(ledPin) == HIGH)) {
    digitalWrite(ledPin, LOW);
    Keyboard.write(32);
  }
  if ((val == HIGH) && (digitalRead(ledPin) == LOW)) {
    digitalWrite(ledPin, LOW);
  }
  if ((val == HIGH) && (digitalRead(ledPin) == HIGH)) {
    digitalWrite(ledPin, HIGH);
  }
}


texts: How to run my IDUINO Yun Shields stand-alone?

texts:
Experts,

How can I power and communicate with the IDUINO shield stand-alone? In other words, without any additional uC for it to plug into.

Failing in that, can a Nano (cheaper, smaller) be wired to give the Yun what it needs?


texts: How to initialize digital output pin as low on arduino board??? I am getting lights on initially and i want lights off

texts:
/*
Please note as I have used the android app you told , the string inputs are taken as
A,B,C,D,E,F,G and a,b,c,d,e,f,g.
I have also written code for voice on and off which has all on and all off function
but since the android app we are using dosent have such key so i didnt took them
*/

String inputs;
#define relay1 2 //Connect relay1 to pin 9
#define relay2 3 //Connect relay2 to pin 8
#define relay3 4 //Connect relay3 to pin 7
#define relay4 5 //Connect relay4 to pin 6
#define relay5 6 //Connect relay5 to pin 5
#define relay6 7 //Connect relay6 to pin 4
#define relay7 8 //Connect relay7 to pin 3
#define relay8 9 //Connect relay8 to pin 2

void setup()
{
    Serial.begin(9600); //Set rate for communicating with phone
    pinMode(relay1, OUTPUT); //Set relay1 as an output
    pinMode(relay2, OUTPUT); //Set relay2 as an output
    pinMode(relay3, OUTPUT); //Set relay1 as an output
    pinMode(relay4, OUTPUT); //Set relay2 as an output
    pinMode(relay5, OUTPUT); //Set relay1 as an output
    pinMode(relay6, OUTPUT); //Set relay2 as an output
    pinMode(relay7, OUTPUT); //Set relay1 as an output
    pinMode(relay8, OUTPUT); //Set relay2 as an output
    digitalWrite(relay1, LOW); //Switch relay1 off
    digitalWrite(relay2, LOW); //Swtich relay2 off
    digitalWrite(relay3, LOW); //Switch relay1 off
    digitalWrite(relay4, LOW); //Swtich relay2 off
    digitalWrite(relay5, LOW); //Switch relay1 off
    digitalWrite(relay6, LOW); //Swtich relay2 off
    digitalWrite(relay7, LOW); //Switch relay1 off
    digitalWrite(relay8, LOW); //Swtich relay2 off
}
void loop()
{
    while(Serial.available()) //Check if there are available bytes to read
    {
        delay(10); //Delay to make it stable
        char c = Serial.read(); //Conduct a serial read
        if (c == '#'){
            break; //Stop the loop once # is detected after a word
        }
        inputs += c; //Means inputs = inputs + c
    }
    if (inputs.length() >0)
    {
        Serial.println(inputs);

        if(inputs == "A")
        {
            digitalWrite(relay1, LOW);
        }
        else if(inputs == "a")
        {
            digitalWrite(relay1, HIGH);
        }
        else if(inputs == "B")
        {
            digitalWrite(relay2, LOW);
        }
        else if(inputs == "b")
        {
            digitalWrite(relay2, HIGH);
        }
        else if(inputs == "C")
        {
            digitalWrite(relay3, LOW);
        }
        else if(inputs == "c")
        {
            digitalWrite(relay3, HIGH);
        }
        else if(inputs == "D")
        {
            digitalWrite(relay4, LOW);
        }
        else if(inputs == "d")
        {
            digitalWrite(relay4, HIGH);
        }
        else if(inputs == "E")
        {
            digitalWrite(relay5, LOW);
        }
        else if(inputs == "e")
        {
            digitalWrite(relay5, HIGH);
        }
        else if(inputs == "F")
        {
            digitalWrite(relay6, LOW);
        }
        else if(inputs == "f")
        {
            digitalWrite(relay6, HIGH);
        }
        else if(inputs == "G")
        {
            digitalWrite(relay7, LOW);
        }
        else if(inputs == "g")
        {
            digitalWrite(relay7, HIGH);
        }
        else if(inputs == "H")
        {
            digitalWrite(relay8, LOW);
        }
        else if(inputs == "h")
        {
            digitalWrite(relay8, HIGH);
        }
        inputs="";
    }
}


texts: Can you charge and use a LiPo battery at the same time?

texts:
I have a system that uses an Arduino Uno board as a "brain". All the elements in the system are powered by a single LiPo battery (3cell, 11.1V, 1800mAh). I made a circuit so the arduino can check the battery voltage and decide when it needs to recharge. I also have a circuit that controls the battery charge sequence and interrupts the power when the battery is charged, sending a signal to the arduino interrupting it's power saving mode. The arduino enters the power saving mode when the charging sequence is initiated. The charging circuit uses 12V and 450mA which I plan to supply with a 12V 6W solar panel.

My question is: can I charge the battery while the arduino is still on, but on power savig mode?

If not, how can I make this system self charging while keeping the arduino continuously on?


texts: Stuck in While loop when case is activated. Arduino

texts:
I have an arduino uno that controls a light using an ir remote. The sketch works fine until I pressed button c which is case 0x10EF58A7. This case reads in values and dims the light accordingly but the only problem is i can not exit the case when another button on the ir remote is pressed! what should i do!?

#include <SoftwareSerial.h>

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

#include <TimerOne.h>

int RECV_PIN = 13;

IRrecv irrecv(RECV_PIN);
decode_results results;
volatile int i=0;               // Variable to use as a counter
volatile boolean zero_cross=0;  // Boolean to store a "switch" to tell us if we have crossed zero
int AC_pin = 7;
int dim2 = 0;                   // led control
int dim = 128;                  // Dimming level (0-128)  0 = on, 128 = 0ff
int pas = 8;                   // step for count;

int freqStep = 65;
char incomingByte;

void setup() {
  Serial.begin(9600);
  // initialize the digital pin as an output.
  pinMode(RECV_PIN, INPUT);
  pinMode(AC_pin, OUTPUT);
  irrecv.enableIRIn(); // Start the receiver
  attachInterrupt(0, zero_cross_detect, RISING);    // Attach an Interupt to Pin 2 (interupt 0) for Zero Cross Detection
  pinMode(AC_pin, OUTPUT);
  Timer1.initialize(freqStep);                      // Initialize TimerOne library for the freq we need
  Timer1.attachInterrupt(dim_check, freqStep);
  // Use the TimerOne Library to attach an interrupt
}

void zero_cross_detect() {
  zero_cross = true;               // set the boolean to true to tell our dimming function that a zero cross has occured
  i=0;
  digitalWrite(AC_pin, LOW);
}

// Turn on the TRIAC at the appropriate time
void dim_check() {
  if(zero_cross == true) {
    if(i>=dim) {
      digitalWrite(AC_pin, HIGH);  // turn on light
      i=0;  // reset time step counter
      zero_cross=false;    // reset zero cross detection
    }
    else {
      i++;  // increment time step counter
    }
  }
}

 void translateIR() // takes action based on IR code received
{

  switch(results.value){

  case 0x10EFD827:
  //power button
   dim = 00;
    Serial.println(" full brightness ");
    break;
  case 0x10EF20DF:
  //circle button
  dim = 128;
    Serial.println("off   ");
    break;
  case 0x10EFF807:
  // button A
  dim = 95;
    Serial.println(" dim level 1   ");
    break;

   case 0x10EF7887:
   //button B
   dim = 50;
    Serial.println("dim level 2     ");
    break;

 case 0x10EF58A7:
 // button C
 {
  while ( Serial.available() > 0) {
 unsigned int num = Serial.parseInt();
 num = map(num, 0, 255, 0, 128);
 unsigned int num1 = map(num, 0, 128, 128, 0);
// num1 = constrain( num1, 0,128);
 dim = num1 ;
   Serial.print(" auto   ");
   Serial.println(dim);

   delay(800);
   Serial.flush();
    //break;
   }
  break;
}
 break;

  case 0x10EF10EF:
//button left
    {
    if (dim<127)
   {
    dim = dim + pas;
    if (dim>127)
    {
     dim=128;
    }
    }
    }
    Serial.print(" dimming ammount=   " );
    Serial.println(dim);
    break;

  case 0x10EF807F:

  //button right
   {
      {
  if (dim>5)
  {
     dim = dim - pas;
  if (dim<0)
    {
      dim=0;  // in vechiul sketch era 1
    }
   }
   }
   }
     Serial.print(" dimming ammount=   ");
      Serial.println(dim);
    break;

   default:
    //Serial.print(" unknown button   ");
    //Serial.println(results.value, HEX);
{}
  }

}

void loop(){
  int i=0;
   if (irrecv.decode(&results)) {

   translateIR();
        irrecv.resume(); // Receive the next value

   }
     delay(700);
 }


texts: This logic level converter does not want to work

texts:
I got this logic level converter to be able to use my lcd but I can't figure out how to get it to work, the problem is that the current is not passing through. This is the model: TXS0108E

Any help is appreciated.

[EDIT]

A few Combinations that I have tried:

And I tried to swap the voltages, same wiring as in the pictures but 3.3v instead of 5v and vice versa.


texts:
I have a new Uno R3, it's pretty cool and I've enjoyed playing with it.

Now I want to build a couple of things:

1) a market price LCD tracker.

2) a servo motor type thing to open my electric gate.

Both of these either require input from an external website or some kind of message to initiate the action on the Arduino.

How do people generally get data onto the Arduino, I found a lot of conflicting information online.

Does this thing have Wifi or Bluetooth??

I got this pack, it doesn't seem to have either Wifi or Bluetooth, if not how do ppl generally get data onto the Arduino?

I have a raspberry pi spare, can I just use that, sending data from pins?


texts: Very long range wireless communication between two arduinos(500-1000 KM)

texts:
I searched for very long range wireless communications between two Arduinos, but can't find solutions. I don't live in USA, In my country there are regions, where GSM does not work.
I want wireless communication approximately 500-1 000 KMs.
What are options without GSM for that distance wireless communication(500-1000 KM)?


texts: Print when echo is read by HR-S04 sensor

texts:
I'm trying to see when an echo is received by my HR-S04 sensor. I have a Serial.println within my while loop to read the signal and see once a change happens to break the loop.

The issue is my serial just prints out the pin my echo to linked to. How can I set it so that the serial output is LOW and then HIGH once an echo is received?

int trig1 = 3; //Trig 1
int echo1 = 4; //echo1
int ECHO1;
double pingTime1;

void setup()
{
  Serial.begin(9600);
   pinMode(trig1, OUTPUT);  //sets the digital pin 3 as output
   pinMode(echo1, INPUT);  //sets the digital pin 5 as input
}

void loop()
{
  ECHO1 = digitalRead(echo1); //assume echo1 is LOW and HIGH once echo is received

  while (ECHO1 == 0) //continuous loop until echo is HIGH
  {
    digitalWrite(trig1,LOW);
    delay(100);
    digitalWrite(trig1,HIGH);
    Serial.println(echo1); //Troubleshooting to see when pulse is read by sensor
   ECHO1 = digitalRead(echo1);
  }
  pingTime1 = pulseIn(echo1, HIGH); //Measure ping travel time in microseconds
  pingTime1 = pingTime1*1000; //convert microseconds to seconds

}


texts: [Arduino UNO]Receive Serial Data from multiple sources

texts:
I have the following system:

As a master, I have an Arduino UNO Chip, more specifically an Atmel MEGA328P. The important thing is that this microcontroller has only one hardware Serial port, and that port is used to communicate with a WiFi adapter.

The problem I'm facing with is that I want to receive data from a Compass and a GPS modules. Booth send data via Serial protocol. The 328p Chip have only one serial which is busy!

I can't use SoftwareSerial as I don't want any delay on master board!
I can't also use Arduino Mega2560 which have 3 Serial ports as its sizes are too big.

So there are are my approaches:

Using MCP4725 I2C DAC for Compass, but what we do with GPS?
Using and intermediate Arduino UNO Chip?
On that chip I could use Software serial but how to transfer data to MASTER using only digital and analogic pins? Maybe using 10 pins to implement a parallel transfer?
Perhaps there is possible to convert Compass and GPS data to analogic then transfer to MASTER?

Anyway, what possibilities would I have to play around?


texts: Connect my arduino with ethernet shield to new router

texts:
I just changed the router for my webserver and I'm having trouble to connect my arduino with the LAN.
I'm using a router which uses Zhone technology, and I've been working with NetGear for a while without problems.
The procedure I've done so far is:

Connect the arduino with the ethernet and run the DhcpAdressPrinter example
Once I got the adress, in my case 192.168.1.125 I run the WebServer example, using the IP assigned by the DHCP.
In the serial monitor, I see it has started the program with the correct IP.

Problem: WHEN PUTTING THE IP INTO A BROWSER, NOTHING CHARGES

More info:

In my router page (192.168.1.1) I can see that each ethernet port has
assigned a MAC adress, I don't really understand why.
I also can see that the arduino has been successfully added to the DHCP with the IP assigned and the MAC adress that I wrote on the code
Finally, add that I've read in another website that sometimes the problem is due to the fact that the router just let the access to some specific MAC adress, but i'm not sure.

Any help will be apreciated! Thanks!


texts: Problem with biased circuit for oxygen sensor (SGX EC410)

texts: I have designed a circuit for an SGX EC410 oxygen sensor by using these application note -PAGE 4, FIGURE 4 - (http://www.sgxsensortech.com/content/uploads/2014/08/A1A-EC_SENSORS_AN2-Design-of-Electronics-for-EC-Sensors-V3.pdf). When I try to measure the biased voltage between working (SENS) and reference (REF) electrode, the value of -600 mV is held for about one second and goes down to few milli volts rapidly. The same happens when I connect the sensor without voltmeter. Am I doing something totally wrong, or the circuit is not quite right?


texts:
I'm trying to write some extremely fast code for the ESP8266, so I'm trying to figure out how to time things.  I've discovered CCLOCK, a register that reflects the number of clock cycles since startup. (https://github.com/esp8266/Arduino/issues/4632#issuecomment-380632906, and other references.) In testing it out, though, I've encountered some weird behavior.  Consider the following code:
static inline volatile uint32_t asm_ccount(void) {
    uint32_t r;
    asm volatile ("rsr %0, ccount" : "=r"(r));
    return r;
}

char outgoingPacket[4];

...

void loop() {

  // ... some stuff ...

  uint32_t startTime = asm_ccount();
  uint32_t stopTime = asm_ccount();
  uint32_t elapsed = stopTime-startTime;

  outgoingPacket[0] = (elapsed >> 24) & 0xff;
  outgoingPacket[1] = (elapsed >> 16) & 0xff;
  outgoingPacket[2] = (elapsed >> 8) & 0xff;
  outgoingPacket[3] = elapsed & 0xff;
  Udp.beginPacket(targetUdpIp, targetUdpPort);
  Udp.write(outgoingPacket, 4);
  Udp.endPacket();
}

(On my computer, I have basically the following Java code running to receive these messages:)
    while (true) {
      DatagramPacket packet = new DatagramPacket(buf, buf.length);
      socket.receive(packet);

      byte[] data = packet.getData();
      StringBuilder sb1 = new StringBuilder();
      StringBuilder sb2 = new StringBuilder();
      for (int i = 0; i < packet.getLength(); i++) {
        sb1.append(String.format("%8s", Integer.toString(((int) data[i]) & 0xFF, 2)).replace(' ', '0'));
        sb2.append(String.format("%2s", Integer.toString(((int) data[i]) & 0xFF, 16)).replace(' ', '0'));
      }
      System.out.println(sb1 + " " + Integer.parseInt(sb2.toString(), 16));
    }

(Yes, it's a little hacky, I know, but the results have seemed correct.)
Now, most of the time, the output looks like
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000000000000001 1

But about 5 times in 77000, I'll get lines like
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000000110101000 424
00000000000000000000000000000001 1
00000000000000000000000000000001 1
...
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000010010100001 1185
00000000000000000000000000000001 1
00000000000000000000000000000001 1
...
00000000000000000000000000000001 1
00000000000000000000000000000001 1
00000000000000000000010001001100 1100
00000000000000000000000000000001 1
00000000000000000000000000000001 1

I ran the code for 1 minute 4 seconds, and got 3 counts of 424, 1 of 1100, and 1 of 1185.  It seems particularly odd that 424 would show up three times.
Given that, as far as I understand, the relevant lines of code (the two calls to asm_ccount) would have been compiled to a given set of instructions, I'd have expected it to take exactly the same number of cycles every time.
Why is this not happening?
Is it interrupts?  Something something caching?  Does that register not actually work as claimed or as I understand?  Have I done something dumb in the transmission or logging code?  Something else?


texts: When trying to write multiple bytes to a serial port, all 0x00s are skipped

texts:
I am using a dynamixel XL320 servo, and am trying to control it using an Arduino Uno. I’m trying to send a simple packet that turns on an LED. I believe the correct format of this packet according to the dynamixel documentation is the following: FF FF FD 00 01 09 00 03 19 00 01 00 00 00 3F 1D (However, the correctness of this packet at the moment is ultimately unimportant to my problem). Before actually writing any more of my servo library, I decided to try to just send an array using Serial.write, to ensure that would transmit properly. I used puTTY session logging, and then a hex editor to track what was actually sent. The results are:
FF FF FD 01 09 03 19 01 3F 1D.

I’ve seen other issues where 0x00 is interpreted as null in a string and so a string like 0x10, 0x00, 0xDD would only send 0x10. But here as an array that shouldn’t be a problem. Here, it seems like the 00’s are just being skipped. Would really appreciate help here, and please let me know if more clarity is needed this is first time posting here.

My code for this test is as simple as I could think to make it:

Serial.begin(9600);
while(!Serial) {;}
uint8_t data[16]= {0xFF, 0xFF, 0xFD, 0x00, 0x01, 0x09, 0x00, 0x03, 0x19, 0x00, 0x01, 0x00, 0x00, 0x00, 0x3F, 0x1D};
Serial.write(data, sizeof(data));```


texts:
I will start an Arduino project and its main requirement is that some RFID readers (at most 6 readers) be connected and controled by the arduino board.

I do not have a strong background in eletronics, and therefore I do not have any idea in how to start it. Is it possible to connect more than one RFID reader to an Arduino board? If it is possible, which reader is the best for this porpouse?

Another requirement of this project is the need to send the data collected by each RFID reader to a PC server through WIFI. For this what is better to use, an Arduino UNO with a WIFI shield or an Arduino YUN? What is better and why?

Thanks!!!


texts: Where to declare timer interrupt variables?

texts:
I have a situation where the majority of the code is residing inside timer interrupt functions.

Setup() does what it has, loop() basically reads ADCs and then all the code is inside timer interrupts.

void loop()
{
  //Read the ADCs
  while((ADC->ADC_ISR & 0x1CC0)!=0x1CC0);   // wait for ADC 0, 1, 8, 9, 10 conversion complete.
  in_ADC0=ADC->ADC_CDR[7];                  // read data from ADC0
  in_ADC1=ADC->ADC_CDR[6];                  // read data from ADC1
  POT0=ADC->ADC_CDR[10];                    // read data from ADC8
  POT1=ADC->ADC_CDR[11];                    // read data from ADC9
  POT2=ADC->ADC_CDR[12];                    // read data from ADC10
}

void TC4_Handler()
{
 if (effect==0)       {/*HERE THE CODE FOR EFFECT 0*/}
  else if (effect==1)  {/*HERE THE CODE FOR EFFECT 1*/}
    else if (effect==2){/*HERE THE CODE FOR EFFECT 2*/}
      else             {/*HERE THE CODE FOR EFFECT 3*/}

  // We need to get the status to clear it and allow the interrupt to fire again
  TC_GetStatus(TC1, 1);
}

The user selects the effect he wants via a button and a hardware interrupt.

What happens when the timer interrupt function ends? Do we go back to loop(), or the timer function is re-run?
In this example, all the vars needed inside each functino of the timer interrupt are declared globally.

I was considering if i can declare variables inside each function in the Timer Interrupt function.
Therefore, we would save space, by not declaring variables that are not run at the moment. And we would only initialize variables for the effect we want.

Is this possible? Because if the effect i have just selected just re-loops, maybe its not wise for vars to get re-initialized  (and their values re-set) each and every time it is looped.

So ultimately, variables taht will be used inside a timer interrupt function, globally or locally?


texts:
I want to power my board using a 9v battery. I also want to power a component in my circuit from the same power source (9v battery) but ONLY when my board sends a signal (say from D1 pin).
What component allows me to restrict power this way? I don't want to activate the component through signal, but actually power it after the signal is sent.


texts: Do we need another controller when using ArduPilot?

texts:
I'm a newbie on the all Arduino platform and I'm currently building a drone with Autopilot functionality. I've heard about ArduPilot and I'm wondering if that is all I need, in terms of controllers (I'm excluding the ESC, engines, and the rest). Can I simply program the ArduPilot, connect a Wireless interface to it and merrily be able to control it ?

Cheers,
r


texts:
There is no GY-30 light sensor part design in the standard Fritzing repository.

Is there an official alternative part repository containing Fritzing fzpz file for this sensor?  Does it go by any other name or part code?


texts: Arduino Due custom platform for school and library installation

texts:
I have made a custom-development hardware for our school, where you can plug in an Arduino Due. It is mainly for driving all kind of motors and reading sensor signals. Therefore I added a custom SAM board into board.h based on a copy of the Arduino Due. Furthermore I need a global PWM frequency on all PWM Channels of 20 kHz. So I also changed the variants.h file.

(I have not found a solution that is setting all the underling Timer/Counters for PWM on the Due Pins 2, 3, 4, 5, 6, 7, 8, 13 to 20 kHz by user code, I think this is only possible with the variants.h file - because some timers can not be reset after they where set within the Arduino IDE once)

The Question now:
Today all students have to find and modify their variants.h file, which can be located almost anywhere! (Sometimes it is located in the support packages of Matlab...).

Is there an easy solution to give the students one .zip containing the Arduino IDE already with the custom Board included?
There is the Arduino IDE working without installation for download on the Arduino website. But how can I add my custom SAM board to it?


texts: What Version of the Sketch did I leave on there?

texts:
Is there a way to "ask" the Arduino what sketch was compiled on it?

There are several versions of the sketch and I need to see which version the Arduino has been running.


texts:
Im quite new to arduino in general and i'm sorry for the beginner question.
could someone explain what the 3.3v and 5v on boards do? I know their voltages. but can you run one on the other? whenever i try to search about it i see people saying that most newer modules are running on 3.3v so they convert their 5v arduino to 3.3v. something about if you run one on the other it could break it.

the arduino I bought looks like it has both! is that even possible?
 I also purchased this LED matrix as I wanted to make a wifi enabled scrolling text display. the matrix says it requires 5v. since this arduino says vin is 5-12v the two should connect and work properly, right?


texts:
I am using the Arduino IDE 1.6.0,
There is a project that has compiled both for Due and Mega on another computer. But on my machine, it only compiles for Due. When compiling  for "Mega or Mega 2560", I get the following error:

  /Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld: skipping incompatible /Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/lib/libc.a when searching for -lc
      /Arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld: cannot find -lc
      collect2: error: ld returned 1 exit status
      Error compiling.

My newbie guess is something is wrong with AVR libraries. But how to solve it? Also could someone please explain what -lc is, which cannot be found? At first glance it looks like an option.


texts: Problems controlling servos using proximity sensor

texts:
I've just started using Arduino and I need to make a code to simulate the behavior of a lizard, meaning that if you come close to it, it moves away from you.

I'm using a "Arduino duemilanove" that my university lend me, I was told that it was an alternative version of Arduino Uno.

Both of the servos says "Tower Pro, mg996r, digihi-speed"

Looking different codes I made one which I think is correct. Also, I checked for each servo motor (I'm using two) and the proximity sensor running codes for everyone of them alone, if they worked well and they did but with this code, they supposed to move when you are closer than a meter but they don't stop spinning.

If anyone could help me with this, it would be great.

Here is the code:

#define Servo1 9
#define Servo2 11
#define trigPin 10
#define echoPin A0

#include <Servo.h>

Servo servo1;
Servo servo2;

int pos = 0;    // variable to store the servo position

void setup() {
  Serial.begin (9600);
  pinMode(echoPin, INPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(Servo1, OUTPUT);
  pinMode(Servo2, OUTPUT);
  servo1.attach(9);
  servo2.attach(11);

}

void loop(){
  long duracion, distancia; // variables

  /* Hacer el disparo */
  digitalWrite(10, LOW);
  delayMicroseconds(2);
  digitalWrite(10, HIGH);  // Flanco ascendente
  delayMicroseconds(10);        // Duracion del pulso
  digitalWrite(10, LOW);  // Flanco descendente

  /* Recepcion del eco de respuesta */
  duracion = pulseIn(A0, HIGH);

  /* Calculo de la distancia efectiva */
  distancia = (duracion/2) / 29.1;

  if (distancia<100){
    for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees
    {                                  // in steps of 1 degree
      servo1.write(pos);    // tell servo to go to position in variable 'pos'
      servo2.write(pos);
      delay(15);                       // waits 15ms for the servo to reach the                 position
    }
    for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees
    {
      servo1.write(pos);              // tell servo to go to position in variable                 'pos'
      servo2.write(pos);
      delay(15);                       // waits 15ms for the servo to reach the position
    }

  }
  else{
  }
}


texts:
I have a project that requires 4 different RFID-RC522 readers.  The RFID-RC522 has the following pins:

SDA
SCK
MOSI
MISO
IRQ
GND
RST
3.3V

I have read that the SDA pin is used for selecting the active device, So I'm thinking that these devices can share data pins.  Is it possible to connect multiple RFID-RC522 readers to the same 3.3V, RST, GND, IRQ, MISO, MOSI and SCK pins if you use a different pin for each SDA?  If so, this would save me a lot of pins.  So far, I have only seen direction on how to connect one RFID-RC522 to an Arduino.

I'm using the MFRC522 library.  It appears to only support one reader because it only allows one SS pin to be identified in the constructor, and offers no way to change it later.  An I missing something or do I need another library?


texts: Using Arduino microcontrollers without board

texts: I am new into Arduino. So if I program the microcontroller using the Arduino board and once it is doing what I want can I just take the microcontroller out of the board and use the microcontroller itself? If so could you please guide me to some tutorials on how to use it?


texts:
I set out to see how much space some arrays have. I used this test code

bool state = false;

uint16_t BuffA[46000];
uint16_t BuffB[20000];
uint16_t BuffC[20000];
uint16_t all = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
if (state==false){
Serial.println(sizeof(BuffA));
Serial.println(sizeof(BuffB));
Serial.println(sizeof(BuffC));
all = sizeof(BuffA) + sizeof(BuffB) + sizeof(BuffC)
Serial.println(all);
state = true;
  }
}

I got this answer from the serial:

92000
40000
40000
40928

Why are the results doubled from those i initiated? Shouldn't the first one be 46kb and the other two 20kb?
Why is the last value only 40928?
The RAM of Due is 96kb. Does this mean that with the initialization of only three arrays it's almost full? Ifi crossed the RAM limit, would the IDE throw an error?
If i still need more RAM, can i use and external one with Due for high speed RAM acquisition?


texts: I fried my arduino. Can I upload code wirelessly?

texts:
So, I'm a complete arduino newbie. I left a live wire close to my arduino and part of it burnt (underneath the USB output). The LED that indicates power still turns on when I plug it into my computer, and a simple LED circuit on my breadboard, when hooked up to the arduino, still works. The only thing that's wrong is that my computer doesn't recognize the Arduino serial port any more, so I can't upload any code onto it.

I also own a bluetooth HC-05 module. Is there any way I could upload code onto my Arduino wirelessly, using that? Or am I better off just buying a new one?


texts: RS485 Multimaster Communication with collision avoidance

texts:
I'd like to know if there is an easy way to implement communication between multiple arduinos that avoids collisions using the RS485 module.

My setup would have multiple masters that send messages to only one slave that performs a task upon been given the message.

I've tried researching some libraries for this, but they normally don't fulfil the multimaster requisite, nevertheless I found this library which apparently does implement what I need, but I haven't been able to understand how it works.

My current options are either finding an easier library that is capable of doing what I need, learning how to make the linked library work (which I have already tried) or building my own serial communication protocol that implements collision avoidance and a multiple master configuration.

What path should I follow? Can you give me any recommendation for any of the paths I'm suggesting? Is there a better way of implementing this type of communication?


texts:
I've been coding for FreeRTOS on the MEGA 2560, and was using some LEDs to determine activity per task by toggling each individual LED each time through the task, and monitoring the time using a scope on the LED pin(s). All worked fine until I added the code for the last task.

Only the LED for the last task showed activity, and I assumed I screwed up in the new code, and spent a full day re-doing the code and troubleshooting. Well, it turns out that the code was working just fine. The problem appears to be RTOS is not manipulating the appropriate LED for each task, but using some other pin. The same configuration but with simple test code works fine.

I've tried just about everything I know, with negative results. The 3 tasks are running OK (I still need to do much more testing) so it's not like there is an issue with stack overflow, plus I decided to make ALL the variables as global variables to minimze stack use, and possible conflicts with the variables, which were the same on two of the original programs. I'm using about 600 bytes of RAM for those variables, and have tons of spece in the MEGA in all aspects. The code only uses 14K of the 256K available.

So, I'm officially stumped, and I assume that there's a problem with the task switching somehow, but I'd expect the code to crash eventually if that were the case, but it runs for hours and hours.

Does anyone have any real experience with FreeRTOS that have experienced similar issues related to simple digitalRead and/or digitalWrite problems similar to what I'm seeing?


texts:
I am working in a project in order to measure spend time.
My sitution is:

There is a competitor that will start the game after he (or she) heard a sound (could be a sound like buzz or whistle).

This sound should be fired by a person, a referee (maybe using a button).

After hear the sound, the competitor will press some buttons near or far from him (depends on the game) as fast as possible.

Who press the button in less time will be the winner.

What a need:

I need to measure the time spend between the sound (fired by referee) and the first button.
The accuracy must be by milliseconds (because some buttons are near him)
The equipment must be near ear competitor, because he will be using a ear muff.

Those buttons are connected by wire on arduino. So, I know the exact time that button is pressed. Using millis() function, I know the pressed time for each button.
Measuring the pressed button is easy, it is ok.
I would like to know, which equipament can I use to  emit a sound and register the exact time that was emmited, in other words, arduino register the current millis().
If I can register the start time I know the spend time between the start and the first pressed button.
The referee equipment must be wilerless (without wired connection with arduino) and works in a far distance from arduino (maybe 50 mts).


texts:
I very accidentally caused a short-circuit to two completely different cheap (under 4$ each) Arduino Uno clones, rendering Windows sound alert for unplugged USB several times.

This subsequently led to a problem with uploading code and not blinking green light on reset on both the Arduinos. Now, I am aware what this means but I am unable to see why this happens. I thought it has protection against that.

Is it normal for them to react like that so easily? How can I prevent this happening AGAIN?


texts: What is the best way to define an I/O pin?

texts:
I read definitions like

const int ledPin = 9;

and also

#define ledPin 9

I know that a definition like

int ledPin = 9;

is a bad practice if you're not going to change it (which you usually won't), though I've see this several times in Arduino programs.
Which one of the other two is preferred?


texts: Combined code and nothing works. Head scratcher for sure

texts:
I have spent a little over 2 hours trying to debug this code. All I did was combine a section of code to write to the SD card. Both of the codes work fine on their own. I can't figure this one out. I am hoping fresh eyes can spot the error. I am using a Arduino Nano with a Robot-Deek data logger board. Pin 10 is used for the data logger. I was using a DTH11 but switched to a LM35, both codes worked with LM35.

#include "RTClib.h"
#include <SD.h>
#include <SPI.h>
#define sample 500
#define current_ms millis()
RTC_DS1307 rtc;
File myFile;
int inPin = 0;   //analog in
float val;       //where to store info from inPin reading
int pinRed = A3;  //output of red led
float tempin = A5;  //input of temp sensor
float tempf;     // variable to hold temp in Fahrenheit
float vout;      // variable to hold voltage from sensor
int array1[sample];  //creates an array with number of elements equal to "sample"
unsigned long averaging;  //the program uses this variable to store the sum of each array it makes
int pinCS = 10;   // write to SD card
float last_dht11_reading_ms = 1;
DateTime now = rtc.now();
#define DHT11_SAMPLE_DELAY 500

void setup() {

  Serial.begin(9600);
  delay(500);//Delay to let system boot
  SD.begin();
  pinMode(pinCS, OUTPUT);
  pinMode(tempin, INPUT);
  Serial.println("Volt and Temperature\n\n");
Serial.println("middle the setup loop");
 // SD Card Initialization
  if (SD.begin())
  {
    Serial.println("SD card is ready to use.");
    File myFile = SD.open("Datalog.csv",FILE_WRITE);
    if (myFile) {
      myFile.println("Time, Temp, Volt");
      myFile.close();
    }
  } else
  {
    Serial.println("SD card initialization failed");
    return;
  }
  rtc.begin();
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}//end "setup()"

void loop() {

  for (int i = 0; i < sample; i++) {         //this code tells the program to fill each element in the array we made with
    array1[i] = analogRead(inPin);           //information from the antenna wire coming out of the Arduino
    averaging += array1[i];                  //more information about for loops http://arduino.cc/en/Reference/For
  }                                          //the averaging line is simply saying: add averaging to whatever is in array position i
                                             //averaging += array[i] is the same as averaging = averaging + array[i]

  val = averaging / sample;                  //here the program takes the sum of all numbers in array1, and divides by the number of elements "sample"
  val = constrain(val, 0, 100);              //this constrains the variable value to between two numbers 0 and 100
  val = map(val, 0, 100, 0, 255);           //for more information about constrain http://arduino.cc/en/Reference/Constrain
  analogWrite(pinRed, val*20);                  //the map statement tells the program to map out 0-100 to 0-255
  averaging = 0;                                 //this line of code sets averaging back to zero so it can be used again
Serial.println("past the emf loop");

  if ( (current_ms - last_dht11_reading_ms) > DHT11_SAMPLE_DELAY ) {
    vout = analogRead(tempin);                //read LM35 output
    float mv = (vout/1024)*5000;              // conversion to mV
    float celc = mv/10;                       // convert to C
    float tempf = ((celc*9)/5 + 32)/10;       // convert to F
    myFile = SD.open("Datalog.csv", FILE_WRITE);      //open datalog file on SD card

  if (myFile) {                              //write to the SD card time, tempf and val
    myFile.print(now.hour());
    myFile.print(":");
    myFile.print(now.minute());
    myFile.print(":");
    myFile.print(now.second());
    myFile.print(",");
    myFile.print(tempf);
    myFile.print(",");
    myFile.println(val);
    myFile.close(); // close the file;    // close the file
    last_dht11_reading_ms = current_ms;
  }
Serial.println("past the logger loop");
  //delay(1000);//Wait 1 seconds before accessing sensor again.

}
}
// end loop()


texts:
In the following code I'm computing crc and setting it as last (11th) byte in the array. The problem is it's sent on I2C just when I print it on the serial terminal.

  static constexpr uint8_t CLICK_MESSAGE_SIZE{11};
  ...
  uint8_t buf[CLICK_MESSAGE_SIZE];
  memcpy(buf, msgMouseClick[clickMessageCounter], CLICK_MESSAGE_SIZE);
  buf[10] = dallas_crc8(buf, 10);
  Serial.println(buf[10], HEX); //!!!has to be here, otherwise is CRC in packet wrong!!!
  Wire.write(buf, CLICK_MESSAGE_SIZE);

When I'm assig the result of to

auto crc = dallas_crc8(buf, 10);
buf[10] = crc;
Serial.println(crc);

and Serial.print ing it. Then It's works. But with  const auto crc = dallas_crc8(buf, 10); It does not!

I have slightly modified Wire library, where I'm passing pointer to the buffer and it's size. With precalculated CRCs on 11th position it's working fine even for hundreds of bytes arrays.

It feels like a black magic, or compiler error. I'm using latest arduino-1.8.10

Any tips or hints?


texts: How to get a button state change within a for loop?

texts:
I have a for loop inside my void loop() that triggers a piezo.

What I want to happen is when I press a button, it breaks the loop of the piezo, but right now, it's as if it isn't detecting the button press inside my for loop.

Here's my code:

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define TONE 8
const int buttonPin = 2;

long fadeTime = 5 * 1000L; // X minutes
int colorStops = 256;
int delaySpeed = fadeTime / colorStops;
int notes[] = {262,294,330,349};
int switchState = 0;         // variable for reading the pushbutton status

Adafruit_NeoPixel strip = Adafruit_NeoPixel(5, PIN, NEO_RGB);

void setup() {
  pinMode(buttonPin, INPUT); // initialize the pushbutton pin as an input

  strip.begin();
  strip.show();
}

void loop() {
  // read the state of the pushbutton value:
  switchState = digitalRead(buttonPin);

  // Fade in light
  for(int i = 1; i<colorStops; i++){
    for(int np = 0;np<strip.numPixels(); np++){
      strip.setPixelColor(np, strip.Color(i,i,0));
    }
    strip.show();
    delay(delaySpeed);
  }

  // Play tone after light fully bright
  for(int i = 1; i<100; i++){
    // Turn off tone on button press
    if (switchState == HIGH) {
      noTone(TONE);
      break;
    }
    tone(TONE, notes[random(0,3)]);
    delay(100);
  }
}

Does switchState = digitalRead(buttonPin); only get called at the start of the void loop and so it can't detect the button change until then? Something else?

Also, in case it's useful, here's my hardware set up...


texts: Can I prevent the Stepper library from holding the motor?

texts:
I'm using the Stepper library to control a single stepper motor. When the Arduino is not running the motor it is holding the motor shaft in place. For my application, this is very wasteful and puts unnecessary strain on the motor.

Is the Stepper library supposed to do this or is something else up with my circuit? Can this behavior be overridden?


texts: send and recieve analog data from one arduino to another arduino via web/ethernet

texts:
i am able to send audio signal through mic and send it via arduino and receive it on speaker.
i need two things
1.) The voice i am hearing on speaker has on speaker has lots of noise with it. i need to reduce it
2.) I need to send that analog signal received  from the mic via Ethernet/web to another arduino. i have Ethernet shield i am able data from switch but not from mic.
let me start from the beginning, i have attached mic to the audio amplifier and have attached output of the amplifier to the a0 pin of the arduino. The arduino is connected to the DAC(PCF8519) with a5 and a4 pin of the aurdino. The output of the dac is connected to the LM386 audio amplifier module and its output is connected speaker. when i speak via mic i am able to hear it on speaker but it has has some noise attached to it. IF you can suggest solution for that it will be great.
now i want to send the data of the mic to another arduino via web/Ethernet. i am able to get the data of the switch but not been able to get proper data from the mic.So pls help out with that.
here is my audio amplifier circuit:

here is my code for one arduino code that worked
`#include "Wire.h"`
 #define PCF8591 (0x90 >> 1)
 void setup()
  {
    Wire.begin();
    pinMode(0,INPUT);
   }
 void loop()
   {
     Wire.beginTransmission(PCF8591);
     Wire.write(0x40);
     Wire.write(analogRead(0));
     Wire.endTransmission();
   }

I need to reduce the noise on the speaker and i want to send the data of the mic via web/Ethernet to another arduino.


texts: I want to make two arduino to communicate over different wifi. Is that possible?

texts: I want to make any 2 Arduino module from different places to communicate over wifi. I really need to know if it possible? If yes, advice me more about it. I want send data from sensor module from one Arduino to another and vice versa. That's the basic idea. Do I need a third party services such as cloud services to make it happen? Or simply can send ovee wifi with the help of Ip adress. Sorry, I have less knowledge on this. Help me out. Thank you in advance.


texts: Serial Communication over Desktop to Arduino

texts:
I have a USB 2 Serial adapter and the device is working fine. I see the device perfectly configured in my System.

I have connected the TX0 pin of Arduino to DB 2 pin (read pin) of the adapter. Below is my Arduino code:

int i = 0;
void setup()
{
  Serial.begin(9600);
}

void loop()
{
  for(i=0;i<6;i++)
  {
  Serial.write('H');
  delay(100);
  }
}

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?


texts:
I'm pulling together a project for my class where students build a solar panel structure/frame that moves with the sun to capture more power than if the panel was just flat on the roof.  I can handle controlling the motors, but I wanted some help to make sure I safely/accurately measured power.
I have an Arduino (the model isn't especially important), a 12V deep cell battery, and 6 V solar cells.  Obviously I don't want to hook the cells straight to an analog pin, but I came up with the schematic below.  The wire to the battery will go through the CT (the inductor) to get current in order to calculate power.
Would the battery still charge even if the cells are only producing, say, 8V ?  Am I overlooking anything or is there any circuit protection I need to include?  Maybe a computer fan as a load on the battery and to cool everything?  Any help is appreciated.  Thanks!


texts: MAX7219 library that can compensate for poorly designed/miswired 8x32 panel?

texts:
I have this sample code:

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define MAX_DEVICES 4
#define CLK_PIN   11
#define DATA_PIN  12
#define CS_PIN    10

MD_Parola P = MD_Parola(DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

void setup(void) {
  P.begin();
  P.print("PPPPPPPP");
}

void loop(void) {
}

And this is how it lights up the display:

I presume that the code displays text incorrectly, because the display manufacturer has connected individual 8x8 displays "differently than any library expects" (i.e. in red I have annotated the column addresses for my display, while with green I have annotated what they would have to be for this library to show text correctly).

I have two questions:

Is there any good Arduino graphics library that would allow me to fix from software the addressing issue specific to my display?
Since in the future I plan to make a 16x64 display out of 4 of these, then is there a library capable of doing that as well (i.e. have vertical font size of 12-16 pixels)?


texts: LCD display not working properly + inconsistent results

texts:
I have soldered the pins to my 20x4 LCD display. The soldering is not very good, but this is the best i can do. I have measured the resistance between each of the pins of the LCD with my multimeter to check if the pins are isolated. And they are! So the bad soldering is not the problem...

Last night, the display showed weird results and non-existent characters, all over the 20x4 display.
This morning, it showed only full blocks. But now it is showing only 2 of the 4 rows.
I think this is weird because i did not touch it in my sleep...

I should see the text 'Welcome', but i only see blocks now.

I dont have a potentiometer any more, so i used a for-loop with a PWM signal to check the contrast i need. This did work the last time for me.

I use the arduino MEGA.
Below you see my code, and photo's of my little project.

#include <LiquidCrystal.h>
LiquidCrystal lcd(9, 10, 48, 46, 44, 42);

const int contrastPin = 8;

void setup() {
  // put your setup code here, to run once:
  lcd.begin(20,4);
  pinMode(contrastPin,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:

  lcd.setCursor(0,0);
  lcd.print("Welcome");

  //LOOP TO CHECK TE CONTRAST
  for(int i = 0; i <= 255; i++){
    analogWrite(contrastPin,i);
    delay(30);
  }
}


texts: What is the function of the /// and ///// in enclosed code

texts:
///
   display.clearDisplay();
   display.drawRect(1, 1, display.width()-1, display.height()-1, WHITE);
   display.setTextSize(2);
   display.setTextColor(WHITE);
   display.setCursor(5,5);
   display.print("Set Time:");
   display.setTextSize(3);
   display.setCursor(7,24);
   display.print(val);
   display.setCursor(50,24);
   display.print("Min");
   display.setTextSize(2);
   display.setCursor(5,48);
   //  display.print("any message!");
   display.display();
/////
if(a==0 && b==1 && c==1)


texts: Use Wii Remote and Arduino to emulate a keyboard for Windows 10?

texts:
Is it possible to use an Arduino to communicate with a Wii Remote, connect the Arduino to a Windows 10 computer, and have the Wii Remote inputs be translated into keyboard keys for Windows 10?

I've used several Wii Remote Windows 10 apps, such as WiiUSoft, but I find such programs very unreliable.

Thanks for any help.


texts: Fatal Exception Error on ESP8266 + Arduino

texts:
When I was trying to blink an LED using ESP8266, I had an issue with it. After successfully uploaded the code (https://diyhacking.com/esp8266-tutorial/), the blue LED stayed on & when I opened the serial monitor using Arduino IDE 1.6.12, I only saw "Fatal Exception" error (showed in the picture). I couldn't see how the code works and the worst thing was I couldn't even try the AT command.

The connections:

Arduino <--->   ESP8266 (ESP-07)

Tx  <--->   Tx
Rx  <--->   Rx
GND <--->   GPIO0
GND <--->   GND
3.3v<--->   CH_PD
3.3v<--->   VCC
            GPIO2 -> LED

I have been trying to troubleshoot this issue but haven't got the solution yet. I am afraid there is an issue with the firmware or the worst situation, I spoiled my ESP8266.


texts:
I have a strange behavior, using ESP32 devkit v.1 boards.
Everything works, I can upload blink sketch, serial works, led blinks.
However, once I upload any sketch which is using the wifi.h (and utilizing it for example calling WiFi.mode(WIFI_STA);), upon upload, the board keeps resetting the serial connection, stays up for not more then 1 second, resets again, and so on.
I could not debug the issue, since serial is unusable. Any ideas what is wrong? I did a fresh ArduinoIDE, ESP32 board manager install, etc. and normal sketches work flawlessly.


texts: Is there a way to replace an Arduino core function without modifying the Arduino code?

texts:
(Let's just skip the suggestions that it's the wrong idea and interrupts for a while...).

Is there a way to replace the digitalWrite() method (for example) so I can add something more to happen in there? But the following rules must be obeyed:

A call to digitalWrite(pin, value) must invoke the new method.
A call to digitalWrite(pin, value) from a different library included in my code (SD.h for example) must invoke the new method.
None of the Arduino files can be modified (I don't want to do it on every Arduino version upgrade).
Everything must be done in a header file that I can include to use the new function.

I have tried this and it works, but only in my code, not in external libraries that I include after this header:

#include <Arduino.h>

class PinsHook {
  public:
    static void digitalWriteHook(uint8_t pin, uint8_t value) {
      digitalWrite(pin, value);
      if (pin == 8) {
        Serial.print("Pin ");
        Serial.print(pin);
        Serial.print(" changed to ");
        Serial.println(value);
      }
    }
};

#define digitalWrite(pin, value) PinsHook::digitalWriteHook(pin, value)


texts: Strange characters after typing an AT command in serial monitor

texts:
I'm trying to test AT commands (I am working with an  Arduino Uno and a GSM/GPRS SIM900  shield; my system is ubuntu 14.10) . Yesterday when I was testing , all  ran well.. For example after typing AT+SAPBR=3,1,"APN","ooredoo" in the serial monitor it  showed me OK.. but But now it  shows me strange  characters.

This is my code

    #include <SoftwareSerial.h>
    SoftwareSerial GPRS(2,3);

void setup() {
  // put your setup code here, to run once:
 GPRS.begin(9600);
  Serial.begin(9600);
 Serial.write("start");

}

void loop() {

  // put your main code here, to run repeatedly:
     while(GPRS.available())
     Serial.write(GPRS.read());

  while(Serial.available())
    GPRS.write(Serial.read());

}

And this it is the result of AT+SAPBR=3,1,"APN","ooredoo" typed in the serial monitor

Thank you for helping me


texts: avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

texts:
So I try to compile and upload a simple code such as the Basic Blink.
I have not connected it to pin 0 or pin 1.

There is an LED with the "L" label on the card that works. So I guess not the chip is damaged?

I have selected the correct model which is Arduino Uno / Genuino. I've checked the drivers several times now, even reinstalled Arduino Software twice and tried on 2 different computers.

5V works with ground, I can get the LED to light up. But I cannot compile / upload code.

Error MSG: avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
(this message repeats 10 times with attempts)

I read something about bootloader, but I have no idea how to do this / what it is. I do not have the right components for bootloading I guess.

Also the COM is correct. I've tried using all the listed COMs without any result. Is this a hardware issue? Is my chip grilled or something?


texts: Uploading a sketch without using the usb cable

texts: I've lost my usb cable used to upload a Sketch to my arduino from my laptop. I do have my Bluetooth 4.0 module. Can I use it to upload my sketches?


texts: Voltage on analog pin arduino when arduino turned off

texts: So can I put a voltage from 0v to 5v on an analog Arduino pin before actually turning the Arduino on? And still read the analog pin correctly when turned on?


texts:
Could the arduino Due take and send image data from 5MP camera module to PC in the following condition?

frame rate = 1fps
resolution = 2592 x 1944
format = 10 bit bayer raw RGB
interface : parallel ports (DVP) between camera and Due
           spi between Due and PC(or SD card)
FIFO(frame buffer): would not be used
SDRAM: would not be used
(But if it is needed, I would SDRAM via spi. Also I can use a frame buffer like AL422B. But if it is possible I would avoid using them.)

The camera would send 50Mbit image data per second and they will be transferred via 8 parallel lines(D0~D7) to the Due. And then they would go to PC directly or after passing SDRAM. But how can one evaluate if the 84Mhz is enough to do this job by calculation?

Arduino Due specs
https://www.arduino.cc/en/Main/arduinoBoardDue

camera module example (OV5642)
http://www.uctronics.com/cmos-camera-adapter-board-for-omnivision-image-sensor-p-248l.html
But this is not what I want to use. In my project I need to build a camera module and it would not include FIFO unless it's highly recommended.


texts: Getting the average of sound in last minute

texts:
I am reading sound input every 60 seconds and I would like to calculate the average of sound during that period using non-blocking code; what should I do to change the way that I calculate it in separated function as I need to do something else with other sensors.

int calculateSoundValue(){
    int average = analogRead(0);
    // loop to calculate the average simple formula sum div nbr of calculated times
    return average;
}

void setup() {
    Serial.begin(9600);

}
void loop() {
  // I donùt wanna calculate the average inside a loop but instead inside a function
  int value = calculateSoundValue();
  Serial.println(value);

  delay(600);
}

UPDATE

Is this what you mean ?

unsigned long previousMillis = 0;
const long interval = 6000;
int totalSamples = 0;
int count = 0

    int calculateSoundValue(){
        int sound = analogRead(0);
        totalSamples+= sound;
        count += 1;
        return totalSamples/count;
    }

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {

  unsigned long currentMillis = millis();
int totalSamples = 0;
int count = 0
  if (currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;

  }
      int value = calculateSoundValue();
      Serial.println(value);
}


texts:
I would like to start with a very simple robot, which should be based on an arduino uno.
I already have an uno and made the decision fpr my robot chassie:
https://www.roboter-bausatz.de/en/diy-electronics/kits/robotic-kits/97/2wd-motor-smart-car-chassis-fuer-roboter-mit-getriebemotor-und-batteriebox

Additionally I want to by an ultrasonic distance sensor and a infrared sensor.
What else do I need to start ? Only a DC motor driver or anything else?

Thanks in advance
LStrike


texts: Hi I'm new to arduino and robotics itself. I have no idea what this giant green board is in the middle of the robot. I really need help!


texts: USB and Arduino: Power Arduino, charge LiPo, and transfer data at the same time

texts:
I was hoping to design my own Arduino board for a recent project of mine, a portable project that was powered by a 3.7 LiPo battery. Most ideally, I wanted to replace the USB B port with a single USB Micro port that implements the following features:

Provides power to the Arduino while it is plugged in (just like a regular Arduino does).
Connect the D+ and D- pins of the USB to the Arduino somehow to allow for on-board programming (however the Arduino accomplishes this already, I'll refer to this as the "onboard usb/serial converter"). I want it to keep it programmable on-the-go.
Charges an on-board 3.7V LiPo Battery. I was hoping to use Adafruit's PowerBoost 500 Shield as a reference for my schematic.

However, I haven't been able to find a schematic or example that implements all 3 features above at the same time from the same USB port. I don't have much experience with charging circuits, so the following questions might sound dumb. Below are some solutions I was thinking of that probably won't work, but I wanted to make sure:

Connect the Output Voltage of the LiPo Battery to the V+/GND supply of the USB cable (probably not safe to connect all V+ sources together).
Just connect the D+/- data cables to the "onboard usb/serial converter" without connecting the Vbat/Vusb somehow, have the USB V+/GND connect to the LiPo charging circuit, and the Battery Voltage power the Arduino.

I know some devices have this charging/data-transfer functionality (e.g. my phone can transfer photos to my computer while being powered on and charging at the same time), but I'm wondering how it's possible to have similar functionality for an Arduino board. Any advice?

Absolute worst case, I'll just have 2 USB ports, one for charging the LiPo and one for Serial Communication/Programming

EDIT: The idea of using an ATMega32U4 seems appealing (despite the 3.3V vs 5V operating voltage), mainly because it has a pin for VBUS for USB and Vcc for main power. But I was wondering how to do this on say an ATMega328P that doesn't have a pin for VBUS.


texts: Problem for control speed of a DC motor with a L298N

texts:
(Not native english speaker here, feel free to edit my sentences)

I try to control the speed of a DC motor with a L298N shield but it doesn't work very well. Here is my scheme :

The power comes from a transfo with an adjustable voltage of ~7v 1.0 Amp. I don't care about the sens of rotation, so I set IN1 to 5v and IN2 to the ground, is it right to do it like that ?

Now here is the code I'm using :

#define CONTROL_M   9  // To Enable input

void setup ()
{
    Serial.begin(115200);
}

void loop ()
{
    test_analog_motor();
}

void test_analog_motor()
{
    for (int i; i < 250; i=i+25)
    {
        Serial.println(i);
        analogWrite(CONTROL_M, i); // Any value between 0 and 255
        delay(500);
    }
}

With that code, the speed of my motor should progressively increase and then goes back to 0. I'm aware that, maybe if the value is too low, the motor will have trouble to start so I "help" it manually.

If I doesn't use the Enable output of my Arduino and just use the jumper instead, the motor turns with a good torque. This prooves at least that my shield isn't damaged.

Now here is the problem I have : With the scheme I've shown above, it simply doesn't work, nothing happens when I set the grounds in common, why ? Then if I remove the cable that goes to the arduino ground, it works but the motor has a very low torque, it seems also that there is a kind of latency in regards to what display the Serial monitor.

I feel a bit stupid with what I did with the grounds, it seems wrong t me  but I don't know what to do instead :/ What can I do ? My goal is to have the best possible control of the speed of that DC motor in term of reactivity, does a L298N is suited for that ?

EDIT
I did tested the PWM with an oscilloscope and a multimeter, the arduino PIN I was using worked correctly. I don't know why but now, the shield works too, I mean : Problem solved. One theory is that I adjusted the tension of my power supply under 5V. In that cas the shield doesn't nothing Arduino is magic sometimes...


texts: Arduino Software Serial reading a value of zero after several reads?

texts:
I am using the ID12-LA RFID reader with an Arduino Pro Mini (5V, 16MHz). I am also using the software serial library to read the serial data form the reader.

Initially the serial data is being read properly, however after several reads (i.e. maybe around 10 - 20) the serial seems to malfunction and calling the read() function always returns a 0.

Right now the only way I can fix this is if I reset the Arduino. Also note that when I reset the Arduino the RFID reader is staying powered up (so it's not being reset or anything; this means the issue seems to be from the Arduino).


texts: Not sure I'm understanding pipes for NRF24

texts: I've started working with the NRF24 library for some fun little side projects. I have only gotten through some basic tests but I'm starting to look at ways to tinker with the code. I have more experience as a programmer so the hardware side is always new to me. Where I'm a little confused is how the pipes are used. Working from this example, I see that one pipe is used to listen and another is used to transmit. If there's just two devices, why don't they both use the same pipe? If you have multiple devices on the same pipe transmitting, can it jumble the signals? Is there a way to receive on multiple pipes? I'd love more information on how pipes are or should be used.


texts: How to burn bootloader/program an ATMega 328P with an external crystal 8 MHz oscilator?

texts:
I need to program a ATMega328P on a breadboard, running on an external crystal at 8 MHz.

All of the guides I can find either use the arduino environment and describe a 16 MHz config, or using the 8 MHz internal oscillator - which is too inaccurate for this project.

How do I do this?  Configure the chip to run at 8 MHz and upload the program?


texts: How does Arduino digital input pin measure its input voltage?

texts:
Just starting with my first Arduino project.
In order to measure voltage in a circuit I connected my multimeter to two points in the circuit (for example before and after a resistor).

I am interested to know how an input pin can measure its voltage (for example 5v or 0v).


texts:
I'm trying to understand a few things about this code.

Why is digitalRead() slower than IRpin_PIN & (1 << IRpin)?
What does IRpin_PIN & (1 << IRpin) mean? I translated it to numbers and I figured out it's actually PIND & (0b100). What does PIND translate to and why is bitwise-and with 0b100 performed on it?
Why is the 20-microsecond delay (RESOLUTION) necessary?
What does _BV in while (! (IRpin_PIN & _BV(IRpin))) mean?

/* Raw IR decoder sketch!

 This sketch/program uses the Arduno and a PNA4602 to
 decode IR received. This can be used to make a IR receiver
 (by looking for a particular code)
 or transmitter (by pulsing an IR LED at ~38KHz for the
 durations detected

 Code is public domain, check out www.ladyada.net and adafruit.com
 for more tutorials!
 */

// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN      PIND
#define IRpin          2

// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20

// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2];  // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}

void loop(void) {
  uint16_t highpulse, lowpulse;  // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length
//  while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
     // pin is still HIGH
     // count off another few microseconds
     highpulse++;
     delayMicroseconds(RESOLUTION);
     // If the pulse is too long, we 'timed out' - either nothing
     // was received or the code is finished, so print what
     // we've grabbed so far, and then reset
     if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // we didn't time out so let's stash the reading
  pulses[currentpulse][0] = highpulse;
  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
     // pin is still LOW
     lowpulse++;
     delayMicroseconds(RESOLUTION);
     if ((lowpulse >= MAXPULSE)  && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;
  // we read one high-low pulse successfully, continue!
  currentpulse++;
}

void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC);
    Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }
  // print it in a 'array' format
  Serial.println("int IRsignal[] = {");
  Serial.println("// ON, OFF ");
  for (uint8_t i = 0; i < currentpulse-1; i++) {
    //Serial.print("\t"); // tab
    Serial.print("pulseIR(");
    Serial.print(pulses[i][1] * RESOLUTION , DEC);
    Serial.print(");");
    Serial.println("");
    //Serial.print("\t");
    Serial.print("delayMicroseconds(");
    Serial.print(pulses[i+1][0] * RESOLUTION , DEC);
    Serial.println(");");
  }
  //Serial.print("\t"); // tab
  Serial.print("pulseIR(");
  Serial.print(pulses[currentpulse-1][1] * RESOLUTION, DEC);
  Serial.print(");");
}


texts:
This is likely a duplicate, but I couldn't find the original question. This is really basic, but just can't figure it out.

I'm trying to combine a few char arrays together. This is what I've tried so far.

float a = 12.3456;
float b = 5.4321;
bool c = true;

char a_string[4];
dtostrf(a, 4, 1, a_string);

char b_string[4];
dtostrf(b, 4, 1, b_string);

char c_string[2] = {'0', '\0'};
if (c) {
  c_string[0] = '1';
}

char output[12] = "-----------";

output[0] = a_string[0];
output[1] = a_string[1];
output[2] = a_string[2];
output[3] = a_string[3];

output[4] = ' ';

output[5] = b_string[0];
output[6] = b_string[1];
output[7] = b_string[2];
output[8] = b_string[3];

output[9] = ' ';

output[10] = c_string[0];

Serial.println(output);

Results in an empty string in seems.

If I remove the second dtostrf(), and change b_string[0] ... to a_string[0] Then I get 12.3 12.3 1. Doesn't seem to like having dtostrf() called more than once, but it seems like the function I want, since it allows me to set a fixed strint size. The output I'd be looking for is 12.3  5.4 1

another approach

String a_string = String(a, 1);
String b_string = String(b, 1);
String c_string = String(c);

String output;
String space = " ";

output.concat(a_string);
output.concat(space);
output.concat(b_string);
output.concat(space);
output.concat(c_string);

Serial.println(output);

This outputs 12.3 5.4 1. Is there a way to make the String fixed width? I'm looking for

12.3  5.4 1 instead of

12.3 5.4 1

What's the proper way of doing this?

EDIT

After trying to use the @Majenko's answer I sometimes get garbage values printed. Any ideas why?

float a = analogRead(A1) / 1023.;
float b = analogRead(A2) / 1023.;
bool c = analogRead(A3) / 1023;

char* output = createString(a, b, c);
Serial.println(output);

char* createString (float _a, float _b, bool _c)
{
    char a_string[5];
    dtostrf(_a, 4, 1, a_string);

    char b_string[5];
    dtostrf(_b, 4, 1, b_string);

    char out[12];
    snprintf(out, 12, "%4s %4s %d", a_string, b_string, c ? 1 : 0);
    return out;
}

and the output:

 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.6  1.0 0
 0.�tS
�
 0.6  `S
�
 0.6  1.0
}
 0.6  1.0 0
 0.7  1.0 0
 0.6  1.0 0
 0.6  1.0 0

using

  Serial.print(a_string);
  Serial.print(" ");
  Serial.print(b_string);
  Serial.print(" ");
  Serial.println(c);

doesn't produce the errors