texts: Run code via NRF24L01+ command "dynamically"?

texts:
I'm trying to make a home automation setup but I'm having a bit of trouble.

I want to be able to send commands of varying sizes to my arduino, separated by "|" and after receiving it completely it runs code corresponding to the command.

Example:

input "RCP=10001|CMD=D|VAL=120"
would result in an array like:

String cmd[][] = {{"RCP", "10001"}, {"CMD", "D"}, {"VAL", "120"}}

with the amount of 'variables' being... well, variable.

The code would continue checking if the RCP (recipient) ID corresponds with the ID of the current client and then run code based on the following variables.
But I don't think that's important info for the code which separated the string.

This string would be sent through an NRF24L01+ (That code already works)


texts: How to change Multiple variable values through Serial Monitor

texts:
I am trying ... with minimal success to change/Check and also run voids through the serial monitor .the code i  put i am having probles is that when i am try to send a value larger than 9 the value assigns a diffrent number Ex i set to 200 but arduino sets it as 512.. i got around it deviding the value by 1.6 and got me the new number and only works upto 90 , but i am tryn to see how it should be done correctly...

const uint16_t inputLength = 512;
int ss = 0;
int bHold = 0;

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

 void loop() {
  if ( Serial.available() > 0 )
  {
    static char input[inputLength];
    static uint16_t i;
    char c = Serial.read();

    if ( c != '\r' && c != '\n' && i < inputLength - 1)
      input[i++] = c;

    else
    {
      input[i] = '\0';
      i = 0;

      uint16_t array[80];
      uint16_t j = 0;

      if ( !strncmp(input, "ss", 2) )
      {
        char* p = input + 2;
        while ( (p = strchr(p, ' ')) != NULL )
          array[j++] = strtol(p, &p, 10); //< changed from 16

        for ( uint8_t i = 0; i < j; i++ )
        {
          ss = array[i];
          Serial.println(ss);
        }
      }

      if ( !strncmp(input, "bHold", 5) )
      {
        char* p = input + 5;
        while ( (p = strchr(p, ' ')) != NULL )
          array[j++] = strtol(p, &p, 10);   //< changed from 16

        for ( uint8_t i = 0; i < j; i++ )
        {
         bHold = array[i];
        // bHold=bHold /1.6;
         Serial.println(bHold);
        }
      }

      if ( !strncmp(input, "Whos There", 10) )
      {
        Serial.print("me");
      }
      if ( !strncmp(input, "hello", 5) )
      {
        Serial.print("hi");
      }
      if ( !strncmp(input, "sa", 2) )
      {
        Serial.print("  ss= ");
        Serial.print(ss);

        Serial.print("  bHold= ");
        Serial.print(bHold);

        Serial.println(" ");
        Serial.println("==============================");
      }
    }
  }
}

Thank you for any tips you can give...

EDIT: I am trying to pass a new value with command on the serial monitor "ss 500"..so that in the arsuino ss = 500. but in this case it makes it equal to 1280.

EDIT2: Chaged the strol to 10...works perfectly ...Thank you TisteAndii!!!!


texts:
Is it possible to use more than 1 device that needs to use SDA for I2C with a mini?
Would you use a different analogue pin with a 10k pull up resistor and tie all of the devices to the SCL?


texts: Powering multiple servos on external battery

texts:
I am working on a project with my school's 3D Printing Club where we are making a humanoid robot and I am attempting to wire the arm at the moment, and program the hands to translate text to sign language. The portion of the arm I am currently working with uses six TowerPro 5010 servos, one for each finger, and another for the wrist, and I am controlling it with an Arduino Uno. I have a 9v wall plug that I am powering the Arduino with, and a 4xAA battery pack (wired in series for 6v, last measured at 5.7) that I would like to use for the servos.

Initially, I wired the servo ground pins to the Arduino GND output, and the servo power pins to the battery pack's 6v output, I connected the ground on the battery to the ground on the Arduino, and I attached the servo motors to their IO pins. This approach worked perfectly for two servos, barely for three, and not at all for four. Even with most of the motors staying still (I was only moving one at a time with three and four servos, but I can move two simultaneously no problem with nothing else connected). Not sure how to describe the load on them quantitatively, but they are pulling on fishing line that has a good deal of resistance, but nothing excessive, or near their limits.

I have been googling around for hours, and I found some tutorials where a similar battery was powering eight servos at a time, and so I am unsure why mine was cutting out so soon.

I tried to reduce the load of the servos, but nothing I tried worked. At one point I tried wiring the servos on a shift register to only power the ones I needed, but then I realized this was a dumb idea because my shift register would never be able to output enough current to power even one servo. I have some 5v voltage regulators, but I don't think they will help since the servo takes from 4v to 6v, and I looked through all my transistors, but they are all designed for very small currents. I have a relay which should be able to switch that voltage that voltage easily, but only one of them. If possible I would like to try and do this without purchasing any additional components such as motor controllers or specialized batteries, but I understand that if I need to I need to.

If anyone has any advice on how to proceed I would greatly appreciate it. Thanks.


texts: How to program for two Arduinos with different code but share one same .h?

texts:
I am now programming for two Arduinos. One is used as Tx and the other is Rx. Of course they are programmed by different codes, but they share some same .h files I programmed(let's say 'share.h'), which are not libraries and shouldn't be put in Arduino's 'library' folder.

So I put 'share.h' and main.ino in one folder, and the ino is like:

#include "share.h"
#define TX
#ifdef TX
void setup(){...something for Tx...}
void loop(){...}
#else
void setup(){...something for Rx...}
void loop(){...}
#endif

The shortage is that every time I want to update my code to the two unos, I have to: first change the board port to 40(the Tx uno) in ide, add the #define line, and upload. Then I have to change port to 42(the Rx one), comment the #define line and upload. So inconvenient!

So do you have any good ideas? Much appreciation!


texts: how can I stop my Arduino code after 1 second?

texts: I want to send message NRF24L01 to NRF24L01. I want to see if I can send just one second. How can I stop code after 1 second?


texts: What's the difference between analogWrite and digitalWrite?

texts:
As the title states. What's the difference between the two?

analogWrite(pin,0-255) vs digitalWrite(pin,LOW-HIGH)


texts: Standalone ATmega clock continuous lifetime

texts:
Here I have made a standalone ATmega328p clock without
any RTC module using the breadboard ATmega328p , LCD I2C , and some buttons which I would like to turn on for atleast an year (supposed to be without any reset or power-interrupts).
I am powering my ATmega using an old mobile charger (5v , 500mA) of a old broken Android.
However I am not using any millis() or something alike these in the clock code,
So how long will my clock run if is it supposed to be online 24/7
Should I reset it sometimes?
If yes , when, after how many days should I reset it?
And do I need a coolant system for it? (I guess not)
Thanks for your precious time .


texts: Simple webpage serve with Arduino ethernet shield on SD card

texts:
I have been experiment with the arduino uno board from few days but can't seem to make it serve web page stored in SD card of ethernet shield.

If I print the contents of the file to serial it works properly, even embedding the HTML code works fine, but client.write() just produces a never ending garbage text of ÿÿÿÿÿÿÿÿÿÿÿÿ

#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 115);
EthernetServer server(80);

File webFile;

void setup()
{
    pinMode(4, OUTPUT);
    digitalWrite(4, HIGH);
    Ethernet.begin(mac, ip);
    server.begin();
    Serial.begin(9600);

// initialize SD card
Serial.println("Initializing SD card...");
if (!SD.begin(4)) {
    Serial.println("ERROR - SD card initialization failed!");
    return;
}

Serial.println("SUCCESS - SD card initialized.");
// check for index.htm file
if (!SD.exists("index.htm")) {
    Serial.println("ERROR - Can't find index.htm file!");
    return;  // can't find index file
}
Serial.println("SUCCESS - Found index.htm file.");
}

void loop()
{
EthernetClient client = server.available();  // try to get client

if (client) {  // got client?
    boolean currentLineIsBlank = true;
    while (client.connected()) {
        if (client.available()) {   // client data available to read
            char c = client.read(); // read 1 byte (character) from client
            // last line of client request is blank and ends with \n
            // respond to client only after last line received
            if (c == '\n' && currentLineIsBlank) {
                // send a standard http response header
                client.println("HTTP/1.1 200 OK");
                client.println("Content-Type: text/html");
                client.println("Connection: close");
                Serial.println("starting to open htm");
                client.println();
                // send web page
                webFile = SD.open("index.htm");        // open web page file
                if (webFile) {
                    while(webFile.available()) {
                        client.write(webFile.read()); // send web page to client
                    }
                    webFile.close();
                }
                break;
            }
            // every line of text received from the client ends with \r\n
            if (c == '\n') {
                // last character on line of received text
                // starting new line with next character read
                currentLineIsBlank = true;
            }
            else if (c != '\r') {
                // a text character was received from client
                currentLineIsBlank = false;
            }
        } // end if (client.available())
    } // end while (client.connected())
    delay(1);      // give the web browser time to receive the data
    client.stop(); // close the connection
} // end if (client)
}

Sorry for the poor formatting, I just copied it from tutorial, please help me out.


texts:
I'm a newbie and I'm trying to read an ADS1232 with an Arduino for a Weight Scale Project.

I read data through the SPI interface, but i don't receive the result.

#include <SPI.h>

#define MISOPIN  50  //DATA
#define SCLKPIN  52  //SCLK
#define PDWN     53  // SS
#define SPEED       5
#define GAIN0       7
#define GAIN1       6
#define CLKIN       10
#define A0          9
#define TEMP        8

uint32_t byte1;
uint32_t byte2;
uint32_t byte3;
uint32_t finaladc = 0;

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

  pinMode(PDWN, OUTPUT);
  pinMode(MISOPIN, INPUT);
  pinMode(SCLKPIN, OUTPUT);
  pinMode(SPEED, OUTPUT);
  pinMode(GAIN0, OUTPUT);
  pinMode(GAIN1, OUTPUT);
  pinMode(A0, OUTPUT);
  pinMode(TEMP, OUTPUT);

  digitalWrite(GAIN0, HIGH);
  digitalWrite(GAIN1, HIGH);
  digitalWrite(SCLKPIN, LOW);
  digitalWrite(A0, LOW);
  digitalWrite(TEMP, LOW);
  digitalWrite(SPEED, HIGH);//0-->  10SPS ,1-->80SPS
  digitalWrite(PDWN, HIGH);  //0-->  POWERDOWN(SLEEPING -NO CONVERSION) ,1-->WORKING MODE

  reset_adc();

  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE1);

  digitalWrite(SCLKPIN,LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(MISOPIN)== LOW) read_adc();

  delay(1000);

}

void reset_adc()  {
  digitalWrite(SCLKPIN,HIGH);
  delayMicroseconds(1400);

}

void read_adc()  {
  drdy_wait();
  uint8_t i;
  finaladc = SPI.transfer(0xff);
  finaladc |= (uint32_t)SPI.transfer(0xff) << 8;
  finaladc |= (uint32_t)SPI.transfer(0xff) << 16;
  Serial.print ("ADC_value:  ");
  Serial.println(finaladc,DEC);
  Serial.println();

}

void drdy_wait()
{
  delayMicroseconds(30);
}

Has anyone worked with this? Can you help me?  Thank you


texts: STM32F103C8 - Arduino Mega FAST MODE(400000L) I2C communcation not working

texts:
I'm trying to connect a stm32F103C8 board (master) to an Arduino Mega (slave) over I2C. I have a master and slave program which runs perfectly fine when the clock frequency for I2C communication is set to standard (100000L) which is default.

