texts: SIM800L is not working with Arduino Mega

texts:
I have connected my SIM800L on my Arduino Uno and it worked, but when I connected it to Arduino Mega it didn't work.
I don't know how to write this program without softwareserial so plz if you reply add a corrected program as well.
I have connected
TXD TO D2
RXD TO D3
RST TO D4
Here is my program plz help me with this.
#include "SoftwareSerial.h"

SoftwareSerial mySerial(2, 3);

String cmd = "";

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  Serial.println("Initializing...");
  delay(1000);

  mySerial.println("AT"); // Sends an ATTENTION command, reply should be OK
  updateSerial();
  mySerial.println("AT+CMGF=1");         // Configuration for sending SMS
  updateSerial();
  mySerial.println("AT+CNMI=1,2,0,0,0"); // Configuration for receiving SMS
  updateSerial();
}

void loop() {
  updateSerial();
}

void updateSerial() {
  delay(500);
  while (Serial.available()) {
    cmd+=(char)Serial.read();

    if (cmd!="") {
      cmd.trim();  // Remove added LF in transmit
      if (cmd.equals("S")) {
        sendSMS();
      } else {
        mySerial.print(cmd);
        mySerial.println("");
      }
    }
  }

  while (mySerial.available()) {
    Serial.write(mySerial.read()); //Forward what Software Serial received to Serial Port
  }
}

void sendSMS() {
  mySerial.println("AT+CMGF=1");
  delay(500);
  mySerial.println("AT+CMGS=\"+923009618697\"\r");
  delay(500);
  mySerial.print("bata message aya ha ya nai");
  delay(500);
  mySerial.write(26);
}


texts: Converting an array of uint8_t to a char array

texts:
I'm trying to convert this array uint8_t data[] in the code below to a character array to be printed in the serial monitor. However, when I run this code I see a blank screen. What am I doing wrong?

Serial.begin(115200);
uint8_t data[] = {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x00,0x01,0x02,0x03,0x04,0x05};
Serial.println((char*)data);


texts: Is there a way of turning a computer into a Arduino type board?

texts:
The Arduino's processing power is not sufficient for some of the tasks I would like it to perform...

I'm thinking of making a Home Automation System and would like some serious processing power at the center of it all.

So I'm wondering if I can just use standard PC parts to essentially put together my own board?!?

Is this possible???


texts:
I am curious if the following scenario is possible.

EICRB |= (0<<ISC60)|(0<<ISC61);
EIMSK |= (1<<INT6);

ISR(INT6_vect) {
  myISR();
}

void myISR() {
     digitalWrite(led_off, OFF);
     // Please break my main for loop :)
}

void loop()
{
      for (i=100; i>=0; i--)
             {

            /* STOP button */
              if (read_switch() == 1) {
                      break;
               }
           .. delays and other logic ...
}

As you see the following code is not complete but quite understandable. I have a heating process done in the main program, each loop temp adjustments, printing, delay etc takes about 2-3 seconds to complete. When somebody pushes a switch read_switch will return 1 and that breaks up this function ending the heating process.
This works just fine except the user have to hold the button for the time it finishes looping and get to this point again.
I have fortunately realized that the switch pin (Arduino promicro pin7) also an interrupt pin so I could do interrupt in real time, as I doing it in other code already.

However what you can do in this ISR routine is limited (eg you cannot print to serial etc). I could setup a global volatile bool variable here of course which would immediately get flipped as the interrupt triggered but it would not solve anything since in the main loop I would have to wait for the next round again.

So is it possible with some hack to tell the ISR to break that for loop (not the whole program with an exit(0)) and continue execution afterwards?


texts:
I am trying to control an led with a bluetooth module, but it is not working with an if else condition.

When I use this code I found on the internet the led blinks when I send the string from an android app:

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

    void loop() {
      // put your main code here, to run repeatedly:
     if(Serial.available()>0)
       {
          char data= Serial.read(); // reading the data received from the bluetooth module
          switch(data)
          {
            case 'a': digitalWrite(13, HIGH);break; // when a is pressed on the app on your smart phone
            case 'd': digitalWrite(13, LOW);break; // when d is pressed on the app on your smart phone
            default : break;
          }
          Serial.println(data);
       }
       delay(50);
    }

Where as when I use this code that I made myself the code compiles and uploads but the serial does not recieve values and the led does not change state when the strings are sent from the app, can someone help me identify why?:

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

    void loop() {
     if(Serial.available()>0)
       {
          char data= Serial.read();
          if (data == 'a')
          {
            digitalWrite(13, HIGH);
          }
          else if (data == 'b')
          {
            digitalWrite(13, LOW);
          }
          Serial.println(data);
       }
       delay(50);
    }

Thank You


texts: Getting no such directory file error when compiling

texts:
I recently got my wifi module and connected it to my Uno. I am now trying to send a http request. I have the code that comes with the esp8266wifi library in which it demonstrates and gives an example on how to send a http request. This is the code:

CODE.

I am getting the following error

    Arduino: 1.8.4 (Windows 8.1), Board: "Arduino/Genuino Uno"

In file included from C:\Users\Yasmeen\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFi.h:33:0,

                 from C:\Users\Yasmeen\AppData\Local\Temp\arduino_modified_sketch_200757\HTTPSRequest.ino:14:

C:\Users\Yasmeen\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFiType.h:26:19: fatal error: queue.h: No such file or directory

 #include <queue.h>

                   ^

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

Obviously it seems to be an file path error but I'm not sure why. I've imported the library through the Arduino IDE.. But maybe the way I aquired the library was wrong? What I did was download the esp8266wifi folder (here) and zipped the file and imported it.. is that okay to do?


texts: Problem with structs and pointers(?) - Mega with QueueArray

texts:
I'm writing a sketch to run on a Mega that builds up an array of timestamps (using the QueueArray library and DS3231 library). I'm having a problem where a struct I'm defining and then queueing is always referring to the first in the list. The relevant bits of the code looks like this:

#include <QueueArray.h>
#include <DS3231.h>
struct payload_t
{
   unsigned long timestamp;
}

QueueArray <payload_t> dataQueue;
DS3231 clock;
RTCDateTime dt;

void setup() {
   clock.begin();
   clock.setDateTime(__DATE__, __TIME__);
}

void loop() {
    payload_t dataPayload;
    dataPayload.timestamp = getTimestamp();
    dataQueue.enqueue(dataPayload);

    payload_t tempItem = dataQueue.dequeue();

    /**
     * At this stage, the dataPayload.timestamp is correct,
     * but tempItem.timestamp will always show the value from
     * the first item in the queue
     */

    sleep(1000);
}

unsigned long getTimestamp()
{
    RTCDateTime dt = clock.getDateTime();
    return dt.unixtime;
}

As per the comment in the main() loop, the first time a packet is added to the queue, the timestamp matches. For subsequent items, the value retrieved from the queue always gives the timestamp from the first item in the queue.

I feel this is my C knowledge letting me down with something basic, but can anyone point me in the right direction?


texts: NodeMCU V3 - Troubleshooting basic TMP36 circuit

texts:
If I follow this example using my Arduino Uno https://learn.adafruit.com/tmp36-temperature-sensor/using-a-temp-sensor

(using the 3.3V code example at the bottom of the page), I get reasonable temperatures from the readings over serial.

However, if I try this w/ a LoLin NodeMCU V3 (same circuit layout), my readings seem to be consistently higher than what I get running essentially the same code on the Uno. (Only difference in code is omission of analogReference(EXTERNAL), as the Node V3 appears to run on 3.3V as standard )

I'm fairly new to the whole electronics thing, so any pointers are much appreciated...

Circuit is:

      ----- |---------------- GND on breadboard with jumper to MCU
     | TMP36|---------------- AD0 pin on MCU
      ----- |---------------- breadboard power w/ 3.3V jumper to MCU


texts: Arduino Uno suddenly not recognized in Windows 8.1 (code 43)

texts:
I had my Arduino Uno connected to an external 12 V supply for 2-3 hours as I was working on other parts of my project. Suddenly the voltage from pin 9 which I was monitoring in the oscillator dropped down to 0 approximately.

I went on removing the external supply. The board was very very hot. I then connected the USB to my laptop and I got an error 43 (Windows did not allow the device to connect because it was reporting problems). I can't load any program of course. The 5 V pin works but it outputs a voltage lower than usual (at about 3.9 V). When I connect the external supply the 5 V pin outputs full voltage.

Any idea? Any fix?


texts: Check if a set of events occur in a limited time period

texts:
I am making a project in which I am using 4 Infrared sensors to take an input. The way I want it to work is such that when one of the sensors is triggered, the code listens for input from the other sensors for a fixed amount of time (say 2 seconds). Based on this data, further functions are executed.

I am assigning a number to each of the sensors, and the sequence in which they are triggered is stored in an array like:

// All relevant pins of the IR sensors are set to input with names ir1,ir2,ir3,ir4
int sequence[] = {0,0,0,0}
int s1 = digitalRead(ir1); //and similarly for all other pins
int counter = 0;

if(s1==1){
  sequence[counter] = 1; //similarly 2 for s2 and so on
  counter ++;
}

What I am attempting to do is something like this:

if(s1 == 1 || s2==1 || s3 == 1 || s4 == 1){
   if(s1 == 1){
      sequence[counter] = 1;
      counter ++;

   //Start listening for other sensors
   } // similarly check which sensor is triggered first

   //Allow 2 seconds for input from all sensors (no input from either one of them is also allowed)
   // After 2 seconds execute some code based on the sequence array which got updated from inputs by different sensors
}

How do I accomplish this?


texts: Able to make continous music loop in Arduino and control the volume of the music with light sensor reading?

texts:
I'm new to Arduino and am planning on making a simple program in Arduino that will play and loop a sound file on the computer whilst controlling the loudness of the music based on reading from a light sensor.

I was wondering if the first part, playing and looping the music on the computer is possible, because the second part of controlling the volume with the light sensor seems more straight forward if I had the first part down.

Thanks!


texts: Not able to control DC motor speed with l298N & pwm pins

texts:
I am using arduino uno to control dc motor speed with L298N. But the problem is that the motor is only going at max speed. PWM pin doesn't work for some reason.
I heard many people had some problem but haven't found the solution yet.

code:-

#include <L298N.h>

#define ENA 9
#define IN1 8
#define IN2 7

L298N motor(ENA, IN1, IN2);

void setup() {
// Setup pin mode

//used for display information
  Serial.begin(9600);

}

void loop() {
//Drive Motor Forward
  motor.setSpeed(10);
  motor.forward();
  delay(500);
  motor.setSpeed(100);
  motor.forward();
  delay(500);
  motor.setSpeed(255);
  motor.forward();
  delay(500);

}

I only see the motor move at full speed every time. I connected 5V of Arduino to +12V pin of motor driver and Arduino is powered with my laptop USB.

I am using 4.5V toy dc motor for test - DC motor

What could be wrong here?


texts: Can anyone tell me the best books for studying UAV?

texts: It's kind of hard to get full guide from the internet. I just wanna buy a book for UAV guide. I gotta make DIY drones. I'd appreciat it if you recommend good books.


texts: Arduino for kids toy with Battery (safe), Can Arduino overheat the Battery with long running code

texts:
I am making a learning toy which kids can play with and learn basics of programming. But i am tired of keep replacing the AA batteries as they run out in few days. So i am thinking of using rechargeable battery. But i am very worried to use it considering it is kids toy and people says lipo and li ion battery can explode. There are dangers or over charge and heat etc.

Is it safe to use them? Which one to use?

I am using Arduino pro mini 3.3v and some times 5v.

I was planning to use: XCSOURCE 5 pcs 1A 5V Micro USB TP4056 Lithium Battery Power Charger Board Module TE420

I think some users have misunderstood the question and have voted this question to be closed. This questions is very much to deal with programming also apologies if i have not made it clear.

We can get the battery level in the code, but is there any way in code we can some how turn off the charging when the battery has been fully charged.
I am under impression (might be wrong, you can correct me), normal
battery single AA cell dies after some time on heavy use (using dc motor etc). But
rechargeable batteries are bigger with multiple cells in it they will
last longer. So if i am running some code in a loop for long time
will the battery get over heated will it be a problem.


texts: How can I connect old door phone to mobile app for audio talking and unlocking door

texts:
I'm beginner to Arduino. I need to connect old door phone (like the picture) to mobile app. Whenever it rings, the mobile user can talk with outdoor standing person and unlock the door.

The communication interface maybe Bluetooth or Wi-Fi (whichever is easier). Indeed, the Arduino should send and receive audio as well as a command for opening the door.
If you have seen similar project, please reference to it or if you know how can I do, please explain.
I think this project can help our old parents, very much!
Thank you!


texts:
I want to classify my data from 3 sensors with arduino so that every time i enter the specific date or hour, or also it can be a period of time like 10 days ago, it shows me the exact data. In other word i want to classify my data so that whenever i want every detail of data, i would be able to get it by entering the information of year,date,time. I also didn't want my data to be in separate files and time stamps. I want to be able to do that within one file and search inside that file...

#include "RTClib.h"
#include <SD.h>
#include <SPI.h>

RTC_DS1307 rtc;
const int chipSelect = 10;

File dataFile;

String print_time(DateTime timestamp) {
  char message[120];

  int Year = timestamp.year();
  int Month = timestamp.month();
  int Day = timestamp.day();
  int Hour = timestamp.hour();
int Minute = timestamp.minute();
      int Second= timestamp.second();

      sprintf(message, "%d-%d-%d %02d:%02d:%02d", Month,Day,Year,Hour,Minute,Second);

      return message;
    }

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

      pinMode(chipSelect, OUTPUT);
      if (!SD.begin(chipSelect)){
        Serial.println("Error: SD card would not initiate.");
      }

      rtc.begin();
      if (!rtc.isrunning()){
        Serial.println("Clock is not running");
      }

      dataFile = SD.open("log0.csv", FILE_WRITE);
      if (!dataFile){
        Serial.println("Could not open file.");
      }

    }

    void loop(){
      Datetime now = rtc.now();
      dataFile.println(print_time(now));

      delay(3000);
    }


