texts: How to implementing timer interrupt with a sensor device using A0 and A1 pins

texts:
I was wondering if there is a way to program a timer interrupt to collect sensor data at a specific sampling rate?
I want to attach two strain gauge sensors to A0 and A1 pins and collect the data at a 20Hz sampling frequency using a timer interupt on an Arduino Uno. Please, let me know if this is possible, or if there is something else I can do.


texts: what is this ets Jan 8 2013,rst cause:4, boot mode:(1,7)

texts:
i dont have any idea about this problem. can anyone help me how to fix this?

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPClient.h>
const char *ssid = "NUS";
const char *password = "s006";
int lo=16.3441;
int la=80.5243;
const char *host = "http://smshorizon.co.in";
void setup() {
   delay(1000);
   Serial.begin(115200);
   Serial.println("Start");
   WiFi.mode(WIFI_OFF);
   delay(1000);
   Serial.println("Status");
   WiFi.mode(WIFI_STA);
   Serial.println("Begin...");
   WiFi.begin(ssid, password);
   Serial.println("");
   Serial.print("Connecting");
   while (WiFi.status() != WL_CONNECTED) {
       delay(500);
       Serial.print(".");
    }
   Serial.println("");
   Serial.print("Connected to ");
   Serial.println(ssid);
   Serial.print("IP address: ");

   Serial.println(WiFi.localIP());
 }
 void loop() {

  }

Sometimes it shows boot mode(1,0)


texts:
I'm working on a modular CANBUS system for offroad racing. The idea right now is that the main Arduino (1284p at the moment) will be the only one connected to CANBUS, and other modules will have their own atmega's that will communicate with the master over I2C. They will not be physically on the same PCB, but will be physically within inches of each other. One module will have 8 MAX31865 IC's for interfacing with RTD's. The 31865 is not compatible with 5V microcontrollers, which right now we planned on running the Atmega's at 5V. Since the IC's are SPI, they can all share a MOSI, MISO, and CLK bus, so only two channels of a hex converter. For the Chip Select pin, would it be acceptable to use a resistor to decrease the voltage instead of using an additional 8 channels of hex converting?

What would the upsides/downsides be of using an atmega running at 3.3v for the module with the MAX31865's and just using a hex converter on SDA/SCL for the I2C communication to the master? What atmega I use for this is flexible.


texts: ESP8266 ESP-01s Not Responding, No LED Blinking, Overheating

texts:
I have an ESP-01s that I want to use as a shield so my Arduino Uno project could communicate with my Blynk app through wi-fi. I used this video as reference.
This is the sketch. It is just the ESP8266_Shield example from the Blynk library.
#define BLYNK_PRINT Serial

#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

char auth[] = "-------";

char ssid[] = "-------";
char pass[] = "-------";

#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2,3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

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

  delay(10);

  // Set ESP8266 baud rate
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

void loop()
{
  Blynk.run();
}

This is the schematic:

What happens:

The moment the Arduino is connected, the Blue LED flashes for a split second then all LEDs will remain off. No red led, no blue led, really just off.
The ESP-01s becomes very hot to the touch
Tried speaking to the ESP-01s through the Serial Monitor with BareMinimum example @115200 baud rate (Many Sources say that this is the default baud rate of the recent boards) however no response whatsoever.
Running the code above will get this error:

What I've done:

Tried using the HW-131 Breadboard Power Supply to supply the 3.3V (Common GND with Arduin) of the ESP-01s because I read that the ESP-01 could need more current than the Arduino Uno could provide. Still the same effect, no LEDs blinking, (even more) hot to touch, not responding to AT commands.
Attempted to follow a video on how to flash the ESP-01s but when I tried to run the flasher, it could not communicate with the ESP-01s.
Switching Rx Tx ESP-01s but no luck.
Added a 10k ohm resistor from 3.3V to the Vcc and EN pins of the ESP-01s. Not heating up anymore but still no response.

I really thought this is a power problem but could it be the ESP-01s itself is defective?
This is what the ESP-01s look like


texts: Sending commands to an STM32 chip via UART with Arduino Pro Mini

texts:
I am having trouble making an Arduino Pro Mini send commands via USART to an STM32 chip. The serial communication protocol is currently set to 9600 baud rate with no flow control or stop bits. Is there anything special that has to be done to make these two devices communicate with each other? I'm using the standard RX/TX pins for this. The Arduino logic level is 3.3V. The STM32 logic level is 2.5V. They share a common ground. I should also note that there is a 1K ohm resistor in series with each data line. Here's the code that I'm trying to use:

#include <Arduino.h>

void setup()
{
  Serial.begin(9600);
  delay(4000);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH);
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW);
  delay(1000);
  String voltage = String("85 2 0 0 10 174 96"); //Command to set voltage output on STM32
  Serial.println(voltage);

  while (1) {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(200);
    digitalWrite(LED_BUILTIN, LOW);
    delay(200);
  }
}


texts: How to change LDR output in simulator 123D Circuits?

texts: I used simulator 123d.circuits.io to create simulation of basic circuit with LDR: LDR is connected to 5V and via 10K resistor to GND. Wire between LDR and resistor is connected to analog pin where I read ADC values and display them using serial monitor. This works fine. But I would like to how to change lighting level of LDR in simulation because this way LDR shows still the same value. I tried putting LED or light bulb near LDR but it doesn't seem to have any influence. Any ideas?


texts: How do I connect components to the Arduino with a motorshield?

texts:
How would I connect components to the Arduino with this motor shield?

Thanks :)


texts: Why does the Pro Mini 5 v and 3.3 v version have different clock frequencies?

texts:
It looks like the 5 volt version used the 16MHz external crystal while the 3.3V one uses the 8MHz crystal. I need to use 3.3v as my operating voltage.

Can I just remove the linear regulator and bring in 3.3V. I still have to select the 5V 16MHz version in the Arduino IDE, right?

https://www.arduino.cc/en/uploads/Main/Arduino-Pro-Mini-schematic.pdf


texts: After burning bootloader, Windows 10 doesn't recognize the USB device

texts:
I just built my own version of an Arduino Micro, using the ATMEGA32u4 chip. I burned the bootloader to it via another Arduino (Arduino Nano from banggood.com).

The Arduino Nano uses an ATMEGA328 chip, so it should work as an ISP programmer. None the less, I hooked up the Nano to my custom board, according to Sparkfun's Guide, and proceeded to burn the bootloader. The Arduino IDE says that I have successfully burned the bootloader.

However, when I plug in the newly burned custom board, Windows 10 throws the error, saying, USB Device Not Recognized followed by The last USB device you connected to this computer malfunctioned and Windows does not recognize it.

I have searched for a solution, but none seem to come up. My question is, what do I need to do in order to get this custom board working as an Arduino? Thanks!


texts: Arduino Uno: Driving a small LED strip with 2N3904 NPN

texts:
I'd like to know why I cannot dim the small LED strip with my design. I can only turn them on and off. This is a problem for me as I wanted to have a fade effect. Here is my circuit:

The voltage from the power jack is 5 volts. My NPN transistor is a 2N3904 (from left to right: emitter, base, collector).
For the Arduino I am only using the fade exemple sketch:

int led = A2; // the PWM pin the LED is attached to
int brightness = 0; // how bright the LED is
int fadeAmount = 5; // how many points to fade the LED by

// the setup routine runs once when you press reset:
void setup() {
   pinMode(led, OUTPUT);
 }

// the loop routine runs over and over again forever:
void loop() {
  // set the brightness of pin 9:
  analogWrite(led, brightness);

  // change the brightness for next time through the loop:
  brightness = brightness + fadeAmount;

  // reverse the direction of the fading at the ends of the fade:
  if (brightness <= 0 || brightness >= 255) {
     fadeAmount = -fadeAmount;
  }
  // wait for 30 milliseconds to see the dimming effect
  delay(30);
}

By the way, this is my first post so please tell me if something is wrong with it! Thank you for your help!

Have a nice day.


texts: How to use printf with Arduino's serial ports without an intermediary buffer?

texts:
How to use printf with Arduino's streams without an intermediary buffer? The following seems unnecessary:

char buf[256];
sprintf(buf, ...);
Serial.print(buf);

Is there a way to connect HardwareSerial or SoftwareSerial to a libc stream or is there a custom implementation of printf that does this?


texts: Arduino read PWM duty cycle value with input (analog / digital)

texts:
I am working on comparing autopilots like Ardupilot, CC3D, KK2.1.5. The comparision is about system reactions/behaviors that it gives during flight. For this purpose, I need to read the PWM duty cycle (like osilascopes - the PWM frequency can be vary from 50 to 430 Hz) values from autopilot card. There are 4 command input PWMs and 4 esc control PWMs for a typical quadrotor. I have to read 8 duty cycle values with digital/analog input pins. How do I measure duty cycle of 8 PWM signals?  Also, is digital or analogue measurement precise and faster?

Note about attachInterrupt command: According to arduino.cc AtMega328 series have 2 interrupts, Arduino ATmega 2560 series have 7 interrupts.


texts: Can anyone suggest me a way to efficiently power my relay module using batteries?

texts:
I hve a very simple project where I have a ttp233 touch sensor which I'm using to control my relay module which inturn switches my fans on and off. The problem here is whenever there is a power loss the relay defaults to a low state and I have to touch the sensor again to turn on my fan. So I thought of using a battery to compensate ,so I want help regarding this. I want to have it in such a way that when the power is ther the relay and sensor should run on wall power and the battery also should be charged but when there is a power loss the battery should kick in and power the circuit with no delay so that my appliances stay on during power loss and when the power comes back on again the circuit should again go back to using wall power .
Is there any way I can achieve this?


texts: Supplying power to arduino by 5V and 2A adapter

texts:
Can I power my Arduino using a 5V/2A adapter by connecting it through the USB port?

More precisely, I have to run a module requiring 200mA but the aim is to make the laptop independent.


texts:
Have you heard about support for IPv6 protocol for any Ethernet shield?
As far as I know only IPv4 is supported.
Maybe some one would like to write library?


texts: Ethernet to Cellular Modem Possible? | GSM + Ethernet + Arduino

texts:
Is it possible to combine an Arduino µC with a GSM shield and an ethernet shield such that a device connected via ethernet to the Arduino has internet access over the GSM network?

I have a system with an ethernet port to connect to the internet. It works fine if I plug it into my switch at home. However, I would like this system to have its own cellular internet connection.

This is what I have found so far:

I'm basically trying to replicate the following:
https://nimbelink.com/e2clink-ethernet2cellular/#parts
If the following reddit post:
https://www.reddit.com/r/arduino/comments/3azxs6/create_gsm_cellular_ethernet_modem_with_arduino/
is any indication, I would think the answer is "no" but I am hoping to confirm from the expertise available here.


texts: Is there a way to put multiple integers in a method?

texts:
I'm working on a project that has 3 RGB LEDs. I want to make a simple method that I can call to control the LEDs for example:

showColor(left, 255, 0, 50);