I wanted the communication to happen a bit faster. So I changed the clock frequency to fast mode i.e., 400000L. I am seeing some weird behavior.

I can send data from master to slave (I can see the data appearing on slave) but when the master requests data from the slave, I don't receive any data on master.

I have tried the same code out on an Arduino Uno (master) and Mega (slave). The code works fine for both standard and fast mode.

I run the code in standard mode by commenting the following line in the master code.

    Wire.setClock(400000L);

Here's the code I have for the Master and Slave:

//Master Code

#include <Wire.h>

int data = 1;
void setup() {

  Wire.begin();
  Wire.setClock(400000L);
  Serial.begin(9600);
}
void loop() {
  Wire.beginTransmission(9);
  Wire.write(data);
  Wire.endTransmission();

  Wire.requestFrom(9, 1);
  int x = Wire.read();
  Serial.print(x);
  delay(500);

}

//Slave Code

#include <Wire.h>

int send_data = 1;
void setup() {

  Serial.begin(9600);

  Wire.begin(9);

  Wire.onReceive(receiveEvent);
  Wire.onRequest(requestEvent);
}
void requestEvent()
{
  Wire.write(send_data);
}

void receiveEvent(int bytes) {
  int x = Wire.read();
  Serial.println(x);
}
void loop() {
delay(500);
}

I'm having hard time understanding what's causing the issue. Please help me make sense as to why it's doing this and how I can resolve it.


texts:
I'm new to arduino and I'm trying to upload a fairly large (I think) program to a arduino yun which includes a 3 dimensional array. I'm using the bridge features of the yun.

when I upload the first time after unplugging and plugging back in again it runs fine. When I try and upload a second time I get the following error regardless of which code I'm trying to upload (blink example for example)

 avrdude: verification error, first mismatch at byte 0x0000
 0xff != 0x0c avrdude: verification error; content mismatch

In the serial monitor I get the following output:

Unable to connect: retrying (1)...
Unable to connect: retrying (2)...
Unable to connect: retrying (3)...
Unable to connect: retrying (4)...
Unable to connect: is the sketch using the bridge?

I'm currently developing as much as I can in another sketch but it's a pain.
I can provide the code if needed.

Thanks for any help


texts: Arduino Uno wont power up when GND is plugged in Logic Converter

texts:
Good day.
I am trying to use an ESP8266 12e Wifi Module that requires 3.3V
I used a Logic Converter to reduce the 5v to 3.3v
My problem is when I plug the GND from the arduino to the GND on the Logic Converter, the Power On Led dies slowly on the arduino and no power at all.
When I plug the 5v only the power is back.

I have tried both the USB power from the laptop and a 9V 250mA power adapter but still the same result.

Any advice would really save me.


texts: Can't power HC-05(5v) with Arduino Pro mini (3.3v)?

texts:
I am trying to use HC-05 (5V) with Arduino Pro Mini (3.3v) but I have had little success.

I am using a coin cell to power the pro mini which powers it on and is working fine.

But, my HC-05 doesn't power on. I am trying to power it externally using two 3.7v Lipo-batteries that gives a total of 7.4v but I have tried numerous changes and nothing seems to work.

Circuit Diagram attached below.

Also, HC 05 has an onboard regulator for levelling it to 3.3v

Please Help!!!


texts: How to interrupt and direct my program where I want it to in the code by clicking a button?

texts:
I want to simulate christmas lights and the different modes of lighting it can produce by pressing a button. I tried to do this by having a button pressed which changes an int variable (1-3) which then corresponds to 1 of 3 of my if statements that each have their own code that lights the leds in a different manner. What I have noticed is that if I were to press the button while my program is in the middle of executing one of these light modes, the operation is NOT interrupted and I'd have to wait for the operation to finish before I could press the button and switch to a different mode. As you know, in actual Christmas lights, this is not the case. One can easily switch between modes with a push of a button with no delays. How can I achieve this through code? P.S. I am a newbie in Arduino. My code is written below

const int buttonPin =2;
int ledPin[5] = {3,5,6,9,10};
int counter = 1;
int brightness = 0;
void setup(){
    Serial.begin(9600);
    pinMode(buttonPin, INPUT);
    for(int i = 0; i<5; i++)
    {
       pinMode(ledPin[i], OUTPUT);
      Serial.println(ledPin[i]);
    }
}
void loop(){

  int reading = digitalRead(buttonPin);
  if (reading != 0){
    counter++;
    if(counter == 4)
    {
      counter = 1;
    }
  }

  if (counter == 1) // mode 1 of the christmas lights (default mode)
  {
    digitalWrite(3, HIGH);
    digitalWrite(6, HIGH);
    digitalWrite(10, HIGH);
    delay(300);
    digitalWrite(3, LOW);
    digitalWrite(6, LOW);
    digitalWrite(10, LOW);
    delay(300);
    digitalWrite(5, HIGH);
    digitalWrite(9, HIGH);
    delay(300);
    digitalWrite(5, LOW);
    digitalWrite(9, LOW);
    delay(300);
  }
  else if (counter == 2)// mode 2 of the christmas lights
  {
      for(brightness =0; brightness <= 255; brightness++)
      {
        analogWrite(3, brightness);
        analogWrite(5, brightness);
        analogWrite(6, brightness);
        analogWrite(9, brightness);
        analogWrite(10, brightness);
        delay(3);
      }
      for(brightness =255; brightness >= 0; brightness--)
      {
        analogWrite(3, brightness);
        analogWrite(5, brightness);
        analogWrite(6, brightness);
        analogWrite(9, brightness);
        analogWrite(10, brightness);
        delay(3);
      }
  }
  else if (counter == 3)// mode 3 of the christmas lights
  {

    for (int i = 0; i < 5; i++)
    {
        digitalWrite(ledPin[i], HIGH);
        delay(150);
        digitalWrite(ledPin[i], LOW);
        delay(150);
    }
    for (int i = 3; i > 0; i--)
    {
        digitalWrite(ledPin[i], HIGH);
        delay(150);
        digitalWrite(ledPin[i], LOW);
        delay(150);
    }
  }
}


texts: What is "tws_delay" and how can I use it? (with an ATTiny85)

texts:
EDIT: Alright I'm stupid, I had the 2012 library installed somehow, maybe when I downloaded it indirectly from another old tutorial site. Thanks a ton to Peter Freerick for pointing that out! It finally compiled now
So I'm currently doing a little project where I have an ATTiny85 controlling some (neopixel) RGB addressable LEDs, which is controlled over i2c from an Arduino UNO Master. The goal is to make an Attiny85 into an i2c slave that receives a simple command (such as a single digit int) and decide which premade LED display program to use.
I'm using ATTinyCore, TinyWireS, and Adafruit's tinyNeopixel library for the tiny, and programming it using an Arduino UNO as ISP.
My issue is this: The led code requires a delay to change the speed of the light show. But I see in the TinyWireS example here that I should be using tws_delay instead of the normal delay.
Various googling attempts have left me nowhere to learn how to use tws_delay, what it is, or how to even declare it. I get a declaration error when I try to use the delay with the TinyWireS library included.
I would like to find a resource for learning how to declare and use this delay. Thank you for reading this far
EDIT: I have now added my code and error below, you can find the tws_delay in void loop near the bottom
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library

#if (F_CPU>7370000) //neopixel library required 7.37MHz minimum clock speed; this line is used to skip this sketch in internal testing. It is not needed in your sketches.
#include <tinyNeoPixel.h>
#include <TinyWireS.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN            3

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      8

// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
tinyNeoPixel pixels = tinyNeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);

int delayval = 500; // delay for half a second

void setup() {

  pixels.begin(); // This initializes the NeoPixel library.
}

void loop() {

  // For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.

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

    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.

    pixels.show(); // This sends the updated pixel color to the hardware.

    tws_delay(delayval); // Delay for a period of time (in milliseconds).

  }
}
#else //neopixel library required 7.37MHz minimum clock speed; these and following lines are used to skip this sketch in internal testing. It is not needed in your sketches.
#warning "Neopixel control requires F_CPU > 7.37MHz"
void setup() {}
void loop() {}
#endif

And the error:
C:\Users\Dean\AppData\Local\Temp\arduino_modified_sketch_145294\simple.ino: In function 'void loop()':

simple:36:5: error: 'tws_delay' was not declared in this scope

     tws_delay(delayval); // Delay for a period of time (in milliseconds).

     ^~~~~~~~~

C:\Users\Dean\AppData\Local\Temp\arduino_modified_sketch_145294\simple.ino:36:5: note: suggested alternative: 'delay'

     tws_delay(delayval); // Delay for a period of time (in milliseconds).

     ^~~~~~~~~

     delay

Multiple libraries were found for "tinyNeoPixel.h"
 Used: C:\Users\Dean\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.3.2\libraries\tinyNeoPixel
Multiple libraries were found for "TinyWireS.h"
 Used: C:\Users\Dean\Documents\Arduino\libraries\TinyWireS
exit status 1
'tws_delay' was not declared in this scope


texts:
I keep reading how Arduinos are "open source", but my understanding of OSH is that all its components must be open source.

Arduino uses an Atmel 8-bit CPU - but Googling this shows the Atmel is proprietary!?

So I ask: how can Arduino be OSH if it's chief component - its Atmel CPU - is proprietary?!?


texts: How to interface with generic IR RGB LED controller?

texts:
I want to hook up an arduino to one of those generic RGB LED controllers, you see them everywhere, they are these little white boxes with power input and RGB strip plug and an IR LED lead. Is there a way to take to the IR + and - and connect them the arduino? Then spoof an IR signal to control the control module? I want to do it this way because I already own both the arduino and control module and that module handles the power for the LEDs. All I am hoping I have to do is send the controller the hex value for the IR command through the the arduino in order to control it. Here's a link to what the module looks like and the remote it comes

https://www.amazon.com/dp/B00ASHQQKI/ref=cm_sw_r_cp_awd_htMywb1W85962


texts:
The RadioHead library only runs on a very old core for the ATtiny85.
It sends data but I would like to send something useful. The problem is I cannot read any sensors using this core. And on any other core the RadioHead library fails.

RadioHead library
ATtiny core

An old post in the Arduino forum, probably the same issue.

I would like to know what is in the DallasTemperature that conflicts with RadioHead making the code to hang.

The problem appears when I add DallasTemperature sensors(&oneWire); to the code.

// RadioHead ASK
#include <RH_ASK.h>

// DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS PB0
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

// Sleep
#include <avr/sleep.h>
#include <avr/wdt.h>

#ifndef cbi
  #define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
  #define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif

// Absolute reference PB to overcome inter-IDE issues
#define T_PIN PB1 // transmission
#define L_PIN PB3 // optional LED pin
#define BAUD 2000

// Baud rate, receiver, transmitter
RH_ASK driver(BAUD, 9, T_PIN); // pin 9 is non existent

// the Tickle structure, what a name, ugh
struct tickle {
  uint16_t id;
  uint16_t value1;
  uint16_t value2;
};

// Watchdog
volatile boolean f_wdt = 1;

ISR(WDT_vect) {
  f_wdt=1;
}

// Sleep
void system_sleep() {
  cbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter OFF

  set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
  sleep_enable();

  sleep_mode();                        // System sleeps here

  sleep_disable();                     // System continues execution here when watchdog timed out
  sbi(ADCSRA,ADEN);                    // switch Analog to Digitalconverter ON
}

