texts:
I am using MPU6050 on an Arduino Mega 2560 with Data logging shield v1.0 and an 8Gb Kingston Micro-SD HC card.I am facing a problem in logging and successfully writing to a file 100 values/sec. Now in my csv file i take only 30-35 values/sec. The delay should be (as i read in an other topic here) in "SD latency problem, which needs to be dealt using a FIFO buffer storing the incoming data in an ISR, while the SD is busy being written."

Can anyone help me?
Thanks in advance.

    #include<Wire.h>
    #include <SD.h>
    #include <SPI.h>
    #include <virtuabotixRTC.h> //Library used
    //RTC
    //Wiring SCLK -> 6, I/O -> 7, CE -> 8
    //Or CLK -> 6 , DAT -> 7, Reset -> 8
    virtuabotixRTC myRTC(6, 7, 8);

    //FILE
    File myFile;
    char myLogName[] = "MyLog.csv";
//Mega CS pin
const int chipSelect = 8;
//GYRO
    const int MPU_addr=0x69;  // I2C address of the MPU-6050
    int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
 // Set the current date, and time in the following format:
 // seconds, minutes, hours, day of the week, day of the month, month, year
 //myRTC.setDS1302Time(0000, 23, 12, 1, 15, 7, 2019); //Here you write your actual time/date as shown above
 //but remember to "comment/remove" this function once you're done
 //The setup is done only one time and the module will continue counting it automatically
 //SD BEGIN
 SD.begin(4);
 myFile = SD.open(myLogName, FILE_WRITE);
 myFile.print("Date, Time, AcX, AcY, AcZ, GyX, GyY, GyZ");
 myFile.println();

 //WIRE BEGIN
 Wire.begin();
 Wire.beginTransmission(MPU_addr);
 Wire.write(0x6B);  // PWR_MGMT_1 register
 Wire.write(0);     // set to zero (wakes up the MPU-6050)
 Wire.endTransmission(true);
 // Serial.begin(115200);
 myFile.close();
 }

 void loop()
 {
 //UPDATE TIME
 myRTC.updateTime();
 //GYRO
 Wire.beginTransmission(MPU_addr);
 Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
 Wire.endTransmission(false);
 Wire.requestFrom(MPU_addr,14,true);  // request a total of 14 registers
      AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C(ACCEL_XOUT_L)
      AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
      AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)

      GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
      GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
      GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)

      myFile.print(myRTC.hours,DEC);
      myFile.print(":");
      myFile.print(myRTC.minutes,DEC);
      myFile.print(":");
      myFile.print(myRTC.seconds,DEC);
      myFile.print(" , ");
      myFile.print(AcX);
      myFile.print(" , ");
      myFile.print(AcY);
      myFile.print(" , ");
      myFile.print(AcZ);
      myFile.print(" , ");
      myFile.print(GyX);
      myFile.print(" , ");
      myFile.print(GyY);
      myFile.print(" , ");
      myFile.println(GyZ);
      myFile.print(" , ");
      myFile.close(); //close file
    }


texts: Please tell me why is it necessary to access pull-up resistors and how can we access them in arduino?


texts:
Is it possible to Power a Arduino Mega 2560 and a NodeMCU V2 ESP8266 ESP-12E from a single 9V Block?

What would be the best solution?

Can i power the ESP8266 directly via the Arduino Mega 5V output? (3.3V Output seems to weak)
Is a Power Converter like this for the ESP8266 necessary?
Should i use another external Power source for the ESP8266?

Thanks for any Help :)


texts: I'm desperate and need help with MFRC522 (stops working randomly)

texts:
I've made a light switcher that switches lights on for 15s after a correct tag is presented, and also when door is opened for 6 seconds (its for outside) so i can see a keyhole after leaving for a brief amount of time. It works perfectly, but the rfid reader stops reading tags after random amounts of time (sometimes after hour and sometimes after days) - I've tried i think everything in terms of software (except watchdog) and i simply ran out of ideas. I need it to work, so i draw all the connections in the picture below - if anyone got any ideas, please let me now.
Side note - everything is mounted and hidden outside so each even smallest hardware change is very hard to do so please, don't throw random ideas in this matter even tho every help is appreciated

EDIT: I made a photo of interior of the enclosure that holds relay, arduino and charger PCB and decided to add it here too

#include <SPI.h>
#include <MFRC522.h>

//blue
const byte UID1[] = {0xA7, 0x8C, 0x24, 0xD9};
//blacks
const byte UID2[] = {0x10, 0x84, 0xD2, 0x2A};
const byte UID3[] = {0xDC, 0x46, 0xB6, 0x91};
const byte UID4[] = {0xB0, 0xE8, 0xC4, 0x2A};
//reds
const byte UID5[] = {0x9E, 0xC8, 0xEA, 0xB3};
const byte UID6[] = {0xFE, 0xA5, 0xF7, 0xB3};
//const byte UID6[] = {0x70, 0xBA, 0x35, 0xA5};

#define RST_PIN 9
#define SS_PIN 10

MFRC522 rfid(SS_PIN, RST_PIN);
MFRC522::MIFARE_Key key;
int in1 = 7;
int dooropen = 8;
int state = 0;
int testerbester = 0;
void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  pinMode(in1, OUTPUT);
  pinMode(dooropen, INPUT);
  digitalWrite(in1, LOW);
  delay(2000);
}

void loop() {
  delay(200);
  state = digitalRead(dooropen);
  if (state == HIGH) {
    //Serial.println("Door Opened");
    testerbester = 1;
    digitalWrite(in1, HIGH);
  } else {
    if (testerbester == 1) {
      delay(6000);
      testerbester = 0;
      digitalWrite(in1, LOW);
    } else {
      digitalWrite(in1, LOW);
    }
    if ( ! rfid.PICC_IsNewCardPresent())
    {
      return;
    }
    if ( ! rfid.PICC_ReadCardSerial())
    {
      return;
    }
    if ((rfid.uid.uidByte[0] == UID1[0] &&
         rfid.uid.uidByte[1] == UID1[1] &&
         rfid.uid.uidByte[2] == UID1[2] &&
         rfid.uid.uidByte[3] == UID1[3]) ||
        (rfid.uid.uidByte[0] == UID2[0] &&
         rfid.uid.uidByte[1] == UID2[1] &&
         rfid.uid.uidByte[2] == UID2[2] &&
         rfid.uid.uidByte[3] == UID2[3]) ||
        (rfid.uid.uidByte[0] == UID3[0] &&
         rfid.uid.uidByte[1] == UID3[1] &&
         rfid.uid.uidByte[2] == UID3[2] &&
         rfid.uid.uidByte[3] == UID3[3]) ||
        (rfid.uid.uidByte[0] == UID4[0] &&
         rfid.uid.uidByte[1] == UID4[1] &&
         rfid.uid.uidByte[2] == UID4[2] &&
         rfid.uid.uidByte[3] == UID4[3]) ||
        (rfid.uid.uidByte[0] == UID5[0] &&
         rfid.uid.uidByte[1] == UID5[1] &&
         rfid.uid.uidByte[2] == UID5[2] &&
         rfid.uid.uidByte[3] == UID5[3]) ||
        (rfid.uid.uidByte[0] == UID6[0] &&
         rfid.uid.uidByte[1] == UID6[1] &&
         rfid.uid.uidByte[2] == UID6[2] &&
         rfid.uid.uidByte[3] == UID6[3]))
    {
      digitalWrite(in1, HIGH);
      delay(15000);
      digitalWrite(in1, LOW);
    }
    rfid.PICC_HaltA();
  }
}


texts: Set array to array passed as parameter in constructor

texts:
I have a constructor which looks like this:

Preset::Preset(char* presetName, MIDICommand* MIDICommands[])
  _presetName = presetName;
  _MIDICommands = MIDICommands;
}

_MIDICommnads is declared like this: MIDICommand* _MIDICommands[];.

When run, this throws the error below on the second line in the constructor:

incompatible types in assignment of 'MIDICommand**' to 'MIDICommand* [0]'

Why do I need to declare _MIDICommands as MIDICommands**, and not MIDICommand* _MIDICommands[]?

The array I pass is declared like this:

MIDICommand* one =  new MIDICommand(1, 2);
MIDICommand* two =  new MIDICommand(2, 2);

MIDICommand* MIDICommandsA[] = { one, two };

EDIT:
When I pass in an array, should I just use MIDICommand* MIDICommands, or do I need the [] at the end?
Now I've taken them off, but then I get trouble with passing the array.

It doesn't find a matching function to call. Basically, this MIDICommand* MIDICommandsA[] = { one, two }; doesn't match this MIDICommand* MIDICommands parameter.

EDIT 2:
So, I've solved the problem of passing the array. I changed the parameter in the constructor to MIDICommand** MIDICommands, and I just pass a pointer to the array.

Now the constructor looks like this:

Preset::Preset(char* presetName, MIDICommand** MIDICommands)
{
  Serial.println(MIDICommands[0]->getProgramChange());

  _presetName = presetName;
  _MIDICommands = *MIDICommands;

  Serial.println(_MIDICommands[0]->getProgramChange());
}

I'm getting an error on the second Serial.println, telling me it is a non-pointer type. I'd like it to be a pointer, so that's what I am looking at now.

_MIDICommands is now declared like this: MIDICommand* _MIDICommands.

EDIT 3: When I try to loop through the array now, it seems I have lost the second element, and have only the first.


texts: What would cause one Arduino to be recognized but not another?

texts:
I have two Arduinos, A cheap china-knockoff and an original one. I have had no problem with either of them before. But when I moved from connecting the original with a USB A-hub to running it over USB-C my computer can't find it any more.

I run OSX and tried to install a new USB serial driver. Didn't work either. Then I tried the cheap clone, same computer, same wire, same computer and it works fine.

The faulty Arduino powers up and I can reset it. So it seems to be working. What might cause this?


texts: How to upgrade ESP8266 NodeMCU SDK from V2.5.2 to V3?

texts:
ESP.getFullVersion() output:

SDK:2.2.1(cfd48f3)/Core:2.5.2=20502000/lwIP:STABLE-2_1_2_RELEASE/glue:1.1-7-g82abda3/BearSSL:a143020Connecting to DO_231455

I upload sketches from the Arduino IDE. How do I update the SDK?

I have the flasher tool but I can't seem to find documentation on what to do from this point:

I've downloaded the assets from Github


texts: ESP-01 not responding to serial data while programming with esptool.py

texts:
I have a Arduino uno board, ESP-01 board and a logic level shifter (bidirectional) and to program the esp module i wired my Arduino and esp like this

Arduino uno(atmega328p removed)  --> level shifter --> ESP-01
5v --> highvolt
3v3 --> lowvolt
TX --> ch1 --> TX
RX --> ch2 --> RX
proper ground connections

but when i click upload the RX pin lights up indicating its receiving data but esp doesn't respond to that when i reset the module while its uploading the compiler throws this
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
  File "C:\Users\TRAJU\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.7.4/tools/upload.py", line 65, in <module>
    esptool.main(cmdline)
  File "C:/Users/TRAJU/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 2890, in main
    esp.connect(args.before)
  File "C:/Users/TRAJU/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.7.4/tools/esptool\esptool.py", line 483, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
_
the selected serial port _
 does not exist or your board is not connected