Which would light up the left LED at 100% red, 0% green, and 20% blue. The code I have running for the method is:

 void showColor(int ledPosition, int redIntensity, int blueIntensity, int greenIntensity)
    {
      if (ledPosition == left)
      {
        analogWrite (redPin1, redIntesity);
        analogWrite (greenPin1, greenIntesity);
        analogWrite (bluePin1, blueIntesity);
      }
      else if (ledPosition == middle)
      {
        analogWrite (redPin2, redIntesity);
        analogWrite (greenPin2, greenIntesity);
        analogWrite (bluePin2, blueIntesity);
      }
      else if (ledPosition == right)
      {
        analogWrite (redPin3, redIntesity);
        analogWrite (greenPin3, greenIntesity);
        analogWrite (bluePin3, blueIntesity);
      }
      else if (ledPosition == all)
      {
        for (int index=0, index < 3 ; index++)
        {
          analogWrite (redPins[index], redIntensity);
          analogWrite (greenPins[index], greenIntensity);
          analogWrite (bluePins[index], blueIntensity);
        }
      }
    }

I'm getting tons of errors, like that all of the Intensity variables are not declared and that left, right, all, and middle are not declared. I don't know if this is possible, or what I'm doing wrong. I think I've seen something like this before somewhere else, and I don't want to just use 1 variable to control everything. An answer would be greatly appreciated!


texts: Arduino communication protocol with python - beyond pyserial and Arduino example

texts:
TL;DR does someone know of a advance and reliable/redudent USB protocol for communicating between a raspberry pi and Arduino due (native port)

I am trying to learn how to build a little robot which I hope could be autonomous at some point. In terms of hardware I am using an Arduino Due and a raspberry pi 3. The former is connected to DC motors, servos, ultrasonic sensors, light sensors, etc... The pi is responsible for running the picam and sending controlles from an Xbox controller to the Arduino as well as running a django web interface.
Long story short, I am trying to have python reliably communicating with the Arduino over serialusb (using the native port) but with no luck. The simple communication protocol shown in the Arduino example is too weak. I found a GitHub project named arduino-robust-serial https://github.com/araffin/arduino-robust-serial which worked at first but for reasons which are quite long to discuss here was not enough.

My question is as follows: does someone know of a reliable serial protocol around which could be used to have a raspberry pi communicating with an Arduino over usb?

I hope I'm not too vague. But looking online I'm struggling to find resources regarding Arduino which are not beginner blinking light examples.

Thx


texts: Arduino Uno + Sim808: Using HTTP client for GPRS GSM

texts:
My problem is that I do not want to use AT commands everywhere to get/post data to my web server because it is brainstorming with all the delay and anything. I want to use library like gsm.h or something similar. Is there simple libraries which I can use to do the HTTP/HTTPS request (get/post) to my web server?

This code is my attempt with gsm.h, but it does not work. I suppose it only works with Arduino + Telefonica GSM/GPRS shield, not Sim808:

/*
 Web client

This sketch connects to a website through a GSM shield. Specifically,
this example downloads the URL "http://www.arduino.cc/asciilogo.txt" and
prints it to the Serial monitor.

Circuit:
* GSM shield attached to an Arduino
* SIM card with a data plan

created 8 Mar 2012
by Tom Igoe

http://www.arduino.cc/en/Tutorial/GSMExamplesWebClient

*/

// libraries
#include <GSM.h>

// PIN Number
#define PINNUMBER ""

// APN data
#define GPRS_APN       "GPRS_APN" // replace your GPRS APN
#define GPRS_LOGIN     "login"    // replace with your GPRS login
#define GPRS_PASSWORD  "password" // replace with your GPRS password

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// URL, path & port (for example: arduino.cc)
char server[] = "arduino.cc";
char path[] = "/asciilogo.txt";
int port = 80; // port 80 is the default for HTTP

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

    Serial.println("Starting Arduino web client.");
    // connection state
    boolean notConnected = true;

    // After starting the modem with GSM.begin()
    // attach the shield to the GPRS network with the APN, login and password
    while (notConnected) {
       if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
       (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
          notConnected = false;
       } else {
          Serial.println("Not connected");
          delay(1000);
       }
    }

    Serial.println("connecting...");

    // if you get a connection, report back via serial:
    if (client.connect(server, port)) {
       Serial.println("connected");
       // Make a HTTP request:
       client.print("GET ");
       client.print(path);
       client.println(" HTTP/1.1");
       client.print("Host: ");
       client.println(server);
       client.println("Connection: close");
       client.println();
    } else {
      // if you didn't get a connection to the server:
      Serial.println("connection failed");
    }
}

void loop() {
     // if there are incoming bytes available
     // from the server, read them and print them:
     if (client.available()) {
        char c = client.read();
        Serial.print(c);
     }

     // if the server's disconnected, stop the client:
     if (!client.available() && !client.connected()) {
        Serial.println();
        Serial.println("disconnecting.");
        client.stop();

        // do nothing forevermore:
        for (;;)
        ;
     }
 }

Is there GSM/GPRS library that I can use with Sim808?


texts: Arduino Uno versus Arduino Nano power consumption

texts:
I have both an Arduino Uno and an Arduino Nano but I can't decide which one to use for my project. My aim is to maximize battery lifetime. I have also implemented an 8-second watchdog timer to periodically sleep and wake up the ATMega328P.

Option 1: Arduino Uno R3 + DHT11 sensor: The board is powered on by 4 * 1.25V (2700 mAh) Nickel Metal Hydride batteries and the 3.3V output voltage of the Arduino is supplied to VCC of DHT11. (Arduino Uno specification DC Current per I/O Pin 40 mA, DC Current for 3.3V Pin 50 mA).
Option 2: Arduino Nano + DHT11 sensor. The board is powered on by 4 * 1.25V (2700 mAh) Nickel Metal Hydride batteries and the 3.3V output voltage of the Arduino is supplied to VCC of DHT11. (Arduino Nano specification: DC Current per I/O Pin: 40 mA but NO information for DC current for 3.3V or 5V).

I would like to know which one will be more power-efficient.


texts: Does Arduino.cc silkscreen the pin headers? What explains the differences here?

texts:
I have two Arduino's. One from .org, and one from .cc. The arduino.org one has really nice silk screening on the header pins. The arduino.cc one does not. In addition there are some visible component differences. One has a 504S (not sure what this chip is), one has a 504L. The button on the .org one is a bit more tactile. The headers on the top (not the ICSP) headers are missing on the .org one. And, the four points that look like they're for soldering or testing are absent. I can try to get a high-res picture of the two up.

I bought the .org one in a beginner kit online from Amazon (from the official seller). And, the .cc I bought from their website directly.

The .org one seems like it's made from higher-end components, and actually having the headers at the top makes it seem more polished. Is there any through guide to what these differences are or a changelog from one hardware revision to another?


texts: using two mpu6050 to get more accurate and precise angles

texts:
i have been using this gyro for a while, now i am aware of all measures taken, to improve the outcome of this board.

my question is: would using two at the same time improve the results?

if yes how to use them both?

thanks in apporch


texts:
I want to take audio signal through mic connected to Arduino and then transfer it to PC using BT module. I want to do it with BT (HC05) and Arduino Mega. I need audio packages at 44 KHz and 24-32 bits per sample.

Can I use AudioInI2S library to receive audio samples? Does HC05 support this type of communication?

I want to save and analyze the audio samples later on. I have worked on Arduino before but I am totally new to audio streaming and I am not sure where to begin from. Any guidance would be appreciated.


texts: I want to code a depth sensor for arduino

texts:
I want to code a depth sensor for a little sub that i am working on. I want it to submerge to a any certain depth  for example 2ft. The speed of the motor is to increase by 5 until it reaches the set point given. The problem that I am facing is: whenever it reaches the set example point of 2ft the motor turns off and the sub resurfaces to the top and doesn't hold the depth .
What I want is that for whatever speed the motor is at for 2ft depth, to maintain its speed and keep the sub submerge at 2ft.

#include <MS5837.h>
#include <Wire.h>
#include "MS5837.h"
#include <Servo.h>
MS5837 sensor;
Servo vertical_thruster;

float x;
float error;
int pwm = 1525;
float currentdepth = sensor.depth();
float recquireddepth = -0.4;  //  set depth u wish to maintain in meters

void setup() {
      Serial.begin(9600);
     vertical_thruster.attach(6);
     vertical_thruster.writeMicroseconds(1500);
 /////////////////////////////////////////////Bar 30 Configuration ////////////////////////////////////////
  Serial.println("Starting");
  Wire.begin();
 while (!sensor.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
    Serial.println("\n\n");
    delay(2000);
  }
  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
}

void loop() {

  sensor.read();
  Serial.print("Depth: ");
  Serial.print(currentdepth);
  Serial.println("m");
error = (currentdepth) - (recquireddepth) ;

if ( error!=0)
  { pwm +=5;
    vertical_thruster.writeMicroseconds(pwm+=5);
    Serial.println( pwm+=5);
    Serial.print ( " Submerging ");
  }
if ( error=0){
  vertical_thruster.writeMicroseconds(pwm);
  Serial.print ( "  At Depth");
}
else if ( error >-0){
  vertical_thruster.writeMicroseconds(1400);
  Serial.print ( "resurfacing");
  delay(1000);
}
}


texts: Can connect to esp8266 AP which is connected to Arduino UNO but no response

texts:
I am new to arduino and am trying to connect the esp8266 to arduino UNO and send commands to the arduino using an android phone.
I have double, triple checked the connections and I am sure they are 100% correct. I have connected esp GND to arduino GND, esp VCC to arduino 5V, esp TX to arduino SoftwareSerial RX and esp RX to arduino SerialSoftware TX and CH_PD to 5V. I can connect to esp using my phone but I can't send commands to it. I am using TCP/UDP Terminal on android to test the connection. Phone is connected to the AP but in the app it is not. I configured the app with 192.168.4.1 IP and 333 Port and I know that app works correctly because I have tested its integrity several times before.
I have searched so much and tried so many but non worked.

My code:

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

boolean FAIL_8266 = false;

#define BUFFER_SIZE 128
char buffer[BUFFER_SIZE];

void setup() {

  Serial.begin(9600);
  ESP8266.begin(115200);  // change this value to your wifi module (esp8266) baud rate

  do{
  ESP8266.println("AT");
    delay(1000);
    if(ESP8266.find((char*)"OK"))
    {
      Serial.println("Module is ready");
      delay(1000);

      //configure ESP as AP
      Serial.println("AT+CWMODE=2");
      delay(1000);

      //Set multi connections
      Serial.println("AT+CIPMUX=1");
      delay(1000);

      Serial.println("Server setup finish");
      delay(1000);

      FAIL_8266 = false;

    }
    else{
      Serial.println("Module have no response.");
      delay(500);
      FAIL_8266 = true;
    }
  }while(FAIL_8266);

  ESP8266.setTimeout(100);

}

void loop() {

  if(ESP8266.available()){
    String msg = ESP8266.readString();
    Serial.println("MSG: "+msg);
  }
}

Could anyone please tell me what is wrong?


texts:
I'm working on an RFID system using a MFRC522 with this Library : https://github.com/miguelbalboa/rfid
Here's the code I have right now:

int A=(mfrc522.uid.uidByte[0]);
int B=(mfrc522.uid.uidByte[1]);
int C=(mfrc522.uid.uidByte[2]);
int D=(mfrc522.uid.uidByte[3]);

Serial.println("UID is %x %x %x %x", A, B, C, D);

This results in the following output:

UID is 35 C5 5A 59

My issue is - how do I first reverse that UID : from 35 C5 5A 59 to 59 5A C5 35
- and second convert and print the corresponding decimal value of that reversed UID. In this case, it would be 1499120949.