// Setup for Watchdog
void setup_watchdog(int ii) {
  byte bb;
  int ww;
  if (ii > 9 ) ii=9;
  bb=ii & 7;
  if (ii > 7) bb|= (1<<5);
  bb|= (1<<WDCE);
  ww=bb;

  MCUSR &= ~(1<<WDRF);
  // start timed sequence
  WDTCR |= (1<<WDCE) | (1<<WDE);
  // set new watchdog timeout value
  WDTCR = bb;
  WDTCR |= _BV(WDIE);
}

// With set_watchdog at 8 (4 sec.) we cycle from 0 to 14
// This timer is not precise
void minute_sleep(int ms) {
  for (int c = 0; c < ms; c++) {
    for (int i = 0; i < 15; i++) {
      system_sleep();
    }
  }
}

void setup() {
  // Debugging, if this takes less than a second, check fuses (core)
  if (!driver.init()){
    pinMode(L_PIN, OUTPUT);
    digitalWrite(L_PIN, HIGH);
    delay(500);
    digitalWrite(L_PIN, LOW);
    delay(500);
  }
  setup_watchdog(8);
  sensors.begin();
}

void loop()
{
  if (f_wdt==1) {
    f_wdt=0;
    struct tickle package; // make a Tickle package

    package.id = 38; // hard-coded device ID
    package.value1 = analogRead(PB0); // any positive int up to 2^16
    package.value2 = analogRead(PB2); // any positive int up to 2^16

    // sending data
    driver.send((uint8_t *)&package, sizeof(package));
    driver.waitPacketSent(); // wait for it ~Barney
    minute_sleep(10); // tested: 10 was 10:30, I like
  }
}


texts: i am working on a project automatic street lighting with arduino.i am done with the code and the circuit.i am able to switch the AC voltage in my house which is 230v,50hz with a 230v relay but when its comes to implementation there are 30 to 40 street lights are connected and the voltage is very high I think around 415 volts.what should I use to control that? need help


texts: Programming bluetooth module JY-MCU v1.06

texts:
I have a popular bluetooth module JY-MCU version 1.06 (picture below). Before i insert it to my arduino project I want to configure the name, bound speed and the pass code using usb-to-serial link. But I am facing a problem where the device does not respond to commands. Please let me explain.

I send the module to programming mode by applying +5V on 'key'

Then I send commands using CoolTerm program:

AT+NAMEmyArduinoProject
> OKyour set name

Ok. setting the name works as expected. But that is the only thing that worked for me. Other commands give no response:

AT

AT+BAUD2

AT+VERSION

AT+VERSION?

Maybe you had this happen to you? I am I sending wrong commands or doing something wrong? Please help me to figure out how to control this module.


texts: Electric meter with Arduino and RS485 module

texts:
I'm a Arduino newbie. I have an Electric meter with an RS485 output. I want to get the MeterID value over the RS485 module and the Arduino. I just have document from manufacturer.

Sent by computer : 68 99 99 99 99 99 99 68 01 02 67 F3 C3 16.
Return from meter : FE 68 99 99 99 99 99 99 68 81 08 67 F3 A6 9B 34 4B 33 33 6F 16.

My Arduino code:

#include <SoftwareSerial.h>

#define SSerialRX        10
#define SSerialTX        11
#define SSerialTxControl 3
#define RS485Transmit    HIGH
#define RS485Receive     LOW

SoftwareSerial RS485Serial(SSerialRX, SSerialTX);
byte request[] = {0x68, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x68, 0x01, 0x02, 0x67, 0xF3, 0xC3, 0x16};
int byteRead;

void setup()
{
  Serial.begin(9600);
  RS485Serial.begin(1200);
  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Receive);
  delay(20);
  Serial.println("Get Meter Address App");
}
void loop()
{
  digitalWrite(SSerialTxControl, RS485Transmit);
  RS485Serial.write(request, sizeof(request));
  delay(2000);
  digitalWrite(SSerialTxControl, RS485Receive);
  delay(2000);
  if (RS485Serial.available())
  {
    byteRead = RS485Serial.read();
    Serial.println(byteRead, HEX);
  }
}

Serial Monitor show:

I'm using combo like this topic modbus-rtu-controller-monitoring-with-arduino-and-rs485-module. My code is in C# below. I used the code before and it worked fine, but on the computer I use a COM port (Baudrate 1200, data 8bits, Parity EVEN, Stopbit 1) with an RS485-R232 converter:

#Send data
dataOUT = WriteData("68 99 99 99 99 99 99 68 01 02 67 F3 C3 16");
serialPort_Meter.Write(dataOUT, 0, dataOUT.Length);

#WriteData method
private static byte[] WriteData(string hex)
{
return hex.Split(' ').Select(s => Convert.ToByte(s, 16)).ToArray();
}

#Read data
private static string ReadData(SerialPort serial)
{
byte[] buffer = new byte[serial.BytesToRead];
serial.Read(buffer, 0, buffer.Length);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < buffer.Length; i++)
sb.AppendFormat("{0:X2} ", buffer[i]);
return sb.ToString();
}


texts: Is it possible to convert RCA(video only) to Arduino Uno then to a computer?

texts: I have an old wireless RCA output camera. I was wondering if I can convert its analog input to a digital one and have it saved on a file in my laptop?


texts: How can I hook up multiple MMA8451 accelerometers, (I2C protocol) using one Arduino Mega?

texts:
How can I hook up four (adafruit) MMA8451 accelerometers (using I2C protocol) using one Arduino Mega? What I'm confused about is I only have one SDA and SCL on the Arduino Mega obviously. So how can I connect these all? Multiplexer? I need four because I have one on each leg of a robot. Or is perhaps this impractical to put an accelerometer on each leg of robot? I'm a little new to electronics so please explain in depth if you could. Thanks.

Note to moderators: I just would really love an answer to this even if this doesn't meet the super strict question guidelines. It seems every time I post here there's always that one person who takes it down for any number of trivial reasons. Please let me get an answer at least. Thank you!


texts: Arduino UNO LED half brightness when connected to digital GND but not analog

texts:
I am using an Arduino UNO. When lighting an LED with the switch button on a joystick module, I have two situations:

If the LED's cathode is connected to GND on the digital pin side of the Uno, the LED only dimly lights up on button press.
If the LED's cathode is connected to GND on the analog pin side of the Uno, the LED fully lights up on button press.

The device is receiving power from my laptop, and I am writing a digital HIGH/LOW to the LED pin (on press/release).

Is this a fault in my board, or is there a (perhaps more enlightening) reason why this is happening?


texts: My two slave SPI setup on arduino not working correctly

texts:
I am trying to connect a DPS310 and an ADXL345 to my Arduino using 4 wire SPI. When the individually tested (i.e. each has its own script), the output is correct, however when the scripts are combined the ADXL output is garbage, but the DPS functions.
What we expect to see:
Temperature = 24.14 *C
Pressure = 857.88 hPa
X: -4  Y: 4  Z: 29

What we actually see:
Temperature = 24.14 *C
Pressure = 857.88 hPa
X: 0  Y: 0  Z: 0    // and does not change when tilted

When the DPS310 line is commented out, the ADXL works fine (this line is indicated in script)
The whole script (with the faulty line indicated):
#include <SparkFun_ADXL345.h>
#include <Adafruit_DPS310.h>

// ADXL obj
#define ADXL345_CS   9 // SPI pin
ADXL345 ADXL = ADXL345_CS; // Instantiate obj with CS pin
int x = 0, y = 0, z = 0;

// DPS obj
#define DPS310_CS   10 // SPI pin
Adafruit_DPS310 dps; // Instantiate obj (pin is set in setup)
sensors_event_t temp_event, pressure_event;

void setup() {
   Serial.begin(115200);
   while (!Serial) delay(10);

   // ADXL SETUP
   digitalWrite(ADXL345_CS, LOW); // START COMM
   Serial.print("ADXL345: ");
   ADXL.powerOn();
   delay(50);
   ADXL.setRangeSetting(16);
   ADXL.setSpiBit(0);
   ADXL.set_bw(ADXL345_BW_12_5);
   ADXL.setInterrupt(0x84, true);
   ADXL.setAxisOffset(0, 0, 5);
   ADXL.readAccel(&x, &y, &z);
   if(x != -1 && y != -1 && z != -1) {
     Serial.println("[PASSED]");
   } else {
     Serial.println("[FAILED]");
   }
   digitalWrite(ADXL345_CS, HIGH); // END COMM

   // DPS SETUP
   digitalWrite(DPS310_CS, LOW); // START COMM
   Serial.print("DPS310: ");
   if (! dps.begin_SPI(DPS310_CS)) { /////////////////PROBLEM LIES HERE//////////////////
      Serial.println(" [FAILED]");
   }
   Serial.println(" [PASSED]");

   dps.configurePressure(DPS310_64HZ, DPS310_64SAMPLES);
   dps.configureTemperature(DPS310_64HZ, DPS310_64SAMPLES);
   digitalWrite(DPS310_CS, HIGH); // END COMM
}

void loop() {
    digitalWrite(ADXL345_CS, LOW);
    ADXL.readAccel(&x, &y, &z);
    digitalWrite(ADXL345_CS, HIGH);

    digitalWrite(DPS310_CS, LOW);
    dps.getEvents(&temp_event, &pressure_event);
    digitalWrite(DPS310_CS, HIGH);

    Serial.print("Temperature = ");
    Serial.print(temp_event.temperature);
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.print(pressure_event.pressure);
    Serial.println(" hPa");

    Serial.print("X: ");
    Serial.print(x);
    Serial.print("  Y: ");
    Serial.print(y);
    Serial.print("  Z: ");
    Serial.println(z);

    delay(50);
}