It as working fine yesterday and it stopped today :(
Please help and thanks in advance.


texts:
I am trying to make a state machine with if/else. But some of the code does not seem to be executing. I have information being displayed on an LCD screen so I know where it is, and it stays on Todo=1 and does not go to the next state. I have tried using switch/case and it works. But I think it might be better for my project if I use if/else. Can I do this using if/else?

Void loop{
  if (state == PLAY) {
    Todo = 1;
    Mastermachine(Todo);
  } else if (state == TRYAGIN) {

  }
}

void Mastermachine(int Todo) {
  if (Todo == 1) {
    lcd.setCursor(16, 2);
    lcd.print(String(Todo));
    SongSeq[largestindex];
    for (int index = 0; index < largestindex; index++) {
      SongSeq[index]();
    }
    Todo = 2;
  } else if (Todo == 2) {
    for (learnindex = 0; learnindex < largestindex;) {
      MIDI.read();
      if (learnindex >= largestindex) {
        Todo = 3;
      }
      lcd.setCursor(16, 2);
      lcd.print(String(Todo));
    }
  } else  if (Todo == 3) {
    if (array_cmp(learn, note, largestindex, largestindex) == true) {
      largestindex++;
      delay(2000);
      Todo = 1;
    } else {
      delay(2000);
      Todo = 1;
    }
    lcd.setCursor(16, 2);
    lcd.print(String(Todo));
  }
}


texts:
I have an arduino uno. Whenever I try to upload code to the arduino I get this error.

avrdude: ser_open(): can't open device "/dev/cu.usbserial-AL01EI7I": Device not configured

ioctl("TIOCMGET"): Inappropriate ioctl for device Problem uploading to board.
See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.


texts: How to add if condition in RFID example?

texts:
Using an Arduino Mega 2560 and PN532 NFC/RFID module, I want to be able to scan a card and see if its value is (0xF0, 0x21, 0x5D, 0xA7). It should print "accepted" in the serial monitor.

However during compilation it keeps telling me:

iso14443a_uid:99:11: error: expected primary-expression before ']' token

if (uid[] = {0xF0, 0x21, 0x5D, 0xA7}){
        ^

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

This is my code:

/**************************************************************************/
    /*!
        This example will attempt to connect to an ISO14443A
        card or tag and retrieve some basic information about it
        that can be used to determine what type of card it is.

    Note that you need the baud rate to be 115200 because we need to print
    out the data and read from the card at the same time!

    To enable debug message, define DEBUG in PN532/PN532_debug.h

*/
/**************************************************************************/

/* When the number after #if set as 1, it will be switch to SPI Mode*/
#if 0
  #include <SPI.h>
  #include <PN532_SPI.h>
  #include "PN532.h"

  PN532_SPI pn532spi(SPI, 10);
  PN532 nfc(pn532spi);

/* When the number after #elif set as 1, it will be switch to HSU Mode*/
#elif 0
  #include <PN532_HSU.h>
  #include <PN532.h>

  PN532_HSU pn532hsu(Serial1);
  PN532 nfc(pn532hsu);

/* When the number after #if & #elif set as 0, it will be switch to I2C Mode*/
#else
  #include <Wire.h>
  #include <PN532_I2C.h>
  #include <PN532.h>
  #include <NfcAdapter.h>

  PN532_I2C pn532i2c(Wire);
  PN532 nfc(pn532i2c);
#endif

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  nfc.setPassiveActivationRetries(0xFF);

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

  Serial.println("Waiting for an ISO14443A card");
}

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

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

  if (success) {
    Serial.println("Found a card!");
    Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("UID Value: ");
    for (uint8_t i=0; i < uidLength; i++)
    {
      Serial.print(" 0x");Serial.print(uid[i], HEX);
    }
    Serial.println("");
    // Wait 1 second before continuing
    delay(1000);
  }
  else
  {
    // PN532 probably timed out waiting for a card
    Serial.println("Timed out waiting for a card");
  }
  if (uid[] = {0xF0, 0x21, 0x5D, 0xA7}){
    Serial.println("Success");
    }
}


texts:
I have the following code (I realise String isn't very efficient, but this sketch doesn't have to be)
debugOutput gets called every loop, but I only want to spam the serial bus (to debug) if the status changes.
However, it runs once, despite changes to the pins being made.
String prevState = "";
void debugOutput() {
  String s = "";
  //s = s + digitalRead(6) ? "1" : "0";
  //s = s + digitalRead(5) ? "1" : "0";
  s = s + digitalRead(4) ? "1" : "0";
  s = s + digitalRead(3) ? "1" : "0";
  s = s + digitalRead(2) ? "1" : "0";
  if(!prevState.equals(s)) {
    Serial.println("State Change: "+s);
    //strcpy(s, prevState);
    prevState = s;
  }
}

My suspicion is it was because of the pointers being the same, but I declare a new string every time this function runs. Just in case, I tried to swap this to strcpy, which isn't valid since I'm using String instead of character arrays.
What can I do, I'm really confused.
This is the Serial output, btw
State Change: 1 So it's clear to me that my string appending isn't even working as expected.


texts: Using the Arduino compiler, is it possible to use Atmega2560 interrupt pins that are unused by Mega?

texts:
Looking into the schematics for the Arduino Mega I noticed that pins PE6 and PE7 are interrupt-enabled (INT6 and INT7 respectively); however, they remain unconnected to any Arduino I/O pin.

I'm designing a custom board based on the Atmega2560 and want to use the Arduino IDE/Compiler to upload my code to it, so I'm pretty much replicating a big part of the Arduino Mega schematic into my board.

However, I would really like to enable these two extra interrupt pins (having 8 interrupt pins in total) in my board, but I'm now sure how to proceed from the software side. How could I enable this new pins in order to use them from the Arduino compiler?

Thanks!


texts: What is the simplest way to "ask" the arduino which input pins are HIGH?

texts:
I am trying to build a 36-line cable tester, using the Digistump DigiX (99 i/o pins). Digital pins 0-35 are outputs, connected via the cable in question, to (in a perfect world) digital input pins 36-72. The plan is to have 36 neopixels (to conserve DigiX pins), one corresponding to each line in the cable. Currently they light up green for connection and red for no connection.

It's easy to check if output 0 goes to input 36, but there are more potential problems in a cable than no connection...

What if there is a short and output 0 goes to 36 and 42? It will still show up as correct when it tests 0 to 36... I somehow need to "ask" it what, if any, inputs (pins 36-72) are HIGH when only output 0 is HIGH.

I'm not sure how I'm going to display this extra data yet (Lcd maybe? Or maybe any pins shorted together all use a unique led color...), but I want to make sure the idea will work before I move on to that. Here is what I have working so far, just using a 3-line cable for now. And yes, I'm new to this. Any advice would be greatly appreciated!

#include <FastLED.h>
#define NUM_LEDS 3
#define LED_PIN 6
CRGB leds[NUM_LEDS];
#define brightness 25
int var = 0;

void setup() {
  for (int sendPins=0; sendPins <= 2; sendPins++) {
    pinMode(sendPins, OUTPUT); }

  for (int recPins=3; recPins <= 5; recPins++) {
    pinMode(recPins, INPUT); }

    FastLED.addLeds<NEOPIXEL, LED_PIN>(leds, NUM_LEDS);
    FastLED.clear();
}

void loop() {
  while (var < 3) {    //so it only runs once for each line in the cable.
    var++;
  for (int sendPins=0; sendPins < 3; sendPins++) {
    digitalWrite(sendPins, HIGH);

    int recPins = map(sendPins, 0, 2, 3, 5);  //made more sense to me than another for loop.

     int recPin = digitalRead(recPins);
     if (recPin == HIGH)
     {
      leds[sendPins].g = brightness;
      leds[sendPins].r = 0;
      FastLED.show();
     }
     else
     {
      leds[sendPins].r = brightness;
      leds[sendPins].g = 0;
      FastLED.show();
     }

      digitalWrite(sendPins, LOW);
      delay(250);      //just for testing so i know it's going through them all.
  }
 }
}


texts: How to setup Arduino Wifi Shield with Red Bear Lab BLE Shield?

texts:
I'm new to Arduino shields.

I'm trying to stack these two shields on an arduino uno for a home automation project.

1 - Arduino Wifi Shield:

2 - Red Bear Lab BLE shield: http://redbearlab.com/bleshield/

I have pin contention, between the two shields:
The WiFi shield uses pins: 4, 7, 10, 11, 12, 13.
The BLE shield uses pins: 10, 11, 12, 13.

Is there a hardware or software way to allow the two shields to work together?

I saw in a similar thread, someone reccomended a go-between shield: https://www.sparkfun.com/products/11002, would this be something that I could use in this case?

If it's not possible, are there other shields that will work together?

Thanks


texts: Error to make a request using Arduino Uno and ESP8266

texts:
I'm using Arduino Uno and ESP8266 in a project.

I'm using AT Commands to connect to wi-fi and make a request. I'm using the monitor serial to test the code before compile it in arduino.

It is connecting to wi-fi and I can make a request to a server in my network but when i try to make a request to my web-service in cloud it doesn't work well.

The return is an HTML with an 404 page instead of what I am expecting:

Hello Versa

Here is my code:

AT+CIPSTART="TCP","ternary.com.br",80
AT+CIPSEND=18
GET /webservice/

Can someone help me telling me what I am doing wrong?

After see the answer of Maximilian Gerhardt, I solved it writing the following sequence in the monitor serialize:

AT+CIPSTART="TCP","ternary.com.br",80
AT+CIPSEND=70
GET /webservice/ HTTP/1.1
Host: ternary.com.br
Connection: Close
[Just press enter and send a new line]


texts:
I am attempting to develop an Arduino project that can identify the bit format of a card (26-bit being the most common but not the only one).

This a library sets the serial to be 9600 baud.
https://github.com/paulo-raca/YetAnotherArduinoWiegandLibrary

This documentation says the data bit width is about 100us and the "inter pulse" or the time between the data bit is 20-100us.
https://docs.tibbo.com/taiko/ser_wiegand_mode

I don't understand how these match up? Also, Wiegand isn't even really serial. It uses two inputs - One input is for the on bits and another input is for the off bits.


texts: Using an Ethernet Shield and a tlc5940 together

texts: I have am using an Arduino Uno R2 and TLC5940 to control a bunch of RGB LEDs. I want to add an Ethernet Shield R3 so that I can control the LEDs over a web-interface. However, the ethernet shield and TLC5940 use many of the same pins. Can I use them together? How?


texts: How do I scale a 0 to 5 V signal to -5 V to +5 V?

texts: In my project, I just want to run a servo motor using an S-curve motion profile. For that, I need a positive and negative power supply that can run on Arduino code. Is there any method to convert the scale of 0 to 5 V signal to -5 V to +5 V?


texts: I have been able to establish a successful connection between an RN-42 Bluetooth module and Arduino Uno, but I could not do the same with an Arduino Due. The module connects to the phone but whatever data I send is not registered. What is different on the Due in the context of Bluetooth connectivity? Baud-rate perhaps?


texts: Can Arduino libraries be compiled for ARM MCU's?

texts:
I am looking for a very low power Micro-controller to interface with the RockBlock Iridium modem. The MCU I am thinking of purchasing is the Gecko Zero by Silicon Labs.

I want to know if it is possible to compile the Rockblock-IridiumSBD Arduino library for the Gecko Zero. The Gecko Zero is a 32 bit ARM MCU.

IridiumSBD Library

Gecko Zero MCU