texts: How to develop or edit an Arduino library?

texts:
I'm not sure if I should split this question in two.
I had to edit some libraries and I plan to make some myself but didn't try yet.

Editing a library seems very laborious comared to editing a sketch.

I have to use an external editor and then compile on the Arduino IDE with the help of a test sketch.

I wish to use the Arduino IDE to edit the libraries but it seems it is not easy, maybe in future reales it is supported.

The libraries used to be on %home%/Arduino/libraries/etc. but now I have to edit some located at %appdata%\Arduino15\packages\esp8266\hardware\esp8266\1.6.5-947-g39819f0\libraries and it seems these packages might get updated so maybe it is not a good idea to edit them there but I am not sure.

What about GitHub and conflicts? I clone the library and edit it but then I have two versions and you can't choose one of them. So I have to delete the original from the arduino instalation or wherever it is to avoid the conflict.

I also wish to post the progress to GitHub and maybe receive collaboration there. Do you have any hint about the clone process or something to avoid any trouble with it?

And what about the .h/.o? Arduino precompile the headers on startup so if I edit a .h I have to find and delete the .o or restart the IDE.

How do you do all of this? Is there any trick that helps?

Thank you.


texts: Not able to read the product ID from ADIS16260 Gyroscope Sensor

texts:
I have interfaced a ADIS1620 sensor to the Arduino UNO using SPI.I am having a bit of trouble here to read the product ID information from the ADIS1620.According to the datasheet here,

on page 11, it is said that to perform a read operation, 2 16bit transactions are to be done with a minimum stall time of 9 us. The first 16 bit consists of the register address to read from i.e. 0x5600 and the second transaction is to read the product ID information. However, I always get the read data as '0' or as '0xFFFF'.I have done the hardware interfacing as per the connections mentioned below:

/* SPI Connections as per pg No.10 in
   the Datasheet (Note: Not using IRQ)
 */

 ADIS1620                 UNO
  (DIN)3                11 - MOSI
  (DOUT)2               12 - MISO
  (SCLK)1               13 - SCK
  (SS)4                 10 - CS
  16                    5V
  18                    GND

Below is .h file,

#ifndef ADIS16260_H
#define ADIS16260_H

/* Register Addresses */
#define LOT_ID1_ADDR          0x5200
#define LOT_ID2_ADDR          0x5400
#define PROD_ID_ADDR          0x5600
#define SERIAL_NUM_ADDR       0x5800

/* Timings */
#define STALL_TIME_US         10

#endif /* ADIS16260_H */

I doubt the problem is to do anything with the code as such, but still, just in case, here is the .ino file,

/* Lib's Include */
#include <SPI.h>

/* Custom Lib's Include */
#include "adis16260.h"

/* MACRO's */
#define CS  10

/* Globals */
char incomingByte;
unsigned int prod_info_data;

/* Definitions */
typedef enum
{
  LOT_ID1,
  LOT_ID2,
  PROD_ID,
  SERIAL_NUM
} Prod_InfoT;

/* Function Prototypes */
void SPI_Init();
unsigned int Get_Product_Info(Prod_InfoT get_adis16260_info);

void setup()
{
  Serial.begin(115200);
  SPI_Init();
  Serial.println("SPI Initialized");

}

void loop()
{
  if (Serial.available() > 0)
  {
    // read the incoming byte:
    incomingByte = Serial.read();
    if (incomingByte == 'a')
    {
      prod_info_data = Get_Product_Info(PROD_ID);
      Serial.println(prod_info_data, HEX);
    }
  }
}

/********************************************************************************
   Function Name    : SPI_Init
   Description      : Initialize the SPI module in the MCU
   Returns          : None
 * *****************************************************************************/
void SPI_Init()
{
  /* configure the line as output */
  pinMode(CS, OUTPUT);

  /* Initialize the CS line to HIGH */
  digitalWrite(CS, HIGH);

  /* Initialize the SPI module--> configures the MOSI, MISO and CLOCK lines */
  SPI.begin();

  /*
    Configure the SPI bus as follows
      1. SPI bus speed  = 1 MHz
      2. Data Out     = From MSB bit ---> To LSB bit
      3. Data Mode    = SPI MODE3
  */
  SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE3));
}

/********************************************************************************
   Function Name    : Get_Product_Info
   Description      : Get Prod ID, Lot ID1, Lot ID2 and Serial Num.
   Returns          : None
 * *****************************************************************************/
unsigned int Get_Product_Info(Prod_InfoT get_adis16260_info)
{
  unsigned int get_data = 0;

  switch (get_adis16260_info)
  {
    case PROD_ID:
      Serial.println("Reading Product ID...");
      digitalWrite(CS, LOW);
      SPI.transfer16(PROD_ID_ADDR);
      digitalWrite(CS, HIGH);
      delayMicroseconds(STALL_TIME_US);
      digitalWrite(CS, LOW);
      get_data = SPI.transfer16(0x00);
      digitalWrite(CS, HIGH);
      break;

    case SERIAL_NUM:
      Serial.println("Reading Serial Number...");
      digitalWrite(CS, LOW);
      SPI.transfer16(SERIAL_NUM_ADDR);
      digitalWrite(CS, HIGH);
      delayMicroseconds(STALL_TIME_US);
      digitalWrite(CS, LOW);
      get_data = SPI.transfer16(0x00);
      digitalWrite(CS, HIGH);
      break;

    default:
      Serial.println("Invalid Arguement");
      break;
  }
  return (get_data);
}

Edit: Added screen shot of the SPI lines:

Any support with this would be helpful. Thanks.


texts: Best way to process data received by EthernetServer

texts:
I have a program where the Arduino acts as an Ethernet Server.

The client continuously sends packets which is of the following format

Start Byte=0x7E;
Some Data/Command Bytes;      //Can be of varying length
End Byte=0x7A;

Some packets take more time to process than others.

So my question is what is the best way to read the bytes of the memory so that we always work on one packet at a time.I can read in data from the buffer one at a time and loop through till the END BYTE is reached but it doesn't seem a very efficient way to get the packets.

I would be interested if someone has better ideas on how to read in packets one at a time from the buffer in the most efficient way possible.


texts:
I have this function in my code and works fine (it returns a valid value, I put this value into a int variable outside function), but when end the function (or continue the code), my sketch stop/die...

///FUNCION PARA RSSI XBEE///
byte rss() {  ///PARA RSSI
union {byte B; char C;} atCmd[3];
AtCommandRequest atCmdReq;
AtCommandResponse atResp;
byte respLen, *resp, dBm;
strcpy(&atCmd[0].C, "DB");
atCmdReq = AtCommandRequest(&atCmd[0].B);
atResp = AtCommandResponse();
xbee.send(atCmdReq);
if (xbee.readPacket(5000)) {
   if (xbee.getResponse().getApiId() == AT_COMMAND_RESPONSE) {
       xbee.getResponse().getAtCommandResponse(atResp);
       if (atResp.isOk()) {
           respLen = atResp.getValueLength();
           if (respLen == 1) {
               resp = atResp.getValue();
               dBm = resp[0];
                  return dBm;
           }
           else {
             //  Serial.println("Unexpected response");
           }
       }
       else {
         //  Serial.println("ERROR");
       }
   }
   else {
     //  Serial.println("Unknown response");
   }
}
else {
 //  Serial.println("No response");
}
}///fin rss()

¿Any tips?


texts: How to measure free RAM on an Arduino Due in Runtime?

texts: I use this Library to measure my free RAM on a Mega in runtime. But this Library does not work on the Due.


texts: Red LED and Yellow LED Oscillating : A Stop Light

texts:
This is supposed to be a traffic light; as red should switch to yellow and then green & vice versa after the button press. However, it does not seem to work that way; instead, the red LED and the yellow LED oscillate at the end of the sequence.
const int redLED = 4;
const int yellowLED = 5;
const int greenLED = 6;
const int pedestrianRedLED = 13;
const int pedestrianGreenLED = A5;
const int buzzer = 12;
const int button = 7;

unsigned long previousMillis = 0;

int segmentPins[] = {11, 10, 9, 8};