I think the fault might lie in the classes written for these devices, for instance maybe they were written for single SPI device or have different frequencies/modes? (I'm probably wrong though XD). I have not yet tried to setup the SPI for each device manually (programming commandment: do no reinvent the wheel), so any help would be greatly appreciated.


texts: Interpreting pull-up values Rp and Rpu in AM3202 (DHT22) datasheet

texts:
In the AM2302 datasheet at page 3, table 4, it gives min, typ and max values for Rpu (that the pull-up resistor as it says verbatim) being 30K, 45K and 60K ohm respectively.

Elsewhere in the same table it gives figures for Rp (no u) < 25K ohm.

What is the difference between Rpu and Rp here, and how should the two rows be interpreted?


texts:
I have a TM1638 board with 8 seven-segment displays, 8 LEDS, and 8 buttons. Each time multiples leds are on, the board makes an annoying high pitch sound.

I'm controlling it with an Arduino Uno.

Should I worry about the sound and is it normal?

This is my board :


texts: How to make a button work a second time in my code?

texts:
I am making a security system, and the alarm starts when the button gets pressed. If i turn the alarm off by the serial communication, and want to turn it on again using the button, it will only let the alarm go on for about 0.5 seconds. Does someone see the mistake i'm making, and can help me? Thanks in advance!

const int ledrood = 11;
const int ledgroen = 12;
const int buttonPin = 2;
int buttonState = LOW;

int statePin = LOW;
const int trigPin = 9;
const int echoPin = 10;
long duration;
int distance;
bool alarm = false;
int speakerPin = 8;
String Message = "";
String NMessage = "";
String Command = "";
int index = 0;
bool Bericht = true;

void PlaySong()
{
  tone(speakerPin, 4699, 500);
  delay(1000);
  tone(speakerPin, 4699, 500);
  delay(1000);
  tone(speakerPin, 4699, 500);
  delay(1000);
  tone(speakerPin, 4699, 500);
  delay(1000);
  tone(speakerPin, 4699, 500);
  delay(1000);
  tone(speakerPin, 4699, 500);
  delay(1000);
  tone(speakerPin, 4699, 500);
  delay(1000);
}
void alarmaan()
{
 alarm = true;

  digitalWrite(ledrood, HIGH);
  digitalWrite(ledgroen, LOW);
  digitalWrite(trigPin, LOW);

 }

void AlarmUit() {
  Serial.println("alarm uit");
  alarm = false;
  digitalWrite(ledgroen, HIGH);
  digitalWrite(ledrood, LOW);
  digitalWrite(trigPin, LOW);

 }
void setup() {
  pinMode(ledrood, OUTPUT);
  pinMode(ledgroen, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600);
 }
String Doorsturen() //Methode om te communiceren via de serial monitor
{
 if (Serial.available() > 0)
  {
   char readChar = (char) Serial.read();
   NMessage = NMessage + readChar;
  }
  if (NMessage.startsWith("#") && NMessage.endsWith("%"))
  {
   index = NMessage.indexOf("%");
   NMessage = NMessage.substring(1, index);
   Serial.println(NMessage);
   Command = NMessage;
   NMessage = "";
   Bericht = true;
  }
  else if (NMessage.endsWith("%"))
 {
   NMessage = "";
 }
 return Command;
}
void loop() {
 Message = Doorsturen();
 int buttonState = digitalRead(buttonPin);
 digitalWrite(trigPin, HIGH);
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 distance = duration * 0.034 / 2;
 Serial.print("Distance: ");
 Serial.println(distance);

 if (alarm == false) {
   digitalWrite(ledgroen, HIGH);
 }

 if (Message == "alarm_off")
 {
   AlarmUit();
   Message = "";
 }
  if (Message == "1234")
  {
   AlarmUit();
   Message = "";
  }
  if (Message == "aan") {
   alarmaan();
   Message = "";
   }

  if (alarm == false) {
   if (buttonState == HIGH) {
    delay(50);
    while (digitalRead(buttonPin) == HIGH) {}
    alarmaan();
    Serial.println("fout");
   }
  }

  if (distance < 10 && alarm == true) {
   PlaySong();
  }

 if (alarm == true) {
   if (buttonState == HIGH) {
    delay(50);
    while (digitalRead(buttonPin) == HIGH) {}
    alarmaan();
    Serial.println("Test");
   }

 }
}


texts:
as a project I have to build a sensor hub based on Arduino. I need a couple of sensors like gyroscope, barometer, etc. This is no problem so far. The problem arises when it comes to power measurement. We have to measure the power consumption of the Arduino AND all the sensors. Sure, I could use a sensor like the Adafruit INA219 sensor. But this only gives the total consumed power of the Arduino and the sensors.

Is it possible to measure the energy, say, for every pin on the Arduino?


texts: Are there any alternatives to Tinkercad Circuits that is PC application based instead of web app based?

texts:
I have been using Tinkercad's Circuits web application to create my Arduino circuits and apply my Arduino code (c++) for testing.

Despite the amazing product they have and the fact it's free, I find myself very disappointed at times.  Don't get me wrong, Tinkercad has a bunch of great products that I use all the time (like "3d Designs").  I just feel like "Circuits" needs work or maybe even a different dirrection.

I have been dealing with some of the following issues...

An extremely slow interface creating my circuit:

I have seen it do a bunch of random things that could use some TLC in the interface.  Sometimes objects get stuck and you have to disconnect them from everything before you can move them.  Sometimes using a breadboard, objects that seem connected to a pinhole does not make a connection and need to be connected to the breadboard using a wire.  There are a bunch of little quarks I see.  None are a show stopper and I can work around them but the slow interface makes me hate dealing with a web app.  It makes me really want a PC app instead.
The lack of support updating the Arduino compiler:

It's a very old version and they are not in a hurry to upgrade it.  I have contacted support a bunch about issues with the compiler not compiling code that works perfectly fine in the Arduino IDE.  Classes need to be defined in a specific way, enums need to be defined in an old way that makes the source look ugly etc.  Also, I have let them know when debugging it's about impossible to find out where your bug is because it does not tell you a line number it had a problem on.  It tries to highlight the line with little success in my tests.  I have suggested to them that maybe they could introduce a new option to choose the compiler version to use for each project this way old designs do not break etc.  I didn't get any feedback on the feedback I submitted.  So I guess that is a no go.
The simulation time:

This is the worst offender by far!  This is the main reason I want to look for different software to replace Tinkercad Circuits.  When simulating code on my circuit design the simulation runs in milliseconds (NOT real-time).  I have my code set to do something in 15 seconds.  Seems like it will happen in no time...  NOPE!  I have to wait about 15 minutes to see the results!!

So back to my original question...  Is there a PC application out there that does the same thing as Tinkercad Circuits?  I want to be able to design an Andrino circuit and then test code with it.


texts: Several SIM with Arduino GSM/GPRS shield

texts:
For some purpose we need to communicate with Arduino using more that one SIM card, but still like to use an only GSM shield.

So, the idea is to use several SIM holders, to commutate each of six SIM wires to the sim we currently use. But it is still the question

1) How we should handle the gsm module itself? Is it okay for it if the SIM wire will be commutated to another SIM when it is in the middle of something? May be we should power off the module before, but it unclear how to do it programmatically when it is installed on the top of Arduina Mega 2560

2) should we commutate all six wires, or may be there are few signal ones and another shouldn't be never commutated?

3) what is the best way to do this commutation? Relays/transistor switches and so on?


texts:
I'm looking for a storage solution for small files that would be moved into a small sensor running arduino-like processor.

Ideally the single memory unit would be cheap (in 1-10 cents range), but the memory can be very limited (several megabytes).

The closest I've got so far is small SD Memory card, but the smallest 4GB ones cost several dollars (at least bought in quantities < 100). Anything else I should be looking at?


texts: Detecting the down time of a system by subtracting the time when the sytem gives ON signal and when it goes OFF

texts:
int pin_state = LOW;
struct Channel {
    byte pin;
    byte state;
    byte count;
    unsigned long fell, rose;  // times of fall and rise
};

const int CHANNEL_COUNT = 3;
Channel channels[CHANNEL_COUNT] = {
    { 2, LOW, 0, 0 },
    { 3, LOW, 0, 0 },
    //{ 4, LOW, 0, 0 },
    //{ 5, LOW, 0, 0 },
    //{ 6, LOW, 0, 0 }
};

void setup()
{
    for (int i = 2; i <= CHANNEL_COUNT; ++i) {
        pinMode(channels[i].pin, INPUT);
    }
    Serial.begin(9600);
    //Serial.println("pin,fell,rose,low time");
    Serial.println("Minutes, Seconds, Count");
}

void loop()
{
    for (int i = 0; i < CHANNEL_COUNT; ++i)
    {
        Channel &c = channels[i];
        byte new_state = digitalRead(c.pin);
        if (c.state == LOW && new_state == HIGH)   // input rose
        {
            c.rose = millis();
            c.count = c.count + 1;
        }
        else if (c.state == HIGH && new_state == LOW)  // input fell
        {
            c.fell = millis();
            display_channel(c);
        }
        c.state = new_state;
    }
}

void display_channel(const Channel &c)
{
  int minutes, seconds;
  unsigned long difference;
  difference = c.fell - c.rose;
  seconds = int(difference/1000);
  if (seconds >= 60)
  {
       minutes = seconds / 60;
       seconds = seconds % 60;
  }
    //Serial.print(difference/1000);
    //Serial.print(",");
    Serial.print(minutes);
    Serial.print(",");
    Serial.print(seconds/1000);
    Serial.print(",");
    Serial.println(c.count-1);
    //Serial.print(",");
  }

In this code, I tried to measure the time taken between the two events (when the ON signal comes and when the signal goes OFF) in two different channels simultaneously. But the code doesn't give any output and the serial monitor is empty except for the statement in the main function.

It would be useful if anyone could find where exact;y the problem is and a valid solution to it would be helpful.

edit : I made the following changes but still output is never displayed. Any error is still ON the program?


texts: Recognize peak in specific frequency area

texts:
I am wondering if it is possible to attach a microphone to an arduino board and make the arduino recognize a volume peak in a specific range of frecuency's.
I want it to detect a specific peak (for example 0,1 db's) in the range of 1000hz to 5000hz.
Thanks in advance.


texts: How to rsync my node.js project to my intel edison board, through ssh?

texts:
I would love to get rid of Intel's heavy XDK software, and be able to quickly push the updates of my node.js code into my Intel Edison (arduino compatible) board.

I tried this: rsync -avz ./ root@192.168.100.177:/node_app_slot/

But rsync is not installed on the board.

How would you do this?


texts: WDT ISR not called when SPI ST7789 module initiated

texts:
Using the .init function for the ST7789 TFT screen prevents my WDT ISR from firing. What explains this behaviour, and is there something I can do? Any other timer ISR I could use instead?
#include <Adafruit_ST7789.h>    // Includes Adafruit_GFX.h

#define TFT_CS 10 // define chip select pin
#define TFT_DC 9  // define data/command pin
#define TFT_RST 8 // define reset pin, or set to -1 and connect to Arduino RESET pin

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);

void setup()
{
    //Serial.begin(9600);
    pinMode(13, OUTPUT);

    WDTCSR = (24); // Change enable and WDE - also resets
    //prescalers only - get rid of the WDE and WDCE bit.
    WDTCSR = (6); // 1 sec
    WDTCSR |= (1 << 6); //enable interrupt mode - WDT as an interrupt is useful to wake up from sleep
    sei();

    tft.init(240, 240, SPI_MODE2); // comment this out and WDT works fine
    tft.setRotation(0);
    tft.setTextWrap(true);
}

void loop()
{

}

ISR(WDT_vect)
{
  digitalWrite(13, (digitalRead(13) ^ 1));   // toggle LED pin
}

Thanks!


texts:
I'm trying to connect my Arduino Galileo to Linux via Arduino IDE. Sometimes I'm able to do so, but other times I ge the following error 'Board at /dev/ttyACM0 is not available'. With dmesg I can see that the device is not recognized, a deeper look at this issue led me to find out that a ls on /dev/ttyACM0 shows this:

-rw-r--r-- 1 root root      296 Apr  8 20:14 /dev/ttyACM0

Here I notice that there's a missing 'c' before the permissions that is common to every other /dev/tty*. I would like to know the reason why and if this is the cause for my problem. This seems to be suspicious..or maybe I'm mistaken...please correct me if I'm wrong.


texts:
My question is how to do it (set it up), not if I can do it or with what Arduino.

I've previously setup OpenCV with Visual Studio 2015. It was a tough one, but I made it through. Now I want to set it up so that it would work with the Arduino and its IDE.

How should I proceed? Is there any specific things to do?

My setup:

Windows 7
Arduino IDE 1.8.1
OpenCV 3.1


texts: What is the output format of PINxn on atmega328p

texts:
I have written this simple code to run on my Arduino:

#ifndef F_CPU
#define F_CPU 16000000UL // 16 MHz clock speed
#endif

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  Serial.begin(9600);
  DDRD = 0x00;
  PORTD = 0x80; //activate pull-up resistor on first pin on port D

  while (1)
  {
    Serial.print(PIND);
  }
  return 0;
}

I simply set my D port as an input and read the value in a loop. The output of PIND is 253. What is this number representing? is it in decimals? where can I see a list of these? How can I see a binary repression of the PIN output (8 bits of them). I don not want to use bit shifting.


texts:
I have been using a HC-SR501 PIR module with my Arduino Mega and it was tracking presence pretty well.