I should mention that I need it as a string at the end to add it to the end of a POST command.


texts: Very Basic Arduino Uno Serial.readString() operation

texts:
I am very new to Arduino Programming.
I am trying to identify the input string from serial monitor and printing the output to the console accordingly

Code is :

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

void loop() {

   while (Serial.available() > 0 ) {

     String str = Serial.readString();

     if (str.equals("send")) {
        Serial.println("identified");
     } else {
        Serial.println("unknown");
     }

   }

}

Whenever i put send string it is showing "unknown" as the output, which is wrong, and i should get "identified" as the output.
Can anyone guide me here to achieve the result.

Note : I am getting output as i wanted by using readStringUntil function but the strings has a lot of "." in it, hence not useful.


texts: _delay_ms() is much slower than expected (by a factor of 6) on TinyAVR 0/1 (ATTiny1604)

texts:
I designed a custom AVR development board using the Atmel ATTiny1604 microcontroller. It belongs to the new Tiny-0 family, due to its recentness, some required changes to relevant toolchains have yet to be included into the stable version  (I prefer to use the original upstream toolchains instead of Atmel/Microchip's SDK). Thus, I compiled the latest versions of toolchains from source. They include...

AVR GCC 10.2.0

avr-libc, svn trunk, with patch avrxmega3-v10.diff applied

After I installed the toolchains, I wrote a LED blinking program to verify whether my toolchain was working properly. The program was built with avr-gcc -mmcu=attiny1604 -Wall -Os -o blink.elf blink.c -Wl,--section-start=.text=0x200 and uploaded via the Optiboot_X bootloader.
#define F_CPU 20000000UL
#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    PORTB.DIRSET = 0b00000001;

    while (1) {
        PORTB.OUTSET = 0b00000001;
        _delay_ms(500);
        PORTB.OUTCLR = 0b00000001;
        _delay_ms(500);
    }
}

However, I found that _delay_ms(500) doesn't work as expected. Instead of a 500-millisecond delay, the actual delay is closer to 3000 milliseconds as seen on the oscilloscope, it has been slowed down by a factor of 6.

I've double-checked my fuse settings.
$ pyupdi -d tiny1604 -c /dev/ttyUSB0 -fr
Device info: {'family': 'tinyAVR', 'nvm': 'P:0', 'ocd': 'D:0', 'osc': '3', 'device_id': '1E9425', 'device_rev': '0.0'}
Fuse:Value
0:0x00
1:0x00
2:0x02
3:0xFF
4:0x00
5:0xF6
6:0x07
7:0x00
8:0x02
9:0xFF
10:0xC5

I saw pyupdi reported that the fuse OSCCFG (No. 2) has been programmed to 0x02, which according to the datasheet, means "Run at 20 MHz with corresponding factory calibration". Why do I get incorrect delays even when the system clock is running at the correct speed? Is my toolchain broken?
Note: This is a question I already solved. But consider there are relatively few tutorials about the new TinyAVR 0/1 on the web, I posted the question and answer here to serve as a reference for the community.


texts: Measure small capacitances with ATtiny85 (Digispark board)

texts:
I have successfully run the code provided here on an Arduino Nano. If nothing is connected, it will output a very small capacitance (~ 1 pF).

Then I tried to migrate the code to the ATtiny85 (using a Digispark USB Development Board), but I fail to get anything reasonable out of the code. The first analogRead will always give 1023, whereas on the Nano it gives a very small value (again for nothing connected to the input pins).

It's a bit trickier on the ATtiny85 because the pin numbers are different for digital and analog, but I thought I got that right, so what went wrong in the migration?

const int OUT_PIN = 2; // digital pin PB2 is 2, positive pin of C
const int IN_PIN  = 5; // digital pin PB5 is 5, negative pin of C
const int OUT_ANA = 1; // analog read PB2 is 1
const int IN_ANA  = 0; // analog read PB5 is 0

const float IN_STRAY_CAP_TO_GND = 24.48;
const float IN_CAP_TO_GND  = IN_STRAY_CAP_TO_GND;
const float R_PULLUP = 34.8;
const int MAX_ADC_VALUE = 1023;

#include "DigiKeyboard.h"

void setup() {
  pinMode(1, OUTPUT);
  pinMode(OUT_PIN, OUTPUT);
  pinMode(IN_PIN, OUTPUT);
  digitalWrite(OUT_PIN, LOW);
  digitalWrite(IN_PIN, LOW);
  DigiKeyboard.update();
}

void loop() {

    pinMode(IN_PIN, INPUT);
    digitalWrite(OUT_PIN, HIGH);
    int val = analogRead(IN_ANA); // IN_PIN in Nano version
    digitalWrite(OUT_PIN, LOW);

    DigiKeyboard.println(val);
    if (val < 1000) {
      pinMode(IN_PIN, OUTPUT);
      float capacitance = (float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val);
      DigiKeyboard.print(capacitance);
      DigiKeyboard.println(" pF");
    } else {
      pinMode(IN_PIN, OUTPUT);
      delay(1);
      pinMode(OUT_PIN, INPUT_PULLUP);
      unsigned long u1 = micros();
      unsigned long t;
      int digVal;

      do {
        digVal = digitalRead(OUT_PIN);
        unsigned long u2 = micros();
        t = u2 > u1 ? u2 - u1 : u1 - u2;
      } while ((digVal < 1) && (t < 400000L));

      pinMode(OUT_PIN, INPUT);
      val = analogRead(OUT_ANA); // OUT_PIN in Nano version
      digitalWrite(IN_PIN, HIGH);
      int dischargeTime = (int)(t / 1000L) * 5;
      delay(dischargeTime);
      pinMode(OUT_PIN, OUTPUT);
      digitalWrite(OUT_PIN, LOW);
      digitalWrite(IN_PIN, LOW);

      float capacitance = -(float)t / R_PULLUP / log(1.0 - (float)val / (float)MAX_ADC_VALUE);

      if (capacitance > 1000.0) {
        DigiKeyboard.print(capacitance / 1000.0);
        DigiKeyboard.println(" uF");
      } else {
        DigiKeyboard.print(capacitance);
        DigiKeyboard.println(" nF");
      }
      DigiKeyboard.println(val); // usually ~ 520 (because we wait until digVal == 1?)
      DigiKeyboard.println(t); // depends on C: ~ 26000 for 1 µF, ~ 2600 for 100 nF, ~ 250000 for 10 µF
  }

  digitalWrite(1, 1);
  delay(10);
  while (micros() % 1000 != 0);
  digitalWrite(1, 0);

}


texts:
I have an Arduino Uno R3 board and after some time not in use it seems to have corrupted. My code is below, basically I want to rotate a servo 90 degrees every 12 hours but as soon as I plug it in the servo starts rotating non-stop. Have tried multiple delay steps and shortening and lengthening the write but the same effect happens.

#include <Servo.h>

Servo myservo;

void setup {
  myservo.attach(10);
}

void loop() {
  myservo.write(90);
  delay(3600000);
}


texts: Power on, power off voice using fx board

texts:
I played with one of those Adafruit FX sound boards in a project a while ago, and see a lot of potential uses for it.
I would like to create “something” for my daughter, when she turns the lights on, (110v bedroom lights) a voice may say “good evening Kyndra” and when she turns the lights off the voice may say “have a good day...”.
The power “on” is not a big problem, the power off is my issue.... I could run a separate circuit and use a solid state off delay that when it sees first circuit go down it triggers a line of code.
With all the new stuff coming out all the time, just wondering if anyone else has a better idea to build a poor mans version “Jarvis 1.0”.  Perhaps using an Arduino may not even be the route I want.

This is just a thought... I’ve been tossing over for a while now.  It’s not imperative it ever gets built. Just thought it would be cool for her.


texts: Using external power supply to power leds on multiple pins (A0-A5)

texts:
I'm totally new to Arduino, and microcontrollers for that matter, so I'm having a hard time figuring out how to connect LEDs to multiple pins, but using a common external power supply...

I've created a starting light that's connected to pin A0-A4 + A5 (turn all LEDs on). I hooked each LED to its own pin directly (A0-A4) for the countdown part ("5, 4, 3, 2, 1, ..."), and then 5 additional LEDs to pin A5 ("GO!").

For the countdown part, when only one LED is on at a time, there's enough power. But if I were to light them all up at the same time, there won't be. So I figured that I should put a relay into the mix for that part, and have them draw power from an external 12 V power supply.

I did manage to make the relay work in the circuit - switching all LEDs on/off, and getting power from the external power supply, but only through one pin.

I'm not sure how to have the start lights use an external power supply, and at the same time get signals from multiple pins. How do I do that?

I'm sorry if my description is unclear. So please let me know if you need more information.

The LEDs are 3.4 V 20 mA.
The power supply I'm planning to use is 12 V.

I'm planning to have this start light - which is built in its own casing - use its own power supply, while the Arduino is running of the power from USB. So all I want to do, is to have the signals sent over to this starting light unit, and not power and ground.

UPDATE:

Here's a quick overview of how I'm testing this whole thing at the moment:

The 5 red countdown LEDs (red) is getting powered by the board itself through the pins, while the 5 "GO!" LEDs (green) are getting powered from a 12 V power supply since they're all are going to be turned on simultaneously.

My question is how I can get both the 5 red LEDs, that uses separate pins, to get powered from the external power supply as well?

Since all the LEDs are built in its own casing, apart from the microcontroller because that also handles other stuff...

Did that make any more sense at all?


texts: Arduino Mega: Interrupt not working? Use any pin for interrupt?

texts:
I am using an arduino mega. I'm trying to use interrupts in one of my programs.
I have 8 pins that I will need to make separate interrupts for.

The pins are 40 - 47. These pins are attached to limit switches, so when the limit switch is pressed or not it'll indicate that via digitalRead().

#define switch_1 43     // Pin 43 is connected to Switch 1 (1: X+)
#define switch_2 42     // Pin 42 is connected to Switch 2 (1: X-)
#define switch_3 41     // Pin 41 is connected to Switch 3 (1: Y+)
#define switch_4 40     // Pin 40 is connected to Switch 4 (1: Y-)
#define switch_5 46     // Pin 46 is connected to Switch 5 (2: FR)
#define switch_6 47     // Pin 47 is connected to Switch 6 (2: BL)
#define switch_7 45     // Pin 45 is connected to Switch 7 (2: BR)
#define switch_8 44     // Pin 44 is connected to Switch 8 (2: FL)
int interruptVar = 5;

In my set up function I have:

attachInterrupt(digitalPinToInterrupt(switch_6), tightenStrings1, CHANGE);

Then I have:

void tightenStrings1()
{
  interruptVar = 9;

}

When I change the status of the limit switches, by pressing them or unpressing them, this function never activates. The variable interruptVar is still 5.

What am I doing wrong?

Also, Serial isn't the problem in this case. I understand now not to use it though, but still doesn't solve the problem. Additionally I tried instead of CHANGE using RISING or FALLING and still no changes.

I have a feeling it's because the pins I'm using aren't technically interrupt pins...is there a way to make them usable as interrupt pins? I'm not allowed to change the pins being used, and using an interrupt is the best solution for the coding portion I'm working on.


texts: How to stole/read data from an output serial port?