int buttonHitCount = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(redLED, OUTPUT);
  pinMode(yellowLED, OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(pedestrianRedLED, OUTPUT);
  pinMode(pedestrianGreenLED, OUTPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(buzzer, OUTPUT);
  pinMode(button, INPUT_PULLUP);
}

void loop()
{
  int buttonState = digitalRead(button);
  Serial.println(buttonState);
  if (buttonState == LOW) {
    buttonHitCount = 1;
  }

  if (buttonHitCount == 1) {
    switchToRed();

  } else if (buttonHitCount == 0) {
    defaultState();
  }
}

void displayNumber(int num, int displayPin) {
  bool binaryValue[][4] = {
    {0, 0, 0, 0}, // 0
    {0, 0, 0, 1}, // 1
    {0, 0, 1, 0}, // 2
    {0, 0, 1, 1}, // 3
    {0, 1, 0, 0}, // 4
    {0, 1, 0, 1}, // 5
    {0, 1, 1, 0}, // 6
    {0, 1, 1, 1}, // 7
    {1, 0, 0, 0}, // 8
    {1, 0, 0, 1}, // 9
  };

  for(int i = 0; i < 4; i++) {
    digitalWrite(segmentPins[i], binaryValue[num][i]);
  }
  digitalWrite(displayPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(displayPin, LOW);
}

void switchToRed() {
  int greenLEDstate = digitalRead(greenLED);
  int switchToGreenOverride = 0;
  unsigned long currentMillis = millis();

  if ((switchToGreenOverride == 0) && (greenLEDstate == HIGH) && (currentMillis - previousMillis >= 2000)) {
    digitalWrite(yellowLED, HIGH);
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, LOW);
    previousMillis = currentMillis;
  } else if ((switchToGreenOverride == 0) && (greenLEDstate == LOW) && (currentMillis - previousMillis >= 1000)) {
    digitalWrite(greenLED, LOW);
    digitalWrite(yellowLED, LOW);
    digitalWrite(redLED, HIGH);
    digitalWrite(pedestrianGreenLED, HIGH);
    digitalWrite(pedestrianRedLED, LOW);
    switchToGreen();
    switchToGreenOverride = 1;
  }
}

void switchToGreen() {
  int redLEDstate = digitalRead(redLED);
  int defaultStateOverride = 0;
  unsigned long currentMillis = millis();

  if ((defaultStateOverride == 0) && (redLEDstate == HIGH) && (currentMillis - previousMillis >= 2000)) {
    digitalWrite(yellowLED, HIGH);
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, LOW);
    previousMillis = currentMillis;
  } else if ((defaultStateOverride == 0) && (redLEDstate == LOW) && (currentMillis - previousMillis >= 1000)) {
    buttonHitCount = 0;
    defaultState();
    defaultStateOverride = 1;
  }
}

void defaultState() {
    digitalWrite(greenLED, HIGH);
    digitalWrite(yellowLED, LOW);
    digitalWrite(redLED, LOW);
    digitalWrite(pedestrianRedLED, HIGH);
    digitalWrite(pedestrianGreenLED, LOW);
}


texts: AnalogRead(0) always returns 0 on RFduino

texts:
I'm using RFduino to do analogRead at pin 2 and pin 0. Pin 2 works perfectly, and I got the result. However, for pin 0 it returns all zero.

#include <RFduinoBLE.h>

static const int topPin = 2;
static const int bottomPin = 1;

int top;
int bottom;

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

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

    bottom = analogRead(bottomPin);
    top = analogRead(topPin);

    Serial.print(top);
    Serial.print(" ");
    Serial.print(bottom);
    Serial.print("\n");
}

I double checked the wires and it's OK. I measured the voltage across pin 0 and it's 3.3V. How do I fix this problem? There's no shortage between pin 0 and 3.3V.


texts: Lifecycle hook in Arduino to know if Arduino is reset or powered down

texts:
I am new to Arduino programming and I'm really fascinated with its working. Is there a way to know if an Arduino is getting switched off or being reset? Like a function would be called before the Arduino gets switched off.

I want to detect this event to preserve a value, where a user resets his Arduino, or switches it off. Is it possible?


texts: Two serials can't work on the same speed

texts:
I have a device which sits on pins 10/11 of Arduino UNO. I am trying to send commands from my PC using Arduino to relay my commands to the device via Serial.

The problem is that if I use speed 9600 both for device and USB communication, then my commands gets damaged. Some letters are replaced by strange symbols, etc. The device uses 9600 baud rate.

If I change speed of the PC communication to 4800 (or any speed other than 9600), everything is fine. But I have to use different speeds for the communication.

I am not comfortable with the workaround, because I don't understand what's going on. Could somebody explain why the same serial port speeds causes problems?

Here is my code:

#include <SoftwareSerial.h>

#define rxPin 11
#define txPin 10

SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);

 void setup()
 {
   digitalWrite(4,HIGH); // 1 - disable
   mySerial.begin(9600);
   Serial.begin(19200);
   while (!Serial) {;}  // wait for serial port to connect. Needed for native USB port only
   Serial.println("Begin");
 }

 void loop()
 {
  if (mySerial.available())
  {
    char c = mySerial.read();
    Serial.write(c);
  }
  if (Serial.available())
  {
    char c = Serial.read();
    mySerial.write(c);
  }
 }


texts: Resurrecting a fried Arduino (Bluno) USB port

texts:
Slightly distractedly, I went and connected 5V to the 3.3V pin on my DFRobot Bluno (the pins are right next to each other!)

The magic smoke leaked out of the AMS1117 3.3V regulator in a neat little puff. The sketch that was loaded on the board still runs fine, but the Bluno is no longer recognised by my Macbook Pro when I plug it into USB (I have tried different ports and different cables; they're all fine—it's the USB on the Bluno that's fried.)

In an attempt to repair it, I've replaced the AMS1117 (check the third paragraph of that tutorial—ha!) with an LF33ABV; this went well and I'm now getting a stable 3.3V on the 3.3V pin. Check out my handiwork:

However, the Bluno still isn't being recognised by the USB ports on my Mac.

Is there another way to upload new sketches to the Bluno? Theoretically you can do so over BTLE, but you need another Bluno to act as the "peripheral" and I don't have one to hand. I have various other Arduinos laying about if that helps.


texts: Optocouplers for Arduino DCC decoder - Explain?

texts:
I am trying to make an Arduino circuit as outlined here.

This is for connecting an Arduino input to a DCC system. DCC is a command control system for model railways that uses the same two wires for power and data (there's a wikipedia article that explains it better than I can)

I'm wondering what the optocoupler has more than 4 pins for? I'm new to this and I understand the purpose of the optocoupler but I am confused as to how this particular one works. It is a 6N136 optocoupler. I don't understand why it has the extra pins compared to 4 pin optocouplers, and I don't understand how it would read the polarity of the signal. DCC sends commands using polarity as I understand it, so I know I need to read the polarity, but how does the optocoupler do it here?

I have a very limited knowledge of electronics right now so pardon anything stupid I said :P


texts: How to program a CLK signal and its inverse with Arduino/AVR

texts:
Is it possible to simultaneously output a clock signal and it's inverse using the timer register(s)?

I'm using the following code in arduino to output a 1MHz signal on OC1A:

//Use Timer/Counter1 to generate a 1MHz square wave on Arduino pin 9.
//J.Christensen 27Apr2012

void setup(void)
{
    DDRB = _BV(DDB1);                  //set OC1A/PB1 as output (Arduino pin D9, DIP pin 15)
    TCCR1A = _BV(COM1A0);              //toggle OC1A on compare match
    OCR1A = 7;                         //top value for counter
    TCCR1B = _BV(WGM12) | _BV(CS10);   //CTC mode, prescaler clock/1
}

void loop(void)
{
}


texts: How to I measure the duration of touch with a soft potentiometer?

texts:
I'm having a soft pot meter here and I would like to register the duration of the touch event. I'm having a different variable, which keeps going from 1024 to 0 , which regularly takes 60 seconds, but for every second you touch the soft pot meter the count adds 50 up to 1024. Like returning the clock backward.

How would I register/code this?


texts:
I'm making touch-sensitive, light up tic-tac-toe board.

That means 9 LEDs + 9 capacitive sensors.

Each LED needs 1 pin and each sensor needs 2...meaning I'd need 27 pins to properly control each touch-and-illuminate sequence.

There aren't enough inputs on the Uno for this, so what sort of workarounds should I explore to pull this off?


texts: Arduino UNO generate square wave, which is exactly the same with trigger pulse, but with a time delay

texts:
I am new in using Arduino so please forgive me if my question is too simple.
I need to generate a square wave with exactly the same duty cycle and frequency with the trigger pulse. The trigger pulse is 15 Hz with two rising edges in each cycle. Besides, I need to introduce an adjustable delay between them.
Is anyone can tell me how to do it please? Thanks in advance!


texts:
I want to make sequential LED by using arduino that controlled by button.
If I press + button, LED will increase from L1 to (L1 and L2 is HIGH), then I press button again, L1, L2, and L3 will be HIGH. If I press again, all the LED (L1, L2, L3, L4) will be high.
Same case if I press “ – “ button, LED will be lower from the previous state. Which mean that if L1, L2, and L3 is HIGH. There will be L1 and L2 only HIGH if I press ‘ – ‘ button. I dont how to do it. This is code for increase but I dont know how to make it reverse flow.

const int buttonPin = 2; // the pin number of the pushbutton input pin
int ledPins[] = {3, 4, 5,};
 // variables will change:
 int buttonState = 0; // variable for reading the pushbutton status
 int buttonPressCount = 0;
 int numberOfLED = 3;
 void setup() {
  // initialize the LED pin as an output:
  for (int i = 0; i < numberOfLED; i++) {
   pinMode(ledPins[i], OUTPUT);
  }
  pinMode(buttonPin, INPUT);
 }
 void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
   for (int i = 0; i < numberOfLED; i++) {
    if (buttonPressCount % numberOfLED == i) {
     // turn LED on:
     digitalWrite(ledPins[i], HIGH);
    } else {
     // turn LED off:
     digitalWrite(ledPins[i], LOW);
    }
   }
   buttonPressCount++;
   delay(400);
  }
 }


texts:
Using RCLib (github) I'm getting this error. The trick is that the RCLib example works on it's own but does not work in my program (github).

Serial Output "Error"

Pin 0 (62) you are trying to use is not supporting interrupts
Pin 1 (63) you are trying to use is not supporting interrupts
Pin 2 (64) you are trying to use is not supporting interrupts
Pin 3 (65) you are trying to use is not supporting interrupts
Pin 4 (66) you are trying to use is not supporting interrupts
Pin 5 (67) you are trying to use is not supporting interrupts


texts: Unable to create a desired periodic signal with Arduino Mega 2560 and DAC0808

texts:
I wrote the code to produce the periodic signal by using arduino and DAC0808 where i turned on and off the respectively pins of PORTA by using a logic in iterative manner and created the periodic signal. But even without using delay logic, i couldn't get signal time period as comparable to 50 Hz voltage signal. And what i seek to get is to decrease the time period of generated signal. Pls note, blue signal is reference signal of 50Hz frequency.

float increment = 3.14159 / 500;
float initial = 0;
float value = 0;

void setup() {
  Serial.begin(115200);
  DDRA  = B11111111;
}

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

  PORTA = B00000000;
  while (1)
  {
    initial = initial + increment;
    value = sin(initial)  * 255;
    PORTA = abs(value);
  }

}


texts: How to determine the source of constants in libraries?

texts:
Preamble:

I am trying to figure out how to program and use the timers in the Feather M0 using the Arduino IDE. I have seen a number of examples published, but I'm not one to just blindly copy some code and expect it to work. The issue that I'm having (and it seems to be ubiquitous in Arduino) is that there does not seem to be a concept of dependencies. In order to reference constants, they have to be defined somewhere.

Question:

How can I find the source of the definition of the constants that people keep referring to in their code? For example, in this code a Arduino Zero, M0 timer example, reference is made to TC_CTRLA_PRESCALER_DIV1 among other constants. Where is this constant defined?