Because of cost constraints, I decided to go with the low cost HC-SR505 sensor - bought a bunch of them. The performance is very bad. It almost seems like it is giving random HIGH and LOW values. Out of the 20 odd sensors I bought, may be one or two are fairly ok - others are all behaving weird. Have someone experienced this kind of behavior with HC-SR505 sensor?

Are they highly sensitive to noise in the power supply - is there any workaround to mitigate the effect? Would an RC filter across the input help?


texts: Can I upgrade my ESP8266 firmware by connecting the pins in Arduino Uno, or do I still need a USB UART to Serial?


texts:
I am trying to operate two DC motors at once using a L293D chip. I have managed to control them however, one of the motors has a slight problem. Whenever I start the program (attached below), one of the motor (I tried switching them, it isn't a problem due to the motor itself) has a counterclockwise spin for a second before starting to spin clockwise as it is suppose to. When it is spinning counterclockwise, the other motor is not doing any movements.

Is something wrong in the code or in the circuit? (I've also attached a hyperlink to my circuit which I found online, as well as my code)

Thank you

#define E1 11  // Enable Pin for motor 1
#define E2 10  // Enable Pin for motor 2
#define I1 12  // Control pin 1 for motor 1
#define I2 13  // Control pin 2 for motor 1
#define I3 8   // Control pin 1 for motor 2
#define I4 9   // Control pin 2 for motor 2

void setup() {
  pinMode(E1, OUTPUT);
  pinMode(E2, OUTPUT);
  pinMode(I1, OUTPUT);
  pinMode(I2, OUTPUT);
  pinMode(I3, OUTPUT);
  pinMode(I4, OUTPUT);
}

void loop() {
  analogWrite(E1, 255); // Run at full speed
  analogWrite(E2, 255); // Run at full speed
  digitalWrite(I1, HIGH);
  digitalWrite(I2, LOW);
  digitalWrite(I3, HIGH);
  digitalWrite(I4, LOW);
  delay(4500);
  // change direction
  digitalWrite(E1, LOW);
  digitalWrite(E2, LOW);
  delay(2000000000000);
  analogWrite(E1, 255);  // Run at full speed
  analogWrite(E2, 255);  // Run at full speed
  digitalWrite(I1, LOW);
  digitalWrite(I2, HIGH);
  digitalWrite(I3, LOW);
  digitalWrite(I4, HIGH);
  delay(000);
}

http://hw.sudarmuthu.com/wp-content/uploads/sites/2/2013/06/basic-bot1.png


texts: Activate a DC motor for a fixed amount of time

texts:
I have a single simple DC motor that upon a condition I wish to let it run for 3 minute. How can I do it in Arduino? a simple addition to the code will be great help.

As I use Adafruit motor shield this is my current code:

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);

void setup() {
   Serial.begin(9600);           // set up Serial library at 9600 bps
   AFMS.begin();  // create with the default frequency 1.6KHz
}

void loop() {
IOvalue = 1000

if (IOvalue = 1000) {

 //this is the motor I wish to run for 3 min
   myMotor->setSpeed(25);
   myMotor->run(FORWARD);
   delay(100);
 }
}

Thanks a lot


texts: Function only taking the first 4 elements of a character array

texts:
I'm writing a function for my arduino program that takes a character array of any size and will mark all the characters that aren't in the alphabet by changing their value to '1'.

I have a switch variable (foundSym) that will turn to 0 if the character IS part of the alphabet. At the end of my first for loop if the switch never changed, that means the character was NOT a letter and will be marked. Note I also don't want to mark space characters (' ').

The issue I have is every array I pass into the function will only have a length of 4, no matter the size.

I've checked the length of each array before it enters the function and when it is in the function, everytime the size gets shortened to 4 elements!

Here is my function...what am I doing wrong??

void markSymbols(char str[]){
  for(int i = 0; i<sizeof(str); i++){
    int foundSym = 1;
    for (int j = 0; j<26; j++){
      if (str[i] == alphabet[j]) {
        foundSym = 0;
        break;
        }
    }
    if (str[i] == ' ') foundSym = 0;
    if (foundSym == 1) str[i] = '1';
  }

}


texts: What is the necessity of “Prototyping Shield” for an arduino UNO R3?

texts: I just want to learn arduino and make some small projects.But in beginner starter kit there's a part named Prototyping Shield .Is it necessary or will it help me?


texts: Error compiling: expected unqualified id before token {

texts:
#include <LiquidCrystal.h>
#define trigPin 12              // the trig pin to digital pin 12
#define echoPin 13              // the Echo pin to digital pin 13
#define led 8
#include <Servo.h>
Servo servoMain; // Define our Servo

LiquidCrystal lcd(7, 6, 5, 4, 3, 2);

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
  Serial.begin(9600); // Starts the serial communication
  lcd.begin(16, 2);
  servoMain.attach(11); // servo on digital pin 11
}

void loop() {
  servoMain.write(5);  // Turn Servo Left to 5 degrees
  delay(1000); // Wait 1 second
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration/2) / 29.1;
  if (distance < 3) {
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("PLEASE REFILL!");
    lcd.setCursor(0, 1);
  } else {
    digitalWrite(led, LOW);
  }
  if (distance < 6) {
    digitalWrite(led, HIGH);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("U May Refill Now");
    lcd.setCursor(0, 1);
  } else {
    digitalWrite(led, LOW);
  }
  if (distance < 8) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Take it easy");
    lcd.setCursor(0, 1);
  }
  if (distance <= 16) {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("FULL!!");
    lcd.setCursor(0, 1);
  }
  if (distance > 16 || distance <= 0) {
    Serial.println("Out of range");
  } else {
    Serial.print(distance);
    Serial.println(" cm");
  }
}
delay(1000);

}
    }


texts: Sending hex data serially and receive it back

texts:
Below is my code. I want to send the hex data serially to some device and also expecting a reply. I want to see the reply in hex form on a serial monitor. Any comment will be appreciated. Thanks.

const byte numChars = 88;
word receivedChars[numChars]; // an array to store the received data
boolean newData = false;

void setup() {
  Serial.begin(9600);
  Serial.println("<Arduino is ready>");
}

void loop() {
  uint8_t message[] = {0xA5, 0x0D, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,0x00, 0x0d };
  Serial.write(message, sizeof(message));
  delay(500);
}

void recvWithEndMarker() {
  static byte ndx = 0;
  char endMarker = '\n';
  word rc;
  while (Serial.available() > 0 && newData == false) {
    rc = Serial.read();
    if (rc != endMarker) {
      receivedChars[ndx] = rc;
      ndx++;
      if (ndx >= numChars) {
        ndx = numChars - 1;
      }
    } else {
      receivedChars[ndx] = '\0'; // terminate the string
      ndx = 0;
      newData = true;
    }
  }
}

void showNewData() {
  if (newData == true) {
    Serial.print("data ");
    Serial.println(receivedChars);
    newData = false;
  }
}

The error I get is call of overloaded println(word [88]) is ambiguous. Thank you for your help.


texts:
I'm a software Engineer, and recently I’ve been working on a new Software
Part of this Software is to be able to turn off and on multiple TV screens using timers in the software
First idea came to my mind is using relays with Arduino and connecting in to computer using Bluetooth chip but not all screens turns on once the power cable is plugged in
So, I tried IR CIRCUIT using NODEMCU and IR LEDS. And it worked but not perfectly,
The way I did this is by sending a combination of IR codes to screen to make a sleep timer so it will turn off the screen after some time.
But there was a delay when sending IR codes, and sometimes the code won’t be sent
This is the circuit I used (in addition to more  IR LEDS)

I just want to know why the codes are not sent every time
And if there is any better way to control the screens from computer?


texts: Switch Case Return , Return not printing