texts:
(Sorry, I'm not a native English speaker)

I have a chip with Serial Input, Serial Output, and a Clock (used by both serials). I want to read the output with an Arduino or ESP-32.

The device I want to read is: https://statics.cirrus.com/pubs/proDatasheet/CS5460A_F5.pdf

How can I do this? I don't have too much expertise in serial communication.

Do I need anything else?

I would appreciate any help.


texts:
I plan to make an air quality monitoring system that uses Arduino uno, but I can't decide how I will be able to distribute the air condition and harmful gas concentration info and have it available to other people.

Aside from using a GSM module to text individual persons and making a new website to chart the data from the Arduino, what else can I use to receive information that my Arduino sensed to people's smartphones/computers wirelessly?


texts: How to transmit more than 1 byte continually?

texts:
In software serial, the write function only sends 1 byte at a time. Is there someway, some library, that i can send multiple bits/bytes, without stopping (and not using digitalWrite)? i want to be able to transmit at least 16 bits as opposed to just 8.

I know i can send 2 bytes, or even 100 bytes. But the thing i'm trying to do is, implement my own LDPC(error correction) codes on the Arduino. Therefore, i'm taking a lot of channel measurements. One of them is figuring out how the error happens during the delay between the stop bit and the next startbit. Often times, this is were synchronization problems occur. So I'm trying to track this down. Hence why, I need to send more than 8 continuous bits. In software serial, it transmits 8 bits, then transmits the stop bit. then write() restarts on the next call. Instead of this, i just want to send more bits, like 64 bits for instance, and look at the BLER on the received data. (the reason why I'm staying away from hardware serial is because i'm doing this with wireless RF modules) Do you guys have any further info regarding this? I'm very grateful! Thank you so much!

Also, it was suggested that I write my own softwareserial, but that's a pretty daunting task. I would like to avoid it, if i can.

EDIT: Let me show you my data.
So, I'm constantly transmitting the values; 123,124,125,126.

1111011
1111100
1111101
1111110

The above 4 lines repeat about 2 times. Then, suddenly, it synchronizes incorrectly, and the following 4 lines are being constantly repeated.

11110101
11111001
11101101
11110001

It never syncs back to the original 4 transmissions. Now, inside the unsynced block of 4 transmitted bytes, there are fragments of the correct transmission inside. For instance, start from the 2nd bit of the 3rd byte of the correct transmitted byte. Now, if you account for the '0' start bit, and try to matchup the bits, the correct bits are being picked up in the correct order. It's just a problem of what the receiver takes as the startbit.

As i'm typing this edit, i realized something else. What i said in the above paragraph is true, then for the unsynced block, there should be a '0' start bit in front. Now, if the messages match up exactly, and if the 0 start bit that is being transmitted is being treated as a payload, then which 0 is being treated as the startbit, because all the bits between the synced and unsynced data are matched up. However, there should be one missing 0 each time because it's being read as a startbit, not databit.

Sorry if this is convoluted. Happy to clarify any part of it. Thank you so much!!


texts: Create one server in AP mode and another in station mode

texts:
I'm trying to connect one ESP8266 to WiFi as a WebServer in station mode and to another ESP8266 as a server (that has no web pages) in AP mode.

The problem is both servers are being created in AP mode, between the ESP's, while one of them (the webserver) should be created in station mode and accessible from WiFi. The only way I can reach the webserver is connecting to the AP and accessing its IP (as access point) from my computer.

What I wanted was to access the webserver connected to my WiFi using the IP that my router gave to the hosting ESP, while the two of them would communicate using the server without web pages.

I've already tried using the same IP for both servers, inverting the order of creation of the servers and using both ESP8266WiFi.h and ESP8266WebServer.h. I've read something about the later not working with too much code inside the loop and, since the web page I want is pretty simple, I'm using ESP8266WiFi.h. Here's my code:

#include <ESP8266WiFi.h>
//#include <ESP8266WebServer.h>

WiFiServer internalServer(81);
WiFiServer externalServer(80);
//ESP8266WebServer externalServer(80);
IPAddress IP(192, 168, 4, 15); // Default IP for the AP mode, the one I'm using.
IPAddress mask = (255, 255, 255, 0);
WiFiClient internalClient;
WiFiClient externalClient;

void setup() {

  Serial.begin(115200);

  pinMode(LED_BUILTIN, OUTPUT);

  WiFi.mode(WIFI_AP_STA);

  // Config. AP mode:
  WiFi.softAP("my-access-point", "my-password");
  WiFi.softAPConfig (IP, IP, mask);

    // This connection is ok:
  internalServer.begin();
  Serial.println("Internal server created.");
  while (!internalClient) { // waiting for the internal client to connect before continuing. This works fine.
    internalClient = internalServer.available();
  }
  Serial.println("Internal client found.");

  // Config. STA mode:
  Serial.print("Connecting to Wi-Fi");
  WiFi.begin("my-wifi", "my-wifi-password");
  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    delay(500);
  }
  Serial.println(" Ready.");

  // Config. external server.
    // This connection isn't working
  externalServer.begin();
  Serial.print("External server created with IP: ");
  Serial.println(WiFi.localIP()); // This is the IP I expected to use to connect to the external server.
                                  // But it is accessible at 192.168.4.15.

void loop() {
  // handling external client:
  externalClient = externalServer.available();
  if(!externalClient) { return; } // proceed only when there is a request.
  String request = externalClient.readStringUntil('\r');
  Serial.println("Request: " + request);

  // The answer is just a hello world:
  String answer = "..."
  externalClient.println(answer)
  Serial.println("Answer: " + answer);

  handleInternalClient();
}

The internal client is supposed to turn on the builtin led when it receives "on" from the server and turn it off when it receives "off", and that is working fine so I think the code for it isn't necessary. If you need it, please ask.

What I want is the other ESP talking to this one through 192.168.4.15 in the AP network and my computer talking to it through whatever IP my router gives to it, in my WiFi.


texts:
This is the idea. I have 2 Arduinos. One with an IR LED and the other with an IR receiver. I want to read the values of multiple sensors and transmit it to the other Arduino via IR. I know how to send data like a fixed HEX code but I dont know how to send values from a potentiometer.

Just think of how a quadcopter sends and receives data from the joysticks, thats somewhat what I want to do.

[EDIT]

This is a precision of what I want to do. I'll read the values of let's say 2 potentiometers, map the values from 0-99, and then I want to send it to the other Arduino with IR and not anything else.


texts: WS2812B LED strip + Arduino First Pixel keeps dying/breaking

texts:
I am trying too hook up a WS2812B LED strip to an arduino nano. The current strip consists of 6 pixels, and the whole thing is powered via a 5.26V Pc power supply.

The problem is that the first pixel keeps dying after about 1 minute. This means i have to cut the strip and re-solder the connections. Before the failure, the strip runs the correct examples from the FastLED package.

As this happened I looked for solutions. https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices suggested:
1) adding a 1000 µF capacitor between ground and  +5v to cancel power peaks
2) adding a 300-500Ohm resistor between the strip_Data_in and D5

I had no 1000µF+ Capacitor, so i used what i had, a 470µF, and installed it with the resistor.

This did not solve the problem. Another recommendation was to place a diode between the data and +5. ( I think this is to remove any power spikes in the data connection. With a good power supply this should not be necessary i guess, but it couldn't hurt.) Another tip was to add a 100kOhm resistor between data and ground.

putting all mentioned above together gives something like this:

But in the end nothing changed. I tried alot of variations of solutions:

With and without condensator between ground and Vin.
With and without resistor between data and arduino, and varied it between 220 Ohm to 1kOhm.
With and without the diodes. I tried connecting data with a diode to ground, +5v, to both, and to none.
I have tried using a 3.7V power source to see wether i could avoid burning the pixel. The Leds had too little power to light up.
I have tried powering via the USB->Arduino->Arduino +5v pin -> strip +5v

Any Idea where i might be fucking up?

I have burnt 30 pixels so far, with all the same result: blinking, tripping, and eventually failure. Removing the first LED always fixed the problem. This brand of LEDStrip did work on some other premade controller.

Some of my own ideas, of causes:

There really needs to be a 1000µF Capacitor. (i have never had trouble with voltage peaks with this powersupply, and this does not explain why the system fails after some time, instead of at plugin.)

EDIT 1):
I did some additional tests.

Raised the resistor before the data pin, from the recommended 470 Ohm, as high as possible. I reached 8kOhm (higher did not work). -> Same result, burned pixel
Lowered the voltage on the Data input pin, with two resistances, one connected to ground. The LedStrip only recognised data input when the ''Din_High'' was above 3.5 volts. Running at a bit lower voltage stopped the leds from recognising data. Yet still, Same result -> Burned pixel.
Changing the power supply: I changed the PC power supply to a 5V Power bank for loading celphones. The voltage this device was regulated to was between 5.2 and 4.8V. The behaviour was the same -> Burned pixel.

I would guess that IF:

the 5V is stable and within 5.5 and 4.5V And
The Din is within 0 and 5V

The cable should be unable to break itself right?


texts:
Everyone, I am new to this. Currently I am trying to make a Whack-a-mole game for my school project. There will be a total of 6 moles (corresponding to 6 LEDs, which will light up randomly). At each moment, there will only be one LED lit up. The whole game duration is 30 seconds. At the end of the game, the score will be displayed.

I use a piezo electric sensor to detect the knock of the user. I program it in such a way that if the reading of the piezo sensor is greater than 50, it will take it as knock, and if the user knocks it correctly, one point will be awarded.

But unfortunately my code isn't working. The score displayed appears to be random numbers, doesn't work as it is supposed to be.

Here is my code, please hep me to have a look and provide me with some guidance. Thank you.

unsigned long time_since_reset;
int previousNum=0;
int currentNum =0;
int randomGenerator (void);
void light(int port);
int checker(int port);
int score =0;

void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  time_since_reset = millis();
  while((millis()-time_since_reset)<30000) {
    randomSeed(analogRead(0));
    currentNum = randomGenerator();
    light(currentNum);
    checker(currentNum);
  }
  Serial.println("End Game");
  Serial.println(score);
}

int randomGenerator(void) {
  int cNum;
  cNum = random(3, 8);
  if(cNum!= previousNum) {
    return cNum;
  }
}

void light(int port) {
  digitalWrite(port,HIGH);
  delay(1000);
}

int checker(int port) {
  jump:
  int mole1 = analogRead(0);
  int mole2 = analogRead(1);
  int mole3 = analogRead(2);
  int mole4 = analogRead(3);
  int mole5 = analogRead(4);
  int mole6 = analogRead(5);
  while(mole1<10 && mole2<10 && mole3<10 && mole4<10 &&mole5<10 &&mole6<10) {
    goto jump;
  }
  if(mole1>50 && port == 3) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole2>50 && port == 4) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole3>50 && port == 5) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole4>50 && port == 6) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole5>50 && port == 7) {
    score++;
    digitalWrite(port, LOW);
  }
  if(mole6>50 && port == 8) {
    score++;
    digitalWrite(port, LOW);
  }
}


texts: LED fade class strobes for unknown reason

texts:
Okay, so here is what I'm trying to accomplish:

I have four LEDs, under my fish tank, that I want to fade in and out.  I want each LED to fade at a different rate, start at a different "brightness" with PWM, and get a "new" fade-rate every once in a while.  Ultimately, it'll make the bottom of the fish tank "pulse" in a "natural" way.

The code I'm using to accomplish this can be found in my GIT repo.  There is also a GIF of it "working," there.

Now, here is my problem:

Every once in a while, one of the LEDs (not a specific one) will stop fading and start blinking like a strobe light.  I'm not sure what's causing this blinking, since it seems to happen randomly.

The other three LEDs seem to continue to fade in/out while the "bad" LED is spaz-ing out, and it doesn't seem to be isolated to a specific LED.  It also doesn't seem to affect only one LED at a time, although it's usually only one LED "blinking" and any given time... but I have seen two going at the same time.

It also doesn't seem to be specific to the "high" or "low" PWM levels, either... it can happen at "bright" levels, "dim" levels, or even in the middle of the fading transition.

Here's what I've tried:

I've tried different Arduino boards, and I've taken the LED count down to a single LED.  I've changed variable types from bytes to ints, and back and forth with that tactic.  I've been combing through this sketch all day, and I don't see anything that stands out to me as causing the problem.

So, now I'm turning to you all, hoping that someone will be able to see where I've screwed up my code.

Thank you, in advance!

EDIT:  Since I've been asked for direct posting of my code, instead of just a link to the source code:

Here is the main .ino file:

#include "led_controller.h"

// Set pin numbers for each LED
byte led1 = 3,
           led2 = 6,
           led3 = 9,
           led4 = 11;

void setup(){
    pinMode( led1, OUTPUT );
    pinMode( led2, OUTPUT );
    pinMode( led3, OUTPUT );
    pinMode( led4, OUTPUT );
}

// Initialize our four classes for our four LEDs
LED a( led1 ),
    b( led2 ),
    c( led3 ),
    d( led4 );

void loop(){
    a.ledChange();
    b.ledChange();
    c.ledChange();
    d.ledChange();

    delay( 60 );
}

And the header file with the class:

// Create our custom LED class
class LED{
    private:
        // Set higest and lowest brightnesses for LEDs
        byte highest = 250,
             lowest = 5;
        byte pin, brightness, isNeg; // Random necessary variables
        int change; // Set the inc/decrement rate for the LED
        int checkNeg(); // See if our change rate is negative, or not
        void changeChange(); // Get a new change rate
    public:
        LED( byte led ); // Define our constructor
        void ledChange ();
};

// Define our constructor
LED::LED( byte led ){
    pin = led;
    changeChange();

    // Set the initial LED brightness by random
    brightness = random( lowest, highest );

    // Randomly determine if the LED will start brightening or darkening
    if( random( 1, 2 ) == 1 )
        change *= -1;
}

// Get a new change rate
void LED::changeChange(){
    change = random( 1, 4 );

    if( isNeg )
        change *= -1;
}

int LED::checkNeg(){
    if( change < 0 )
        return 1; // If `change` is negative, return true
    return 0;
}

void LED::ledChange(){
    // Flip LED change value between brightening and darkening
    if( brightness <= lowest || brightness >= highest ){
        change *= -1;

        isNeg = checkNeg(); // Determine if we're brightening/dimming the LEDs

        // A 1-in-25 chance to change the fade-rate
        if( random( 25 ) == 13 )
            changeChange();
    }

    brightness += change; // Adjust the LEDs brightness

    analogWrite( pin, brightness ); // Brighten/darken the LED
}


texts: Determining if an LED on another device is on

texts:
I'd like to check if this circuit I'm making is correct -- I'm concerned I'll mess up my Arduino. Essentially, I would like to determine if an LED on another device is on or not by measuring the current etc running through it. I know that device uses a CR2032 watch battery, with 3V and 220 mAH. I'd rather not do this using a photosensor since there will usually be a lot of ambient light.

I looked at this answer, and tried to adapt its circuit, which looks like this:

The solution I came up with would look like this on a breadboard:

Not pictured is the existing connections to the two leads of the LED of the device, which send current through it.

I was hoping that with this setup I could measure the current hitting the analogue input of my Arduino when the LED is turned on by the device, and in doing so figure out when the device LED is on.

Does this circuit seem accurate, or is there something I need to change? Thank you!

Edit:

Would this simpler circuit work, given that the device only has 3Vs?


texts:
I have a project that uses timers and interrupts frequently. A lot of CPU time is spent handling ISRs over an extended period of time.

Would this affect code inside the main loop that relies on the millis() function since a significant amount of time is spent processing the ISRs?


texts: max current while using a shift register

texts:
In arduino's official page about ShiftOut https://www.arduino.cc/en/Tutorial/ShiftOut, a drawing with two 74HC595 powered by the arduino board, is displayed.

Since the resistors are 220Ω, the total current should be 5/220x16 = 0.36A which exceeds the maximum total current of 0.20A for the arduino device.

So, could someone turn on simultaneously 16 LEDs using two shift registers without damaging the device?

Thank you


texts: How to send 2 data to processing from Arduino

texts:
I am new to Arduino and processing so sorry for any mistakes.
I have a problem with sending multiple data to processing from Arduino. I can send 1 data easily ut I can't send more than 2 data can somebody help?!??.
This is my Arduino code:

#include <DHT.h>
#define Type DHT11
int dhtpin =2;
float temopValC;
float temopValF;
DHT HT(dhtpin,Type);

#include <Servo.h>
int servopin=9;
int servopos;
Servo servo1;

int trigpin=10;
int ecopin=11;
float distance;
float spedd=343;
float timee;

void setup() {
Serial.begin(9600);
HT.begin();
delay(200);
pinMode(trigpin,OUTPUT);
pinMode(ecopin,INPUT);

servo1.attach(servopin);

}

void loop() {

 temopValC=HT.readTemperature();
 temopValF=HT.readTemperature(true);

spedd =331.3 +(0.6 *temopValC);
//Serial.println(spedd);

 /*Serial.print("Temp C/F "); //temp val
 Serial.print(temopValC);
 Serial.print("   ");
 Serial.println(temopValF);
 delay (1005);*/

for(servopos=0;servopos < 180; servopos +=1 ){

digitalWrite(trigpin,LOW);
 delayMicroseconds(2000);
digitalWrite(trigpin,HIGH);
 delayMicroseconds(15);
digitalWrite(trigpin,LOW);

timee=pulseIn(ecopin,HIGH);
timee= timee /1000000.;
timee= timee /3600.;

distance= spedd * timee;
distance = distance /2;
distance = distance * 63360;//inch
distance =distance *2.54; //cm
distance= distance *2;

 //Serial.print(distance);
 //Serial.print("  ");
 // delay(200);

  servo1.write(servopos);
  //delay(100);
 // Serial.print(servopos);
  //Serial.println("  ");
   delay(100);
  }
for(servopos=180;servopos >= 1; servopos -=1){

digitalWrite(trigpin,LOW);
 delayMicroseconds(2000);
digitalWrite(trigpin,HIGH);
 delayMicroseconds(15);
digitalWrite(trigpin,LOW);

timee=pulseIn(ecopin,HIGH);
timee= timee /1000000.;
timee= timee /3600.;

distance= spedd * timee;
distance = distance /2;
distance = distance * 63360;//inch
distance =distance *2.54; //cm
distance= distance *2;

// Serial.print(distance);
// Serial.print("  ");
//delay(200);
  servo1.write(servopos);
 //delay(100);
 // Serial.print(servopos);
  //Serial.println("  ");
  // delay(100);
}

/*if(distance < 14.28){
  Serial.println("..............o");
  delay(800);
  }
 if(distance> 14.28){
  Serial.println(" h  ");
  delay(800);
  }

  if(distance== 14.28){
    Serial.println("i   ");
    delay(800);
    }

*/

}

And this is my processing code for one data:

    import processing.serial.*;
Serial mySerial;

String mystring= null;
int nl=10;
float myVal;

void setup(){
size(800, 600);
String myport= Serial.list() [2];
mySerial=new Serial(this,myport,9600);

}

void draw(){

while(mySerial.available() >0){

  mystring =mySerial.readStringUntil(nl);

  if(mystring != null){
  background(0);
  myVal=float(mystring);
  println(myVal);
  }
}
ellipse(250,myVal,10,10);
rect(0,0,20,10);
rect(0,40,20,10);
rect(0,80,20,10);
rect(0,120,20,10);
rect(0,160,20,10);
rect(0,200,20,10);
rect(0,240,20,10);
rect(0,280,20,10);
rect(0,320,20,10);
rect(0,360,20,10);
rect(0,400,20,10);
rect(0,440,20,10);
rect(0,480,20,10);
rect(0,520,20,10);
rect(0,560,20,10);
rect(0,600,20,10);

}

I want to change the x value of the ellipse with the second data fromthe Arduino.


texts: Using digital weighing scales with INA125p

texts:
Complete electronics beginner here. I'm attempting to build a weighing scale with an Arduino.

I'm attempting to follow this tutorial, with the shield that they use.

I've arranged my load cells on the scale into a Wheatstone Bridge, and I can get some readings just by taking a voltage reading from the two cells marked V+ and V-. The board has terminals that are linked to a INA125p, and the pins should give an amplified reading.

Pin A1:0.96
Pin A2:1.42
Pin A3:5.00
Pin A4:5.00
Pin A5:5.00

Regardless of whether I have the scale wired in or not, I get these readings from the individual pins. The scales seem to be able to take power from the Arduino shield.

The scales that I have are different from the ones in the example. From what I can figure out, the yellow cables that they reference turn their particular scale on when weight is put on it.

I've put the wires where I take the reading into the 2 and 4 terminals on the circuit board that they have (where the tutorial references a differential signal), but again, it makes no change.

  unsolder or cut the white wire that is referred to as G3 (Wheatstone bridge mass) on the original printed circuit, extend take it to terminal 1 on the new printed circuit;

  unsolder or cut the white wire that is referred to as G2 (Wheatstone
  bridge positive) on the original printed circuit, extend take it to
  terminal 3 on the new printed circuit;

  unsolder or cut the white wire that is referred to as G1 and G4 on the
  original printed circuit, extend take it to terminal 4 and 2 on the
  new printed circuit (differential signal on the Wheatstone bridge)

I've attempted lots of different combinations of cables and terminals on the new circuit, but it appears to make no difference to the readings.

My question is:
Based on the tutorial and the drawing above, am I taking the readings from the correct place? Are there any things I'm obviously doing wrong with the circuit itself?
If the circuit is correct, how would I go about trying to get correct readings from the scale when I add weight to it?

I apologise for the vague nature of this question, but I am a complete beginner trying to figure this out, and I am struggling to follow the tutorial. I'll try and provide any additional information that you need.

EDIT - I have a Salter SAL-3003 SSSVDR08 scale.

Each load cell has 3 cables, Red, Black and White. The red ones are the ones marked with the V+, V- etc. On the original board, they were wired in threes.


texts: How to convert Arduino GSR values to microsiemens?

texts:
In my project Arduino provides value range between 0-1024. I need to convert this serial value to a standard µSiemens value to measure emotional stress.

Can anybody point me to an answer that would give an appropriate equation for the conversion?


texts: Arduino - My problem is when the condition is greater than 900.00 it will continue the loop and do the code below once

texts:
I want is to stop the loop and when it read  Greater than 900.00 again it will do task again.

I need condition. When it back to greater than 900.00 the code below will do task and then it will stop. And when it will reach the condition again it will do the code again and it will stop .. Please help me