Efforts:

I've searched generally and specifically for these constants. But, as you would imagine in C, it's difficult to find the actual source versus a simple reference to the constant.

I've also tried a search in the installed Arduino IDE with SAMD and Adafruit SAMD libraries installed. For example

~/Arduino$ grep -r --include=*.h --include=*.cpp "TC.*_PRESCALER_DIV"

Did not yield anything. I apologize if this is a naive question, but I haven't been able to find a simple, obvious answer. Actually, I haven't been able to find any answer.


texts:
I'm attempting to read data from my SD card, but I have strange behavior and can't figure out why this is happening.

I'm using CardInfo from the Arduino example and am trying to read the data from my SD card.

I'm faced with two different problems, but maybe they can be related:

1:  If I format my SD card from my Mac (FAT32), if my card is still empty, the program can read my card and output the right information. But if I add data from my Mac to the SD Card, card.init never initialise, and my data are never read (because of the hidden files). If I remove those hidden files, but let only the expected files be, the program never find them, like if my card was still empty. I don't know how to handle this.

2: From my Arduino, if I feed the card from the 3.3 V output, I get the

  Card type: SD2 Could not find FAT16/FAT32 partition. Make sure you've
  formatted the card

It only works on 5 V (but the card type becomes SDHC). So I've tried to feed my card with another 3.3 V/5 V supply (my Arduino is grounded to this supply as well), but this is only working on 5 V. On 3.3 V my card isn't detected. My wires to the SD card are about 15 inch. I don't know if it can affect it drastically, but this is the only 'weird' thing about this circuit. By the way I naively think my 3.3 V supply should handle that.

Here are my materials:
- Arduino Duemilanove

For the SPI wiring I'm using pin 10 for SS.
Using the Cardinfo from the Arduino library.


texts: How to count positive electrical pulses?

texts:
I have a device that has one blinking LED.
I want to count the number of blinks. I planned to do it using Arduino. I will connect two terminals of LED input to Arduino digital input pins, and I will count the number of positive voltage pulses
I just want to know if it is possible? and if yes then can you please hint the code for the same?


texts: POST request on Arduino MKR1400 GSM not working

texts:
Im trying to send a POST request from the Arduino MKR1400 GSM board to a server with a database.

I've tested the server using Postman (https://www.getpostman.com/) and it handles the POST request correctly, the json data gets uploaded to database fine.

The problem is that the same POST request from the Arduino MKR GSM 1400 does nothing. I've tried using client.print and I get the same result.

I'm not sure what I'm doing wrong or how to debug this issue, any ideas?

Arduino code:

#include <MKRGSM.h>
#include "Credentials.h"

// Definiciones para el GPRS
const char PINNUMBER[]     = SECRET_PINNUMBER;
const char GPRS_APN[]      = SECRET_GPRS_APN;
const char GPRS_LOGIN[]    = SECRET_GPRS_LOGIN;
const char GPRS_PASSWORD[] = SECRET_GPRS_PASSWORD;

GSMClient client;
GPRS gprs;
GSM gsmAccess;
GSMScanner scanner;

char ip[4] = {xxx,xxx,xxx,xxx};
char ipstring[14];
char path[] = "/atcapp.php";
int port = 80; // port 80 is the default for HTTP

char respName[30] = "Arduino MKR GSM 1400";
char toolName[30] = "Herramienta martillo";
char location[30] = "Mave Aeronautica S.L.";
char tlState[4] = "OUT";
unsigned long int user_id = 4294967295;
unsigned long int tool_id = 1234567899;
unsigned long int tmeStmp = 1532684104;
char notes[100] = "";

char postData[200];
char packetData[500];

void setup() {

  Serial.begin(9600);
  while(!Serial);
  sprintf(ipstring,"%d.%d.%d.%d",ip[0],ip[1],ip[2],ip[3]);
  post(respName,user_id,location,toolName,tool_id,tlState,tmeStmp,notes);

}

char post(char* resp,unsigned long int userid,char* location, char* toolName,unsigned long int toolid,char* toolState,unsigned long int timeStamp,char* notes)
{
  Serial.println("Connecting to GPRS Network...");
  boolean connected = false;

  while (!connected) {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
    } else {
      Serial.println("GPRS connection failed");
      delay(1000);
      return -1;
    }
  }

  if (client.connect(ip, port)) {
    sprintf(packetData,"POST %s HTTP/1.1\nHost: %s\nUser-Agent: Arduino/1.0\nConnection: close\nContent-Length: %d\nContent-Type: application/json\nCache-Control: no-cache\n\n{\n\"responsable\":\"%s\",\n\"user_id\":%lu,\n\"loc\":\"%s\",\n\"tool\":\"%s\",\n\"tool_id\":%lu,\n\"tool_state\":\"%s\",\n\"timestamp\":%lu,\n\"note\":\"%s\"\n}\n",path,ipstring,sizeof(postData),resp,userid,location,toolName,toolid,toolState,timeStamp,notes);
    client.beginWrite();
    for(int i=0;i<sizeof(packetData);i++){
        Serial.write(packetData[i]);
        client.write(packetData[i]);
    }
    client.endWrite();

    while(client.connected()){
      Serial.println("Client still connected.");
      while(client.available()){
        Serial.println("Client still available.");
        char c = client.read();
        Serial.print(c);
      }
    }

    Serial.println("disconnecting.");
    client.stop();

    Serial.println();
    Serial.println("Done.");
    return 1;
  }else{
    Serial.println("Cannot connect to server.");
    return 0;
  }

}

void loop() {}

Serial port output:

It's my first time ever asking a question here, any contructive criticism is more than valuable to me. Thank you in advance,


texts: Problem with DHT11 and DS18B20 temperature sensors

texts:
I am trying to connect to my Arduino Uno board two temperature sensors: DHT11 and DS18B20. The problem is with the DHT11 sensor: apparently there's an error with reading the temperature every two measurements.

Here's what I get on the serial monitor (temperature 1 is from the DHT sensor):

As I am new to this, I was wondering what the problem may be. I have read about the one wire interface used by the DS18B20, but I noticed that the DHT is not using the same protocol.

If I use the DHT11 alone, it works perfectly fine.

Also, I am using 4k7 pull-up resistors for both sensors.

Here's the code:

#include <DallasTemperature.h>
#include <OneWire.h>
#include <dht.h>

dht DHT;

#define ONE_WIRE_BUS 8
#define DHT11_PIN 7

OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup(void) {
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
  sensors.begin();
}

void loop(void) {
  int chk = DHT.read11(DHT11_PIN);
  sensors.requestTemperatures();
  Serial.print("Temperature1: ");
  Serial.print(DHT.temperature);
  Serial.print(" Temperature 2 : ");
  Serial.println(sensors.getTempCByIndex(0));
}


texts: Change Servo Speed With RedBearLabs BLE Shield

texts:
I recently got the RedBearLabs BLE shield to use it to control two high spped continuous rotation servos. I have the BLE example sketch loaded and the ios controller app works. The problem is that the servos are too fast to control and I want to slow them down. I cannot use the app to slow them down. I was wondering how I could modify the example sketch or servo library to change the ax speed or something. Thanks in advance.

BLE Shield Homepage: http://redbearlab.com/bleshield/

BLE Libraries and Example Sketch: https://github.com/RedBearLab/nRF8001


texts: At what level does low dynamic memory effect performance?

texts:
I have a few Arduino sketches that take 70-90% of dynamic memory. It seems that over 70%, the compiler gives the warning:

Low memory available, stability problems may occur.

but otherwise I wasn't noticing any problems.

Then I uploaded a sketch that took 89%, which logged String data to the serial port, and found that only newlines were being written out. When I commented out some global variables so that dynamic memory usage got to 88%, then it started printing out the data.

Is there any hard/fast rule on when this problem occurs? I was surprised by this problem, because the global variables I removed weren't even being used in the sketch, so I had thought the compiler would have removed or optimized them so they didn't waste any space. Are there any ways to automatically improve compilation efficiency and detect wasteful variables?


texts: Running an LCD keypad shield from a separate power source

texts:
I need to use a motor shield and an LCD keypad shield simultaneously hooked up to a single Arduino Mega Board. Since I can't physically stack them, I decided to reroute all the pins used for the LCD keypad shield. When I reroute all pins except the two power pins, the LCD and keypad work fine. But when I disconnect those 2 pins and connect them to any other power source than the Arduino Mega, it fails. The screen becomes either blank / jumble of illegible characters / brief moments of expected output followed by the same jumble.

This behavior is really strange since the power pins don't carry any information, they are just power sources. The LCD keypad shield shouldn't be able to discriminate whether the power is coming from the Arduino Mega or not - but it does. I checked with a voltmeter that all power sources I tried are DC 5V.

At first I thought this is because the lcd.begin() function is called only once, so I rewrote my code to re-initialize the lcd at every iteration. This doesn't solve the problem.

Here is a picture of the setup that works. (rerouting all pins except the power.) Ignore the location of analog input cable, since it doesn't do anything in the current code.

And one that fails. The only difference from above is the power source.

And my code.

#include <LiquidCrystal.h>

// select the pins used on the LCD panel
LiquidCrystal lcd(28, 29, 24, 25, 26, 27);

void setup()
{
  lcd.begin(16, 2);
  lcd.print("Hello World!");
}

void loop()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Hello World!");
  delay(1000);
  lcd.setCursor(0, 0);
  lcd.print("Hello Again!");
  delay(1000);
}

Any suggestions?


texts: Bluetooth not transmitting refreshed sensor values

texts:
I have a 9 DOF sensor attached to a BLE chip and Arduino Uno. I want to send the position measurements (i.e. x, y and z coordinates) from the sensor to my iPhone app (Bluefruit LE). The code below starts off well and I am able to see the coordinates on the iPhone. But after showing 6 sets of x-y-z coordinates on the phone all it prints are the x-coordinates. The y and z coordinates do not get shown on the phone at all. I have put the code below (likely not the most efficient code). Any suggestions on how to fix it will be very helpful. thanks in advance.

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>
#include <SPI.h>
#include "Adafruit_BLE_UART.h"

/* Set the delay between fresh samples */
#define BNO055_SAMPLERATE_DELAY_MS (100)

#define ADAFRUITBLE_REQ 10
#define ADAFRUITBLE_RDY 2
#define ADAFRUITBLE_RST 9

Adafruit_BNO055 bno = Adafruit_BNO055(55);
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ,     ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

void displaySensorDetails(void)
{
sensor_t sensor;
bno.getSensor(&sensor);
Serial.println("------------------------------------");
Serial.print  ("Sensor:       "); Serial.println(sensor.name);
Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
Serial.print  ("Unique ID:    "); Serial.println(sensor.sensor_id);
Serial.print  ("Max Value:    "); Serial.print(sensor.max_value);
Serial.print  ("Min Value:    "); Serial.print(sensor.min_value);
Serial.print  ("Resolution:   "); Serial.print(sensor.resolution);
Serial.println("------------------------------------");
Serial.println("");
delay(500);
}

/*
Arduino setup function (automatically called at startup)
*/

int x = 0;
int row = 0;
void setup(void)
{
Serial.begin(9600);
Serial.println("Orientation Sensor Test"); Serial.println("");
Serial.println("CLEARDATA");
Serial.println("LABEL,x,y,z");

/* Initialise the sensor */
if(!bno.begin())
{
/* There was a problem detecting the BNO055 ... check your connections */
Serial.print("Ooops, no BNO055 detected ... Check your wiring or I2C ADDR!");
while(1);
}

delay(1000);

/* Display some basic information on this sensor */
displaySensorDetails();
bno.setExtCrystalUse(true);

BTLEserial.begin();

}