texts:
I am trying to get the value of a key pressed and set it to return a value to use in a loop.  In the code below the Print(t) does not show anything

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char hexaKeys[ROWS][COLS] = {
    {'1', '2', '3', 'A'},
    {'4', '5', '6', 'B'},
    {'7', '8', '9', 'C'},
    {'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[ROWS] = {5, 4, 3, 2};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys),rowPins,colPins,ROWS,COLS;

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

void loop()
{
    int t;
    switch (customKeypad.getKey())
    {
    case 'A':
        t = 8;
        break;
    case '2':
        t = 9;
        break;
    }
    return t;
    Serial.print(t);
}


texts: Arduino button voltage versus HIGH/LOW state

texts:
I'm measuring voltage between button's ground and input pole on the following sketch. When button is on off state, there's 5V there, when it's switched on and led turs on, there's 0. Is this a correct way, and also how do I make it easier to write code and have LOW represent led being off. In this sketch, digitalWrite(led1, LOW); means the LED is actually turned on, so how do I tweak this to be representative of actual state, high=led on.
#include <ezButton.h>

// -----
// Declaration
// -----

const int button1  = 9;
const int led1     = 4;
int ledState = LOW;

ezButton button(button1);

// -----
// Setup
// -----

void setup()
{

  pinMode(led1, OUTPUT);
  pinMode(button1, INPUT_PULLUP);
  button.setDebounceTime(50);

}

// *****
// Main Loop
// *****

void loop()
{

  if( digitalRead(button1) == LOW ) {
    digitalWrite(led1, HIGH);
  }
  else  {
    digitalWrite(led1, LOW);
  }

}

// *****


texts: If I use an Arduino board to bootload a new chip, is it still possible to use the microcontroller on the board for another project, or it will only be for bootloading new chips.


texts: I am looking for the boards.txt, platform.txt and core files needed for the programming of the ATtiny13 with the Arduino Uno. Those I find on the internet probably only works with Arduino 1.0 and not with 1.6.


texts: How to use HM-10 as client, and send messages to specific services/characteristics?

texts:
I have been messing around with this module, unfortunately i bought a fake one, but got the original firmware running inside it (V550).
So far i can set the HM-10 up as client/master and by using an peripheral emulator on Android, i set up a peripheral as my server/slave
The peripheral is able to write to its own characteristic and it sends a notification to the client HM10 that fetches this value and displays it correctly on my serial reader (cutecom and arduino serial monitor)
After this, i'd like to write to the peripheral's characteristic, but i can't find any information about this, but it should be in the realm of possibility, i think.
I am using the Arduino IDE to interface with the HM-10 module.
Any information pointing in the right direction is very, very welcomed. Its driving me crazy now...


texts: Arduino Uno, HM-10 Bluetooth Module, Not Discoverable

texts:
In short, I've hooked up an HM-10 to digital pins 10 and 11 on my Uno (required because TX/RX (0/1) can't be used whilst a serial connection is present). The Bluetooth module is a Sunfounder HM-10 which comes with a data sheet. I'm successfully communicating with the HM-10 and I've written a modified version of serial comms tutorial code provided so it stores the reads up in a buffer before outputting them which works fine, I can set all properties on the HM-10 using this method.

The delays were necessary as it seems the clock cycle can't 'keep up' - bytes go missing when reading/writing, so if I attempt to write by just using Serial.read() in loop() alone then not all of it is read/written.

Here's the code.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup()
{
  // Open serial communications and wait for port to open:
  Serial.begin(57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("Goodnight moon!");

  delay(500);

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.print("Wake up wake up wake up wake up wake up! Wake up wake up wake up wake up wake up!");
}

void loop() // run over and over
{
  if (mySerial.available()) {
    String s = "";
    char c;
    while((c = mySerial.read()) != -1) {
      s += c;
      delay(10);
    }

    Serial.println("Received: " + s);
  }

  if (Serial.available()) {
    String s = "";
    char c;
    while((c = Serial.read()) != -1) {
      s += c;
      delay(10);
    }

    delay(10);

    Serial.println("Sent: " + s);

    mySerial.print(s);
  }
}

This allows me to show input and output as follows:

Sent: AT+ADDR?
Received: OK+ADDR:F4B85EB42D64
Sent: AT+ADVI?
Received: OK+Get:0
Sent: AT+ALLO?
Received: OK+Get:0
Sent: AT+BATT?
Received: OK+Get:077

So good so far. Here's what I can't figure out from the data sheet. How do I make the bluetooth module discoverable on, say, my Mac or from my iPhone? I've tested setting AT+ROLE0 or AT+ROLE1 followed by AT+RESET and also set AT+NAME so I know what to expect, yet I can't discover the module.

Also to note, the status LED is flashing as per the specification as an unconnected status (500ms high, 500ms low) which indicates AT+PIO10 is setup. AT+ADTY? is set to 0 which allows it to be advertising, responds to scanning and connectable.

I'm likely missing something quite obvious. Any ideas?


texts: Arduino UNO R3 + SIM800L / NodeMCU via Hadware Serial. Possible?

texts:
I'm using Arduino UNO R3 with NodeMCU and SIM800L module. I have to connect these two devices to UNO and make a serial communication between them: UNO<>SIM800L and UNO<>NodeMCU.

Can I use GPIO0 and GPIO1 of UNO (RX, TX) to communicate with one of above devices?

Thanks in advance.


texts: Finding min and max value in 3rd column and printing the whole row

texts:
I am currently using an RTC module and a Dissolved Oxygen Sensor.
Data is stored in a csv file and I want to find the 3rd row's min and max, but print all the rows including the time.
void data() {
  dataString = String(t.hour) + "," + String(t.min) + "," + String(DO);
  saveData();
  delay(000);
}

void saveData() {
  sensorData = SD.open("data.csv", FILE_WRITE);
  if (sensorData) {
    sensorData.println(dataString);
    sensorData.close();
  }
}

void Read() {
  File sensorData = SD.open("data.csv");
  for (int i = 2; i < 30; i++) {
    input = sensorData.parseInt();
    arr[arrIndex] = sensorData.parseInt();
    arrIndex++;

    if (input > maxValue) {
      maxValue = input;
    }
    if (input < minValue) {
      minValue = input;
    }

    Serial.print("max");
    Serial.print(maxValue);
    Serial.print("\t");
    Serial.print("min");
    Serial.println(minValue);
  }
  lcd.begin(20, 4);
  lcd.setCursor(5, 0);
  lcd.print("Maximum DO");
  lcd.setCursor(8, 1);
  lcd.print(maxValue);
  lcd.setCursor(5, 2);
  lcd.print("Minimum DO");
  lcd.setCursor(8, 3);
  lcd.print(minValue);
}

Basically the output should be:


texts: Is there any way I can stop the Arduino Mega 2560 from resetting all variables after losing and reconnecting power?

texts:
I am using an Arduino Mega 2560 board. I have tried connecting a 115 Ω resistor from 5V to Reset, and 10 µf capacitor form reset to GND (to disable autoreset), and the variables still seem to reset themselves when I unplug and replug-in the Arduino. Any way to stop this from happening?

Basically I am making a device that is sensitive to time, and must run for about 2 months, but if it is unplugged, it can't lose its place in time and reset the whole program.

I think one alternative would be for me to have it actually write how long it has been running into a .txt file on the microSD card and then verify that in the start-up...

Any ideas?


texts: A function-definition is not allowed here before '{' token

texts:
I'm trying to light up 81 on a 4-digit 7-segment display, but when I try to upload the code to my Uno R3 it gives me this error: "a function-definition is not allowed here before '{' token". I'm new to Arduino and this is my second day using it, so I would like to get help and know how to fix this problem. Here is my code:

int isej1 = 2;
int isej2 = 3;
int vienetas[] = { 12, 11 };
int astuonetas[] = { 13, 12, 11, 10, 9, 8, 7 };

void setup() {
  pinMode (vienetas[2], OUTPUT);
  pinMode (astuonetas[8], OUTPUT);
  pinMode (isej1, OUTPUT);
  pinMode (isej2, OUTPUT);
}

void uz_vien() {
  digitalWrite (vienetas[0], HIGH);
  digitalWrite (vienetas[1], HIGH);
}

void uz_astuon() {
  digitalWrite (astuonetas[0], HIGH);
  digitalWrite (astuonetas[1], HIGH);
  digitalWrite (astuonetas[2], HIGH);
  digitalWrite (astuonetas[3], HIGH);
  digitalWrite (astuonetas[4], HIGH);
  digitalWrite (astuonetas[5], HIGH);
  digitalWrite (astuonetas[6], HIGH);
}

void is_vien() {
  digitalWrite (vienetas[0], LOW);
  digitalWrite (vienetas[1], LOW);
}

void is_astuon() {
  digitalWrite (astuonetas[0], LOW);
  digitalWrite (astuonetas[1], LOW);
  digitalWrite (astuonetas[2], LOW);
  digitalWrite (astuonetas[3], LOW);
  digitalWrite (astuonetas[4], LOW);
  digitalWrite (astuonetas[5], LOW);
  digitalWrite (astuonetas[6], LOW);

void loop() {
  digitalWrite (isej1, LOW);
  digitalWrite (isej2, HIGH);
  void uz_vien();
  delay(5);
  void is_vien();
  digitalWrite (isej1, HIGH);
  digitalWrite (isej2, LOW);
  void uz_astuon();
  delay(5);
  void is_astuon();
}


texts: Is an Ultrasonic Sensor or Infrared Sensor better for measuring distance (to/from a human body)?

texts:
I'm trying to make a sensor to detect that a person is within 50cm to trigger a function. But when I use the HR-SR04 sensor, it works accurately on flat surfaces (e.g. walls, books) with a margin of error around 5cm, but not on uneven surfaces (e.g. humans) where the value randomly jumps between 0cm to 1000cm.
I was thinking whether using an IR distance sensor would be better.


texts:
I am using 3 Esp32 modules. One being master and other two being nodes.
Nodes are connecting to the master's AP. Master is connected with GSM module to execute the web api.
Master esp is having a Async Webserver which takes the http requests from the nodes and executes the appropriate web api. This web api returns the result and finally this result is sent back to the node as the response to the http request.

While running this code, Randomly on any request i face wdt reset.

Hence my question is, how should i handle the wdt resets and keep my program running softly.

E (32706) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (32706) task_wdt: - async_tcp (CPU 0/1)
E (32706) task_wdt: Tasks currently running:
E (32706) task_wdt: CPU 0: IDLE0
E (32706) task_wdt: CPU 1: async_tcp
E (32706) task_wdt: Aborting.
abort() was called at PC 0x400e1cc3 on core 0
Backtrace: 0x4008c434:0x3ffbe170 0x4008c665:0x3ffbe190 0x400e1cc3:0x3ffbe1b0 0x40084771:0x3ffbe1d0 0x4016aaf3:0x3ffbc0d0 0x400e307a:0x3ffbc0f0 0x4008a361:0x3ffbc110 0x40088b7d:0x3ffbc130

My Code Snippet is given below,

Master

HttpClient http(gsmClient, "www.mydummyserver.com", 80);
AsyncWebServer server(80);

const char* ssid = "ESP32-Access-Point";
const char* password = "123456789";
IPAddress ip(192,168,5,2);
IPAddress gateway(192,168,5,1);
IPAddress subnet(255,255,255,0);
const char* PARAM_MESSAGE = "message";

void notFound(AsyncWebServerRequest *request) {
    request->send(404, "text/plain", "Not found");
}

void setup() {

  Serial.begin(115200);
  WiFi.mode(WIFI_AP);
  delay(100);
  WiFi.softAPConfig(ip, gateway, subnet);
  WiFi.softAP(ssid, password);

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
        request->send(200, "text/plain", "Hello, world");
    });

 server.on("/myApi", HTTP_POST, [] (AsyncWebServerRequest *request) {

        String message;
        if (request->hasParam(PARAM_MESSAGE)) {
            message = request->getParam(PARAM_MESSAGE)->value();
        } else {
            message = "No message sent";
        }

        http.setTimeout(20000);
        String postData = "Param1=abcd&Param2=pqrs";
        http.beginRequest();
        http.post("http://www.mydummyserver.com/testapi.php");
        http.sendHeader("Content-Type", "application/x-www-form-urlencoded");
        http.sendHeader("Content-Length", postData.length());
        http.beginBody();
        http.print(postData);
        http.endRequest();
        int statusCode = http.responseStatusCode();
        String response = http.responseBody();

        Serial.print("Status code: ");
        Serial.println(statusCode);
        Serial.print("Response: ");
        Serial.println(response);
        request->send(200, "text/plain", "Response: " + message);

    });

 server.onNotFound(notFound);

    server.begin();

}

void loop() {

}

Node

HTTPClient httpClient;

void setup() {

  Serial.begin(115200);

  WiFi.begin("ESP32-Access-Point", "123456789");

  Serial.print("WiFi ");

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(10);

  }

  Serial.println("connected:" + WiFi.SSID());

}

void executeApi() {

  Serial.println("Executing Api...");

  httpClient.setTimeout(20000);
  httpClient.begin("http://192.168.5.2/myApi");
  httpClient.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  String contentStr = "Param1=abcd&Param2=pqrs";

  int httpResponseCode = httpClient.POST(contentStr);

  Serial.print("HTTP Response code: ");
  Serial.println(httpResponseCode);

  httpClient.end();

}

String cmd = "";
void loop() {

  if (Serial.available() > 0) {

    cmd = (Serial.readStringUntil('\n'));

    if (cmd.length() > 0) {

      if (cmd == "api") {
        executeApi();

      }

    }

  }

}

For sulutions i have tried following things,

a. I tried to write this into the loop() function.

 while(true){
   delay(1);
 }

b. Tried disabling the wdt

disableCore0WDT()
disableCore1WDT()

but none of these giving good results.


texts: NRF24L01+ scanning and connecting to wifi hotspots or creating one

texts: I've seen this video so I think I can connect it through my wifi router to any device. How can I scan for and discover wifi hotspots and then connect to it? Or is there a way to create wifi hotspot of it's own?


texts: Exit status 1 expected primary-expression before ']' Arduino

texts:
Here's the whole error:

 Arduino: 1.6.7 (Windows 7), Board: "Arduino/Genuino Uno"

 *\readMifare\readMifare.ino: In function 'void loop()':

 readMifare:113: error: expected primary-expression before ']' token

    if (uid[] == { 0x04, 0xEC, 0x89, 0x32, 0x55, 0x42, 0x80 }) {

            ^

 readMifare:113: error: expected primary-expression before '{' token

    if (uid[] == { 0x04, 0xEC, 0x89, 0x32, 0x55, 0x42, 0x80 }) {

                 ^

 readMifare:113: error: expected ')' before '{' token

 readMifare:121: error: expected '}' at end of input

    }

    ^

 exit status 1
 expected primary-expression before ']' token

   This report would have more information with
   "Show verbose output during compilation"
   enabled in File > Preferences.

Here's the code

 #include <Wire.h>
 #include <SPI.h>
 #include <Adafruit_PN532.h>

 // If using the breakout with SPI, define the pins for SPI communication.
 #define PN532_SCK  (2)
 #define PN532_MOSI (3)
 #define PN532_SS   (4)
 #define PN532_MISO (5)
 // If using the breakout or shield with I2C, define just the pins connected
 // to the IRQ and reset lines.  Use the values below (2, 3) for the shield!
 #define PN532_IRQ   (2)
 #define PN532_RESET (3)  // Not connected by default on the NFC Shield

 // Uncomment just _one_ line below depending on how your breakout or shield
 // is connected to the Arduino:

 // Use this line for a breakout with a software SPI connection (recommended):
 Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS);

 // Use this line for a breakout with a hardware SPI connection.  Note that
 // the PN532 SCK, MOSI, and MISO pins need to be connected to the Arduino's
 // hardware SPI SCK, MOSI, and MISO pins.  On an Arduino Uno these are
 // SCK = 13, MOSI = 11, MISO = 12.  The SS line can be any digital IO pin.
 //Adafruit_PN532 nfc(PN532_SS);

 // Or use this line for a breakout or shield with an I2C connection:
 //Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);

 #if defined(ARDUINO_ARCH_SAMD)
 // for Zero, output on USB Serial console, remove line below if using      programming port to program the Zero!
 // also change #define in Adafruit_PN532.cpp library file
 #define Serial SerialUSB
 #endif
 #include <Servo.h>

 Servo servo1;

 void setup(void) {
   #ifndef ESP8266
   while (!Serial); // for Leonardo/Micro/Zero
   #endif
   Serial.begin(115200);
   Serial.println("Hello!");

   nfc.begin();

   uint32_t versiondata = nfc.getFirmwareVersion();
   if (! versiondata) {
     Serial.print("Didn't find PN53x board");
     while (1); // halt
   }
   // Got ok data, print it out!
   Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
   Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
   Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

   // configure board to read RFID tags
   nfc.SAMConfig();

   Serial.println("Waiting for an ISO14443A Card ...");
   servo1.attach(9);
 }

 void loop(void) {
   uint8_t success;
   uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
   uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

   // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
   // 'uid' will be populated with the UID, and uidLength will indicate
   // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
   success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

   if (uid[] = { 0x04, 0xEC, 0x89, 0x32, 0x55, 0x42, 0x80 }) {

      int position;
      for(position = 0; position < 180; position += 2){
       servo1.write(position);
       delay(20);
      }

   }

Please note that I'm using an example from the Adafruit official PN532 library examples and trying to edit it.


texts:
I'm reading on the DFRobot website to implement this Voltage divider: Analog Voltage Divider SKU: DFR0051

void setup()
{
  Serial.begin(9600);
}
void loop()
{
      float val;
      float temp;
      val=analogRead(2);//This divider module will divide the measured voltage by 5, the maximum voltage it can measure is 25V.
      temp= val/40.92;
      val=(float)temp;
      Serial.println(val);
      delay(1000);
}

Where does 40.92 come from? And even when printing only VAL it's something like 210 and I'm not sure what this is supposed to be. I don't get how to get the actual voltage of the battery etc. being measured? If it's divided by 5, why do you not multiply by 5 anywhere?


texts: Arduino Yun with PoE does not work when powered via PoE

texts:
I have a Arduino Yun with PoE with LininoOS version

  Linux arduino 3.3.8 #1 Thu Jun 2 12:28:33 CEST 2016 mips GNU/Linux

I have the Version 4.0 of the module.

I often notice that when I connect the module via a USB cable and login via Serial the WAN and WLAN LEDs blink and I can SSH via both the mediums.

However I cannot do the same when the Yun is completely powered via an Ethernet Cable and the I see the Yun frequently restarting and becoming inaccessible via SSH.

I cannot troubleshoot this problem via software as whenever I connect the USB cable along with the Ethernet Cable the power supply switches completely to the USB and the PoE stops and everything suddenly works well again.

Has someone faced the same issue? Is it because of the High Frequency Whistle problem where I need to solder a 100µF Electrolytic Capacitor to the PoE adapter?

Update

I measured the 5 V and 3.3 V pins on the Yun they provide their respective voltages via a multimeter.

I have a Microsens fast ethernet switch with PoE which provides standard (minimum 44V DC)

  Apparently, the WAN LED blinks indicating the Ethernet Connection is available however everytime I ping the Yun it goes down.


texts: Replacement for #include  on particle photon

texts:
I've run into this a couple of times when trying to use libraries written for Arduino on a particle photon. Many have the line:

 #include <pins_arduino.h>

which returns the error on the photon compiler:

 fatal error: pins_arduino.h: No such file or directory

I had similar trouble with:

 #include <WProgram.h>

and found an easy fix was to replace that with

 #include "application.h"

I'm wondering if there's a similar easy fix for pins_arduino?


texts: Can I safely connect my original Arduino Uno to a 19V adapter?

texts:
I have an original Arduino Uno R3. According to the specifications the recommended input voltage is 7 to 12 Volt.

However, I have a laptop adapter of 19V that I want to use to power my arduino because it offers more current than the 9V adapter I have as well.

I don't want to damage the Arduino or the DFRobot 2A Motor Shield I'm using. Can I safely plug in the adapter and will it still work correctly?


texts: Mega + SIM808 GPRS GSM GPS IPX-SMA module power on from code

texts:
Is it possible to turn on the SIM808 module from code? There is a button in the SIM808 board to activate the module, but I need to turn it on from the code automatically. This is because my device will be stored hidden inside a vehicle so I do not have to keep turn on and off by hand.

This is the model.


texts: Arduino UNO capacitive sensor not working

texts:
This is a visualization of my Arduino connections:

I wish to read the data using the Capacitive sensor Library. iv'e tried the following code but variables total1, total2, total3 always have the value 0 and i don't know what is wrong.

My code:

// Import the CapacitiveSensor Library.
#include <CapacitiveSensor.h>

// Name the pin as led.
#define speaker 11

// Set the Send Pin & Receive Pin.
CapacitiveSensor   cs_2_3 = CapacitiveSensor(2,3);        // 10M resistor between pins 4 & 2, pin 2 is sensor pin, add a wire and or foil if desired
CapacitiveSensor   cs_2_4 = CapacitiveSensor(2,4);        // 10M resistor between pins 4 & 6, pin 6 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_5 = CapacitiveSensor(2,5);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_6 = CapacitiveSensor(2,6);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_7 = CapacitiveSensor(2,7);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_8 = CapacitiveSensor(2,8);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil
CapacitiveSensor   cs_2_9 = CapacitiveSensor(2,9);        // 10M resistor between pins 4 & 8, pin 8 is sensor pin, add a wire and or foil

void setup()
{
  cs_2_3.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example

  // Arduino start communicate with computer.
  Serial.begin(9600);
}

void loop()
{
  // Set a timer.
  long start = millis();

  // Set the sensitivity of the sensors.
  long total1 =  cs_2_3.capacitiveSensor(60);
  long total2 =  cs_2_4.capacitiveSensor(60);
  long total3 =  cs_2_5.capacitiveSensor(60);
 /* long total4 =  cs_2_6.capacitiveSensor(60);
  long total5 =  cs_2_7.capacitiveSensor(60);
  long total6 =  cs_2_8.capacitiveSensor(60);
  long total7 =  cs_2_9.capacitiveSensor(60);*/

  Serial.print(millis() - start);        // check on performance in milliseconds
  Serial.print("\t");                    // tab character for debug windown spacing

  Serial.print(total1);                  // print sensor output 1
  Serial.print("\t");                    // Leave some space before print the next output
  Serial.print(total2);                  // print sensor output 2
  Serial.print("\t");                    // Leave some space before print the next output
  Serial.print(total3);                  // print sensor output 3
  Serial.print("\t");                    // Leave some space before print the next output
  Serial.print("\n");
}


texts: I have to make an LED with an ultrasonic distance sensor, the idea is to make the LED blink faster when getting closer to at an specific distance

texts:
i alread have this code, but i do not know how to make the led blink.

CODE:

const int ledPin = 6; // The pin of your LED, D06
const int trigPin = 5; // The pin to which the TRIG is connected, D05
const int echoPin = 4; // The pin to which the ECHO is connected, D04
const int ledOnTime = 1000;
// The time that the LED stays on, after detecting the motion (in milliseconds, 1000ms = 1s)
const int trigDistance = 40;
// The distance (and lower than it) at which the sensor is triggered (in centimeters)
//
int duration;
int distance;

void setup() {
    pinMode(ledPin, OUTPUT);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
}

void loop() {
    digitalWrite(trigPin, LOW);
    digitalWrite(trigPin, HIGH);
    delay(1);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = duration * 0.034/2;
    if (distance <= trigDistance) {
        digitalWrite(ledPin, HIGH);
        delay(ledOnTime);
        digitalWrite(ledPin, LOW);
    }
    delay(100);
}


texts: how to find find out capacitance using time constant?

texts:
i'm trying to find out the capacitance value using the time constant of the RC ciruit. so i followed the technique on the below link.

http://www.gammon.com.au/forum/?id=12075

Now, it's working fine.. but still i need wider range so i want to know the full core logic of that program like how the capacitance formula has been derived out in those program?

thanks in advance...


texts: Force TCNT to stay below OCRxA on ATmega328P

texts:
I'm using a timer and the TIMERx_COMPA ISR to generate a signal in "the background".

This ISR is triggered when the timer reaches a certain value (OCRxA), which in turn can be changed by the user.
Once the ISR triggers, the timer is reset and the next waiting period occurs.

If the compare value (OCRxA) is changed to a value below the current timer value before having hit the old compare value, the timer keeps running until it overflows back to 0 and hits the new OCRxA value. This results in no signal being generated until the timer has looped around, which can be quite long for the 16-bit TIMER1 timer.

There are multiple way to get around this:

Reset TCNTx to zero whenever OCRxA. Easy, but one signal will always be off-clock
If TCNTx is greater than OCRxA (after changing OCRxA), reset it to just below OCRxA
If TCNTx is greater than OCRxA, trigger the interrupt manually, where the signal is generated and TCNTx is reset

I belive the third option would be the cleanest, both in checking whether the issue has occured as well as for the signal quality.

This is certainly an X -> Y problem, so I'm open for other approaches.

My question, for now, would be:
Can I manually jump to an ISR regardless of its "normal" trigger?


texts: What is the actual range of Xbee RP-SMA antenna?

texts:
I'm building a Model rocket, and i will use xbee series 1 pro, so i think RP-SMA antenna would be the best to use because i will put the xbee into the rocket. So does anyone know what is the range of the xbee with this antenna?
Can it reach 1000 feet?


texts: Is there a way to read real-time port selection on Arduino IDE when using third-party toolchain and uploading program?

texts:
I am using a third-party program to build the binary file and upload it under Arduino IDE's GUI, meaning I am not using the built-in avr-gcc nor avrdude for building and uploading. As there is a on-board DAP chip, uploading binary file is done by copy&paste the binary file into the flash memory recognized as a removable storage by the OS.

However, this make reading user's current port selection very difficult because the IDE is written in Java, but the thrid-party program I am using is in C++.

Knowing which port the user has currently selected is very important to me, as sometimes I need to program multiple boards at the same time and monitor their received data on the serial port.

If someone can point me into the right direction or link me to the previously-solved similar question , it will be much appreciated!

PS: I am working under Ubuntu&Windows10 OS and using latest Arduino IDE.


texts:
I'm currently trying to make a quadcopter flight controller based on the Arduino Uno, and I've managed to make everything work for one axis by printing the values of two of the motors, except now that I try connecting the ESCs to the arduino, the ESCs won't start. I think there is something wrong when the microseconds are written to the ESCs, but I can't figure out what is wrong. Here is the GitHub repo for the code:

https://github.com/bybel/R2-Quadcopter

Thanks for your help !


texts: Connecting Web Server in GoDaddy Hosting

texts:
I have a domain. It is hosted by GoDaddy. I need to connect that server and receive some data by executing PHP files.
I am not sure about the components.
Tutorials on internet describes how to control esp8266 from web server which is i do not want.
Also i found arduino uno wifi board/wifi shield but in arduino store, it says: this product is 'retired'.
So do you recommend any component for this task or should i go with arduino uno wifi?


texts: Why can't my Arduino IDE recognize serial ports? (Mac El Cap, Ard. UNO)

texts:
My Arduino UNO I bought directly from Arduino.cc, so I'm pretty certain it's not a cheap clone. I have a MacBook Pro El Capitan 10.11.5. My Java is 1.8, but I'm pretty sure that doesn't matter. I have never used Arduino before, though I know a good bit of programming and some about computers. Whilst setting up Arduino, the only serial port my computer/Arduino recognizes is /dev/cu.Bluetooth-Incoming-Port. Please comment if there is more information I should provide.

My computer recognizes that I have a USB device as seen here:

Here is a screenshot of the Arduino IDE:

Finally, the commandls /dev/tty.* outputs only /dev/tty.Bluetooth-Incoming-Port. Is it possible no other serial ports exist for me?
Sorry for the barrage of pictures but I thought they'd help.

Things I have tried:

Installing CH34x driver

I'm convinced it's not a driver issue though, as users and Arduino say that OS X does not need drivers installed to run Arduino

Turning off System Integrity with csrutil --disable and also tried csrutil --enable without kext
Installing a FTDI USB Serial Driver
Bought a new USB A/B cable, as many reported the cable was faulty. I am getting a green light on my board

Does anyone know why my computer and/or Arduino does not list more serial ports that work? It's as if I don't have any besides the one Bluetooth port. I've been getting frustrated over this for several hours, so a solution would be much appreciated :)! I've tried all the solutions I've seen on SE thus far, but maybe I'm missing something

Thank you ahead of time!


texts: Cannot receive and transmit at the same time

texts:
I have 2 arduinos I made some code and I managed to send from the first to the second and from the second to the first with two different pairs of code. What I want to do is to send from the first to the second and from the second to the first with no code change. I added in my current code some monitoring commands but what I can see in my Serial monitor is that not all characters are passed thru. I attach something like my code below only more simplified because it is a big project.

1st arduino:

radio.stopListening();
  for(int i=0; i<lnth; i++){
      chartosend=data.charAt(i);
      radio.write( &chartosend, sizeof(chartosend) );
  }
  radio.write(&endchar,1);
radio.startListening();
  if(radio.available()){
    radio.read( &inchar, sizeof(inchar) );
    inradio+=inchar;
    //Serial.println(inchar);
  }

2nd Arduino:

radio.startListening();
  if(radio.available()){
    radio.read( &data, sizeof(data) );
    inradio+=data;
  }
radio.stopListening();
  if(analogRead(0)>20){
     for(int i=0; i<6; i++){
      chartosend=pir1.charAt(i);
      radio.write( &chartosend, sizeof(chartosend) );
    }
    radio.write( &endchar, sizeof(endchar) );
  }

Where is the problem and how I could solve this?


texts: Photoresistor value drops when board stacked on Arduino Uno

texts:
I have a simple photoresistor displaying values on a serial monitor every second so I can establish a value that I want to use to have it activate a relay.

It has worked fine for a few weeks, with bright sunlight values about 1000, total dark is 0. I soldered only the headers on a protoshield, and stacked it on the Arduino. I have nothing else on the protoshield and I am still using jumper wires to a breadboard, which I have not changed.

Why would the photoresistor values drop to approximately 40 (from 900's) when I stack the second board on the Arduino?


texts: I am going to use few Figaro TGS sensors, which including TGS2600, 2602 and 2620 with my Arduino. I referred to the datasheet and found that these sensors need more than one voltage source. May I know the correct way to connect them to my arduino? (Arduino Mega or Uno probably)...(beginner here)


texts: Burning servos like crazy, what am I doing wrong?

texts:
For some reason my servos keep burning out.

My code is simple, if condition, rotate to 0 degrees, else rotate to 180.

However, what that does to the motor is keep it in a constant struggle to stay in rotation 0 or 180, when there is no movement in between. Sure enough, leave it running for 1 hour, the motor burns out.

if (!strcmp("1",output)){
    myservo.write(0);
}
else {
    myservo.write(180);
}

Is there something like myservo.release or something? I presuming i need to get the servo in to position, then release it so it doesnt try to stay in position.

Please help, i've burned through 4-5 of them so far, it's not fun :(


texts:
I am a beginner at AVR and programming. I am using ATtiny461 and asked to make code to use timer in PWM and CTC mode and use interrupts and pin toggle, this code worked for me with normal timer and toggle but I don't know how to make it work with CTC and PWM:

#include <avr/io.h>
#include <avr/interrupt.h>

//Init PD6 pin as output
void InitPort(void)
{
    PORTB&=~(1<<PB1);//initial value 0
    DDRB|=(1<<PB1);
}
//Initialize Timer0
void InitTimer0(void)
{
    //Enable Timer0 overflow Interrupt
    TIMSK|=(1<<TOIE0);
    //Set Initial Timer value
    TCNT1=5;
}
void StartTimer0(void)
{
    //Set prescaller 64 and start timer
    TCCR0B|=(1<<CS01)|(1<<CS00);
    //Enable global interrupts
    sei();
}
//Timer0 Overflow ISR
ISR(TIMER0_OVF_vect)
{
    //Reset Initial Timer value
    TCNT1=5;
    //toggle PD6 pin
    PINB=(1<<PB1);
}

int main(void)
{
    InitPort();
    InitTimer0();
    StartTimer0();
    while(1)
    {
        //doing nothing
    }
}

and I know those commands for setting fast PWM and CTC:

TCCR1D |= (0<<WGM10)|(0<<WGM11);
TCCR1A |= (1<<PWM1A)|(1<<COM1A0)|(0<<COM1A1);


texts:
When using ESP8266 - getting seconds from epoch is done using

NTP.begin(NTPserver, 2, true);
delay(delay_tries);
time_t t = now();

while t stores amount of seconds from 1-1-1970.

When trying to do the same, using ESP32 - I cant get that numeric representation.

code below is from ESP32 example- updating time using NTP server ( process is done correct ). BUT when using now() yields 1970, as if NTP update has never occured.

How can I get time from Epoch ?

#include <WiFi.h>
#include "time.h"
#include <TimeLib.h>    <------- Added to original Code

const char* ssid       = "YOUR_SSID";
const char* password   = "YOUR_PASS";

const char* ntpServer = "pool.ntp.org";
const long  gmtOffset_sec = 3600;
const int   daylightOffset_sec = 3600;

void printLocalTime()
{
  struct tm timeinfo;
  if(!getLocalTime(&timeinfo)){
    Serial.println("Failed to obtain time");
    return;
  }
  Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}

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

  //connect to WiFi
  Serial.printf("Connecting to %s ", ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
      delay(500);
      Serial.print(".");
  }
  Serial.println(" CONNECTED");

  //init and get the time
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  printLocalTime();

  //disconnect WiFi as it's no longer needed
  WiFi.disconnect(true);
  WiFi.mode(WIFI_OFF);
}

void loop()
{
  delay(1000);
  printLocalTime();
  Serial.println(now());   <-------- Added to original code
}


texts: Is there some way to do raw radio on a esp32 and change frequencies. If not what would I need to transmit rf, wifi, bluetooth, zigbee etc. There seems to be no tutorials on how to do anything of the sort.


texts: Detect if a 3 phase AC submersible pump is on

texts: I need to know when a 3 phase AC submersible pump is turned on, for the sake of logging it to a online database. Thing is, I do not know how tell if it is ON, or OFF. I've given a thought to using a current transformer, specifically the "STC-013-30" one, but it requires to be wrapped around one of the AC wires (live/neutral) but the motor i have has both the wires insulated together forming a single, huge wire. Plus, its 3 phase, and I do now know if the STC can detect 3 phase currents. Can it be done some way? Can I utilise some other tool to tell if the motor is ON?


texts: Is there a way to adjust the duty cycle (PWM) based upon input gained by a sensor. For example, if the sensor picks up a really high value, it would increase the duty cycle for an LED making it brighter. Can we also do this task without a potentiometer? Can all of this be done "hands-free" by the Arduino?


texts:
I am trying to read my ultrasonic sensor. It sends a pulse in the trigger pin and the echo pin receives the pulse. Using pulseIn I can know exactly the time it took to the pulse go and back. But I need to use port register which is much faster and I need it to be fast in this specific case.

My code is very simple:

void setup() {

    Serial.begin(9600);
    //pin 12 as output
    DDRB = B00010000;
    //pin 12 as low
    PORTB = B00000000;

}

void loop() {

    //pin 12 as high
    PORTB = B00010000;
    delayMicroseconds(10);
    //pin 12 as low
    PORTB = B00000000;

    long start_time = micros();

    //While reading high in pin 13 keep running the loop
    while (PINB & B00100000)) {

    }

    Serial.println(micros() - start_time);

    delay(1000);

}

The problem is that it does not work, I mean, the while loop is not being processed so the serial is always printing a very small number. It doesnt matter if I move the ultrasonic sensor to distant walls the while loop still does not work. What am I doing wrong?


texts:
I have an Arduino UNO with a CNC shield. The Arduino is almost certainly a clone.

I installed GRBL with no issue and I have assembled a jig with CD-ROM motors. My first attempt to control this with UGS worked no problem.

I powered down to change the stepping with the jumpers and powered back up and was presented with a very hot smell after a few moments.

I removed the power quickly but now I can no longer program the UNO. It gets recognized in my devices but I can't send any code, even blink.

The jumpers were set like many examples I have seen on the web so I don't think this was the issue.

I am wondering if the way I powered it up was the issue? I am supplying the UNO with 12V 2A supply and I can't recall what order I plugged them in but I get the feeling it must have been supplying 12V to the Arduino.

I have now removed the shield and powering the unit solely from the USB and still can't communicate.

I have resigned to the fact this board is now toasted. Is it important which order you plug in the Arduino? USB first? Do you think it will be possible to recover this Arduino.


texts: Programming standalone Atmega328p-PU with NE555N timer IC

texts: I know I may sound a little idiotic to ask, but as I have seen in the internet that to program a standalone Atmel chip like that from of the Arduino's, you need 2 22pF ceramic capacitors and a 16mhz oscillator. As the oscillator is needed is clock the frequency of the chip, so a timer IC should work just fine, isn't it? or do I have wrong information?


texts: Time information from GPS receiver: how to tell whether it is fresh or stale?

texts:
I see that TinyGPS++ library extracts time information from GxRMC and GxGGA NMEA sentences streamed by GPS receiver. However, in my experiments I observed that both of my GPS receivers generate GxRMC sentences with time data in them at least once a second even when they have no access to satellites.

I presume that the time data comes from the internal clock of the receiver (and is maintained between warm startups). This is perfectly OK. However, I would like to know what measures are required by NMEA specification to ensure the reliability of this time data.

Am I correct in assuming that the device itself is supposed to understand that after certain period of time its internal clock will diverge? And that after that period the device will by itself stop pumping out these GxRMC sentences, until it gets a chance to see a satellite and re-sync its internal clock? Or should I expect to see the next field in GxRMC sentence to change from A to V?

If not, then what is the proper way to ensure that I receive "satellite time" (or close to that) or nothing at all?