void loop(){
  float reading = analogRead(LIGHTSENSORPIN); //Read light level
  float square_ratio = reading / 1023.0;      //Get percent of maximum value (1023)
  square_ratio = pow(square_ratio, 2.0);      //Square to make response more obvious

  analogWrite(LEDPIN, 255.0 * square_ratio);  //Adjust LED brightness relatively
  analogWrite(LED_BUILTIN, 255.0 * square_ratio);  //Adjust LED brightness relatively
  Serial.println(reading);                    //Display reading in serial monitor

if(reading >= 900.00){

  digitalWrite(smDirectionPin, LOW); //Writes the direction to the EasyDriver DIR pin. (LOW is counter clockwise).
    /*Turns the motor fast 1600 steps*/
      for (int i = 0; i < 400; i++){
    digitalWrite(smStepPin, HIGH);
    delayMicroseconds(700);
    digitalWrite(smStepPin, LOW);
    delayMicroseconds(700);
}
}

  delay(1000);

}


texts:
I’m completely new to arduino, so be polite. I’m trying to program my esp32 to drive neopixels as seven segment display. So I take a digit and pass it to switch case and in switch case I mention which led number should be lit.
`

function showDigits(digit){

switch(digit){

 case 1:
   int a[]={1,3,4,.....};
  break;

 case 2:
    int a[]={1,3,4,6,8,...};
   break;
  .
  .
  .
default:
   int a[]={1,2,3,4,5,6,7,8,9,....};
  }
}

Now this is throwing multiple errors including redeclare of array a in same scope. Is there any better way to code this?


texts:
I am trying to build a ZigBee network using XBee Pro S2 devices (API Mode).
Setting up the network and sending packets is easy enough.

Is it possible to trace the route a packet travelled from the end-device to the coordinator?

Example:
I have 2 routers, one in area A connected to the coordinator, and the other in area B connected to the router in area A. End-device enters area B, and transmits a packet to the coordinator. Path: end-device->routerB->routerA->Coordinator.
Is it possible to know the end-device is in area B as it is the first router device the packet travelled through?


texts: What is the purpose of Serial.println() without an argument?

texts:
I am attempting to control a stepper motor with Sparkfun's Big Easy Driver, and I see the line "Serial.println();" they put in the example code. Why is there no argument and what function does this serve?

//Declare pin functions on Arduino
#define stp 2
#define dir 3
#define MS1 4
#define MS2 5
#define MS3 6
#define EN  7

//Declare variables for functions
char user_input;
int x;
int y;
int state;

void setup() {
  pinMode(stp, OUTPUT);
  pinMode(dir, OUTPUT);
  pinMode(MS1, OUTPUT);
  pinMode(MS2, OUTPUT);
  pinMode(MS3, OUTPUT);
  pinMode(EN, OUTPUT);
  resetBEDPins(); //Set step, direction, microstep and enable pins to default states
  Serial.begin(9600); //Open Serial connection for debugging
  Serial.println("Begin motor control");
  Serial.println();
  //Print function list for user selection
  Serial.println("Enter number for control option:");
  Serial.println("1. Turn at default microstep mode.");
  Serial.println("2. Reverse direction at default microstep mode.");
  Serial.println("3. Turn at 1/16th microstep mode.");
  Serial.println("4. Step forward and reverse directions.");
  Serial.println();
}


texts: Can you access the EEPROM of an ATtiny with Arduino Code?

texts:
I'm attempting to reduce the amount of RAM being used by my program by writing some values to the EEPROM of my micro controller. I'm currently programming on the ATtiny85 which has 512 Bytes of EEPROM. According to the documentation this is how you write to EEPROM:

#include <EEPROM.h>

void setup() {
  EEPROM.write(0, 1);
  EEPROM.write(1, 0);
  EEPROM.write(2, 3);
  EEPROM.write(3, 2);
  EEPROM.write(4, 1);

}

For some reason this isn't working for me and I can't seem to find the error. Am I programming this wrong or can the EEPROM of the ATtiny simply NOT be accessed with Arduino Code?

Here is the Datasheet: http://www.atmel.com/Images/Atmel-2586-AVR-8-bit-Microcontroller-ATtiny25-ATtiny45-ATtiny85_Datasheet-Summary.pdf

Here is the second sketch I'm using to test the EEPROM:

    #include <EEPROM.h>

void setup() {
  EEPROM.write(0, 1);
  EEPROM.write(1, 0);
  EEPROM.write(2, A3);
  EEPROM.write(3, A2);
  EEPROM.write(4, A1);

byte CLK = EEPROM.read(0);

}

void loop() {

  if(CLK == 1)
  {
    for(int i = 0; i < 3; i++)
    {
    digitalWrite(0, HIGH);
    delay(1000);
    digitalWrite(0, LOW);
    delay(1000);
    }
    exit(0);
  }
  else
  {
    for(int i = 0; i < 100; i++)
    {
    digitalWrite(0, HIGH);
    delay(1000);
    digitalWrite(0, LOW);
    delay(1000);
    }
    exit(0);
  }

  exit(0);

}


texts:
I'm using an Arduino Leonardo to interface with two pressure sensors and Python on my laptop, a MackBook Pro.

I'm using arduino IDE V. 1.5.4, Python V. 2.7.6, and OSX 10.8.5.

One pressure sensor is digital, using the Wire lib, and the other is analog.

My sketch compiles, runs, and works until I try to get the data in Python using pyserial.

If I try to grab a bunch of data using the readlines method in the scrip it will only return blank data or hang, depending on the serial object timeout settings. My python code sometimes works from the repl when I initialize the serial object and wait before reading from it.  If I don't wait the serial object will only partially fill a list and then any future reads will return an empty string.  This continues even after closing the serial object and reopening it in Python, or closing the serial object in Python and then opening the Serial Monitor in the Arduino IDE.  Once the serial port stops sending, I have to reset the Leonardo in order to read new data.

I could be running into some kind of buffering problem, but if that were the case I would expect future calls to return data.  Another option is that the Wire protocol is getting stuck and halting the program.

Here's my sketch

#include <Wire.h>

int ADDRESS = 0x28;//I2C address of sensor
int REQUEST = 4;//# of bytes to request from sensor
int BAUD = 19200;//serial rate
int PRESSURE_PIN = 1;

void setup()
{
  pinMode(A1, INPUT);
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(BAUD);  // start serial for output
}

void loop()
{
  Wire.requestFrom(ADDRESS, REQUEST);    // request 6 bytes from slave device #2

  Serial.print(analogRead(PRESSURE_PIN));
  Serial.print(',');

  while(Wire.available())    // slave may send less than requested
  {
     Serial.print(((unsigned int)Wire.read() << 8) + Wire.read());
     Serial.print(',');
     Serial.println(((unsigned int)Wire.read()) << 3) + (Wire.read() >> 5);
  }

  delay(10);
}

and here is how I read it from python

import serial

serial_port = '/dev/tty.usbmodem1a1221'
ser = serial.Serial(serial_port, 19200, timeout=0)

vals = [val.split(',')[0:2] for val in ser.readlines(1001*14)]


texts: How to send signal ONCE when within constant range of sensor?

texts:
I am working on a project to have a open/close a solenoid at certain ranges (using HC-SR04 ultrasonic sensor).

#include <NewPing.h>2

#define Relay1 7
#define Relay2 8

NewPing SonarRight(12, 11, 400);

void setup() {
  pinMode(Relay1, OUTPUT);
  pinMode(Relay2, OUTPUT);
}

void loop() {

  unsigned int uS1 = SonarRight.ping();
  delay(50);

  if (uS1 / US_ROUNDTRIP_CM > 15)
    digitalWrite(Relay1, HIGH);
    delay(100);
    digitalWrite(Relay1, LOW);
    delay(1000);

  if (uS1 / US_ROUNDTRIP_CM < 5)
    digitalWrite(Relay2, HIGH);
    delay(100);
    digitalWrite(Relay2, LOW);
    delay(1000);
}

I got the sensor to ping correct and the distances are reading accurately.  I have it to where once sensor reads that the object is more than 15cm away, the solenoid opens but it keeps clicking open until the object goes back to the dead zone (5-15cm).  Same thing when less than 5cm.  Essentially what i am trying to accomplish is to have the solenoid fill up a tank when the water level get low.  So when the water drops 10cm (x>15) the solenoid opens and then once the water is replenished (x<5), the solenoid closes.

How do i go about doing this without sending a constant OPEN/CLOSE to the solenoid?  Is there a way to make a loop to have it send a the signal only once until it exits that defined range?

Please note that i have not actually used it for its intended purpose im supply moving an object back and forth to simulate water distance.

Thanks


texts: Comparing a String after reading it from Serial fails

texts:
I have bought an Arduino starter kit online, everything seem to work but when I try for example to use ifs (and other conditional statements), the LEDs do not turn on. Here is a code for a little project I am currently working on:
int redpin = 3;
int greenpin = 2;
int bluepin = 4;
String color;
String msg = "Insert color: ";

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

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(msg);
  while (Serial.available() == 0) {}
  color = Serial.readString();

  if (color == "red") {
    digitalWrite(redpin, HIGH);
    digitalWrite(greenpin, LOW);
    digitalWrite(bluepin, LOW);
  }
  if (color == "green") {
    digitalWrite(greenpin, HIGH);
    digitalWrite(redpin, LOW);
    digitalWrite(bluepin, LOW);
  }
  if (color == "blue") {
    digitalWrite(greenpin, LOW);
    digitalWrite(redpin, LOW);
    digitalWrite(bluepin, HIGH);
  }

  if (color == "off") {
    digitalWrite(greenpin, LOW);
    digitalWrite(redpin, LOW);
    digitalWrite(bluepin, LOW);
  }
}

I tried turning on the RGB LED with single digitalWrite() functions and it works. I think that the if statements in the code are the problem.
I`m using an Arduino MEGA 2560 BTW.


texts: How can I get an Arduino Uno run the Feather9x_RX example?

texts:
How do I get this example to run on using an Arduino Uno. I've updated RFM95_RST, RFM95_CS & RFM95_INT to the relevant pins (2,4 & 3 respectively).
This is the output on the Serial Monitor when the sketch is loaded:
Feather LoRa RX Test!
ERROR: Failed to put device in LoRa mode.
RH_RF95_REG_01_OP_MODE: 0
LoRa radio init failed

I've followed this wiring set up:

#include <SPI.h>
#include <RH_RF95.h>

#define RFM95_RST     2
#define RFM95_CS      4
#define RFM95_INT     3

// Change to 434.0 or other frequency, must match RX's freq!
#define RF95_FREQ 915.0

// Singleton instance of the radio driver
RH_RF95 rf95(RFM95_CS, RFM95_INT);

// Blinky on receipt
#define LED 13

void setup()
{
  pinMode(LED, OUTPUT);
  pinMode(RFM95_RST, OUTPUT);
  digitalWrite(RFM95_RST, HIGH);

  Serial.begin(115200);
  while (!Serial) {
    delay(1);
  }
  delay(100);

  Serial.println("Feather LoRa RX Test!");

  // manual reset
  digitalWrite(RFM95_RST, LOW);
  delay(10);
  digitalWrite(RFM95_RST, HIGH);
  delay(10);

  while (!rf95.init()) {
    Serial.println("LoRa radio init failed");
    Serial.println("Uncomment '#define SERIAL_DEBUG' in RH_RF95.cpp for detailed debug info");
    while (1);
  }
  Serial.println("LoRa radio init OK!");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM
  if (!rf95.setFrequency(RF95_FREQ)) {
    Serial.println("setFrequency failed");
    while (1);
  }
  Serial.print("Set Freq to: "); Serial.println(RF95_FREQ);

  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then
  // you can set transmitter powers from 5 to 23 dBm:
  rf95.setTxPower(23, false);
}