texts: Can Arduino uno adjust input square wave duty, phase and frequency with just timer-counter?

texts:
Requirement:

I have input 4KHz pulse input
Divide it's frequency in half
Arbitrarily adjust phase
Arbitrarily adjust duty
Out put the modified pulse

My solution (CPU):
uint8_t cnt = 0;
uint16_t t1 = 235;
uint16_t t2 = 5;
String cmd;

void setup() {
  pinMode(3, OUTPUT);
  pinMode(2, INPUT);

  Serial.begin(9600);
  delay(500);
  attachInterrupt(digitalPinToInterrupt(2), rising_edge, RISING);
  Serial.println("PWM init");
}

void loop() {
  if (Serial.available() > 0) {
    cmd = Serial.readString();

    if (cmd.substring(0,8) == "setdelay"){
      t1 = cmd.substring(9).toInt();
      Serial.print("setting delay to ");
      Serial.print(t1);
      Serial.println(" us");
    }
    else if (cmd.substring(0,7) == "sethigh"){
      t2 = cmd.substring(8).toInt();
      Serial.print("setting high time to ");
      Serial.print(t2);
      Serial.println(" us");
    }
  Serial.flush();
  }
}
void rising_edge() {
  cnt = cnt + 1;
  if (cnt >= 2) {                           //divide by 2
    delayMicroseconds(t1);
    digitalWrite(3,HIGH);
    delayMicroseconds(t2);
    digitalWrite(3,LOW);
    cnt = 0;
  }
}

However this makes heavy use of CPU, and I need to use CPU for something else.Is it possible to implement all this with TC ?
Thanks in Advance !


texts: I need to Get my changed SSID and Password in my Serial monitor

texts:
I have this(Wifi Manager - Autoconnect IP) program run in my arduino IDE. And I get the output in serial monitor as this

Can Anyone help me in displaying my SSID and PASS in this serial monitor output?

My code is this

#include <ESP8266WiFi.h>          //https://github.com/esp8266/Arduino

//needed for library
#include <DNSServer.h>
#include <ESP8266WebServer.h>
#include <WiFiManager.h>         //https://github.com/tzapu/WiFiManager

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

    //WiFiManager
    //Local intialization. Once its business is done, there is no need to keep it around
    WiFiManager wifiManager;
    //reset saved settings
    //wifiManager.resetSettings();

    //set custom ip for portal
    //wifiManager.setAPStaticIPConfig(IPAddress(10,0,1,1), IPAddress(10,0,1,1), IPAddress(255,255,255,0));

    //fetches ssid and pass from eeprom and tries to connect
    //if it does not connect it starts an access point with the specified name
    //here  "AutoConnectAP"
    //and goes into a blocking loop awaiting configuration
    wifiManager.autoConnect("AutoConnectAP");
    //or use this for auto generated name ESP + ChipID
    //wifiManager.autoConnect();

    //if you get here you have connected to the WiFi
    Serial.println("connected...yeey :)");
}

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

}

I am using WIFImanager library example - Autoconnect


texts:
I'm trying to run a SPS-15RF stepper motor from an old cd rom drive. I'm using a CNC shield and a4988 driver with a 6v power supply. The motion is smooth and fine. I know it has 18 pulse/revolution and works with 5v but It gets quite unexpectedly hot. It feels that it can burn my fingers if I keep it running.
What is wrong with it? is it related to micro-stepping or sth else!?


texts:
I don't know what is wrong in my code.
The S1 are the button numbers that I will record when the stepper motor is going to for example number 1 button.
MY CODE
// steppmm*moveX=240

#include <Stepper.h>

int BUTTON_PIN[7] = {26, 27, 22, 23, 24, 25, 10};

int lastState = LOW;

int currentState;

float Stepmm = 250 ;

float A = 0;

float B = 0;

int S1[0];

const int stepsPerRevolution = 200 ;

int switchPos[9] = {0, 3, 6, 9, 12, 15, 18, 21, 24};

Stepper myStepper(stepsPerRevolution, 11, 9, 7, 5);

int stepCount = 0;

void setup() {

  Serial.begin(9600);

  myStepper.setSpeed(180);

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

    pinMode(BUTTON_PIN[i], INPUT_PULLUP);

  }

  moveX(2);

  while (digitalRead(BUTTON_PIN[6]) == 1) {

    moveX(-1);

    Serial.println("a");

  }
  moveX(1.5);

  while (digitalRead(BUTTON_PIN[6]) == 1) {

    moveX(-0.05);

    Serial.println(digitalRead(BUTTON_PIN[0]));

  }

}

void loop() {

  Serial.println(sizeof(S1) / 4);

  while (sizeof(S1) / 4 > 0) {

    while (A != switchPos[S1[0]]) {

      moveX((A - switchPos[S1[0]]) / abs(A - switchPos[S1[0]])*3[enter link description here][1]);

      A = A + (A - switchPos[S1[0]]) / abs(A - switchPos[S1[0]]);

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

        if (S1 = 0) {

          S1.push(i);

        }

      }

    }

    S1.pop(0);

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

      Serial.print(digitalRead(BUTTON_PIN[i]));

      if (digitalRead(BUTTON_PIN[i]) == 0) {

        point(switchPos[i]);

        delay(1000);

      }

    }

  }

}
void moveX(float X) {

  myStepper.step(X * Stepmm);

}
void point(float X) {

  moveX(X - A);

  A = X;

  Serial.println(A);

}

IT SAYS
Stepper_Motor_1.3:44:18: error: incompatible types in assignment of 'int'
to 'int [0]'

         if (S1 = 0) {
                  ^

Stepper_Motor_1.3:45:14: error: request for member 'back' in 'S1', which is of non-class type 'int [0]'

           S1.back(i);
              ^~~~

Stepper_Motor_1.3:50:8: error: request for member 'pop' in 'S1', which is of non-class type 'int [0]'

     S1.pop(0);
        ^~~

exit status 1

incompatible types in assignment of 'int' to 'int [0]'

i want to make it like this
[1]: https://www.youtube.com/watch?v=sC8sxy9vP_w


texts: Send AT commands programatically to ESP8266 without Arduino

texts:
Let me explain my question in more details. I want to use ESP8266-01 as standalone micro-controller for my project. I don't want to use Arduino or any other board with that.
Using Arduino i can use two of the pins as software serial and can send different AT commands to ESP module to ESP's Tx and Rx pins, but now what I want is to eliminate the need to Arduino.

What I want to do is to to program ESP itself to toggle mode from AP mode to Host mode on press of a push button. for that I has to send AT commands to ESP from the code while i will write to the ESP itself. Is there any way to achieve the same.

I tried searching a lot but what I found everywhere is how to send AT commands from Arduino.

Thanks in advance.


texts: I am not very experienced in this, but I was wondering if Code::Blocks has a way of getting a debugger that runs for Arduino chips, specifically. I understand there is Arduino IDE for but does it allow debugging specific to those microcontrollers (Amtel and such)?


texts:
I am developing a project for my college.

PROJECT OUTLINE:
There are 3 sensors (Temp., Accelerometer & Humidity) will read the respective parameters continuously. in between if I press 'PushButton1' for 2 seconds  the Arduino must enter into programming mode.

The programming mode has 6 Switch cases. Each case gets selected one after one on the even of 'PushButton1' gets pressed for short time.

Also if I press 'PushButton1' again for 2 seconds in Programming mode the Arduino should come out of the programming mode.

PROBLEM:
In my current sketch I have to press 'PushButton1' for 2 seconds in Programming Mode for 2 seconds to change the case. Also I don't understand how to get out of the Switch Case loop.

The sketch is attached with this topic.

const int btn = 2;
const int ledPin =  13;
int selector = 0;
boolean  volatile wait = false;
const unsigned long event=2000;
unsigned long a=0;
unsigned long b=0;
unsigned long c=0;
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(btn, INPUT);
attachInterrupt(digitalPinToInterrupt(btn),decoder,CHANGE);
}

void loop()
{
  while(wait) {  }
  if (digitalRead(btn) == LOW) {
    a = millis();
  }
  else
  {
    b = millis();
    c=b-a;
    Serial.println(c);
        if (c>=event)
            {
              doSwitchStatement();
              selector++;
              if (selector >6)
                  {
                  selector = 0;
                  delay(500);
                  }
            }
  }
  wait = true;
  interrupts();

}

void decoder()
{
  noInterrupts();
  wait = false;
}

void doSwitchStatement()
{
  switch(selector)
  {
  case 0:
    Serial.println("Case 0");
    break;

  case 1:
    Serial.println("Case 1");
    break;

  case 2:
   Serial.println("Case 2");
    break;

  case 3:
   Serial.println("Case 3");
     break;

  case 4:
   Serial.println("Case 4");
    break;

  case 5:
  Serial.println("Case 5");
    break;

  case 6:
  Serial.println("Case 6");
    break;

  }
}


texts: arduino --verify / --upload not working (command line)

texts:
I installed Arduino IDE version 2.1 on Ubuntu via apt-get. Then I typed the following command in terminal to see if the Arduino IDE compiles my sketch.

 arduino --verify xx.ino

However, this command launches the GUI IDE. Is the CLI not supported anymore, or is the cause in apt-get the package?


texts:
I am working towards debouncing my keyes rotary encoder using the Bounce2 library found here ( https://github.com/thomasfredericks/Bounce2 ).

I believe the problem lies in my code as there isn't much in terms of a circuit. The encoder is connected to my arduino as follows

5V : connected to 5v out on arduino
GND : connected to GND
SW : connected to pin A1
DT : connected to pin 3
CLK : connected to pin 2

I am trying to call an ISR from a CLK input. When the ISR is called it should increment or decrement a value based on the direction the encoder was turned. This encoder is tied to an ISR because it will be used for user input and I would like it to remain responsive throughout the sketch.

Previously, I was using millis() to debounce the encoder, but I was still having trouble receiving more than one input from the encoder. I was hoping that this libary would resolve this issue.

The current output of the code I have included never increments/decrements the starting value no matter which direction the encoder is turned. In short, it always outputs 0.

If someone could explain what I am doing wrong that would be wonderful! Then maybe, but just maybe, I can stop beating my head against my desk. :p

Thanks,
Kevin

#include <Bounce2.h>

#define sw A1
#define LED_PIN 9
#define clk 2
#define dt 3

int ledState = LOW;
int onOff = LOW;

volatile int virtualPosition = 0;
int lastCount = 0;

// Initiate bounce objects
Bounce debouncerSW = Bounce();
Bounce debouncerROT = Bounce();

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

  pinMode(sw, INPUT_PULLUP);
  pinMode(clk, INPUT);
  pinMode(dt, INPUT);
  pinMode(LED_PIN, OUTPUT);

  // set up button instace
  debouncerSW.attach(sw);
  debouncerSW.interval(100);

  // set up rotary encoder instance
  debouncerROT.attach(clk);
  debouncerROT.interval(10);

  // setup the LED
  digitalWrite(LED_PIN, ledState);

  // attach ISR
  attachInterrupt(digitalPinToInterrupt(clk), isr, LOW);

  Serial.println("Start"); // just to let me know sketch has finished setup
}

void loop() {

  debouncerSW.update();

  if ( debouncerSW.fell() ) {
    ledState = !ledState;
    onOff = !onOff;
    digitalWrite(LED_PIN, ledState);

    //read-outs
    Serial.print("onOff = ");
    Serial.println(onOff);
  }
  virtualPosition = lastCount;

  //read-outs
  Serial.print ("lastCount = ");
  Serial.println (lastCount);

  delay(1000); // for readability / simulates delay time for rest of main sketch
} // end main loop