aci_evt_opcode_t laststatus = ACI_EVT_DISCONNECTED;

void loop(void)
{

BTLEserial.pollACI();

/* Get a new sensor event */
sensors_event_t event;
bno.getEvent(&event);

/* Display the floating point data */

Serial.print("X: ");
Serial.print(event.orientation.x, 4);
Serial.print("\tY: ");
Serial.print(event.orientation.y, 4);
Serial.print("\tZ: ");
Serial.print(event.orientation.z, 4);
Serial.println("");

/* This is the code that sends x, y and z coordinates to BLE */
  uint8_t sendbuffernew_x[20];
  char buff_x[20] = "";
  String xorient = "";
  dtostrf(event.orientation.x, 4, 1, buff_x);  //4 is mininum width, 6 is precision
  xorient += buff_x;

  xorient.getBytes(sendbuffernew_x, 20);
  char sendbuffersizenew_x = min(20, xorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_x, sendbuffersizenew_x);
  memset(sendbuffernew_x, 0, sizeof(sendbuffernew_x));

  uint8_t sendbuffernew_y[20];
  char buff_y[20]= "";
  String yorient = "";
  dtostrf(event.orientation.y, 4, 1, buff_y);  //4 is mininum width, 6 is precision
  yorient += buff_y;

  yorient.getBytes(sendbuffernew_y, 20);
  char sendbuffersizenew_y = min(20, yorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_y, sendbuffersizenew_y);
  memset(sendbuffernew_y, 0, sizeof(sendbuffernew_y));

  uint8_t sendbuffernew_z[20];
  char buff_z[20]="";
  String zorient = "";
  dtostrf(event.orientation.z, 4, 1, buff_z);  //4 is mininum width, 6 is precision
  zorient += buff_z;

  zorient.getBytes(sendbuffernew_z, 20);
  char sendbuffersizenew_z = min(20, zorient.length());

  // write the data
  BTLEserial.write(sendbuffernew_z, sendbuffersizenew_z);
  memset(sendbuffernew_z, 0, sizeof(sendbuffernew_z));

delay(1000);

delay(BNO055_SAMPLERATE_DELAY_MS);
}


texts: Interfacing 4 ESCs and an Arduino with a single LiPo battery

texts: I have 4 BLDC motors, and 4 ESCs, one for each motor. But I have one LiPo battery from which I want to power one Arduino Mega and all the 4 ESCs. Can I remove the connectors from the ESCs and put them on a breadboard in a single column/row so that they are connected together, and then connect the + and - of the battery (after removing its connector as well) to the respective breadboard column/row, so that they are essentially connected together to power all the ESCs? Also, I would want to use a jumper from the Arduino Vin and GND pins to the same column/row on the breadboard. Will this method of powering all the 4 ESCs and the Arduino from a single LiPo work?


texts:
I'm using EEPROM to store project settings non-volatile.
After reuploading the sketch to my board (over SPI via ArduinoISP), the EEPROM is reset to full 0xFFs and I have to manually do a "software reset" with a second switch, which initializes the EEPROM with its default values.

Is it possible to run a segment of code once, and only once, after booting up the first time after being programmed?

I'm working around it by checking whether a piece of EEPROM is 1 at startup when it would always be 0 after the initialization and during usage, but surely there's a cleaner alternative than checking for an EEPROM bit each time.


texts: How can I power MKR1000 and 25 NeoPixels 24hrs or longer?

texts: I have an arduino MKR1000 which I would like to run off battery power for a few days with 1-3 dimly lit NeoPixels active. Every day for an hour there will be 10 NeoPixels active. Brightness for both set to 15. I'm having 2 issues. The NeoPixels start to morph into another color after an hour or thereabouts, and the MKR seems to lose track of time, as the Leds don't turn on and off on the right hour. I have also noticed that if I have the usb and battery both plugged into the MKR, the serial monitor stops working. What should I do?


texts: TQFP Atmega328pu-th cant upload sketch sync error (breadboard)

texts: So I have a USB to ftdi connected to my qtfp 32 socket trying to upload a sketch but I get a sync error , as far as I am aware I have uploaded the sketch correctly


texts: AttachInterrupt - fail to initiate inside a class

texts:
I'm trying to create a class that uses attachInterrupt, but get this error msg:

 In member function 'void ledDoor::attach()':
ClosetLedStrip:31:82: error: invalid use of non-static member function
         attachInterrupt(digitalPinToInterrupt(_sensorPin), detection_door, CHANGE);
                                                                                ^
exit status 1
invalid use of non-static member function

I found few answers regarding static member, but it was not clear for my needs.

Appreciate help,

#define USE_SLEEP true

#if USE_SLEEP
#include <avr/sleep.h>
#endif

#define sensorPin_1 2
#define sensorPin_2 3
#define RelayON HIGH
#define doorOpen HIGH

#define pwrdown_timeOut 10*(1000*60) // mins to powerdown

// volatile boolean detectDoor_1_Open = false;
//volatile boolean detectDoor_2_Open = false;
const int relayPin1 = 4;
const int relayPin2 = 5;

class ledDoor {

private:
int _sensorPin;
int _interruptPin;
int _relPin;

void  attach(){
        attachInterrupt(digitalPinToInterrupt(_sensorPin), detection_door, CHANGE);
}

void detection_door(){
    #if USE_SLEEP
        sleep_disable();
    #endif

        detachInterrupt(digitalPinToInterrupt(_sensorPin));
        if (digitalRead(_sensorPin) == doorOpen) {
                _doorOpen = true;
        }
        else {// trun off
                _doorOpen = false;
        }
        attach();
}

public:
bool volatile _doorOpen;
ledDoor(int sensorPin, int relPin){
        _sensorPin=sensorPin;
        _relPin=relPin;

        pinMode(_relPin, OUTPUT);
        pinMode(_sensorPin, INPUT); // sensor io
        attach();
}
void go2sleep() {
  #if USE_SLEEP
        sleep_enable();
        set_sleep_mode(SLEEP_MODE_PWR_DOWN);
        sleep_cpu();
  #endif

}
void switchLeds(){
        if (_doorOpen == true) {
                digitalWrite(_relPin, RelayON);
        }
        else{
                digitalWrite(_relPin, !RelayON);
        }
}

};

ledDoor door1(sensorPin_1, relayPin1);
ledDoor door2(sensorPin_2, relayPin2);

void setup() {
        Serial.begin(9600);
        Serial.println("UP");
}

void loop() {
        door1.switchLeds();
        door2.switchLeds();

  #if USE_SLEEP
        door1.go2sleep();
        door2.go2sleep();
  #endif
}


texts:
I'm using the SDFat library and the FatFile type has the functions:

  bool FatFile::dirEntry(dir_t* dir)

  Return a file's directory entry.

  Parameters

    [out] dir    Location for return of the file's directory entry.

  Returns

    The value true is returned for success and the value false is returned
    for failure.

And

  uint8_t FatFile::dirName(const dir_t *dir, char *name)

  Format the name field of dir into the 13 byte array name in standard
  8.3 short name format.

  Parameters

    [in] dir The directory structure containing the name.

    [out]    name    A 13 byte char array for the formatted name.

  Returns

    length of the name.

From what I understand, I should be able to pass something like this into the functions:

dir_t Bass;
char dName [13];
FatFile BrowseFile;
BrowseFile.open("/Folder1/File1.txt", O_RDONLY);
Serial.print(BrowseFile.dirEntry(&*Bass));
Serial.print(BrowseFile.dirName(Bass,*dName));
Serial.println(dName);

to which the program should output