void loop()
{
  if (rf95.available())
  {
    // Should be a message for us now
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);

    if (rf95.recv(buf, &len))
    {
      digitalWrite(LED, HIGH);
      RH_RF95::printBuffer("Received: ", buf, len);
      Serial.print("Got: ");
      Serial.println((char*)buf);
       Serial.print("RSSI: ");
      Serial.println(rf95.lastRssi(), DEC);

      // Send a reply
      uint8_t data[] = "And hello back to you";
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent a reply");
      digitalWrite(LED, LOW);
    }
    else
    {
      Serial.println("Receive failed");
    }
  }
}


texts:
Recently I started some tests controlling water heater with temperature sensor data as described in detail here
So far I've been testing a small dataset to control water temperature that is quite easy to write down by myself.
#include <NTPClient.h>
#include <WiFi.h>
#include <WiFiUdp.h>

//WiFi Conf
const char *ssid     = "ssid_addr";
const char *password = "wifi_password";
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP);
unsigned long current_time;

// Sensors Conf (fixed value just to test relay response)
float temperature = 30.5;

//Relay Conf
const int relay = 26;

struct SetPoint {
  unsigned long time;
  float temperature;
};

#define DATA_SIZE  8

SetPoint scen1[DATA_SIZE] = {
  {1616952559, 32.4},
  {1616952739, 10.2},
  {1616952859, 10.4},
  {1616952867, 40.2},
  {1616952927, 20.4},
  {1616952928, 35.2},
  {1616952945, 22.4},
  {1616952947, 28.2}
  };

unsigned int pos = 0;

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

  pinMode(relay, OUTPUT);

  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }

  timeClient.begin();

}

void loop() {
  timeClient.update();

  long current_time =  timeClient.getEpochTime();

  if (pos < DATA_SIZE && current_time >= scen1[pos].time) {
    set_thermostat(/*data[pos].temperature, temperature*/);
    pos++;
  }

  Serial.println(timeClient.getEpochTime());
  Serial.println(timeClient.getFormattedTime());
  Serial.println(pos);
  delay(3000);

}

void set_thermostat() {
  if (temperature < scen1[pos].temperature) {
    digitalWrite (relay, HIGH);
  }
  else if (temperature > scen1[pos].temperature) {
    digitalWrite (relay, LOW);
  }
}

But now I'm planning to use a larger file with different datapoints and an option is to store them in a sdcard and, then, the microcontroller parses each line to control the temperature with an interval of three hours.
There will be about 720 lines with the following structure ("Scen" is the temperature simulation scenarios that will be the reference to turn the relays on or off):
    Time,UNIX,Scen1,Scen2,Scen3
    21/04/2021 00:00:00,1618963200,"27.45","29.01","30.85"
    21/04/2021 21:00:00,1619038800,"26.16","27.82","29.75"
    21/04/2021 06:00:00,1618984800,"25.28","26.83","29.02"
    21/04/2021 09:00:00,1618995600,"24.62","26.49","28.51"
    21/04/2021 12:00:00,1619006400,"27.19","29.47","29.53"
    21/04/2021 15:00:00,1619017200,"30.65","34.07","30.50"
    21/04/2021 18:00:00,1619028000,"31.87","35.78","31.78"
    21/04/2021 21:00:00,1619038800,"30.43","35.20","30.88"
    22/04/2021 00:00:00,1619049600,"28.45","31.86","29.47"

The problem is that it is hard to find out how to parse data from the file into two variables (UNIX Time and temperature), for each temperature scenario, as used here:
struct SetPoint {
  unsigned long time;
  float temperature;
};

#define DATA_SIZE  8

//scenario 1 array
SetPoint scen1[DATA_SIZE] = {
  {1616952559, 32.4},
  {1616952739, 10.2},
  {1616952859, 10.4},
  {1616952867, 40.2},
  {1616952927, 20.4},
  {1616952928, 35.2},
  {1616952945, 22.4},
  {1616952947, 28.2}
  };

Is there an effective way to get what I'm looking for?


texts:
I am at my wit's end with these Nrf24l01s. A bit of history: I have ordered about 25 of these, tried the adapter board, read every article, tried every sketch (including Robin's tutorial), powered the modules with a separate power supply.
Has anyone else had these issues? Is there anything anyone has discovered on getting these to work? I am 12 years old and am trying to use these for a science project. Any help is greatly appreciated!!
Tnx,
Ricky
edit:
I went back to just the simplest "hello world" sketch and I can't even get this to work: nothing received in serial monitor (I did notice the Tx LED is lit in the receiver, is this correct?) Sorry if I posted this wrong.
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//create an RF24 object
RF24 radio(9, 8);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

void setup()
{
  radio.begin();

  //set the address
  radio.openWritingPipe(address);

  //Set module as transmitter
  radio.stopListening();
}

void loop()
{
  //Send message to receiver
  const char text[] = "Hello World";
  radio.write(&text, sizeof(text));

  delay(1000);
}

Receiver:
//Include Libraries
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

//create an RF24 object
RF24 radio(9, 8);  // CE, CSN

//address through which two modules communicate.
const byte address[6] = "00001";

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

  radio.begin();

  //set the address
  radio.openReadingPipe(0, address);

  //Set module as receiver
  radio.startListening();
}

void loop()
{
  //Read the data if available in buffer
  if (radio.available())
  {
    char text[32] = {0};
    radio.read(&text, sizeof(text));
    Serial.println(text);
  }
}


texts: Arduino OTA port not updating in Arduino IDE

texts:
The OTA (from the ArduinoOTA library) on my ESP8266 does not show up in the programming ports on the Arduino IDE unless I restart the IDE.   Even when I plug in a usb cable and the ports list updates to show that device, it does not show the network port without a restart.   Does anyone know why this would happen or how to solve it?

I downloaded the newest version of the IDE and this is still the case.


texts: How do I use two PulseIn() functions simultaneously in Arduino?

texts: I want to connect multiple Ultrasonic sensors to my Arduino board. For that, I need multiple pulseIn() functions to work at the same time. How can I do that?


texts: How to rotate servo every 12 hours using RTC module?

texts:
I am trying to make a auto fish feeder to feed my fish every 6hours. I want to implement RTC module to my code. So far I've been using only an arduino and a servo using this as a code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

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

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo.write(15);
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
      // Wait for 12h
    delay(6 * 3600000);
}

The RTC module I have is the DS1302. It's library cn be downloaded here
The code for the clock is this:
// DS1302_Serial_Hard
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS1302-library to
// retrieve time- and date-date for you to manipulate.
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

// Init a Time-data structure
Time t;

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);

  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
}