void isr ()  {

  // Update the Bounce instance :
  debouncerROT.update();

  if (debouncerROT.fell()) {
    if (digitalRead(dt) == LOW)
    {
      virtualPosition -- ; // Could be -5 or -10
    }
    else {
      virtualPosition ++ ; // Could be +5 or +10
    }

    // Restrict value from 0 to 100
    virtualPosition = min(100, max(0, virtualPosition));
  }
} // end ISR


texts: Solar Tracker Code - how to limit steppers to max & min angle?

texts:
a couple of friends and i are working on a double axis solar tracker with a Adafruit Motor-shield V2 and 2x Adafruit bipolar stepper motors (200/rev).
We got the following code so far but are stuck with getting the steppers to stop at a certain angle (90° for vertical and 180° for horizontal) so that we dont tangle up the wires and avoid unnecessary movement. Any help and sugestions would be much appreciated.

Cheers

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

Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_StepperMotor *stepperh = AFMS.getStepper(200, 1);  // declaring horizontal stepper
Adafruit_StepperMotor *stepperv = AFMS.getStepper(200, 2);  // declaring vertical stepper

int ldr1 = A0;  // right ldr
int ldr2 = A1;  // centre ldr
int ldr3 = A2;  // left ldr
int ldr4 = A3;  // top ldr
int ldr5 = A4;  // bottom ldr

const int threshold = 550;  // limit to stop tracker from moving at night

const int tol = 50;  // tolerance for ldrs // maybe vertical AND horizontal depending on difference?

//int = countv
//int = counth

//const int maxh = ?    // to prevent overturning horizontal (50 steps = 90°)
//const int minh = ?    // combine with count int's // i.e. if counth > 90 - stop
//const int maxv = ?    // to prevent overturning vertical
//const int minv = ?

void setup()
{
  AFMS.begin();
  stepperv->setSpeed(10);
  stepperh->setSpeed(10);
}

void loop()
{
  int right = analogRead(ldr1);
  int centre = analogRead(ldr2);
  int left = analogRead(ldr3);
  int up = analogRead(ldr4);
  int down = analogRead(ldr5);

  //STOP MOVEMENT//
  if ((left < threshold) && (right < threshold) && (up < threshold) && (down < threshold)) {}  // stop any movement if sensor values below threshold
                                                                                // at begining to check after every sensor reading

  //HORIZONTAL MOVEMENT//
  if((right > centre + tol) && (left + tol < centre))   // && (right - ? > tol)
  {
    stepperh->onestep(BACKWARD,DOUBLE);  // add +1 to int counth // if (minh < counth < maxh) - move // else - stop // counth=counth++ , counth=counth--
  }
  else if((left > centre + tol) && (right + tol < centre))  // && (left - ? > tol)
  {
    stepperh->onestep(FORWARD,DOUBLE);
  }
  else {}  // do nothing

  //VERTICAL MOVEMENT//
  if((up > centre + tol) && (down + tol < centre))  // && (up - ? > tol)
  {
    stepperv->onestep(BACKWARD,DOUBLE);
  }
  else if((down + tol > centre) && (up + tol < centre))  // && (down - ? > tol)
  {
    stepperv->onestep(FORWARD,DOUBLE);
  }
  else{}  // do nothing
}


texts: Interfacing ArduCam with NRF24L01 to Arduino Uno

texts:
I am currently finalizing a purchasing order to get several of the ArduCam CMOS OV7670 cameras. I am purchasing them because they have the capability to return an array of the RGB565/555/444 which would make it easier to send over a RF transmitter. The camera would have to be plugged into some of the same ports as the NRF24L01.

My question is that can I wire the NRF24L01 and the ArduCam into the same SPI and MOSI pins without running into any problems?


texts:
I've tried many codes for this to work but anything isn't helping at all, so my code should work like this: If a sound sensor (3 pins, A2) sends 5 signals into the Arduino within 10 seconds (the time gap of every signal varies, but doesn't matter as long as it sends 5 signals), the LED (13) will light up. This is my recent code if it could help

int led=13;
int sensor=A2;

void setup()
{
   pinMode(led, OUTPUT);
    pinMode(sensor, INPUT);
    Serial.begin(9600);
}

void loop()
{
    unsigned long StartMillis = millis();
    unsigned long CurrentMillis = millis();
    int signal_count=digitalRead(sensor);
    int signal_limit=5;
    Serial.println(signal_count);

    while ((CurrentMillis - StartMillis)==5000)
    if (digitalRead(sensor)=0)
    {     signal_count ++;
        Serial.println(signal_count);
    }
    if (signal_count>signal_limit) {
        digitalWrite(led, HIGH);
    }
    else {
    digitalWrite(led,LOW);
    }
}


texts: While condition with & bitwise of PINx read

texts:
I was looking into ATmega32u4 datasheet to configure the SPI, and there is initialization snippet for data transmission.

void SPI_MasterTransmit(char cData)
{
/* Start transmission */
SPDR = cData;
/* Wait for transmission complete */
while(!(SPSR & (1<<SPIF)));
}

What I didn't quite get is the last line of the snippet with the while condition to check the state of the SPIF bit in SPSR register.

What I think I understand that it means, if SPIF bit with the a conditional value of 1 which would be in the ALU for comparing it with the actual bit state in SPSR. If this is true with & bitwise operator which would be true if the actual bit in the SPSR is set with the given value (1 << SPIF).

My questions:

Am I understanding it right?
What this line actually means?
I have removed the semicolon at the end of the line and it compiled OK! Is what I did OK?


texts: Arduino Doesn't Work With Just Battery and Vin Pin

texts:
I'm currently working on a drone project, and I have a bit of a problem. I am using a motor driver for my propellers, but the motor only runs continuously when connected to the computer. I have the battery connected via the vin and ground pins, but when I disconnect the computer the motor only moves a little bit and then turns off, then turns back on again within three seconds. So instead of running continuously, it turns on and off very quickly and repeatedly. Thank you for any help, Here's my code if it will help.
int IN1 = 2;
int ENA = 3;

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

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(IN1, HIGH);
  analogWrite(ENA, 255);
}


texts: client.connect() fails except the first time

texts:
I am communicating with the Web server's database via Arduino GSM shield + GPRS connectivity

void loop()
{
  if (client.connect(server, port))
     {
       .......
      }
  else
     {
      Serial.println("Server not found");
      }
  delay(1000);
}

The first time when the loop() runs in the serial port, the code works perfectly and stores in my server's db. The second time when the loop() runs after some delay, It is unable to connect to the server and results "server not found" . I don't know what is the problem.

Please let me know if there is a way to connect continuously. Thank you


texts:
As per the Arduino 101 schematic.

The Arduino 101 has level shifters (TI make LSF0108) connected to the I/O ports I guess these are to make them Arduino compatible(5V) since the Intel Curie Module is 3.3V rated.

I have 2 doubts regarding this

The level shifters are also connected to the analog pins so I was wondering how do these shifters pass through analog signals?
I have some 3.3V sensors that I want to interface to the Arduino 101 via I2C. My question is can I use 3.3V levels at the I/O ports or am I restricted to 5V?

TIA


texts: How to start serial monitor on Windows startup

texts: How can I get Windows to start the Serial Monitor window after a restart? Is there something I have to copy into the Windows startup folder for my account? Thanks


texts:
For one of my projects, I would like to transfer a camera image with the best possible resolution and as many FPS as possible with the ESP32Cam.
For this I successfully used the code from
https://RandomNerdTutorials.com/esp32-cam-video-streaming-web-server-camera-home-assistant/
A grayscale image would be enough for further processing, if it allows a higher speed.
Problem is, if I set the format to PIXFORMAT_GRAYSCALE, the ESP only outputs "Camera capture failed".
Are there any other settings to do?


texts:
I successful installed arduino, added me to uucp and lock and loaded cdc_acm module.

I use Arduino Uno R3, so I also installed arduino-avr-core.

I have Arduino on /dev/ttyUSB0.

I configured with:

stty -F /dev/ttyUSB0 cs8 9600 ignbrk -brkint -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

I have this folder with these files:
~/Documents/Arduino

build.options.json
------------------------------------------------------------
{
    "fqbn": "archlinux-arduino:avr:uno",
    "hardwareFolders": "/usr/share/arduino/hardware",
    "toolsFolders": "/usr/bin"
}

sketch.ino
------------------------------------------------------------
void setup() {
    pinMode(13, OUTPUT);
}

void loop() {
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
    delay(1000);
}

After this commands I got output:

arduino-builder -build-options-file build.options.json sketch.ino

Sketch uses 914 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

But nothing happened on my Arduino, what's my problem?

Thanks.

P.S. I don't have external LED, I try to use bultin LED.