1
[Folder1's 8.3 name length]
[Folder1's 8.3 name]

However, I'm getting an error and I can't find any included examples that use these two functions in a sketch. if someone could explain what I'm doing wrong, it would be greatly appreciated.


texts: How to know the external interrupt origin from the ISR

texts:
I'd like to know if there is any way to know what is the origin of an external interrupt by programming inside the ISR.

I know I can use a different ISR for each external interrupt and that works but I'm thinking if it's possible to use the same ISR for all external interrupts

If you check the origin pin and trigger condition inside ISR it's not a reliable way to do.

Is there any memory record which store the external interrupt activation?

This is a general question for any AVR microcontroller.


texts: In the AnalogRead example, would the thing work if I remove or short the A0 and the ground pin?

texts: What I want to know is that how exactly does analogRead work because I have want to use it with a flex sensor and it has only two pins.I tried to find other examples on the internet, but this is the only example I find.If the middle pin of the 10k potentiometer and a0 pin are shorted or the gnd  pin is removed altogether,then would this thing work?


texts:
I am currently using an atmega328 along with the mcp 2515 and the 2551 for CAN communication in my systems.

However, I've now decided to upgrade to the arduino due for my operations. Can anybody tell me if the arduino due along with it's inbuilt CAN controller be used with the mcp2551 transciever to operate CAN successfully.

If not, can somebody also tell me if there are other alternatives I should look into. Thanks :)


texts: ESP8266-01 Upload Sketch Problem Arduino UNO

texts:
My problem is actually in two stages.
I am very new to arduino uno and 8266-01. I have read many documents and watched videos for nearly 2 weeks, but I cannot even run the simplest "blink" example.
First of all, I installed the compatible software with an esp download tool as follows according to 6014h. And it seems okay.

After triple check, my wires and connections where they have to .
Rx->Rx  Tx->Tx  CH-3.3v GPI0 grounded Ground->Ground  and also 8266-01 VCC connected to Arduino 5v with 3.3v regulator and connected with capacitor, to debug voltage i check with voltmeter.
Problem is:
When I try to upload simple Blink example below imag.  My IDE gives a very different output from the videos I watched. I could not understand the reason for this.
the IDE outputs on the all of videos that i watched, are while uploading

This kind of upload starts when it says upload and when it's finished, the program runs.
BUT!In my case my  IDE is acts like that and nothing happens end of the upload.

My 8266 generic settings are as follows.

Led out pin in the blink example is 2 and GPI1 is connected to led to blink after all this explanation, where i missed up ?
Why i am taking different uploading process and code is not working?


texts: Checking for multiple values in IF separated by commata

texts:
My code is:

if ((minute == 31) && (hour == 4, 6, 9, 11))
{
  digitalWrite(8, HIGH);
}

I want to turn on the LEDs when it is exactly

04:31,
06:31,
09:31,
11:31

However, the code above doesn't work.
Might be the multiple values the reason for this?


texts: Transfer serial data to struct variable in Arduino

texts:
I have declared a struct with some variables that right now are fixed, but one of the variables on the struct needs to be what the Arduino's serial port reads.

struct testing_var
{
    const char *name;
    byte key[32];
    byte pt[16];
};

static testing_var const test1 = {
    .name        = "Speck-128-ECB",
    .key         = {0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
                    0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00},
    .pt   = {0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
                    0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20},
};

As you can see for how I have declared it, I'm trying to get a plaintext from the serial port and the Arduino should encrypt that. I have a function that does this encryption, but I can't quite figure out how to pass what the serial port reads to the struct.

void loop() {

  if (Serial.available()>0) {
    var1 = Serial.read();
}

I need to pass this var1 as the variable pt in the struct. Any clues? I'm maybe missing something very obvious, but I don't usually work with structs.

EDIT:
I'm trying to assign the value read by the serial port to the struct by creating another function that goes like this:

void setPlain(struct PlainText *myPlain, const char* thePlain){
    myPlain -> plaintext = the Plain;
   }

Then, in the loop, I use:

  if (Serial.available()>0) {
    var1 = Serial.read();
    setPlain(&PlainText, var1)
}

I'm getting an error using this function, I guess that it has something to do with the type of variable I'm trying to assign, these values are in HEX, not in char. But I'm not really sure it that's it or what other workaround should I use.


texts: Which wireless technology should I use for my outside "check-if-door-is-open" project?

texts:
I want to connect a magnetic door open/closed sensor to a device that can transmit (or be queried for, whichever) the state of the door to a hub inside (probably RaspberryPi). The outside unit should...

Operate on as little power as possible (outside unit will consist of board, open/closed sensor, power, and transmitter)
Be able to transmit from my back yard to inside my house (~15 meters to house & 1 or 2 walls).

I am new to this and pretty confused as to whether I should use BLE, Zig/xbee, or 2.4ghz rf (is that different? I am not even sure...).

Other considerations are cost (of course) and ease of use. I am a novice with hardware & want something easy to get up and running.


texts:
I want to connect this analog Vernier temperature probe to my Arduino with this British Telecom Connector (BTA).
According to datasheet, when sensor is in the connector, the PIN 6 of the connector should give us the value from 0-5V. I think it should work with this connector because it is supposed to work with this adapter, which is approved by Vernier. It's hard to get any real details about this official Vernier adapter, but I think it doesn't do anything different than just the BTA (linked above).
Of course, I also connected 5V and GND to connector, but when I want to read that 0-5V from Arduino, it says 0. Every single time. The sensor is not broken, because it works with Vernier sensor interface shield which I put on the Arduino (yes, I could use it, but I want to make my project smaller).
That's how the PINS work:

Sensor Pin
Arduino Pin

1 (+/-10 V output line)
A1

2 (Ground)
Ground

3 (Vres/resistance reference)
A4 (also for I2C autoID)

4 (AutoID)
A5 (also for I2C autoID)

5 (+5 Volt power)
5V

6 (0-5 V output line)
A0

I don't know if that's important, but the sensor is based on a thermistor. Also, if I connect A0 to PIN number 1 (+/- 10V output line), it gives me a value.  But, I really can't find anywhere how is that value connected with temperature. I hope I presented my problem well enough so you will understand it.
Thanks :)


texts:
First, my setup:
I have an Arduino Uno with an Adafruit Audio Shield.  I have a Wemos D1 Mini controlling the project.

I need for the D1 to know when a file is playing.

I have a GPIO pin on the Uno programmed to be high when a file is playing.  Low otherwise.  I have two GPIO pins on the Wemos that are unused, D3 and D4 (GPIO0 and GPIO2).  (I use a divider circuit of a 10K over a 20K resistor to bring the 5V from the Uno down to 3v3 for the Wemos). D4 is already a problem because it has to be high to boot and the GPIO from the Uno is normally low. D3 (GPIO0) has to be high to boot and has an internal pullup.

Here's my problem.  How do I turn off the pullup on GPIO0? Even when the Uno GPIO is low (0V), the GPIO0 measures 2.4V, which my sketch sees as a logical 1.

Any tips would be appreciated.  (I thought of reversing the polarity on the Uno so that low=true, but even when the Uno is driving the pin low, the Wemos GPIO0 pin is still at 2.4V, so low-true logic won't work either.).


texts: Unable to connect Ethernet shield W5100 to localhost

texts:
I have an Arduino Uno and a W5100 Ethernet Shield. I am trying to post some data from the Arduino board to the WAMP server running on my computer. I do not have a router so I have directly connected my Ethernet shield stacked onto the Arduino Uno to the laptop's Ethernet port via an Ethernet cable. I have also assigned the Ethernet connection a static IP address 192.168.0.1 and my localhost page opens when I put this address in my browser.

In my Arduino sketch I have assigned the Arduino shield an IP address 192.168.0.4, i.e. on the same IP segment. When I try to do client.connect to the server (192.168.0.1), i.e. localhost, I get "Connection failed".

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0x6F, 0xED };
IPAddress ip(192,168,0,4);
byte server[]={192,168,0,1};

int value=9;
EthernetClient client;

void setup() {
  // Serial.begin starts the serial connection between computer and Arduino
  Serial.begin(9600);
  // start the Ethernet connection
  Ethernet.begin(mac,ip);
}

void loop() {
  // Connect to the server (your computer or web page)
  if (client.connect(server, 80)) {
    Serial.println("Connecting...");
    client.print("GET /Ethernet/getData.php?"); // This
    client.print("value="); // This
    client.print(value); // And this is what we did in the testing section above. We are making a GET request just like we would from our browser but now with live data from the sensor
    client.println(" HTTP/1.1"); // Part of the GET request
    client.println("Host: 192.168.0.1");
    client.println("Connection: close");
    client.println(); // Empty line
    client.println(); // Empty line
    client.stop();    // Closing connection to server
  }

  else {
    // If Arduino can't connect to the server (your computer or web page)
    Serial.println("--> connection failed\n");
  }
  delay(10000);
}

Now when I upload the sketch onto the board and run the serial monitor, I get this output:

My Ethernet connection detail screenshot is as follows:

Please tell me any changes that I must make and also are there any WAMP settings which I should change to allow the connection to get established?

Please consider the fact that I don't have a router anywhere in this connection - just my laptop and Ethernet shield connection.


texts:
Why when I press the reset button it takes 2 second before I see my sketch start?
The model of Arduino is UNO, and the text in serial communication.


texts: What does a higher clock signal frequency actually mean for my AHRS?

texts:
I've got an Arduino with an ATmega328 processor. It can be operated at 3.3V which nets a clock signal frequency of about 12 MHz respectively 16 Mhz at 5V.

I've got an IMU connected to the Arduino and a AHRS algorithm turning accelerometer, gyroscope and magnetometer data into orientation data.

What does the higher frequency of 16 MHz actually mean in this context?

Will the AHRS be calculated faster so I get a lower latency? Can I poll the sensors more often? I want a deeper understanding of what I'm doing here.


texts: How do I connect Arduino to a Bluegiga112?

texts:
I am a new user of Arduino (I have a Arduino Due) and also I am a new user of BLE112 (Bluegiga module 112)

My teacher told me to make the BLE112 advertisable and furthermore he told me to look for information about UART@115K. (The Ble112 he gave me came with wires already soldered to the selected pins: I'm assuming I only need to use those.)

PIN NUMBER [PIN NAME] for BLE112

    2         AVDD                    (Supply voltage 2-3.6V)
    3         AVDD                    (Supply voltage 2-3.6V)
    4        [P2_2]  DC- Debug clock  (DIGITAL I/O)
    5        [P2_1]  DD- Debug data   (DIGITAL I/O)
    9        VDD_USB                  (Supply voltage 2-3.6V)
    20        DVDD                    (Supply voltage 2-3.6V)
    23       [P0_5]  RXD(Rx)          (DIGITAL I/O)
    24       [P0_4]  TXD(TX)          (DIGITAL I/O)
    25       [P0_3]  RTS              (DIGITAL I/O)
    26       [P0_2]  CTS              (DIGITAL I/O)
    29        RESET
    30         GND

I put:

BLE pins [2,3,9,20]    to     3.3v pin of Arduino
BLE pin  [30]          to     GND pin of Arduino

Then I found a picture (attached at the bottom of this post) that describes that I should put CTS of BLE on RTS of Arduino and vice versa. Where is the CTS on an Arduino board? I think I have to program one of the Digital pins.

I tried some other connections. I put:

BLE pin 26(CTS)   to    Arduino random digital pin 32, and
BLE pin 25(RTS)         Arduino random digital pin 34.

BLE pin 24(TX)          Arduino RX pin 0
BLE pin 23(RX)          Arduino TX pin 1

I didn't connect DC(Debug clock), DD(Debug data) and Reset on the BLE112.

So then I found some more info on the web that if I use USART than I should use a wake up pin which is by the default P0_0(??) more about that in this PDF. (Search wake_up)

Now I should mention sleep mode Ble112 (there are three kinds of it) and I believe that the one I am after is MODE 3 (that means that it consumes the minimum (power) of them all)

I found some example named UART@115K

  UART@115k
  This example configures the BLE112 or BLE113 Bluetooth Smart module to expose the BGAPI protocol over UART interface with the following settings: 115200 bps, 8n1 and hardware flow control enabled. The power mode 3 is enabled in this example and the wake-up pin is configured to P0_0 pin (P0_0 button on DKBLE112
  and DKBLE113). When the power mode 3 is enabled the device will not be able to receive commands or data over UART unless the wake-up pin is asserted.

  The example uses UART in the pin configuration channel 1 and alternate 1, which is the configuration used in the DKBLE112 and DKBLE113 development kits.
  If you try this example with DKBLE112 or DKBLE113 make sure the UART interface is enabled and the device is NOT powered with a CR2032 battery as it’s not able to power up the level shifter or UART to USB converter.

  This is also the factory default configuration for BLE112 and BLE113 Bluetooth Smart Modules.

Source: https://bluegiga.zendesk.com/entries/22412436


texts: Arduino Pro Mini ATmega 328P: garbage output on serial console

texts: Arduino Pro Mini ATmega 328P 3.3V 8MHz, connected to USB port via USB to Serial breakout board built around the FT232RL FTDI chip. JTAGenum project code uploaded to the Arduino. I opened terminal and tried to run test command (without connecting wires between target and Arduino), but terminal output show garbage values. The baud rate of the serial console has been set 115200, as specified in JTAGenum code. Not sure whether this issue can be related to CPU_PRESCALE defintions in code.


texts:
I'm trying to make a led sign with a WS2812b ledstrip, using the FastLed library (by the way, this is a great library!), I'm already able to show a text (so far only one, which I leave saved in an array of characters at the beginning of the program), but I would like to be able to change this text using the serial port of the Arduino, and here is the problem:

When setting the text to be displayed in the array of LEDs, the function that I should use is:

ScrollingMsg.SetText ((unsigned char *) TxtDemo, sizeof (TxtDemo) - 1);}

Where TxtDemo is a variable type char array.

Until here all is right, as I commented I can show the text, but at the time of receiving the data from the serial port and save them in the char array TxtDemo, when I use the function sizeof(TxtDemo), the value I get remains with the original size (quite understandable) of this array.

For example: If the initial text was (saved in TxtDemo):
"Hello world", the sizeof() function, returns "11",
But when I pick up what I want to show on the serial port and store it in the variable TxtDemo, there's no way I can alter the size of that array. So ... what can I do? What do you recommend me to do?


texts: pushing accelerometer data in packets from an arduino due to the pc and unto processing

texts:
I'm quite a newbie to this and I've been struggling for sometime now with my school project, trying to find a way to send accelerometer data from my MMA7361 in data packets, I understand that I have to send the data in packets, but I'm having problems going about it. One of the requirements of the project is that I have to send the data in array-packets of all the individual axes (e.g. a buffer array to hold the x-axis value, another for the y-axis value and also for the z-axis value). I have read quite a lot of documentation on the internet about this  but putting it together is a challenge. Below is the infamous MMA7361 code sketch, do please help out if you can thankyou.

    #include <AcceleroMMA7361.h>

    AcceleroMMA7361 accelero;
    int x;
    int y;
    int z;

    void setup(){
        Serial.begin(9600);
        accelero.begin(13, 12, 11, 10, A0, A1, A2);
        accelero.setARefVoltage(3.3);     //sets the AREF voltage   to 3.3V
        accelero.setSensitivity(LOW);           //sets the sensitivity to +/-6G
        accelero.calibrate();
    }

    void loop(){
        x = accelero.getXRaw();
        y = accelero.getYRaw();
        z = accelero.getZRaw();
        Serial.print("\nx: ");
        Serial.print(x);
        Serial.print("\ty: ");
        Serial.print(y);
        Serial.print("\tz: ");
        Serial.print(z);
        delay(500);                                     //(make it readable)
    }


texts:
I've had an idea for an Arduino project, but I'm not sure where to start. My idea is this: have an Arduino Nano connected to an HC-SR04 ultrasonic sensor, as well as an nRF24L01+ radio. This will be the tripwire module, which will send an alert to a second Arduino (connected to another nRF24L01+ of course) whenever something passes by.

This wouldn't be a stationary unit, it would need to be able to be placed and sense in a variety of locations so the distance would need to be set on power up.

Another issue I'm running into is getting the nRF24L01+ units to work for this purpose. I want to know that the units are wirelessly connected, so having a packet sent every second or so lets the receiving unit know that they're connected, and an additional packet for the tripwire trigger sets off an indicator led.

Is this even possible?


texts:
I am looking for a way of generating booleans rapidly. For booleans, one usually uses random(0,2); but in my case I need about 250 booleans and calling random every time is slow.
So I thought about using all bits of a random number on the whole range as such:
randomSeed(100); // A seed to always keep the same sequence
long rdm = random(MIN,MAX);  // Generate a number in range MIN,MAX of type long
long mask = 1;
for(int i=0; i<32; i++){
    if((rdm>>i)&mask){
        //do something
    } else {
        //do something else
    }
}

But with this I have three questions:

What are MIN and MAX so that the LONG random uses all bits, with value ranging from -2,147,483,648 to 2,147,483,647 (arduino long type). I tried several MIN and MAX, also simply random(); but without success.
Is it a valid approach? Do I expect each bit to be uniformly distributed? Should I use fewer bits, e.g. random(0, 2^16); for a "better" distribution?
Is there some seed known to be good or bad at this?

My project
I am working on a device made of Neopixel LED strips. It is for a visual neuroscience experiment where each "pixel" is either ON or OFF. I need the speed to be able to reach high refresh rate (60-100Hz), with normal statistical distribution to avoid bias in neuron response analysis. With this approach, I can reach the desired speed but I'm concerned about the statistics. So I need a better understanding of random()'s behaviour to do it right!


texts: Are these lcd and motor-shields stackable?

texts:
first of all, I'm kindly apologizing for asking such stupid questions, but as my electronic-knowledge is dramatically limited, you are my only hope to get my problem solved.

I'm pretty new to Arduino and my plans are to stack a lcd shield on a motor shield, which is stacked on the Arduino.

My setup would be the following:

Arduino MEGA2560
LCD-Shield http://www.sainsmart.com/arduino/arduino-shields/lcd-shields/sainsmart-1602-lcd-keypad-shield-for-arduino-duemilanove-uno-mega2560-mega1280.html
Motor-Shield http://www.sainsmart.com/arduino/arduino-shields/motor-shields/sainsmart-l293d-motor-drive-shield-for-arduino-duemilanove-mega-uno-r3-avr-atmel.html

My target is to enter specific values trough the LCD-shield (with its buttons) and to control a stepper-motor related to those.

Now to my question: Can I realize my project with the mentioned parts and are the two shields stackable (with head extentions on the motor-shield) without creating interferences?

Thank you very much for your time and answers in advance.

Best regards,

irie


texts: Common ground serial communication trouble SIM800L

texts:
I have a trouble when i'm using SIM800L module with common ground with combinaison with : FTDI232+ARDUINO PRO and Li-po battery. I use common ground to allow Arduino see the serial of SIM800L.

I use battery (lipo) to power the SIM800L to allow 2A peak current.

Serial work but sometime the module reset(i think) and i see strange character. The SIM800L no work correctly.

I meet the same trouble when i use the FTDI's VCC, every time I use the common ground i have this problem.

Look the gif you can see the problem :

I'm using this wiring

It's strange because when i connect the SIM800L directly with FTDI232 i have no problem all work fine.

I use this code to debug the Serial communication :

#include <SoftwareSerial.h>
SoftwareSerial serialSIM800(RX,TX)
[..]
//On Setup
 Serial.begin(115200);
  while(!Serial);

  //Being serial communication witj Arduino and SIM800
  serialSIM800.begin(115200);
  delay(1000);
  serialSIM800.print("AT\r");
  //[..]
void loop(){

 if (serialSIM800.available())
     Serial.write(serialSIM800.read());

 if (Serial.available()) {
    while(Serial.available()){
      Serial.print(">");
      char test=Serial.read();
      Serial.print(test);
      Serial.println();
      serialSIM800.write(test);
 }

There are a few things that escape me that's why I need your lights, thanks by advance.
Regards


texts: I mostly program in C/C++ so I conviniently have a GCC compiler for all my compilations. I was wondering if there is a special compiler for Arduino that can be used just like the GCC Compiler? Because just taking a .ino sketch and passing it to the comiler with a few arguments will be a lot easier for me that all those things in the IDE, and furthermore I use Sublime Text as my text editor. And making a C program work in Sublime is as simple as providing it a path to the compiler. So I would like a portable smaller version of the Arduino Compiler that is NOT the whole IDE folder. Hope I get nice answers!! Thanks in advance.


texts: Programming arduino with FT232RL, not in sync: resp=0x00

texts:
I realize this generic error has been asked about lots of times before, but I have been unable to find an answer that works for me.

I have a bunch of pro mini's that I program with an FT232RL. It works perfectly fine for some time, but eventually it stops working and I get the error:

avrdude: stk500_recv(): programmer is not responding

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

Using the same FT232RL on an unused pro mini still works fine. Burning a new bootloader through an Uno as ISP works fine, as well as uploading code to the pro mini that way, but even after burning the bootloader the FT232RL does not work on that pro mini again.

I have experienced this exact behavior on three different pro minis in a row now. Is there any sort of factory reset-ish thing I can do other than the bootloader to try to get these back to square one?


texts: Some Blocks of Code gets stuck in a loop, I do not know why

texts:
The code below Gets stuck at function "Led Off?" & "Check button".
I'm using Blockyduino editor.
The check button code was intended as a toggle switch for the lights. When I deleted "Led Off?" and "Turn off All LED", the code did not get stuck.

int Button_Status;

// Toggle Code for the button.
void Check_Button() {
  Serial.println("Check button Activated");
  if (Button_Status == 1) {
    if (digitalRead(13)) {
      Button_Status = 0;
    }
  }
  if (Button_Status == 0) {
    if (digitalRead(13)) {
      Button_Status = 1;
    }
  }
  LED_OFF_();
}

void Left_Animation() {
  Check_Button();
  digitalWrite(2, HIGH);
  digitalWrite(3, HIGH);
  Check_Button();
  delay(1000);
  digitalWrite(4, HIGH);
  digitalWrite(5, HIGH);
  Check_Button();
  delay(500);
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  Check_Button();
  delay(300);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  Serial.println("Finshed Left cycle");
}

void Right_Animation() {
  Check_Button();
  digitalWrite(8, HIGH);
  digitalWrite(9, HIGH);
  Check_Button();
  delay(1000);
  digitalWrite(10, HIGH);
  digitalWrite(11, HIGH);
  Check_Button();
  delay(500);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  Check_Button();
  delay(300);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  Serial.println("Finished Right cycle");
}

// Main Loop Core
void Main_Loop() {
  while (Button_Status == 1) {
    Left_Animation();
    Right_Animation();
    Serial.println("Finshed Main Loop 1111");
  }
  while (Button_Status == 0) {
    Check_Button();
    Serial.println("Finished Main Loop 2222");
  }
}

// Checks if button toggle variable is off.
void LED_OFF_() {
  Serial.println("LED off? Activated");
  if (Button_Status == 0) {
    Turn_Off_All_LED();
  }
  Main_Loop();
}

// Turns off all LED
void Turn_Off_All_LED() {
  Serial.println("LED Turn off Activated");
  digitalWrite(2, LOW);
  digitalWrite(3, LOW);
  digitalWrite(4, LOW);
  digitalWrite(5, LOW);
  digitalWrite(6, LOW);
  digitalWrite(7, LOW);
  digitalWrite(8, LOW);
  digitalWrite(9, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  Main_Loop();
}

void setup()
{
  Serial.begin(9600);
  pinMode(13, INPUT);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
}

void loop()
{
  // Start
  Button_Status = 1;
  Main_Loop();
}


texts: Is using malloc() and free() a really bad idea on Arduino?

texts:
The use of malloc() and free() seems pretty rare in the Arduino world. It is used in pure AVR C much more often, but still with caution.

Is it a really bad idea to use malloc() and free() with Arduino?


texts: ESP8266 - Sending a software Reset Command

texts:
I have an ESP8266 running an Arduino code to control a dual relay device ( Up, Down, Off ), both from a physical switch and MQTT commands. After mounting the device in place I have no access in case of a need to reset ( just as a precaution ).

My workaround:

1) condition: function that on 4 detection of 4 repeated UP button presses - it should send a reboot signal.

2) the reboot signal is :

void sendReset() {
  Serial.println("Sending Reset command");
  Serial.println(1/0);
}

sendReset function actually reboots the device and boot occurs as needed, BUT - is doing it this way is a valid solution ? does boot process actually boots all services and freeing/ memory or any other.... AS NEEDED ?

Guy


texts: I ordered an esp12e UART. So how can I start using it? Since I have seen a lot of articles online, but all of them are complicated for me. I'm pretty new to the arduino world, but I have some experience. Thanks in advance. For more info comment on my post and I will reply.


texts: How well will the Arduino Uno survive in a vacuum?

texts: Im doing some experiments with Pocketlab and Arduino, Vacuum will get to around -30inHg. I tried with my raspberry pi and it just kept dying everytime a vacuum was pulled. The only problem I can image is the arduino heating up.


texts:
I am trying to optimize the memory usage of my ESP8266 arduino sketch by using 8.3 SFN folder names internally, but LFN when needed for user output. Unfortunately when opening a folder by using the SFN, getName also returns the SFN:
sdfat::SdFile _currentFolder;
_currentFolder.open("BLUBBE~1");
char foldername[100];
_currentFolder.getName(foldername, sizeof(foldername));

results in "BLUBBE~1" while
sdfat::SdFile _currentFolder;
_currentFolder.open("blubberblub");
char foldername[100];
_currentFolder.getName(foldername, sizeof(foldername));

results in "blubberblub" (and getSFN would return "BLUBBE~1"). Is there any chance to open the folder using the SFN "BLUBBE~1", but get the LFN ("blubberblub") later on?


texts: How to use an Arduino Speaker module with DFPlayer Mini?

texts: I've bought an Arduino speaker module. How should I connect the module, if I want to use it with DFPlayer Mini? The problem is that the speaker module has 3 pins: GND, VCC, and IN; though the DFPlayer Mini has 2 pins for connecting a speaker: SPEAKER + and SPEAKER -.


texts: Powering USB cable that powers Arduino with regulated 5V

texts: I am having an issue with external loads causing the computer I have my Arduino connected to to momentarily drop out, which causes the Arduino to lose USB power momentarily and the port drops out and won't reconnect unless I physically remove and reconnect the USB cable. Since I need the USB connected in order to send and receive serial data to/from the Arduino, I was wondering if I could physically open the USB cable, cut the 5V line, and supply it via and external regulated 5V supply. I wouldn't cut the ground wire, but would tie it to the external 5V supply. I have read conflicting information on this (something about handshaking) but was wondering if that applied to Arduino's specifically.


texts: Real range of long range transceptor LORA RA-02 SX1278 with Arduino UNO

texts:
I'm working in a project where I have to send data from long distances (about 1 km) between 2 Arduinos UNO which are powered by computer's USB ports. The place is a small city with no large buildings. I have bought two transceptors LORA RA-02 SX1278 at 433 MHz with an antenna for this frequency, like this:

The results are dissapointing. I can reach 300-350 meters with a stable communication (1 data send every 5 seconds). I was only able to, only one time, receive a data from a 1.4 km distance, but the message was corrupt, like this:

I have tried:

Different programs and libraries (Now, i'm working with this library)
Frequencies from 410 MHz to 525 MHz, according to the range inscriptions on the module

But the distance is still far away from 1 km for a stable communication. I have seen some people reaching 2-3 km with this module and some documents say that it is possible to reach 10 km.
The question is, what am I doing wrong or what I should change to improve the results?
Any help or related experience is very useful!


texts:
I'm planning to buy an ESP8266. Do I really need to learn Lua to play with it? I have seen some people using it with the standard Arduino IDE.

Do you need a custom firmware to use the Arduino IDE instead of Lua?

The Arduino IDE seems better for me because I already know the syntax. Is there any downside to using the Arduino IDE instead of NodeMCU with Lua?


texts: How can I make an AC analog voltage with Arduino?

texts:
I am trying to create an AC voltage in Arduino. Until now I have only managed to get a square wave. How can this be achieved with Arduino?

If I try:

int up;
int down;
int out = 11;

void setup() {
  pinMode(out, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for (up = 0; up <= 255; up++) {
    analogWrite(out, up);
    delay(1);
  }
  for (down = 255; down >= 0; down--) {
    analogWrite(out, down);
    delay(1);
  }
}

is it still pulsed DC?


texts:
I have a function SetTFgr(float T, int FGr) to set the time and filtergrade of my LED enlarger.
It works without a problem and changes the values of T or Fgr according to the buttons I press. Both T and FGr are global variables.
Now I want to use the same funtion with different variables.
When I call the function with SetTFgr(TExp[i], FGrExp[i]) I would expect the function to work with the values of TExp[i] or FGrExp[i] and increase/decrease these values. It does not, it appears to use the value of T or Fgr instead.
How can I get what I am after?


texts: I'm using Arduino MKR GSM 1400. I know this board uses Atmel SAMD21 and SAMD21 support half duplex (USART with full-duplex and single-wire half-duplex configuration). My question is, How Can I configure one of the SERCOMs to use it as Half-Duplex (Use one pin for rx and tx)?


texts: Are there ultrasonic transducers which are able to produce a "chirp" sound wave?

texts:
I'm working in a ultrasonic radar project and the supervising teacher wants us to produce a chirp sound wave (a frequency-varying sinusoid).

I'm familiarised with the usual ultrasonic module, but as far as I know, it cannot do the task.

I searched on-line for transducers that I could use, but couldn't find anything useful.
Are there any commercially available component that could do this task? If not, what could I possibly do?


texts: Encoding an entire Byte for File Reading

texts:
I'm using an Arduino Yun to read from a data file, which will then populate a data structure. The file.read() function "returns: The next byte (or character), or -1 if none is available."

This functionality is identical to the SD.read() function in the SD card library.

The data file will never have any value that exceeds 1 byte with all numbers in the range 0-255. If I print these numbers as a long string in the data file, each character is read as a byte. So I need to call file.read() 3 times to read in a single 0-255 value. And then do some additional processing to construct the final 8-bit value for storing.

I could reduce this to 2 calls by printing the Hex code in the data file, but this isn't much of an improvement.

Is there a way to encode a full byte in a single character?

Effectively , is there a particular way I can format my data file so that I can read in an 8-bit unsigned value in a single call to file.read()?


texts: Arduino Interface with Serial device and LCD display

texts:
I want to connect my Arduino UNO to a serial device that once powered displays signature numbers. I want to then display those numbers on an LCD display. I have my 16x2 LCD wired correctly and it works fine even when I use the SerialDisplay example code from the library.

My questions are:

Can I use a USB to TTL serial cable to connect the RX/TX pins of the serial device to the TX/RX pins of the arduino?
The two numbers are more than 16 characters. How can I cut the numbers down and then display the two numbers on two seperate lines of the LCD display?

Let me know if I should provide further details.


texts:
I'm trying to interface with a serial device utilizing Serial1 (pins 18,19) on the Arduino Due. The normal serial port (Serial) is working just fine and is acting as a debug port at the moment - It's also able to communicate with the serial device without a problem when using the normal port.

I noticed that within the libraries for the Arduino hardware, the avr directory contains HardwareSerial files for the Mega's multiple serial lines, but the header file under the sam director does not. Simply a declaration of the HardwareSerial class with no elaboration on Serial1,Serial2 or Serial3 like the Mega's header contains.

Has anyone modified the libraries to set up the Arduino Due's multiple serial lines? Thanks in advance!


texts: how do i connect my Arduino Nano to my Linux Laptop

texts:
update:
I uninstalled the portable package of Arduino IDE, completely, and installed the IDE using sudo apt install arduino. yes, I verified that my Nano was plugged in, the status on the bottom right says Arduino Nano w/ ATmega328 on COM1, but sadly the IDE won't explain to me why the Tools > Serial Port section is still unavailable.

Also, the online version doesn't recognize the board even though it's plugged in and configured in the settings to look for a "Nano". I also used a reliable USB Hub I use for my drawing tablet, because that was one of the remedies to troubleshoot the lack of connection, and because the Hub seems to do a lot of good things around here.

end of update

I received an Arduino Nano as a gift a couple months ago and had to place it on a shelf as a mere dust collector, because it was not as easy as I thought it would be to get it working.
I plugged the Nano into my computer with a cable, and attempted to load an example "blink" program and it gives errors saying "no device connected" in the errors.

It does light up and flash, so I know it is receiving power, so how do I specify where the Nano is?
I am familiar with the /dev category and how to use code in Linux, but I don't know how to communicate with the Arduino, as in, know which block device the Nano is in /dev

now that Thomas has brought to my attention the "port" setting in the drop down menus, I just realized that the port is greyed out. that could be a good detail in troubleshooting this issue.


texts: Getting the I2C Address from a Max9744 amplifier

texts:
I just bought 2 Max9744 amplifiers that I wish to scan the I2C addresses, just to check against what is said in documentation. I have the amplifier powered with a 12 v supply and the Arduino powered via usb. I run an I2Cscanner it says Devices found: in the serial monitor but doesn't say the address. The wiring is correct and the 5 v supply is giving 5 V. So what gives?
Thank you
Andrew


texts:
I want to use stm32duino to control 5110, I use the library http://www.rinkydinkelectronics.com/download.php?f=LCD5110_Basic.zip

Before, I use arduino pro mini to control 5110 by this library, it works well. But when I use stm32, it fails. Whether this library is not suitable for stm32duino ? If so, which library is suitable for me ?


texts: ble_write slows down my sketch causing problems (Blend Micro & NRF8001)

texts:
I'm working on a prototype which uses the RedBearLabs Blend Micro with the NSC's nrf8001 ble chip, but have ran into a problem that I'm not sure how to solve.

I have two tactile buttons connected to the input pins on the Blend Micro, which are used to increase or decrease counters (integers) in my sketch that is in turn displayed on a OLED screen. When I use these buttons to manipulate the counter in offline mode (meaning that the bluetooth is not connected) I can repeatedly press the buttons very quickly and the counter is increased with every push - but when I connect to my phone and try to push the buttons with high frequency (>1-2 per second) the program is not able to react to every button interaction, causing only every second or third click to be registered.

The only thing that I do differently when I am connected is that I'm sending 5 bytes using "ble_write" (part of the RBL nrf8001 library), which seem to cause this delay resulting in missed clicks. Even sending one byte using "ble_write(X)" seem to slow down the sketch so much that this phenomena occurs.

Do any of you had similar problems and possible ways to solve this? I've been considering batching clicks together until I reach a certain amount and then send them at all once - this however may risk that a button is being pressed at the same time as the ble_write is executed, causing missed click.

Offline click looks like this:

if(digitalRead(A4)) {
while (digitalRead(A4)) {        }
offlineIn++;
localIn++;
totCount++;
sleepTimer = 0;
  }

And the online like this:

if (digitalRead(A4)) {
  while (digitalRead(A4)) {        }
  totCount++;
  localIn++;
  sleepTimer = 0;
  ble_write('0');
  ble_write('0');
  ble_write('0');
  ble_write('1');
  ble_write('1');
}

Thanks!


texts: ESP8266 - How to know if incoming connection is from AP or station network?

texts:
I have an ESP8266 module connected with my Arduino configured as a server, with both AP and station modes (AT+CWMODE=3) activated, and I want to know if an incoming connection comes from the AP's network or the station's network. This is the package I'm receiving, and it's exactly the same whether it comes from one or another network:

+IPD,0,437:GET /?uuid=7be547af980d13c5&cmd=10 HTTP/1.1
Host: 192.168.0.222:51813
Connection: keep-alive
Cache-Control: max-age=0
Accept: */*
Origin: http://127.0.0.1:8020
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36
DNT: 1
Referer: http://127.0.0.1:8020/domo_ctrl/www/index.html
Accept-Encoding: gzip, deflate, sdch
Accept-Language: es-419,es;q=0.8,en;q=0.6

At first I thought that it would reject packages addressed towards another IP (AP's IP is different from station's IP), but since this IS the gateway, it receives ALL incoming traffic. Please help!

EDIT:

This is the firmware and other stuff shown by AT+GMR:

AT+GMR

AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK


texts: I need my ESP8266 web server to load my website files with .php extensions. So far I managed to load .htm .css and .js files from my SD card, but when I upload PHP files on my SD card, they won't run. How can I do that?


texts:
I want to control the contrast and backlight of an HD44780 LCD display with two PWM signals. I would like to use PB1 and PB2 (Pin 9 and Pin 10) for this.
As far as my research goes, timer1 is responsible for the two pins.
OCR1A and OCR1B are responsible for the pulse length.

With the code below I get a frequency of 7.823 kHz and a duty cycle of 88%. But it works only on PB1. PB2 is still constant 0V. I am using the AtmelStudio, therefore I don't have access to functions like pinMode(10, Output)

How can I have different duty cycles on pin 9 and 10?

#define F_CPU 16000000UL
#include <avr/io.h>

int main(void)
{
    DDRB |= (1 << DDB1) | (1 << DDB2);
    OCR1A = 900;
    OCR1B = 400;
    TCCR1A |= (1 << COM1A1);
    TCCR1A |= (1 << WGM11) | (1 << WGM10);
    TCCR1B = (TCCR1B & 0b11111000) | (1 << CS10);

}