void loop()
{
  // Get data from the DS1302
  t = rtc.getTime();

  // Send date over serial connection
  Serial.print("Today is the ");
  Serial.print(t.date, DEC);
  Serial.print(". day of ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" in the year ");
  Serial.print(t.year, DEC);
  Serial.println(".");

  // Send Day-of-Week and time
  Serial.print("It is the ");
  Serial.print(t.dow, DEC);
  Serial.print(". day of the week (counting monday as the 1th), and it has passed ");
  Serial.print(t.hour, DEC);
  Serial.print(" hour(s), ");
  Serial.print(t.min, DEC);
  Serial.print(" minute(s) and ");
  Serial.print(t.sec, DEC);
  Serial.println(" second(s) since midnight.");

  // Send a divider for readability
  Serial.println("  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -");

  // Wait one second before repeating :)
  delay (1000);
}

So the question here is, how can I set up my code to work with RTC, in order to move the servo every 6 hours?


texts:
I currently have a loop that runs without a time condition:

unsigned long previousMillis = 0;        // will store last time LED was updated

int WET=4;//wet line
int DRY=5;//dry line
int Inhale=1000;//msec
int Exhale=1000;//msec
//int Noflow=3000;//msec

void setup() {
  // put your setup code here, to run once:
  pinMode (WET, OUTPUT);
  pinMode (DRY, OUTPUT);
}

void loop() {
  //inhale
  digitalWrite(WET,LOW);
  digitalWrite(DRY,HIGH);
  delay (Inhale);
  //exhale
  digitalWrite(WET,HIGH);
  digitalWrite(DRY,LOW);
  delay (Exhale);
  //No flow
  //digitalWrite(WET,HIGH);
  //digitalWrite(DRY,HIGH);
  //delay (Noflow);
}

Then i have tried to code a "timer" for each cycle,but i got error:"
exit status 1
Error compiling for board Arduino/Genuino Uno."

Code with timer:

unsigned long previousMillis = 0;        // will store last time LED was updated

int WET = 4; //wet line
int DRY = 5; //dry line
//int Inhale=1000;//msec
//int Exhale=1000;//msec
//int Noflow=1000;//msec
int BPM = 60;
int IE = (((60 * 1000) / BPM) / 2);

void setup() {
  // put your setup code here, to run once:
  pinMode (WET, OUTPUT);
  pinMode (DRY, OUTPUT);
}

void loop() {
  for (int i = 0; i = 20;)
    int BPM = BPM + 10;
#include <elapsedMillis.h>

  elapsedMillis timeElapsed;
  unsigned int interval = 60000; //one minute in ms

  while (timeElapsed < interval) {

    //inhale
    digitalWrite(WET, LOW);
    digitalWrite(DRY, HIGH);
    delay (IE);
    //exhale
    digitalWrite(WET, HIGH);
    digitalWrite(DRY, LOW);
    delay (IE);
    //No flow
    //digitalWrite(WET,HIGH);
    //digitalWrite(DRY,HIGH);
    //delay (2000);
  }
}

Target ouput: to run every cycle of the loop for 1 min.

Any one familiar with this error?
Many thanks for your help


texts:
I've connected the circuit as shown in
https://www.arduino.cc/en/Tutorial/HelloWorld?from=Tutorial.LiquidCrystal
and I ran the program, but I can't fix this problem:

the LCD seems not to respond correctly: the first row is black and for what concerns the elements of the second, they all have three top lines of pixel high and the others low..

I checked over and over if I made some mistake connecting wires but I haven't found any error..

Is the LCD broken according to you? How can I fix?

Here the photos of the circuit:
https://drive.google.com/open?id=0B2h2zzEgtaqydElrRDVUNGVuWDA


texts:
When I plug in my nanoatmega328 to my computer, nothing shows up in /dev as I expect it to. If I plug in my Uno, /dev/ttyACM0 shows up. I have tried several Nanos.

Linux Mint 17.2.


texts: Switch setting 'running' state boolean doesn't hold

texts:
I have a rotary encoder and I want to use the switch to stop the rest of my code running, essentially switching off what I have going on.

I have this

boolean running = true;

void setup() {
  pinMode(swPin, INPUT);
  digitalWrite(swPin, HIGH);;
}

void loop() {

  if(digitalRead(swPin) == LOW) {
    running = !running;
  }

  if(running) {
    ...
  }
}

When I enter the if statement catching the switch press running does become false and the rest of the code is stopped. However, once released; running is becoming true again and the rest starts again.

I guess it is because the rotary encoder isn't fixed in the LOW state but I expected the running variable to be set to false and remain since it is declared outside of the loop().

Any guidance would be much appreciated!!


texts: How should I decide the cut-off frequency for my low-pass filter?

texts:
I'm trying to generate some basic thumping stereo sound using Arduino's PWM pins along with low-pass filters.
This is the frequency spectrum for the sound I want to play using Arduino UNO's PWM pins:

Based on this, I think (from what I understand) the cut-off frequency for the low-pass filter should be around 8900Hz. But, wouldn't the PWM function operate at a much higher frequency to generate the same wave? If that's how it'll be, how should I decide the cut-off frequency for my low-pass filter?
I understand that the fastest frequency one can get for 8-bit PWM on an UNO is 62.5 kHz. So, I might not be able to generate this wave using the UNO itself. Unfortunately, I won’t be able to use another microcontroller for this project. However, what I can do to solve this issue is - generate a different sound wave of lower frequency. If someone can help me with finding out by how much will the frequency of the wave increase if I use PWM to generate it, I’ll be able to generate an appropriate wave.


texts:
I'm just trying to understand how vscode can compile arduino sketch. Now I uploaded some sketch to arduino and it was fine. Now I'm trying to add my own header files to .ino sketch and I got weird faults. I don't understand whats happening. I know this header files in under project.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "chcStandart.h"
#include "chcDefines.h"

When I try to verify my code I get this error:

> c:\Users\Desktop\Main_Code\chc.h:7:25: fatal error: chcStandart.h: No
> such file or directory

Also ı configured my json (c_cpp_prop) file and it looks like that.

"name": "Win32",
            "includePath": [
                "C:\\Program Files (x86)\\Arduino\\tools\\**",
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\**",
                "C:\\Program Files (x86)\\Arduino\\libraries\\**",
                "C:\\Users\\Musa Ünal\\Documents\\Arduino\\libraries\\",
                "C:\\Users\\Musa Ünal\\Desktop\\Main_Code\\**"

            ],
            "forcedInclude": [
                "C:\\Program Files (x86)\\Arduino\\hardware\\arduino\\avr\\cores\\arduino\\Arduino.h"
            ],
            "intelliSenseMode": "msvc-x64",
            "compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
            "cStandard": "c11",
            "cppStandard": "c++17",
            "C_Cpp.intelliSenseEngine": "Tag Parser"

My question is: How I can handle this problem? Thanks!


texts: ATMega328 functions, but will not output to any pins

texts:
Problem:
ATMega328 Refuses to digitalWrite() to any pins, I can upload and run sketches using the board UNO from the ide on the 328 and can confirm it is working using the serial monitor (see code).
I am using this FTDI module.
Board Manager -- UNO works, but ATMega328 Doesn't

By using the UNO board under board manager, I am capable of writing sketches and communicating with the 328 just fine.
But when I use the ATMega328 at 5.5V,16Mhz I receive the following error.
         Using Port                    : COM3

         Using Programmer              : arduino

         Overriding Baud Rate          : 57600

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

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xe0

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

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

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xe0

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xe0

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

avrdude done.  Thank you.

Code & Serial Monitor "Proving" it works
I have tried every usable PWM and other pins to attempt to output using LED's, buzzers and even other Arduino's to read inputs but none of the pins will output high when requested.
I believe that Arduino IDE is attempting to compile my code for the UNO and those pins do not work on the ATMega328 but this could be completely incorrect and someone please correct me if this is a wrong assumption.
Lastly, I have been able to use the SCL and SCA pins to communicate with an I2C LED shield.
Does anyone know why I cannot write sketch to the ATMega328 using the FTDI and my configuration.
Posted Below are images and very rough Fritzing schematics of how I am setup.
void setup() {
  Serial.begin(9600);
  pinMode(5,OUTPUT);
}

void loop() {
  Serial.println("TICK");
  digitalWrite(5,HIGH);
  delay(1000);
  digitalWrite(5,LOW);
  }

My Breadboard

Fritzing Schematic


texts:
I am new to Arduino programming. Let me describe the application I am working on. I am pressing a button for a certain period of time (30 sec). I can not hold it in a pressed position for all the time. I want to avoid accidental transition from button state going from logic HIGH to LOW. I am trying to drive a solenoid valve only at the end of the event.

The algorithm I am using is if once the system detects a HIGH from the sensor it goes in a loop and looks for transition to LOW. It checks if there is continuous LOW for more than 5 sec. If NO then it resets to start checking LOW again. If YES that means end of event and drives the solenoid valve.

The problem I am facing with the code is although the transition to LOW and remaining in LOW is less than 5 sec, the system is sending pulse to drive the solenoid valve. I have incorporated Serial.print() function to observe the value of the sensor input state and elapsed-time. The elapsed-time variable does not reset and keep increasing even though the button state reverts from LOW to HIGH.

I am incorporating part of the code here which is related to the algorithm. I will greatly appreciate if you kindly take a look at the code and the output file and help me detect the bug.

Thanks again!
Niloy.

void loop() {

      buttonstate = digitalRead(button);   // read the state of the microswitch value: HIGH "on" or LOW "off"

      if (buttonstate == HIGH ){
          countstart = 1;

          while(countstart == 1) {
          buttonstate = digitalRead(button);   // read the state of the microswitch value: HIGH "on" or LOW "off"

          if ( ( buttonstate == LOW ) && ( startFlag == 0 ) ) { //start new time sequence
                  startFlag = 1;
                  startTime = millis();
            }
          if ( ( buttonstate == LOW ) && startFlag == 1 ){
                  endTime = millis();
                  elapsedTime = endTime - startTime;
          }

          if ( ( buttonstate == HIGH ) && startFlag == 1 ){
                  startFlag == 0;
                  endTime = startTime =0;
                  elapsedTime = endTime - startTime;
                  countstart = 0;
          }

          Serial.print(buttonstate);
          Serial.print("\n");       // Print tab space
          Serial.print(elapsedTime);
          Serial.print("\n");       // Print tab space

      if ( elapsedTime >= 5000)
      {
          delay(2000);  //2 sec delay
          solenoid->run(FORWARD);
          delay(40);
          solenoid->run(RELEASE);

          delay(500);

          solenoid->run(BACKWARD);
          delay(40);
          solenoid->run(RELEASE);

          countstart = 0;
          endTime = startTime =0;
          elapsedTime = endTime - startTime;
          buttonstate = LOW;
          delay(15000); //wait for 15 sec

      }
     }

    }
}


texts: How to send volume +/- on Mac/OSX from Leonardo

texts:
I saw this answer but I can't find the analog for Mac.

I've tried cycling thru keycodes from 0x01 thru maybe 0x500, and I went thru ascii a few times, also found brightness up/down, and F11, F12, but they get pressed with fn key by default which makes them do operations other than vol +/-.


texts: Trying to make sense of the coding style in Arduino libraries. (Particularly the Radiohead library)

texts:
I've been using the Arduino IDE for some time now, and I want to shift to coding for the bare AVR microcontroller. So I wanted to begin by porting required arduino libraries to C/C++.
I started with the Radiohead library, but I've noticed a lot of variables/tokens that are directly used without a definition for them. For example:

    // path :RadioHead/RH_ASK.cpp
#if (RH_PLATFORM == RH_PLATFORM_GENERIC_AVR8)
 #ifdef RH_ASK_PTT_PIN
    RH_ASK_PTT_DDR  |=  (1<<RH_ASK_PTT_PIN);
    RH_ASK_TX_DDR   |=  (1<<RH_ASK_TX_PIN);
    RH_ASK_RX_DDR   &= ~(1<<RH_ASK_RX_PIN);
 #else
    RH_ASK_TX_DDR   |=  (1<<RH_ASK_TX_PIN);
    RH_ASK_RX_DDR   &= ~(1<<RH_ASK_RX_PIN);
 #endif
#else
    // Set up digital IO pins for arduino
    pinMode(_txPin, OUTPUT);
    pinMode(_rxPin, INPUT);
    pinMode(_pttPin, OUTPUT);
#endif

None of the tokens in this snippet like "RH_ASK_PTT_PIN" or  "RH_ASK_TX_PIN" were mentioned anywhere in the code before or any other file that was included.

I understand what the code does, but how does the compiler know what these tokens mean? I tried to compile this code using Atmel Studio but it gives me an error (As it should):
"RH_ASK_PTT_PIN" not declared in this scope
So how does this library work with the Arduino IDE?

Link to the library : https://github.com/PaulStoffregen/RadioHead

Also can someone suggest tags for this post? Its my first post here.


texts: What is this shield? (AST Space Arduino Kit)

texts:
I recently got a box with Arduino components from someone who didn't want it (in part, because the manual was (probably) in Chinese). However, to my surprise, I could not find this kit on the internet. I would like to know: is this a copy of another kit?  Or, is there documentation available for this particular kit?

Box contents:

Arduino Uno
Unknow shield "by AST Space" with

AI-THINKER wi-fi module
Songle relais
YLB3641AH 4-digit LED display
DHT-11 relative humidity, temperature sensor
IR receivers, switches, microphone/buzzer, light sensor, connectors to the other components

MPU6050 accelerometer
HC-SR04 ultrasonic rangefinder
QAPASS LCD unit
"Car MP3" IR remote
2x green, 2x red LED, 5x resistor
17x10 green breadboard
2x DC motor, 1x geared stepper motor
40-wide female-female jumper ribbon cable
USB connector cable (black)

It came in an intricate folding box, bright orange. The QR code links to http://weixin.qq.com/r/2kgtNVXEKwhUrRFW9x3I (which did not get me anywhere - visiting this link is at your own risk). Pictures:


texts: Recommend development environment for Arduino on Mac in the year 2021?

texts:
I'm using a Macintosh (Big Sur) and am about to begin developing an Arduino project in C++.  (I am an experienced C++ programmer.)  I notice that add-ons for Apple's "XCode" editor appear to have been sunsetted before Big Sur and are therefore no longer available now.  I'd therefore like to hear your suggestions:
• Just use the Arduino IDE.
• Install a Ubuntu Linux VM and use (which?) development environment from there.
• Use a Windows-10 VM and (which?) development environment from there.
Most of the available websites and tutorials which discuss MacOS at all do not discuss the latest version – Big Sur (11.2) – and I am very keenly aware that MacOS itself has been changing very considerably(!) in these recent versions.
Finally – what's the best recommended online resource discussing Arduino when one is presumed to be familiar with C++?


texts: How to process this XBee analog pins signal?


texts: How to use existing (non-arduino-specific) library with subfolders in Arduino IDE?

texts:
I have a generic c++ library that i'd like to use in an arduino project without making changes to the library code.
The library contains subfolders and files in the library include other files of the same library with includes of the form

#include "libraryroot/subfoldername/header.h"

I tried putting 'libaryroot' into C:/Users/Username/Documents/Arduino/libraries but while I can include headers that lie directly inside 'libraryroot' using #include <filename.h> (not #include <libraryroot/filename.h>), Arduino fails to find the headers these files include

How can I make use of such a library in Arduino without having to change the library?


texts: How to connect an industrial sensor to Arduino Uno?

texts:
I want to use a sensor to read pressure in rooms. But sensor like MPX series isn't capable to read air pressure change under 100 Pa. So I want to use industrial sensor like Dwyer 607 Series, and dont have a clue how to connect it to arduino. Anyone can help?
Thanks :)
Fyi, this is the manual instruction for the sensor http://www.dwyer-inst.com/PDF_files/E_76_low.pdf