texts:
I am working on a project which uses two 18650 3400ma batteries to power some sensors, an Arduino Mini Pro, an 433mhz RF transmitter and an ESP8266-01. Most of the time the Arduino is in sleep mode and I only wake it up to check sensors, send info to Wi-Fi, and if needed switch on RF transmitter.
On the original prototype I turn on the Arduino ever two hours. I then turn on a capacitive proximity sensor and I check the battery level once. I next turn on a potentiometer and temperature sensor for eight seconds while reading them then turn them off.
I then read the proximity sensor. Then I turn on the ESP8266-01 for eight seconds while I post all reading on line. Then off with the ESP.
Depending on the readings from the proximity sensor I turn on the RF transmitter for about one second and then turn off the proximity sensor and put the Arduino back to sleep.
I have made a second prototype in which the coding is the same except I check the battery 50 times in quick succession for a truer average reading. I check the potentiometer ten times for a better average reading and I only wake the Arduino up every six hours instead of two.
The schematic (I'm posting) is basically the same except I have added four small capacitors to smooth out the current. I will circle them in red. Wiring on the first prototype is with .5mm copper wire while on the second prototype the traces on the pcb are .25mm 1 oz copper and some of them have been redone with 28 gauge copper wire.
My problem is that the original prototype will last for seven days before needing to be recharged while the second prototype only makes it four days. Could the capacitors be making a difference, or the sampling of the battery and potentiometer, or is it the wiring size. Is there too much resistance?
If the wiring is the problem what is a good size to have my pcb traces be? Is 2.5mm at 1oz or 2oz enough?
I know there are things I can rewrite in my code to cut times when things are on and cut energy use but I want to know why such a difference in the two prototypes.
Does anyone have any suggestions or questions?


texts: Curve fitting Gnuplot session for mapping voltage on a sensor and outputting a value in liters

texts:
I have another post regarding mapping voltage on a sensor and outputting a value in liters.
Code for mapping voltage on a sensor and outputting a value in liters
There is a great answer by user timemage that suggests using Curve fitting and He or she demonstrates a Gnuplot session based on the values I found by mapping the output voltage on the sensor as i added amounts of liquid to the tank. It worked great!  However it was all over my head and i ended up paying a Uni Student to code it for me :-s
Now I would like to implement the same code for a different tank.  The previous one was a cube, this one is more of a rounded wedge (it is in a boat).
Here is the Code for the previous tank:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
double SensorAnalogValue;
uint8_t calculation=1;
String Show_value;
void setup()
{
  lcd.init();                      // initialize the lcd
  lcd.init();
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(0, 0);
  lcd.print("Liquid Volume:");
  lcd.setCursor(0, 1);
  lcd.print("Initializing...");
  delay(2000);
  Serial.begin(9600);
}

void loop()
{
  SensorAnalogValue = analogRead(A1) * 5.0 / 1023.0;
  if (SensorAnalogValue < 1.726) {
    calculation=0;
    Show_value="Low";
  }
  if (SensorAnalogValue > 4.04) {
    calculation=0;
    Show_value="High";
  }
  if(calculation!=0){
  //  Serial.println(SensorAnalogValue);
    Show_value=(String)Liquid_Volume(SensorAnalogValue);
  }
  Serial.println(SensorAnalogValue);
  lcd.setCursor(0, 1);
  lcd.print("                ");
  //Serial.println(Show_value);
  lcd.setCursor(0, 1);
  lcd.print(Show_value);
  delay(500);
  calculation=1;
}
int Liquid_Volume(double Volt) {
  double A =   2.81842;
  double B = -11.00151 ;
  double C =  14.4765 ;
  double D =  28.73579 ;

  return A * Volt * Volt * Volt + B * Volt * Volt + C * Volt + D;
}

My new tank yields:

V
L

0
0

1.389
30

1.618
45

1.814
70

1.981
100

2.107
120

2.218
155

2.319
180

2.409
210

2.554
240

2.678
265

2.783
310

I do not understand what part of the code refers to the above information, and therefore I can't manage to change the code to suit my new tank.  The current code works perfectly on the old tank so I assume it could be made to work on any tank by altering the values.  I also assume that the below is what needs changing, but I have no clue how to do that.
int Liquid_Volume(double Volt) {
      double A =   2.81842;
      double B = -11.00151 ;
      double C =  14.4765 ;
      double D =  28.73579 ;


texts: How can an Arduino do multiple actions in parallel without interfering with each other?

texts:
I am working with my son (9) and we are having a great time learning. But, we've run into a problem and could use your help.

We have two separate loops that we want to run without interfering with the other. Currently we have two LEDs that are blinking in a sequence that has delays built in to keep them on/off.

We also have a Photocell circuit that turns another LED on/off depending on the light.

The problem is, the photocell circuit is lagging 1/2 second due to the light sequence from the other loop.

How do we fix this?

// this is declans photo cell and led program

const int photoCell    =  0;  // photo cell variable
const int ledLightButt = 11;  // Led light variable assignment

int lightCal;                 // idk what dis iz
int lightVal;                 // this is the reading from photo cell I think

void setup() {
    pinMode(13, OUTPUT);
    pinMode(12, OUTPUT);

    pinMode(ledLightButt, OUTPUT);
    lightCal = analogRead(photoCell);
}

void loop() {

    lightVal = analogRead(photoCell);

    if (lightVal < lightCal - 50) {
        digitalWrite(ledLightButt, HIGH);
    }
    else {
        digitalWrite(ledLightButt, LOW);
    }

    digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
    delay(250);

    digitalWrite(13, LOW);
    digitalWrite(12, HIGH);
    delay(250);

}


texts:
I was reading about external interrupts using the ATmega328p, and I saw in the chip datasheet under the paragraph "Bits 3:2 – ISC1n: Interrupt Sense Control 1 [n = 1:0]" the following table:

Value | Description
------+------------------------------------------------------------
00    | The low level of INT1 generates an interrupt request.
01    | Any logical change on INT1 generates an interrupt request.
10    | The falling edge of INT1 generates an interrupt request.
11    | The rising edge of INT1 generates an interrupt request.

From what I understand from the table title and the definition in the datasheet that ISC1n where n=1|0, is dedicated for INT1. And that ISC0n where n=1|0, is dedicated for INT0. However, in the table above, the value 00 is described as "The low level of INT1 generates an interrupt request.".

What I don't understand is how can ISC0n where n=1|0 be dedicated for INT0 but in the table above the value 00 (or ISC00) is used for INT1 ? I could totally be missing something but I would appreciate any guide.


texts: Code for Heart Rate Detection using PPG Sensor

texts:
I am using the "MIKROE Heart Rate 3 click" PPG sensor (https://www.mikroe.com/heart-rate-3-click) and an Arduino Nano (https://store.arduino.cc/usa/arduino-nano) to find heart rate estimation. Does someone know what code to use?
The library associated to the MIKROE is unavailable, therefore, I tried using the AFE4404 library through the code shown below and running a separate algorithm for finding heart rate, however, once I ran it, the monitor and plotter do not provide any peaks that must be used to run the algorithms.
PPG TEST CODE (used previously but do not know how to find heart rate)
/*
 * AFE4404 Basic Read library example.
 * https://github.com/rakshithbk/AFE4404-Library
 *
 * On Arduino Uno -  | AFE4404 | Uno Pin
 *                   | I2C_Dat | A4
 *                   | I2C_Clk | A5
 * get_led_val() will return uint32_t values.
 *
 * Advanced - you can modify the sample period and other
 * parameters in the library files (refer AFE4404 datasheet)
 */

#include <Wire.h>
#include <AFE_connect.h>

AFE A;

void setup() {
  Serial.begin(115200);
  Serial.println("AFE4404 basic readings -\n");
  A.init();
}

void loop() {
  Serial.print("LED 1 Val = ");
  Serial.print(A.get_led1_val());
  Serial.print("\t LED 2 Val = ");
  Serial.print(A.get_led2_val());
  Serial.print("\t LED 3 Val = ");
  Serial.print(A.get_led3_val());
  Serial.println();
}

GitHub
rakshithbk/AFE4404-Library
Basic Library of AFE4404 for Arduino Uno. Contribute to rakshithbk/AFE4404-Library development by creating an account on GitHub.


texts: Stacking Arduino Shield (Motor Shield, LCD Keypad, LED Sensor)

texts:
I'm building a line follower with arduino, here some part that I'm going to use

Arduino Uno
Motor Shield 2A http://www.dfrobot.com/index.php?route=product/product&product_id=69
LCD Keypad
4 Channel Line Tracking Sensor http://www.aliexpress.com/item/4Channel-Infraed-Line-Tracking-Sensor-Module-w-Connector-Line/2021343637.html

I'm using LiPo Batteries 3 Cell 11.1v for power source.

I'm new in here so I didn't know how to stack that shield, if I recall I can stack up Arduino and the LCD Keypad, and Arduino and the Motor Shield, but didnt know how to stack those 2 together and adding another sensor like that line tracking sensor. May I know how to resolve that? thanks.


texts: How to connect MPU9250 with NodeMCU using SPI or I2C Slave?

texts:
I want to connect 3 MPU9250 sensors, but since there is just one I2C bus, so there are another 2 sensors I want to connect through SPI.

Library used - https://github.com/bolderflight/MPU9250/blob/master/examples/Basic_SPI/Basic_SPI.ino

There is an SPI example code written, but I don't know about the connections. There are no MISO and other pins on the sensor which i use but its SPI compatible. How do I connect 2 MPU9250 to NodeMCU with SPI?

If SPI connection is not possible then please post about I2C slave connection.


texts:
Is communication using tx/rx from an arduino to mkr1010 the same as any other serial communication?

I ask because I can't find any tutorials or info on connecting an arduino to mkr1010, but there are plenty on connecting one arduino to another.


texts:
I am writing an SIM900A + arduino(Arduino UNO with Atmega 328P) code to just send the current time stamp every 20 minutes.
The code keeps crashing in the SendMessage() function as the setup prints keep coming again and again. Please let me know what I am doing wrong. Thanks in advance
#include <SoftwareSerial.h>
#include <LowPower.h>
SoftwareSerial mySerial(9, 10);
char msg;
char call;
int ctr;

#define TIME_STR_LEN 100  // the actual number of characters for date and time

char timeStamp[TIME_STR_LEN]; // holds the time string

void setup()
{
  mySerial.begin(9600);   // Setting the baud rate of GSM Module
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println("GSM SIM900A BEGIN");
  mySerial.println( "AT+CLTS=1");
  delay(1000);
  ctr = 0;
  delay(10000);
}

void loop()
{

  if(mySerial.available()>0)
  {
    while (mySerial.available()>0)
    {
      mySerial.read();
    }
  }

  if (ctr%1 == 0)
  {
    delay(1000);
    SendMessage();
    delay(100);
    ctr = 0;
    Serial.println("just sent a message");
  }
  delay(60000);
  ctr++;
  //LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
}

void SendMessage()
{
 mySerial.println( "AT+CCLK?" );
 delay(2000);

 int i = 0;

 if (mySerial.available()>0)
 {
      while (mySerial.available()>0 && i < TIME_STR_LEN)
      {
        timeStamp[i]=(mySerial.read());
        i++;
      }
  }
  delay(2000);

  mySerial.println("AT+CMGF=1");
  delay(1000);
  mySerial.println("AT+CMGS=\"xxxxxxxxxx\"\r");
  delay(1000);
  mySerial.println("Motor is ON ");
  delay(100);
  mySerial.println(timeStamp);
  mySerial.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
}


texts: I have seen many tutorials on programming an Arduino to control a HC-05 bluetooth module. In that I did not understand the term called 'flag'. What does that mean?


texts: Is DS18B20 temperature sensor makes Arduino processing slow?

texts:
I recently run into a problem that causing my whole code processing slow down, for example i had a millis timer set for one minute but it took 1:30m to finish, pressing buttons was laggy etc.

After hours of digging and commenting out codes piece by piece i finally found out what is causing the slow down!

my DS18B20 temperature sensor DATA pin is connected to pin A0 when i remove the library and related codes to the sensor processing became MUCH faster more snappier/responsive...

After googling a bit i realized that everyone connected the sensor to pin 2 of Arduino!

So is the processing slow because DS18B20 is on pin A0 instead of pin 2 or there's something wrong with the sensor itself or it is because of This library?


texts:
I am doing a school project and wanted to implement HMAC on a arduino UNO like board. I have been testing the Cryptosuite, but none of the examples work for me. Such as this one: https://github.com/Cathedrow/Cryptosuite/blob/master/Sha/examples/hmacsha256test/hmacsha256test.pde

This one https://github.com/simonratner/Arduino-SHA-256, a trimmed-down version, which sounds good but there's none working example.

Can any one point me to the right direction? Thanks a lot!!


texts:
I got a problem where pulse voltage from acceptor is about 20mV. How can I solve my problem? and I can't detect the pulse using arduino uno.
please any one can help ?


texts: Is there some sample code for operating a servo with an Adafruit Motor Shield?

texts: I have an Adaruit Motor Shield v2, and a Tower Pro SG92R micro servo. I've got it setup so the shield works with my Arduino Uno, and I've successfully tested using other types of motors on the shield. I could not find any sample code for working with a servomotor though. The shield has two dedicated spots for a servo (labeled "Servo 1" and "Servo 2"). I'm planning to use wall wart transformer to power the motor separately from the Arduino. Any pointers/links to documentation/sample code would be appreciated.


texts: Soil moisture sensor not working in "pcb"

texts:
I have a little and common application in which a sc-28 moisture sensor reads humidity levels and turns a servo (which drives a little faucet) if the soil needs water. Arduino nano is the brain.

All of them is tested and working fine on the proto board. Soil sensor is powered by 5v rail of arduino and everything seems fine even with the servo pulling from 5v rail too.

With all working, I try to translate that to a perfboard. The only difference in circuits are how they are powered.

While the prototype is powered via usb, the definitive one is powered through a 24v psu, leveling the voltage with a lm2596 module down to 5v.

Then this 5v feeds the nano (vin pin) and servo, while the soil sensor still pulls from 5v rail of the arduino to avoid vref problems.

And then, the sensor does not work. No led indicating power or data. This were my steps trying to debug it:

Triple check every connection on the board. While I am a decent programmer, my solder skills are kind of lacking. But everything looks fine, nothing shorted or loose.
measure voltage. On the perfboard, voltage between vcc and gnd connector pins spits 4.78v, which is supposed to be in range for the sensor to work.
Power the board through usb I tried this too, and is not working. Lm module and arduino lights up, code can be executed. I can't explain why the lm2596 module lights up too, and I'm thinking is part of the problem but I do not know. Voltage at soil sensor is still 4.78

And then I'm done. I dont know what could be happening and I only can make wild guesses. It's obviously a board problem, and i am aware I am doing something wrong but I can't see it.

Below, my horror soldering skills and the board. Soil sensor is the 4pin females at the bottom left and servo the 3pin males at the bottom right.


texts: Flexibility of SoftPot Membrane Potentiometer during the use?

texts:
Does anybody have some information or experiences with the flexibility of Spectra Symbol's SoftPot Membrane Potentiometer during the use? Is it possible to partly wind it up on a reel (or something similar) and use the remaining part dynamically without loosing precision and control? Are there "ghost touches" caused by the force/pressure of bending/winding the sensor strip? Or should the sensor always be used in a flattened position?

Thanks for any helpful comments.


texts: Using Arduino as ISP and SoftwareSerial at the same time

texts:
I'm trying to use my Arduino Uno as an ISP to program an ATTiny85 and at the same time check my board by using the SoftwareSerial library to output the values I'm getting from my sensor.

Is this actually possible? Or does it require 2 different setups? Because I found a lot of tutorials and threads about one or the other, but never both. Which I find odd because once you send your program to the chip you might want to test it as well (or debug it).

Many thanks for your help and input! :)


texts: Can the Leonardo Arduino be used as a USB HOST for CDC Com devices?

texts:
I am trying to connect a CDC communication device to the Leonardo USB port and have communication with it via the TTL com port. Basically I want to echo to the TTL port whatever is transmitted over USB and vice-versa.

ASCII data is transmitted out the USB from the CDC device into the USB port of the Leonardo Aurduino. The Arduino needs to xtransfer this info over to the UART pins D0 (RX) and D1 (TX) that are connected to the UART of another micro-controller. I should be able to test it by connecting an FTDI TTL-RS232 cable and see results and have comms in my terminal program.

I came across this sketch that appears to be basically what I want, but I think the "hosting" portion is not being set up:

void setup() {
  Serial.begin(9600);  // rx/tx pins
  Serial1.begin(9600); // USB port
  Serial1.write("2nd Version");
}

void loop() {
  // copy from virtual serial line to UART and vice-versa
  if (Serial.available()) {
    char c = (char)Serial.read();
    Serial1.write(c);
  }
  if (Serial1.available()) {
    char c = (char)Serial1.read();
    Serial.write(c);
  }
}

What am I missing? Note I am NOT trying to do HID but CDC. Basically I want to eliminate using a PC as a Host device and use the "bridge" between my CDC device and another micro-controller.


texts: Is it difficult to do high voltage parallel programming using Nick Gammon library?

texts:
I have bricked a few AT328P by invalid fuse settings.

Has anybody used the above sketches and the associated circuitry to perform high voltage programming?


texts: Using Bluetooth module HC-05 when Arduino is powered using a battery

texts:
I have a project that involves sending messages from an Android device to an Arduino using a bluetooth module. I am using an HC-05 bluetooth module and an Arduino Mega 2560.

It works as long as I power the Arduino to my laptop using a USB cable. However, I need to use an external power source and have been using a 6F22 9V battery connected through the VIN pin for this purpose, without facing any problems. But on connecting the HC-05, it does not even light up.

The Arduino is also connected to four dc motors, five servo motors (all of which are externally powered, only get digital signals from the Arduino), and seven HC-SR04 ultrasound sensors, whcih are powered through the 5V pin.

I have connected the HC-05 to the Arduino as follows:

HC-05   Arduino

VCC      3.3V

GND      GND

TX       RX

RX       TX           through a voltage divider

I am new to all this, and would be grateful for any help. Thank you.


texts: How to add hysteresis to threshold values?

texts:
This code compares the analog input value against two thresholds, having three voltage regions. Then it will turn on an LED according to what region the read voltage is in.

The problem is that when the voltage read is very close to the threshold, the noise will disturb the output, resulting in an uncontrolled switching between LEDs.

I would need to add some sort of HYSTERESIS around my thresholds to avoid the uncontrolled switching, but I have no idea how to write this into the code language. Would anyone be able to help me writing the threshold bit?

This is the full code:

// these constant won't change:
const int BatteryVoltagePin = 14;   // the pin that battery voltage is attached to
const int GreenLedPin = 3;           // the pin that the green LED (On charge) is attached to
const int OrangeLedPin = 4;          // the pin that the orange LED (no risk) is attached to
const int RedLedPin = 5;             // the pin that the red LED (low battery) is attached to

// Variables will change:
int currentVoltage ;         // current voltage value
int previousVoltage ;     // previous voltage value

void setup() {
  // initialize the battery voltage pin as a input:
  pinMode(BatteryVoltagePin, INPUT);
  // initialize the green LED as an output:
  pinMode(GreenLedPin, OUTPUT);
  // initialize the orange LED as an output:
  pinMode(OrangeLedPin, OUTPUT);
  // initialize the red LED as an output:
  pinMode(RedLedPin, OUTPUT);
}

void loop() {
  // read the voltage across the battery voltage pin:
  currentVoltage = digitalRead(BatteryVoltagePin);

  // compare the current voltage value to its previous value
 if (currentVoltage != previousVoltage)

 delay(10);

    // value above maximum threshold
    {
     if ((( ( analogRead(BatteryVoltagePin) ) > ( 699 ) ))
        {
        digitalWrite(GreenLedPin, HIGH);
        }
        else
        {
          digitalWrite(GreenLedPin, LOW );
        }
    }

    //value between two thresholds (middle region)
    {
     if (( ( ( analogRead(BatteryVoltagePin) ) <= ( 699 ) ) && ( ( analogRead(BatteryVoltagePin) ) >= ( 628 ) ) ))
        {
        digitalWrite(OrangeLedPin, HIGH );
        }
        else
        {
          digitalWrite(OrangeLedPin, LOW );
        }
    }

    // value below minimum threshold
    {
     if (( ( analogRead(BatteryVoltagePin) ) < ( 628 ) ))
        {
        digitalWrite(RedLedPin, HIGH);
        }
        else
        {
          digitalWrite(RedLedPin, LOW );
        }
     }

  // save the current state as the last state,
  //for next time through the loop
  previousVoltage = currentVoltage;
 }


texts: If I'm going to measure an AA battery (about 1.5 v) with a USB-powered Arduino, I will connect the battery's +ve terminal to the A0 pin. Shall I connect the -ve terminal to the gnd pin too?


texts:
I'm a newbie on Arduino and NodeMCU so now I'm trying to run  my relay module trough the NodeMCU v3  and so far I have wired them all respectively as the instruction below:

NodeMCU
5v Relay

D2
+

Gnd
-

VIN
S

but somehow it doesn't work when I try vin pin but the led of  Relay module just turns automatically on when I connected to 3v pin  works on vin3 without me doing anything through the app (Blynk).
I wonder if I'm missing something here?
Thanks very much for your help in advance.
Sani


texts: Can I control a Arduino from an apache server?

texts: So I have a PC running a few services for my house. I'm trying to automate my home a little and would like to control various things in my house. Is it possible to control an Arduino from my HTML Apache server? I was thinking about going from the PC -> Raspberry pi -> then serial connection to an Arduino but that seems over excessive.


texts: avrdude: stk500_recv(): programmer is not responding, bootloader problem

texts:
Yet another question with this title. I just bought an Arduino Uno R3, as part of a ARDX kit. When trying to upload the first sketch, I get this error message:

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

Full output:

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.
/home/stephan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/bin/avrdude -C/home/stephan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyACM2 -b115200 -D -Uflash:w:/tmp/arduino_build_795770/BareMinimum.ino.hex:i

avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "/home/stephan/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino17/etc/avrdude.conf"
         User configuration file is "/home/stephan/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyACM2
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I'm using Arduino IDE 1.8.10 on Ubuntu 19.10, but I've tried an older version and the newest version on Windows 10 as well. I' ve selected the correct port (/dev/ttyACM2 recognizes Arduino Uno), selected Arduino Uno as board and AVRISP mkII as programmer. I've read this great post and this is what I found out:

The power LED doesn't flash when the reset button is pushed or when power is plugged in.
The loopback test succeeds. Everything I type is echoed back.
When uploading a sketch, only the RX LED flashes quickly.

  Board info

BN: Arduino
Uno VID: 0x2341
PID: 0x0043
SN: 55639313533351C050F1

So as far I can understand it, there is a "problem with the bootloader, or the main processor chip (Atmega328P)".

What can I do to find out if there is a problem with the bootloader and how can I fix this, without an extra Arduino? And how could a problem with the bootloader occur? It's a brand new board an just followed all instructions.


texts: What alternatives are there to the Optiboot bootloader?

texts:
Nearly all modern Arduino boards use the Optiboot bootloader. Compared to the ATmegaboot used before, this is smaller in flash terms (by about 1.5KB) and faster in upload speed (115.2k vs 57.6k) and starts your sketch quicker (the delay whilst waiting after reset is shorter).

Are there any alternatives to the Optiboot bootloader? Specifically, are there any smaller (in flash terms) boot loaders? What differences do they have?


texts: Can someone help me figure out why my menu gets stuck?

texts:
When I try to run my code so far with the menu and select buttons, it seems that it works, except that the main menu will not move past "Main Garden" to "Currants". There's also a problem with the submenu where after the first watering warning, pressing the select button makes it simply return to the main menu without lighting the LED on the LEDPower pin or running that watering routing for the whole watering interval.
The one guess I still haven't tried is that maybe I should change void MainMenu() to a Switch Case structure instead of If-Else?
.
edit:
.


texts: How much current and voltage has my resistor + LED

texts:
I have a very simple circuit: 5v -> LED (5mm, forward voltage of 2 V and max. current of 20mA) -> 1k ohm resistor -> GND.

I want to know how much current is flowing in my circuit. I am using this formula:

U = R x I

Since U = 5, and R = 1000 the current is (according to the formula): 5/1000 = 0.005A.

So far so good. The problem is when I try to check the voltage drop over the resistor and the LED. For calculating the voltage drop in the resistor I would use the same formula where I is my current (0.005A) and R is the resistor 1k ohm. The result is: 5 V.

Something very weird is happening here cause the voltage drop around my resistor should not be 5 V cause I know there must be another voltage drop around the LED. If 5V is in the resistor it would mean that 0v is around the LED (and it should not light up but it does).

Thank you helping me with this basic calculus.


texts: Is there a way to get about a 10ns Timer resolution from an AVR CPU?

texts:
I have an 8Mhz ATM32u4 that is able to read external pulse inputs at 125ns ticks using InputCapture3 (PC7) on its 16-bit timer.  Is there a magical way (bitbanging?) to get around 10ns tick resolution to read pulses?  Edit:  like ADC conversions to allow 16-bit systems 24-bit accuracy via creative coding, etc.
If there is no magic, I should use a faster CPU?  I am limited in coding pretty much to AVR type CPUs in the Arduino IDE.  So wondering what AVR CPU would be fast enough for a 10ns tick that is incorporated already into like a Nano, UNO, etc?
Unless I am able to use Pin Interrupts that are able to read at 10ns intervals, then I could use ARM CPU types with Arduino IDE code which does not require me to dive deep into register level language.
Or, is there a stand-alone analog or digital IC that is able to read at 10ns intervals pulses that an Arduino can process?
Thank you.
Edit:  I would need to measure the length of a one-shot pulse only, not a continuous or changing signal. Down to 70us length with an accuracy of at least 18ns tick, but preferably 10ns to account for hardware, etc inaccuracies. This one-shot pulse could repeat not more frequently then 1 second apart, but likely several seconds apart. The signal is two positive square waves forming a pulse measuring not less than 70us from the positive rising edge to rising edge. The system measures the pulse length and sends it the user (serial, BLE, etc).
Edit 2: someone suggested a "one-shot pulse stretcher". Interesting concept...   The more I am looking into it, the more I think it's a very viable hardware solution to the AVR's processing speed limitation. One may say that this is hardware "bitbanging" by streching out the short pulse to a proportionally longer one that the MCU capture process can measure reliably/accurately. An example is this old IC from Linear Tech. See Fig 12 and Fig 13.    https://www.analog.com/media/en/technical-documentation/data-sheets/6752fc.pdf
http://www.anderswallin.net/2014/02/pulse-stretcher-v1/

The shortest expected pulse would be about 70us which needs to be measured at (around) a resolution of 18ns for the accuracy I need.  So I went with 10ns for design to allow for some accuracy "overhead".  That is between 4000-7000 counts/ticks  (18ns-10ns ticks) for the 70us signal.
If I stretch this same 70us signal to be measured with the pulse-stretcher to 700us and use the currently available 125ns tick interval of the ATM32u4, I should arrive in theory to about the same accuracy as using an 18ns tick for a 70us signal to be measured.
Here is a similar problem that was answered: https://electronics.stackexchange.com/questions/46922/lengthening-a-5-ns-pulse


texts: 5V power supply negative terminal connection

texts:
I am currently developing some basic led board using Arduino Uno R3. Basically,
the LEDs are connected in parallel so that 5V DC supply can light up about 3 LED. Each LED has its resistor and its connected to 3 Arduino digital pin where I ground it by using digitalWrite(pins, LOW). Each ground on the schematic is the Arduino digitalWrite(LOW). My question is where should the negative of the 5V should be connected?

Also, if I wanted to measure the voltage of the LED, where should I connect my probe so that analogRead() can read the voltage?

Thanks and sorry if my explanation is not correct since it's my first time using this site.

simulate this circuit – Schematic created using CircuitLab


texts:
Please check the arduino program given below and help me to find out error.
The program is for following hardware.
GSM 800 module
Arduino Uno board
Limit switch(2)

We place two limit switch at main door & back door as main door is open the message will be send that is Main door is open & when it closed it will send message Main door is closed. This is same for Back door also.

We run this program & it run but it sends the massage repeatedly after some time.
Please help me to find out error..

my ARDUINO code is

const int Main = 7;
const int Store = 8;
const int Main_led =  13;
const int Store_led =  14;
bool i = true;
bool j = true;
bool k = true;
bool l = true;
int buttonState1 = 0;
int buttonState2 = 0;
void setup() {

  Serial.begin(9600);
  pinMode(Main_led, OUTPUT);
  pinMode(Store_led, OUTPUT);
  pinMode(Main, INPUT);
  pinMode(Store, INPUT);
}

void loop() {
  buttonState1 = digitalRead(Main);
  if (buttonState1 == HIGH && i == true ) {
    digitalWrite(Main_led, HIGH);
    Serial.println("OK");
    delay(1000);
    Serial.print("AT+CMGF=1\r\n");
    delay(500);
    Serial.print("AT+CMGS=\"+91-------------");
    Serial.print("\"\r\n");
    delay(5000);
    Serial.print("Main Door is closed");
    Serial.write(0x1A);
    delay(5000);
    i = false;
    j = true;
  }
  else
  { if (buttonState1 == LOW && j == true )

    { digitalWrite(Main_led, LOW);
      Serial.println("OK");
      delay(1000);
      Serial.print("AT+CMGF=1\r\n");
      delay(500);
      Serial.print("AT+CMGS=\"");
      Serial.print("+91---------------");
      Serial.print("\"\r\n");
      delay(5000);
      Serial.print("Main Door is open");
      Serial.write(0x1A);
      delay(5000);
      i = true;
      j = false;
    }
  }

  buttonState2 = digitalRead(Store);
  if (buttonState2 == HIGH && k == true) {

    digitalWrite(Store_led, HIGH);
    Serial.println("OK");
    delay(1000);
    Serial.print("AT+CMGF=1\r\n");
    delay(500);
    Serial.print("AT+CMGS=\"");
    Serial.print("+91-------------");
    Serial.print("\"\r\n");
    delay(5000);
    Serial.print("Store room is Closed");
    Serial.write(0x1A);
    delay(5000);
    k = false;
    l = true;
  }
  else
  { if (buttonState2 == LOW && l == true)
    {
      digitalWrite(Store_led, LOW);
      Serial.println("OK");
      delay(1000);
      Serial.print("AT+CMGF=1\r\n");
      delay(500);
      Serial.print("AT+CMGS=\"");
      Serial.print("+91------------------");
      Serial.print("\"\r\n");
      delay(5000);
      Serial.print("Store room is Open");
      Serial.write(0x1A);
      delay(5000);
      k = true;
      l = false;
    }
  }
}


texts: Adafruit ImageReader Library 2.3.5 added several library dependencies

texts:
Why has Adafruit ImageReader Library v2.3.5 recently added six dependencies on other libraries for hardware I'm not using?

I used the v2.3.2 of the Adafruit ImageReader Library successfully two months ago. An example sketch worked fine with my ILI9341 3.2" display and its SD card.

Now there is an updated v2.3.5 available but the library manager wants to add six more "dependency" libraries:
- Adafruit ST7735 and ST7789 Library
- Adafruit seeswaw Library
- Adafruit HX8357 Library
- Adafruit SSD1351 library
- Adafruit SSD1331 OLED Driver Library for Arduino
- Adafruit EPD

As far as I know, the ILI9341 uses none of the hardware that corresponds to the six libraries it's trying to drag in. I don't want unneeded dependencies and don't want the code bloat.

If I don't accept the additional libraries, my sketch fails to compile. The error message is "C:\Users\barry\Documents\Arduino\libraries\Adafruit_ImageReader_Library\Adafruit_ImageReader_EPD.h:18:10: fatal error: Adafruit_EPD.h: No such file or directory"

However, EPD code is for "e-paper displays" which does not apply to my ILI9341 which is a TFT display. I don't think EPD code should be a real dependency.

Kindly redirect me if there's a better place to ask.


texts: Connection problem with Arduino Mega 2560 and GSM shield ( official M10)

texts:
As I don't want to stack the shield over the mega 2560 board, I try to connect only the pins that used for GSM communication. Here are my connection:

Pin 3 on Mega <==> Pin GSM Rx on Shield

Pin 10 on Mega <==> Pin GSM Tx on Shield

Pin 4 on Mega <==> Pin 4 on Shield

Pin 5V on Mega <==> Pin Vin on Shield

Pin GRD on Mega <==> Pin GRD on Shield

Code I used is from the Examples library, GsmScanNetworks:

#include <GSM.h>

// PIN Number
#define PINNUMBER "8888"

// initialize the library instance
GSM gsmAccess;     // include a 'true' parameter to enable debugging
GSMScanner scannerNetworks;
GSMModem modemTest;

// Save data variables
String IMEI = "";

// serial monitor result messages
String errortext = "ERROR";

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

  Serial.println("GSM networks scanner");
  scannerNetworks.begin();

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  // get modem parameters
  // IMEI, modem unique identifier
  Serial.print("Modem IMEI: ");
  IMEI = modemTest.getIMEI();
  IMEI.replace("\n","");
  if(IMEI != NULL)
    Serial.println(IMEI);
}

void loop()
{
  // scan for existing networks, displays a list of networks
  Serial.println("Scanning available networks. May take some seconds.");
  Serial.println(scannerNetworks.readNetworks());

    // currently connected carrier
  Serial.print("Current carrier: ");
  Serial.println(scannerNetworks.getCurrentCarrier());

  // returns strength and ber
  // signal strength in 0-31 scale. 31 means power > 51dBm
  // BER is the Bit Error Rate. 0-7 scale. 99=not detectable
  Serial.print("Signal Strength: ");
  Serial.print(scannerNetworks.getSignalStrength());
  Serial.println(" [0-31]");

}

Questions:

After opening the serial port, only a line "GSM network scanner" is read. Seems that the program is stuck ongsmAccess.begin(PINNUMBER), how shall I fix that?
Is it a must that I shall supply 5V 2A power to the shield seperately in order for the shield to work? (with connection mentioned above, the ON led light on the shield does turns on with an orange light)
For the PINNUMBER defined in the program, my SIM has default PIN 8888. I checked with a mobile phone that the SIM card does work. But my phone shows that the SIM card is not locked with PIN. So shall I define the PIN as 8888 for ''?

EDIT:

GSM shield link

Note for using GSM shield with Mega

* And yes! The shield did work when stacked! (Orginally I don't want to bend pin 2...but...unnh...stacking and bending out pin 2 did work)

* Tried the examples "GSMScanNetwork" and "SendSMS", works fine. But for "GsmWebServer", an IP address is shown, but when I enter the IP address on my browser, chrome/ie says they cannot find the IP address.....Any clues?

* And does the status LED on the GSM board have anything to do with power? It goes on and off and on and off.....

* For question 1 & 3, PINNUMBER is set to ''. Worked fine.


texts: Where can I find beginner tutorials for the Arduino?

texts: I am new to all of this so anything is helpful.


texts:
I have a function that reads rfid card and return rfid string. Function reads string well but.
I am using ArduinoJson libray to generate json .
this is the function that i am using to read rfid cards.
String rfidOku(){
  String kartid= "";
  if( mfrc522.PICC_IsNewCardPresent() && mfrc522.PICC_ReadCardSerial()){
    for (byte i = 0; i < mfrc522.uid.size; i++)
    {
        kartid.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
        kartid.concat(String(mfrc522.uid.uidByte[i], HEX));
    }
    kartid.toUpperCase();
    //Serial.println(kartid);
  }
  kartid.trim();
  return kartid;
}

and in the loop function , if button pressed i am getting an rfid and ı am creating json using it
    const size_t capacity = JSON_OBJECT_SIZE(4);
    DynamicJsonDocument doc(capacity);
    const String str_rfid = rfidOku();
    doc["id"] = odeme.id;
    doc["fiyat"] = odeme.fiyat;
    doc["rfid"] = str_rfid;

    serializeJson(doc, Serial);

When i look to serial monitor rfid field is null. Why it happens. I tried to write other string there it works well with other string but why it does not with str_rfid.
I also print value of str_rfid using Serial.print str_rfid getting rfid card id from function well.


texts: Two TH02 Sensors to Grove Base Shield V2

texts:
We are trying to connect two TH02 (Grove - Temperature&Humidity Sensor (High-Accuracy & Mini))  sensors to Grove Base Shield V2 that is connected to Arduino Wifi Uno.

We connected the each sensor alone to I2C of the Base shield and it is working just fine, but when we connect two, we cannot get simultaneous readings.

We are new to Arduino and we are trying ti figure out if these two sensors can be connected to I2C even if they have the same address.

Please tell if we need to provide more information. Thanks!


texts:
I would like to calculate the amount of voltage from my A0 pin. I am using a 9v battery to power my load in my circuit. The formula to calculate voltage from the A0 pin is:

    sens = analogRead(A0);
    vol = sens * ( 5.0 / 1023.0);

If my power source is 9v, should i replace the 5.0 to 9.0?


texts: How to set "IPAddress ip" using a variable?

texts:
Created a "variableInput.h" file for editing variables in one place; instead of searching multiple lines of code, to find lines needing editing.

//   variableInput.h
//
//   User defineable variables; one location for editing variables

// Replace with your network details
#define host = "esp32"
#define ssid = "YOURSSID"
#define password = "YOURPASSWORD"

//NTP Time Servers
#define udpAddress1 = "198.50.238.156"  //NTP Time server
#define udpAddress2 = "132.163.96.3"  //NTP Time server

//publicIP accessiable over Internet with Port Forwarding; know the risks!!!
//WAN IP Address.  Or use LAN IP Address --same as server ip; no Internet access.
#define publicIP = "YOURPUBLICIP"
#define LISTEN_PORT  8030  //default listening Port 80 for "GET" requests.

//Graphing requires "FREE" "ThingSpeak.com" account..
//Enter "ThingSpeak.com" data here....
//iframes of graphed data are available from "ThingSpeak.com."
#define myChannelNumber = 123456
#define myWriteAPIKey = "E12345"

//FTP Credentials
#define ftpUser = "FTPUSER"
#define ftpPassword = "FTPPASSWORD"

//setting the addresses
#define ip(10,0,0,200);
#define gateway(10,0,0,1);
#define subnet(255, 255, 255, 0);
#define dns(10,0,0,1);

//Restricted access to client ip list.
#define Restricted = "/ANYNAME"

//OTA Credentials
//default username: USERNAME
//default password: PASSWORD

// "setting the addresses" is the part that I do not understand.

Segment of related code from "wifi_Start" function:

//setting the addresses
IPAddress ip;
IPAddress gateway;
IPAddress subnet;
IPAddress dns;

Is there a solution?

William


texts: How to use a precompiled library in a project with Arduino-IDE

texts:
I'm discovering the Arduino development and after quite some googling, I can't find an answer to the following question.

I'd like to distribute some code as mylib.h + precompiled mylib.o (this will be code ported from sources which I can't divulgate).
How is it possible to build a sketch using this precompiled mylib.o in the Arduino-IDE environment?
Do I simply have to put this mylib.o in a specific path and include the mylib.h in the sketch? If yes, which path? If no, what specific configuration steps do I have to follow?

Thanks in advance.


texts: 2 buttons pressed at the same time elevator logic

texts:
I have currently created a working elevator code where the elevator goes up when pressed a button, and stops at a floor when the sensor senses that it has reached the floor. This is how it works:

#define Buzzer 5

#define pwmMot 6

#define halPin 8

#define butto1 9  //level 1
#define butto2 10 //level 2
#define butto3 11 //level 3

#define SeEcho 12
#define SeTrig 13

int button1_status = 0;
int button2_status = 0;
int button3_status = 0;

int current_level = 1;
int required_level =-1;

void setup(){
  Serial.begin(9600);
  pinMode(Buzzer, OUTPUT);
  digitalWrite(Buzzer, HIGH);
  pinMode(halPin, INPUT);
  pinMode(butto1, INPUT);
  pinMode(butto2, INPUT);
  pinMode(butto3, INPUT);
  pinMode(SeTrig, OUTPUT);
  pinMode(SeEcho, INPUT);
  pinMode(pwmMot, OUTPUT);
  Serial.println("you are in level 1");
}

void emergencyStop(){
  analogWrite(pwmMot, 255);
}
int sensor() {
  unsigned long duration;
  int distance;
  digitalWrite(SeTrig, LOW);
  delayMicroseconds(2);
  digitalWrite(SeTrig, HIGH);
  delayMicroseconds(5);
  digitalWrite(SeTrig,LOW);
  duration = pulseIn(SeEcho,HIGH);
  distance = int(duration/2/29.412);
  return distance;
}

bool hallSen(){
  return digitalRead(halPin);
}

int going_up(){
  while (sensor() > 12){
    analogWrite(pwmMot, 1600);
  }
  return 1;
}

int going_down(){
  while (sensor() > 12){
    analogWrite(pwmMot, 570);
  }
  return 1;
}

void loop() {
  button1_status = digitalRead(butto1);
  button2_status = digitalRead(butto2);
  button3_status = digitalRead(butto3);
  required_level = button1_status == HIGH ? 1 : button2_status == HIGH ? 2 : button3_status == HIGH ? 3 : -1;
  if (required_level != -1 && required_level != current_level){
    while (current_level != required_level){
      if (current_level > required_level) Serial.println("Going Down"), current_level-=going_down();
      else if (current_level< required_level) Serial.println("Going Up"), current_level+=going_up();
      Serial.print("you are in level "); Serial.println(current_level);
      delay(1000);
    }
    analogWrite(pwmMot, 1550); //stop elevator
    digitalWrite(Buzzer, LOW);
    delay(100);
    digitalWrite(Buzzer, HIGH);
    required_level = -1;
  }
}

Now I am just curious as to how I will extend this so that for example if we are in level 1, both the levels 2 and 3 are pressed it should go to level 2 even if level 3 was pressed first. Or if we are in level 2 and both level 1 and 3 are pressed, it should go to the one that is pressed first as both levels are the same distance from level 2.


texts: How to connect a varying output voltage to the Arduino?

texts:
I have a smart meter and I want to connect my output pulse meter to the Arduino in order to count the pulses, but the problem is my  output pulse voltage is varying (between 1V to 17V approximately) and the Arduino accepts only a stable voltage (5V).

Therefore, how can I make my output pulse voltage stable to connect it to the Arduino?


texts: changing analog pins data logging using sdFat library

texts:
Background:

My goal is to use sdFat library, more precisely AnalogBinLogger example.

I want to log data from changing analog pins for example, I want to log from pin 0 to pin 3 for 5 minutes and then from pin 4 to pin 6 for another 5 mins and then from pin 7 to pin 9 for another 5 mins. that is going to be continuously which means I am going to get rid of the part where you have to enter "r" to start logging.

Regarding the time, I managed to figure it out, I am just using the value of the variable count, if my sampling rate is 1000 samples/sec for example then 5 minutes will be 1000*60*5 and the change will be done in this line:

if (Serial.available()) {
  // Stop ISR calls.
  adcStop();

to

if (count >1000*60*5) {
  // Stop ISR calls.
  adcStop();

and this worked fine.

My problem is with the changing pins:

const uint8_t PIN_LIST[] = {1};

I changed this line to

uint8_t PIN_LIST[3] = {};

First I removed the word const, because it's not going to be constant anymore, and I just declared an empty array, and second I am changing the pins in the loop.

Here is the loop after I got rid of doing the serial input:

void loop(void) {
int i;
for (i=0;i<=12;i+3)
{
  PIN_LIST[] = {i,i+1,i+2};
  logData();
  Serial.println("done");
 }}

The problem is I get this error :

AnalogBinLogger.ino: In function 'void loop()':
AnalogBinLogger:808: error: expected primary-expression before ']'
token
AnalogBinLogger:808: error: expected primary-expression before '{'
token
AnalogBinLogger:808: error: expected `;' before '{' token

The line 808 is:

PIN_LIST[] = {i,i+1,i+2};

So this is the only error, any help please?

The code is so long (800+ lines) if this information is not enough and you need me to explain a part then just tell me.


texts:
I know it's possible to hook up multiple SPI devices, but how can one access the second drive from a sketch?

Looking at the SDWebServer.ino example, my doubt is with the SD.begin(SS); part. If I call begin() again with the other CS pin, it seems that I would lose a reference to my first volume, or maybe it won't work at all. I would instantiate another SD instance, but the sketch never seems to instantiate that object, it first appears in setup() with SD.begin(SS);

If I copy the lib (sd.h+sd.cpp) and replace all literal instances of SD with SD2, can I then include and use SD2 just like the original (provided the different .begin(pin))? Is there a less hacky way of using two SD cards in ESP8266 Arduino?

In case anyone's wondering, it's for a crypto project where one card will contain one-time-pads of plaintext length and the other contains the XOR'd ciphertext, both are fed by wifi upload, and the max file size must be bigger than SPIFFS, so I really need two SD cards...


texts:
According to data sheets, the MKR1000 runs a SAMD21 Cortex-M0+ processor at 48 MHz. For a project I need to drop that down to 16MHz to get some accurate timing in us. How can I do this? Most of the suggestions on the internet involve the ATmega* boards.

Thanks in advance.


texts: How to switch on 32A/240VAC with Arduino?

texts:
I have an air conditioner switch rated at 32A/240V AC - how do I turn this on using Arduino and Relay.

I'm based in India and I am unable to find a relay switch rated higher than this.

I don't want to try anything that results in a fire hazard. My aim is to switch on the AC with my mobile phone. I'm using Arduino Uno with a 2.4GHz transceiver for communication.


texts: Setting pinMode(pin,input/output) as per user requirement

texts:
I am working on arduino IDE and esp8266 nodemcu.
As i am going through the IDE I saw that there is a structure of void loop() and void setup() and all examples in the internet included defining the pinModes within the void setup() block.
I want to make a program where through mqtt or http the user will give input as to what type of device he/she wants to attach to the esp8266, so based on that i will have to set, INPUT/OUTPUT state on the following pins.

Now my initial idea was :

void setup()
{
    connectwifi();
}

void loop()
{
   call_some_function();
}

where call_some_function() will recieve the requirements from user over http. For example he wants a light on pin3, so pinMode(pin3,OUTPUT);

now what I wanted is that,
call the method - call_some_function() whenever the user needs to add an extra device to it, which means initally when we wanted to add 4 lights to esp8266, we will write

pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);

But now when I have a user defined input, my code will become something like this,

call_some_function()
{
     pin=(user gave me the pin no);
     state=(based on the device the server will send the state i.e IN/OUT);
     pinMode(pin,state);
}

Now my question is , calling this function 4 times and writing pinMode() function 4 times will result in same thing or separate?
Also is this doable, like can i write like this?
I will be calling this function from void loop() instead if void setup(), since I continuously listen for user input,
Cause I cannot find any other way of making user specific input


texts: What Minimum Value Can I Measure With ACS712 30A Current Sensor?

texts: I am making an Arduino multimeter for current measurement. I first thought about using a shunt but that fails to work since I need to measure current in the mA range.


texts: How far can a HC-SR04 can stand from the microcontroller?

texts: I was wondering if I connect a HC-SR04 to an Arduino or any other microcontroller by normal cables, what would be the maximum length of this cable so that the measurements will still be true, and not affected by the length of this cable?