texts: How to post image using Arduino HTTPClient

texts:
I am using arduino HTTPClient to do the post request in ESP32. Can anyone help me with the part where I will be able to post an image file along with some data.
The below code works perfectly fine with only sending user_name and image_type-
#include <HTTPClient.h>

http.begin("https://www.somelink.com/post-image");

http.addHeader("Content-Type", "application/x-www-form-urlencoded");

String httpRequestData = "user_name=Shidhartha&image_type=Outdoor";

int httpResponseCode = http.POST(httpRequestData);
if(httpResponseCode > 0){
  String response = http.getString();
  Serial.println(response);
}else{
  Serial.print("Error on sending POST: ");
  Serial.println(httpResponseCode);
}


texts: Use of struct and sizeof in C for Arduino

texts:
I am a newbie in C and I can not understand the point of using a structure in C. Could someone explain to me what is the point of defining a structure in C programming?

For example, this code(written in C for Arduino)

struct books
{
  char name[30];
  char author[30];
  int ID;
} Mybook, Yourbook;

void setup()
{
  Serial.begin(9600);
  // put your setup code here, to run once:
  strcpy(Mybook.name, "Girl in the train");

  strcpy(Yourbook.name, "Gone");

  Serial.print("Name of the book is:");
  Serial.println(Mybook.name);
  Serial.println((long)&(Mybook.name));
  Serial.println((long)&(Mybook));
  Serial.println((long)&Mybook);
  Serial.println(sizeof(Mybook));

  Serial.print("Name of the book is:");
  Serial.println(Yourbook.name);
  Serial.println((long)&Yourbook);
  Serial.println(sizeof(Yourbook));
}

Would use the same amount of memory as defining

char Mybookname[30];
char Yourbookname[30];

And you should type the same amount of lines.
So what is the point?

I have another question:

Why I get 62 for the sizeof(Mybook)? I have not defined it anywhere. Is it set automatically?


texts: Reading and interpreting Serial information

texts:
I am trying to use a Raspberry Pi to control a ESC and for that I am sending the instructions for the ESC using serial. My problem is that when i send the instructions i can not interoperate them, and by interoperate I mean check what the first letter is and then remove it and make the Arduino output a PWM signal. My problem is when I use the serial monitor to send an instruction it firstly comes up on several lines, and when I try and look at the first letter of the string the if statement thinks it is true for all inputs of "FirstLetter" my function to get the serial input it

String readSerial()
{
  char SerialInput;
  String Data = "";
  if (Serial.available())
  {
    SerialInput = Serial.read();
    Data.concat(SerialInput);
    //Serial.println(Data);
  }
  return Data;
}

the function that should interoperate  the information from readSerial() is

void DecodeInput()
{
  String input = readSerial();
  if (input != "")
  {
    char FirstLetter = input.charAt(1);
    if (FirstLetter = 'U')
    {
      Serial.println("Hello World");
      //input.setCharAt[0, '');
      //SetPower('U', Power);
    }


texts: Digital Input with long cable - flickering values

texts:
I have an Arduino Nano with two attached Motion sensors "PIXNOR HC-SR501". This sensor puts 5V on its middle Pin, when it detects motion. I have connected this Pin to my Arduino and read the value with digitalRead

Here is the simplified code of my loop:

void loop() {
    motion1 = digitalRead(motion_pin1);
    motion2 = digitalRead(motion_pin2);

    if(motion1== HIGH) {
      if(debug){
        Serial.println("Motion 1");
      }
    }
    if(motion2== HIGH) {
      if(debug){
        Serial.println("Motion 2");
      }
    }

    // Wait 1,0 Second
    Sleepy::loseSomeTime(1000);
  }

Problem is... This used to work fine, but I had to extend the cable to the motion sensors from ~10 cm to 500 cm. Now I have the problem, that the Arduino sometimes (quite often) detects voltage on the motion pins, although there is no motion. I guess the Input-pins are is too sensitive?
What can I do to prevent this flickering?


texts:
I am having an issue with the LCD1602A and Arduino Uno. I have followed a tutorial on youtube that has got the device working, however the LCD is only displaying white blocks in all 16 segments of the top row.

Pin Out

LCD

VSS -> GND on Breadboard
VDD ->  5V on Breadboard
V0  -> Connected to 5K potentiometer
RS  -> Pin 1 on Arduino Uno
RW  -> GND on Breadboard
E   -> Pin 2 on Arduino Uno
D0  -> Not Connected
D1  -> Not Connected
D2  -> Not Connected
D3  -> Not Connected
D4  -> Pin 7 on Arduino
D5  -> Pin 6 on Arduino
D6  -> Pin 5 on Arduino
D7  -> Pin 4 on Arduino
A   ->  5V on Breadboard
K   -> GND on Breadboard

Code

#include <LiquidCrystal.h>
LiquidCrystal lcd(1, 2, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs, enable, d4, d5, d6, d7)
void setup() {
 lcd.begin(16,2); // Initializes the interface to the LCD screen, and specifies the dimensions (width and height) of the display }
}
void loop() {
 lcd.print("Arduino"); // Prints "Arduino" on the LCD
 delay(3000); // 3 seconds delay
 lcd.setCursor(2,1); // Sets the location at which subsequent text written to the LCD will be displayed
 lcd.print("12345");
 delay(3000);
 lcd.clear(); // Clears the display
 lcd.blink(); //Displays the blinking LCD cursor
 delay(4000);
 lcd.setCursor(7,1);
 delay(3000);
 lcd.noBlink(); // Turns off the blinking LCD cursor
 lcd.cursor(); // Displays an underscore (line) at the position to which the next character will be written
 delay(4000);
 lcd.noCursor(); // Hides the LCD cursor
 lcd.clear(); // Clears the LCD screen
}

Now the program compiles and uploads OK the potentiometer dims the blocks perfectly fine.

However it is supposed to print Arduino and 12345 and I am unsure why.

What am I missing?

Thanks


texts: ATtiny85: Power consumption vs clock speed

texts:
Short and simple: What is the power consumption for an ATtiny85 running at 1 MHz and 8 MHz using the internal clock? Not using any sleep modes.

I have googled a lot and can't find any info on this. I ask because I want to know if it is worth using 1 MHz to increase battery life.


texts:
I am building a IR-based laser tag system. The basics are working fine. One feature, that I want to have, is different weapon modes with different ranges.

How can I change the range of an IR transmitter with as little hardware as possible, or at best, completely in software?


texts:
I'd like to know if there are events worldwide or in Latin America regarding how to introduce Arduino as an extra-curricular activity.
Thanks, Marcelo from Argentina.


texts:
I am trying to make an H-bridge with two NPN and two PNP transistors to drive a motor which works fine on the 5 V Arduino. I have a schematic in the picture. When I use a simple code to have pin 9 HIGH and pin 8 LOW, the motor doesn't do anything. The transistor which I circled green is getting very hot. Is there something wrong with the schematic or code? Or is it my wiring?

I know people use diodes as well, but in my case the motor doesn't work, so the diodes aren't the problem.

This is my code:

     void setup()
    {

    pinMode(8, OUTPUT);
    pinMode(9, OUTPUT);

    digitalWrite(9, HIGH);
    digitalWrite(8, LOW);
    }


texts:
I'm fairly new to arduino programming and C/C++. I would like to read a .csv file element wise, and send each element via. a nRF24L01 tranceiver to a raspberry pi. Right now I'm able to read the .csv file with Serial.write(<file>.read()). I was wondering if there's a way to read each element one at a time, if so how would i do that?

My thoughts (Pseudo code-ish):

loop through every element in .csv file {
    save the current element to X.
    send X to raspberry pi (I already have a function for sending)
}

I hope someone can help. Thanks in advance.


texts: Correlated signal from two sensors in one circuit

texts:
I have water level/humidity sensor and a LDR diode hooked to arduino like this (the resistor is 10k)

On A0 I can read signal from water sensor (blue)
On A1 I can read signal from light sensor (yellow)

The problem is that both signals seem to be correlated. When I dip the water sensor to water and keep the light levels the same, the signal from light goes up as well (dramatically).

I suspect that this is due to Ohm's law. The voltage in a circuit depends on the total resistance of the circuit. Both sensors act as a sort of resistors so when one's resistance changes the voltage in the circuit changes as well.

How can I wire the sensors such that the change in resistance of either sensor doesn't affect the second? Or do I need a separate power supply for each sensor?


texts: Can I use analogRead to read a digital pin?

texts: analogRead(nGPIO_max + lockerVal) were nGPIO_max(maximum digital pins in Arduino Uno is 13) and lockerval is 2. Which pin is it reading?


texts: The Ultrasonic sensor just detects the same distance

texts:
int tPin = 11;
int ePin = 12;
long duration, inches, cm;

void setup()
{
    Serial.begin(9600);
    pinMode(tPin, OUTPUT);
    pinMode(ePin, INPUT);
    pinMode(2, OUTPUT);
}

void loop()
{
    digitalWrite(tPin, LOW);
    delayMicroseconds(5);
    digitalWrite(tPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(tPin, LOW);
    duration = pulseIn(ePin, HIGH);
    cm = (duration / 2) / 29.1;
    inches = (duration / 2) / 74;
    Serial.print(inches);
    Serial.print("in, ");
    Serial.print(cm);
    Serial.print("cm");
    Serial.println();
    delay(100);

    if (inches <= 10) {
        digitalWrite(2, HIGH);
        delay(50);
        digitalWrite(2, LOW);
        delay(50);
    }
    else {
        digitalWrite(2, HIGH);
        delay(500);
        digitalWrite(2, LOW);
        delay(500);
    }
}

The serial print displays the same distance that it first detects. How can I fix this?


texts: Connection of Seeeduino GPRS with relay module

texts:
Good day. I'm working on home automation. I'm now at the implementation stage, where I want to assemble all the materials I need to use.

The materials are: Seeeduino GPRS (Arduino Leonardo), relay module, LCD display and electrical appliances. How do I connect them? I need the connection diagram, and some tips about the microcontroller. Thanks.


texts: How to get current WiFi signal strength?

texts:
I have a LCD display where in I'm displaying a WiFi signal logo. I want to reduce the number of bars on the logo, indicating that the signal strength is dropping. I got the reducing bars on the LCD completed, I still have to find out the actual signal strength.
How do I find the signal strength of the connected network with ESP8266 based NodeMCU?


texts: How to retrieve the data type of a variable?

texts:
I am using Arduino and I would like to know if there is a function that returns the data type of a variable. That is, I would like to run something as like the following:

// Note: 'typeof' is a sample function that should return the data type.
Serial.println(typeof(myVar));


texts:
Good day,
I have a sensor which supports serial data output using RS422 which has 4 wires (RX+, RX-, TX+, TX-)
my question is how can I connect this sensor to the Arduino.
I read that i can use 2 max485 chips to do this but uncertain of the exact procedure.
Thanks in advance.


texts:
I am using the following code and when I am probing pin 13(SCK), I can't see any clock signal in the oscilloscope.

#include <SPI.h>
int SCS=10;
int SI=11;
int SCLK=13;
int EXTCOMIN=4;

void setup()
{
 pinMode(SCS,OUTPUT);
 pinMode(EXTCOMIN,OUTPUT);
 pinMode(SCLK,OUTPUT);
 digitalWrite(SCS,HIGH);
 tone(EXTCOMIN,50);
 SPI.setClockDivider(SPI_CLOCK_DIV16);
 SPI.begin();
}

void loop()
 {
 }


texts:
Arduino Uno user here

I am building a project with 4 analog inputs A0 dose not work. A1 A2 and A3 work perfectly fine! But for last input when I connect to A4 or A5, then they do not go to zero. They are stuck between 400 to 900. Even when connected to arduino ground it gives 400 instead of 0.

Am I missing something here cause the circuit for A4 connected to A3 gives perfect input value. They both work fine as output. Same situation with A5.

Is there another way to get one more Analog Input without multiplex?

Thank you!


texts:
I have the 14051 Demux set up with an Arduino Uno R3 and I am able to light up all three LED's at once with a 1 second delay however, I want to light up 1 LED at a time how can I do this?

  My Hardware Setup

  Sketch

/*  Arduino sketch   */

int64_t wait= 1000;
void setup()
{
  pinMode(7,OUTPUT);
  digitalWrite(7,LOW);
  DDRB = 0b00000111;  //PORT 8,9,10 as output
  PORTB = 0b00000000; //PORT 8,9,10 set to LOW
}

void loop()
{
  PORTB=0b00000000; //Data falow - X0
  uint8_t Sensor0 =  analogRead(A0); //read data from X0
  delay(wait);

  PORTB=0b00000001;  //Data flow - X1
  uint8_t Sensor1 =  analogRead(A0); //read data from X1
  delay(wait);

  PORTB=0b00000010;  //Data flow - X2
  uint8_t Sensor2 =  analogRead(A0); //read data from X2
  delay(wait);

  digitalWrite(7,HIGH);  // Inhibit / stop all data
  delay(wait);
  digitalWrite(7,LOW);  // Inhibit /  let data flow
}


texts: arduino sketch on Win7 vs. MAC op system?

texts: I have a friend who is just getting started with Arduino UNO.  He downloaded a sketch and is using a UNO on Mac OS.  He loaded the sketch and verified.  it comes up with errors.  He sent me the same sketch and i opened it under Win7 arduino software.  verified, and it says it is fine.  i made an arduino file and emailed it back to him.  he is still getting the same errors.  can anyone help and let me know what is wrong?  i am not a MAC expert and wonder why  this works in win and not MAC????????  appreicate any help anyone can give me


texts: Recently I have gotten some Touchscreens to add to my projects and I am very excited to use them. However, I am not sure where I can find a guide to help me create my own GUI with the touchscreens. The touchscreen I am using right now is the HiLetgo 2.4 inch TFT LCD Display Shield with a ILI9341 Driver. I have experience programming GUI's in Python and I feel fairly confident in myself that I can create the GUI's that I want if I had a resource to learn from. Please Let me know if you'd like anymore information. Thank you!


texts: Is it possible to read-write the memory of a Gikfun ISD1820 voice recording module?

texts:
I just got a Gikfun ISD1820 voice recording module for an Arduino project that I'm working on. I want to be able to record a few seconds message and then send the message over wifi to another Arduino Mega 2560, which will then play back the message.

The ISD1820 module can record and play back short messages and can be controlled from the Arduino, but I want to know if it is possible to access the memory / read-write the memory of the ISD1820 module to accomplish my goal. And how would I do it?

If it is impossible, what hardware should I get instead? Do I need a wave shield with a SD card or a wifi shield with an SD card?

Thanks!


texts:
I'm using LCD QC1602A with a 10k potentiometer and changing contrast. It works well but the problem is that no text is appearing.

I'm using the LCD hello world examples and a few other examples. I tried reconnecting wires at least 5 times but every time it's the same problem. I connected it like this but the screen is not displaying any text at any contrast.

PS: It was showing white squares only in the top row, and now it's in both rows.


texts:
I'm working on a prototype with a Particle Photon, but I've realized the required number of pins is bigger than the number of pins on my photon.

I thought I could have an Arduino Uno wired to some sensors, and link the Arduino to the photon via a Software Serial from the Arduino (as its serial pins will already be busy) to the Serial pins of the photon.

Is it possible, and is there a better way to solve my problem?


texts:
Friends, I am trying to achieve half duplex communication between two Arduinos using RS485 Protocol. The hardware I am using is a MAX485 module and an Arduino Uno. I am using the SoftwareSerial library for Arduino, but I am not be able to transmit data from sender to receiver. The length of the wire between MAX485 modules is 1 meter.

My question is, what wrong I am doing here, please guide me.

The code:

SenderDevice

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);

String strCmd;
int counter;

void setup()
{

 Serial.begin(9600);
 mySerial.begin(9600);

 pinMode(5, OUTPUT);
 digitalWrite(5, HIGH);
 counter = 0;

}

void loop()
{

  counter++;
  strCmd = "Counter" + String(counter) + "$";
  Serial.println("Sending " + strCmd);
  mySerial.print(strCmd);

  delay(10);
  mySerial.flush();
  Serial.flush();
  memset(&strCmd, 0, sizeof(strCmd));
  delay(2000);

}

ReceiverDevice

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7);

String strCmd;

void setup()
{

 Serial.begin(9600);
 Serial.println("ready");

 pinMode(5, OUTPUT);
 digitalWrite(5, LOW);
 mySerial.begin(9600);

}

void loop()
{

   while (mySerial.available() > 0) {

        char c = mySerial.read();
        if (c == '$') {

           Serial.println("Received " + strCmd);
           memset(&strCmd, 0, sizeof(strCmd));

        } else {

          strCmd = strCmd + c;

        }

  }

}

My Wire Connections are :

(Both Sender & Receiver Device)
Arduino Uno 6 -> Max485 RO
Arduino Uno 7 -> Max485 DI
Arduino Uno 5 -> Max485 DE
Arduino Uno 5 -> Max485 RE
Arduino Uno 5V -> Max485 VCC
Arduino Uno GND -> Max485 GND

Sender Max485 A -> Receiver Max485 A
Sender Max485 B -> Receiver Max485 B


texts: Data Logging without Interfacing SD Card module

texts:
I want to log data to a text document without connecting the SD card module. I don't want to print the data on Serial Monitor I want to store it in a file. Is it possible? Can someone help me with it?
I am using a Arduino Nano on a Windows 10 system, and I want to know if there is an Arduino library to write logs to a file.


texts: Help with wiring? Fritzing example inside

texts:
I am trying to prep my wiring for a 8x8 Led Matrix w/ Bluetooth according to the following instructable:

http://www.instructables.com/id/Arduino-SPI-7-Bi-color-LED-Matrix-Scrolling-Text-D/?ALLSTEPS

Instead of soldering everything together I'd much rather use a breadboard. I'm new to wiring, breadboards, and Arduino's in general. I was wondering if anyone could look over my sketch and see that the connections I've made are valid.

I'm basing my wiring off this image (See original instructable for higher resolution):

I realize the bluetooth module isn't the same. I'm just using this as a reference. The wires leading off the top of the board will be going to the LED Driver module.

EDIT: Thanks for the feedback guys. I have decided to go with the Innogear HC-05 module. I've adjusted the wiring according to that model.
As per the suggestions, I've switched my power and ground rail and eliminated the resistors and ground for TX communication. (I've still kept a ground for the BT).
Here's my new attempt:


texts: Can I create an hemi-cycle raising signal with one pin and the other hemi-cycle signal with another pin?

texts: I am new to Arduino, I would like to know if someone could help me to create this type of signal with the Arduino Uno. Many thanks!!


texts: Using softwareserial with a TFT, how can I use a variable to position cursor?

texts:
I have tried several different ways to do this, but in the line:

myTFT.println("DS32(32,g,'Hello!',4);");

where g is an int, it simply doesn't print. If I just replace the g with a value of any kind, all is well.

I'm using an Uno (well, an Orion board from Makeblock) and the Makeblock TFT.

All my other print lines work fine but of course, none contain variables.


texts: Power on reset with arduino uno can never happen. Can this be fixed?

texts:
When an Arduino Uno is powered on, the USB chip's DTR output pin may (is, in fact) low for a while.  This means that the capacitor C5 is connected from the 328p reset pin to ground.  Thus, when power is applied, the reset pin is held low for 10's of milliseconds after power up (while C5 charges) .

Thus, when the 328p starts, the reason for reset (the MCU register) always is "external reset", not "power on reset", even when  power turns on.

This can be fixed by removing C5, or opening the "reset en" jumper, but then the chip is never reset by the falling of DTR,...that is, bootloading is disabled.

Is there a solution that allows POR and external reset for the bootloader?
Thanks!


texts: HC-05 and cheap Nano clone not powering on

texts:
I have a HC-05 module which works absolutely fine with an Arduino Uno. Because I need to reduce the size of it, I tried using an Arduino Nano.

After correctly wiring it up to the Nano, sometimes the LED doesn`t turn on, or sometimes it does not appear in the devices listing of my smartphone. It also resets randomly the Arduino. I have tested it and it fully works without any problems with the Uno.

I think it is a power issue, but not from my computer or any other computer because I tried on all my computers.


texts: No Socket Available message floods serial monitor

texts:
Serial Monitor get's flooded with "No Socket Available" message.  This seems to occur even before I Try to communicate with my Hue bridge through my hub port.  Does anyone see why this is occurring after my wireless connection is established?

Serial Output:

Firmware needs upgrade
Attempting to connect to WPA SSID: ifiw_ym
connected to the networkSSID: ifiw_ym
BSSID: 0:B2:8F:6A:C4:28
signal strength (RSSI):-47
Encryption Type:4

IP Address: 192.168.1.7
192.168.1.7
MAC address: 78:C4:E:1:9F:B1
in loopin loopin loopNo Socket available
No Socket available
in loopNo Socket available
No Socket available
in loopNo Socket available
No Socket available
in loopNo Socket available
No Socket available
...

code:

#include <SPI.h>
#include <WiFi.h>

//  Hue constants
const char hueHubIP[] = "192.168.1.6";
const char hueUsername[] = "my_hue_app";
const int hueHubPort = 80;

boolean activated = false;

//  Hue variables
boolean hueOn;
int hueBri;  // brightness value
long hueHue;  // hue value
String hueCmd;  // Hue command

unsigned long buffer=0;  //buffer for received data storage
unsigned long addr;

// Wireless network
char ssid[] = "**********";
char pass[] = "**********";
int status = WL_IDLE_STATUS;
WiFiClient client;

//0:B2:8F:6A:C4:28

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

  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv != "1.1.0") {
    Serial.println("Firmware needs upgrade");
  }

  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }

  Serial.print("connected to the network");
  printCurrentNet();
  printWifiData();
}

void loop() {
  Serial.print("in loop");
  // printCurrentNet();
  alterHueColors();
}

void alterHueColors() {
  if(activated){
    client.println("Hue is activated");

     // A series of four sample commands, which colour fades two lights between red and pink. Read up on the Hue API
    // documentation for more details on the exact commands to be used, but note that quote marks must be escaped.
    String command = "{\"on\": true,\"hue\": 50100,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(3,command);
    command = "{\"on\": true,\"hue\": 65280,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(4,command);
    command = "{\"hue\": 65280,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(3,command);
    command = "{\"hue\": 50100,\"sat\":255,\"bri\":255,\"transitiontime\":"+String(random(15,25))+"}";
    setHue(4,command);

    activated = true;
  }
  else{
      activated = false;
      client.println("deactivated");

      //was activated, so send a single off command
      String command = "{\"on\": false}";
      setHue(3,command);
      setHue(4,command);
  }
}

It's also interesting to not that my print calls in alterHueColors()  aren't triggering.

Full .ino file


texts:
I'm trying to pass an array to a library (written in c++) but the error:

undefined reference to `MyLib::arrayTest(int*)'
collect2: error: ld returned 1 exit status
Error compiling.

Is being produced.

My Code Is As Follows:

Testing.ino:

MyLib test = MyLib(5,4,6);

void setup(){
    int arr[10];

    test.arrayTest(arr);

    Serial.println(arr[0]);
}

MyLib.h:

class MyLib {
    public:
        MyLib(int x, int y, int z);

        void arrayTest(int* n);

MyLib.cpp:

void arrayTest(int* n){
    n[0] = 15;
}

Any help is greatly appreciated :)


texts: I want to measure the conversion rate of an arduino DUE. I know I could just take it from the datasheet but I need to measure it because I am running the ADC in free running mode. Hints are welcome, I really don't know where to start.


texts: Arduino button-controlled LED with AVR Assembly

texts:
I am trying to make a simple button-controlled LED, but I cannot seem to get any input from the button that would change the state of the LED. In other words, the program keeps branching to lighton, keeping the LED always on, regardless of the button state. I am using an Elegoo Uno R3.

Schematic:

Code:

.text
.global setup
.global loop

setup:
  ser r16
  sts DDRB, r16
  ldi r16, 0b00000000
  sts DDRD, r16
  ldi r16, 0b00100000
  sts PORTB, r16
  clr r16
  sts PORTD, r16

loop:
  lds r20, PORTD
  cpi r20, 0x00 ; PORTD always equal to 0x00 ?
  breq lighton
  clr r16
  sts PORTB, r16
  rjmp loop
lighton:
  ldi r16, 0b00100000
  sts PORTB, r16
  rjmp loop

Edit: I also implemented the method in https://stackoverflow.com/questions/39361410/creating-a-toggle-switch-in-avr-assembly to create a short delay with r18 instead of del, but it didn't help; see revised loop method below:

loop:
  cpi r18, 0
  brne dec_jmp
  lds r20, PORTD
  cpi r20, 0x00 ; PORTD always equal to 0x00 ?
  breq lighton
  clr r16
  sts PORTB, r16
  ldi r18, 250
  rjmp loop
lighton:
  ldi r16, 0b00100000
  sts PORTB, r16
  ldi r18, 250
  rjmp loop

dec_jmp:
  dec r18
  rjmp loop

With delay:

lighton:
  ldi r16, 0b00100000
  sts PORTB, r16
  call delay150
  ldi r16, 0b00000000
  sts PORTB, r16
  call delay150
  rjmp loop


texts:
I have a project where I use 22 servos. I attach all 22 of the servos in the setup and in the loop, I use myservo.write() command to make a particular servo move to a particular position.

The problem here is that, all the other servos become stiff at this point of time, even though I am not writing any value to those servos. By stiff I mean that the servo is holding at a particular random value. Which for most of the 22 servos is at or near 90°.

My question is how can I make a particular servo move, while allowing all the other servos to freely rotate. I think that when I attach a servo the program prevents the free rotation of the servo.

I was wondering if the signal to one of the servos is leaking to other servos because of an issue with wiring, but this is not the case. The other servos become stiff only when I attach them to the pins which have been "attached" as a servo in the program.


texts: Extremely unstable analogRead() on Arduino Nano when powered from an external source

texts:
I'm doing a really simple project with an Arduino Nano and found a problem.
The circuit is a simple temperature sensor and a tension read from an analog pin everything showed on a Nokia 5110 LCD.
When the Nano is connected to the USB everything works and the reads are perfect.
When I install the circuit on my car taking the 12V to the Vin and the GND from the centraline everything goes bad: I certainly know that the 12V is obviously not stable and oscillates a lot (between 12V and 14V).
What can be the solution? Should I add some ref or should I regulate the input tension to maintain it stable to a certain quantity?


texts: Unable to connect ESP8266 to WPA2+Enterprise network

texts:
I am trying to connect ESP8266 module to WPA2+Enterprise network with my ssid, username and password and the latest version supports such connection. I followed this link, and the code:

#include "ESP8266WiFi.h"
extern "C" {
  #include "user_interface.h"
  #include "wpa2_enterprise.h"
}

static const char* ssid = "ssid";
static const char* username = "username";
static const char* password = "password";
const char* host = "host_ip";

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

  Serial.print("Connecting to ");
  Serial.println(ssid);
   // Setting ESP into STATION mode only (no AP mode or dual mode)
  wifi_set_opmode(0x01);

  struct station_config wifi_config;

  memset(&wifi_config, 0, sizeof(wifi_config));
  strcpy((char*)wifi_config.ssid, ssid);

  wifi_station_set_config(&wifi_config);

  wifi_station_clear_cert_key();
  wifi_station_clear_enterprise_ca_cert();

  wifi_station_set_wpa2_enterprise_auth(1);
  wifi_station_set_enterprise_username((uint8*)username, strlen(username));
  wifi_station_set_enterprise_password((uint8*)password, strlen(password));

  wifi_station_connect();
  Serial.print("Wifi station connect status:");
  Serial.println(wifi_station_get_connect_status());

  // Wait for connection AND IP address from DHCP
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println(WiFi.status());
    delay(2000);
    Serial.println("Not connected");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()
{
  delay(2000);
}

OUTPUT:

Connecting to ssid
Wifi station connect status:1
6
Not connected
6
Not connected
.....

Status 6 is  WL_DISCONNECTED,i.e., module is not configured in station mode. I am not able to figure out what is causing the problem.


texts: Ublox GPS with Arduino Mega 2560 not working

texts:
Recently I bought a GPS module (ublox neo-6M-0-001) for my Arduino Mega 2560. I connected Vcc and Gnd (LED at GPS module glows blue and sometimes blinking).

GPS module RX port is connected to the Arduino's TX3, Port 14.
GPS module TX port is connected to the Arduino's RX3, Port 15.

As a first step I just want to print the serial data received from the GPS module:

#include "SoftwareSerial.h"

SoftwareSerial mySerial(15, 14); // RX, TX

void setup() {
  Serial.begin(9600);
  Serial.println("uBlox Neo 6M Test");
  mySerial.begin(9600);
}

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

Saldy, there is no data received from the GPS module. According to the datasheet the baud rate 9600 seems to be correct.

Do I need to configure the GPS module somehow before it delivers data? Do I need to buy an external antenna?

Thanks for your help.


texts: Use of additional i/o ports in Arduino Mega

texts: I'm a newbie in Arduino and I bought an Arduino Mega instead of the Uno. I want to know what the so-called additional i/o pins do. Are they the same with PWM and SPI? What can they do?


texts: Background processes - Arduino Mega and SeeedStudio CAN shield

texts:
I am attempting to interface an Arduino Mega 2560 with a system of four Black Jaguar motor controllers connected in CAN. I'm using the CAN shield from SeeedStudios to accomplish this.

The way Jaguars in CAN mode are configured, you must send a message every 100 ms to the network to keep the link active. However, I'm also getting input from Serial to another Arduino as well as sending other commands to the Jaguars, but not regularly enough to specifically time it out.

Is it possible to have the link message sent asynchronously in the background while I perform other code? I have looked into timers and interrupts, however I am unsure if this would truly solve the issue considering I have other processes that take more than 100 ms to complete.

Here's my loop statement:

loop() {
  CAN.sendMsgBuf(HEARTBEAT,1,0,volModeEnable); //HEARTBEAT keeps CAN link active
  setVoltage(3,.5); //Sets voltage of Motor by percent
  setVoltage(4,.5);
  setVoltage(6,.5);
  setVoltage(8,.5);
  //GrabFromSerial(); Takes longer than 100ms
  //Control Statement for Additional Commands goes here... (also necessary to be > 100ms)
}


texts:
#include <SoftwareSerial.h>

SoftwareSerial BTSerial(10, 11); // RX | TX

void setup() {
  pinMode(9, OUTPUT);
  // this pin will pull the HC-05 pin 34 (key pin) HIGH to switch module to AT mode
  digitalWrite(9, HIGH);
  Serial.begin(9600);
  Serial.println("Enter AT commands:");
  BTSerial.begin(38400);
  // HC-05 default speed in AT command more
}

void loop() {
  // Keep reading from HC-05 and send to Arduino Serial Monitor
  if (BTSerial.available())
    Serial.write(BTSerial.read());

  // Keep reading from Arduino Serial Monitor and send to HC-05
  if (Serial.available())
    BTSerial.write(Serial.read());
}

I have tried this code but I am not able to change the baud rate. Please suggest me a solution.


texts: to increase the reading and writing/printing speed of data from Arduino Nano to Raspberry Pi 3B+

texts:
In my project, I have to read the input pin number(send by RPi), where 8 sensors are attached to Arduino Nano, after reading Arduino Nano send the real-time values of all sensors through serial USB communication. All is fine, but my problem is that I need to speed up the sending of data since it takes to long to read from Rasberry pi.
I put the delay of 70 milliseconds but if I try to reduce more than that, I encounter a problem i.e data overwrites. My baud rate is 115200.
Kindly help me with the code to make it fast.

int analogInputPin;
float voltage;

void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(115200);
}

void loop() {
  // if any data on the serial port are available
  // read it and try to update the analogInputPin
  // based on the number that was read on the serial
  if (Serial.available() > 0) {
    analogInputPin = Serial.parseInt();
  }

  // read the analog value:
  int analogInputPinValue = analogRead(analogInputPin);
  voltage=(5./1023.)*analogInputPinValue;

  // print the results to the serial port:
  // the output should have the following form: INPUTPIN:VALUE
  // followed by a newline character
  Serial.print(analogInputPin);
  Serial.print(":");
  Serial.print(voltage);
  Serial.println("");

  // wait 50 milliseconds before the next loop
  delay(50);
}


texts: How to control 19 RGB LED strips with one arduino?

texts:
I need to light up 19 RGB LED strips, which it seems would require 19*3=57 PWM outs and 57 transistors.  The transistors aren't an issue, but of course the 57 PWM's is.  Even if I hacked the digital IO ports to work as PWM, I still wouldn't have enough.

How can I do this more simply?  Is there some kind of device I can get that would let me just pass data to it, perhaps over I2C, and it would control many PWMs? Is there another solution I haven't considered?  Maybe whatever is used to control those 8x8 RGB LED dot matrixes?

Any help would be greatly appreciated.  Thank you!


texts: In a line there're voltage levels representing words of dots and dashes. In particular, the device is intended to raise an output each time a given pattern of five short/long signals (say 1s and 2s durations, respectively) is recognized (and restart if nothing comes in for a given time). A sort of Morse code recognizer (Arduino Uno preferred, but others are also OK) would be a good starting point. Any hint is welcome, I'm new in this community.


texts: Is it possible to program an ESP8266 12F using an Arduino Nano?

texts: I just got my ESP8266, but I am unable to program it. Since it can't be connected to via USB, I was wondering if I can program it using an Arduino or perhaps use it as a shield for an Arduino Nano. I haven't been able to find a good guide online. Any help is greatly appreciated.


texts:
I'm wanting the results from each of the 6 ultrasound modules to print on their respected line after new results have been generated instead of spitting out a continuous flow (see attached image). I've downloaded Realterm and got the results to show on there as I've read that the serial monitor can't do that but I don't know where to put the '\r' syntax within my script as I have multiple serial.prints to display the data I need.

Here is a section for 1 of the ultrasound modules, they are just repeated for the differing modules.

Thanks in advance for any help!

  //Object Ahead Distance.
  long duration1, distance1;
  digitalWrite(trigPin1, HIGH);
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = (duration1/2) / 29.1;

   delay(500);
   if (distance1 >= 40){
    Serial.print("Nothing Ahead, Okay");
    Serial.print(distance1);
    Serial.println("cm");}
   else if (distance1 <= 39 || distance1 >= 29){
    Serial.print("Vehicle Ahead, Slow ");
    Serial.print(distance1);
    Serial.println("cm");}```


texts:
Case 1
I am measuring output voltage of PIR sensor, I am getting 3.3v

Case 2
I have connected a resistor and a led to output of PIR sensor. Now when I measure voltage at the output pin of the sensor, I am getting 2.04v only.

In case 2 as the output voltage is dropped, it is not able to trigger a high state to arduino pin.

Where am I going wrong? What shall I change?


texts: How do I control multiple LEDs strips with Arduino

texts:
I want to decorate my house with LEDs strips on each step of my stairs.
I will buy LEDs strips with a 12V power supply.

I want that if I put my foot on the first step, the first LEDs strip turn on, and after every second, the next step turn on too until the last step.
After 10 seconds on, the step must turn off.

To detect my foot, I'm thinking of using that kind of component : PIR (motion) sensor (product 189 on adafruit website). It act like a push button.

My first thought was to create two circuit loops.
One to supply the LEDs strips with a transistor between each strip.
And the second to control the transistor, so the turn on/off signal.

Thanks to your advices, I decided to use an Arduino to do the control loop.

I found this (http://www.zem.fr/decouverte-du-composant-74hc595-8-bit-shift-register/):

It's two 8-bit shift register, I have 16 steps on my stairs.
With a simple bit of code, I successed in writing a Arduino code that push ten HIGH(1) bits from the right then sixteen LOW(0) bits. So I have what I want with the LEDs.

The question is : how to connect the 16 LEDs strips with my circuit (instead of the single led) ?

English is not my native language, I tried to do my best.


texts: What bootloader does the Arduino Micro come with?

texts: I've been looking to modify the Arduino Micro bootloader (specifically changing the VendorID and ProductID) of the Arduino. What bootloader comes pre-installed on the Arduino Micro? and how would I go about building and uploading a modified bootloader?


texts: Continuous Servo not setting speed correctly

texts:
I have two continuous servos connected to my Uno, and I'm running this code on it:

leftServo.write(91);
rightServo.write(102);
delay(3000);

leftServo.write(112);
rightServo.write(81);
delay(3000);

leftServo.write(91);
rightServo.write(102);
delay(3000);

int i;
while(1) {
  i++;
}

When I run the code, the wheels stop for three seconds (91 and 102 are the zero values for these servos) then they spin for three seconds, then the left servo stops, but the right one only slows down about half way, it doesn't stop, even though the exact same number is used as before.

I can't figure out why this is?


texts: I fried the AMS1117 voltage regulator on my Arduino Clone, is this the cause?

texts:
I had the 12V DC power jack plugged-in all the time, and "to make things more exciting" I also plugged-in the "data" USB whenever I had a new sketch to upload. Is this combination a big no-no, or is my step-up converter to blame?

I am completely new to this stuff but now when thinking of it those 12V from the power jack + 5V from the "data" USB probably violate this clause:
If using more than 12V, the voltage regulator may overheat and damage the board.


texts: Is is possible to hook up an SD card and a GSM/GSRM module?

texts:
Is it possible to hook up a GSM/GSRM module AND an SD card at the same time to an Arduino Uno, or any Arduino?

I want to build a cellphone to read off the buttons that are being dialed into it for a poor guy who has no hope of using a regular cellphone, and I figure I need to include wav files for the buttons (and any other functions) on an external source.

I'm a good programmer, so if I can hobble the parts together I can make them talk to each other.  But, I'm not so sure the different schemes for this all use the same pins, so I was wondering if someone would be so kind as to enlighten me..


texts: Why isn't my ESP32 staying in Deep Sleep longer than 35 minutes?

texts:
I've been having an odd issue with a new custom ESP board. I can't push deep-sleep time past 35 minutes no matter how I adjust the timing.
Below is my current pertinent code, but basically the device wakes up, reads several environmental sensors, sends them to the cloud and then turns off. I'm aiming to sleep for an hour between readings to preserve battery power.
 #include <esp_deep_sleep.h>

int SLEEP_TIME;

#define uS_TO_S_FACTOR 9e9  //Conversion factor for micro seconds to seconds
#define TIME_TO_SLEEP  9e8 //Time ESP32 will go to sleep (in seconds)

SLEEP_TIME = (uS_TO_S_FACTOR * TIME_TO_SLEEP);
esp_sleep_enable_timer_wakeup(SLEEP_TIME);

esp_deep_sleep_start();


texts: RC522 RFID reader doesn't read NTAG216 chip

texts:
I have an RFID-RC522 module based on the MFRC522 chip. This chip is described in the datasheet as supporting "ISO/IEC 14443 A/MIFARE and NTAG" protocols. I have wired it up to an Arduino Uno using the recommended wiring in the documentation for the MFRC522 library I'm using. I have a sketch that (among other things) polls for presence of a new card:

void setup() {
    lcd.setup ();       // initialise LCD display
    SPI.begin();        // Init SPI bus
    mfrc522.PCD_Init(); // Init MFRC522 card
}

void loop() {
    // Look for new cards
    if ( ! mfrc522.PICC_IsNewCardPresent()) {
        return;
    }
    lcd.println ("Found new card");
    ...
}

This sketch correctly detects the presence of the card that was supplied with the module (I believe this is a Mifare Classic card) but does not detect my NTAG216 implant. Does anyone have any idea why it might be failing to find the implanted chip?


texts: Using arduino mega is making my cnc claw buggy. Help

texts:
I have three nema 23 steppers with one 8 channel relay(all the pins used) powering two dc motors and 4 IR sensors for feedback on the machine.
The problem is my machine is working fine for only 2 to 3 minutes until it just resets itself in the middle of the routine and crashes my whole system.
I am using 1/2 step microstepping with TB6600 stepper driver.
Also my arduino is mega 2560, maybe thats the problem I don't know about.

Here I am attaching the code
const int dirPin1=2;
const int stepPin1=3;
const int dirPin2=4;
const int stepPin2=5;
const int dirPin3=6;
const int stepPin3=7;
int del=1;
void setup() {
 pinMode(2,OUTPUT);
 pinMode(3,OUTPUT);
 pinMode(4,OUTPUT);
 pinMode(5,OUTPUT);
 pinMode(6,OUTPUT);
 pinMode(7,OUTPUT);
 pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(13,OUTPUT);
pinMode(14,OUTPUT);
pinMode(15,OUTPUT);
pinMode(16,INPUT);
pinMode(17,INPUT);
pinMode(18,INPUT);
pinMode(19,INPUT);
digitalWrite(8,HIGH);
digitalWrite(9,HIGH);
digitalWrite(10,HIGH);
digitalWrite(11,HIGH);
digitalWrite(12,HIGH);
digitalWrite(13,HIGH);
digitalWrite(14,HIGH);
digitalWrite(15,HIGH);

}
void picker_up(){
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,LOW);
  digitalWrite(11,LOW);
  delay(570);
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  delay(100);
}
void picker_down(){
  digitalWrite(8,LOW);
  digitalWrite(8,LOW);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  delay(320);
  digitalWrite(8,HIGH);
  digitalWrite(9,HIGH);
  digitalWrite(10,HIGH);
  digitalWrite(11,HIGH);
  delay(100);
}
void claw_close(){
  digitalWrite(12,LOW);
  digitalWrite(13,LOW);
  digitalWrite(14,HIGH);
  digitalWrite(15,HIGH);
  delay(100);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  digitalWrite(14,HIGH);
  digitalWrite(15,HIGH);
  delay(100);
}
void claw_open(){
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  digitalWrite(14,LOW);
  digitalWrite(15,LOW);
  delay(100);
  digitalWrite(12,HIGH);
  digitalWrite(13,HIGH);
  digitalWrite(14,HIGH);
  digitalWrite(15,HIGH);
  delay(100);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(dirPin1,HIGH);
digitalWrite(dirPin2,HIGH);
digitalWrite(dirPin3,LOW);
for(int i=0;i<=1200;i++){
  digitalWrite(stepPin1,HIGH);
  digitalWrite(stepPin2,HIGH);
  digitalWrite(stepPin3,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  digitalWrite(stepPin2,LOW);
  digitalWrite(stepPin3,LOW);
  delay(del);
}
for(int i=1;i<=400;i++){
  digitalWrite(stepPin1,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  delay(del);
}
delay(1000);
picker_down();
claw_open();
claw_close();
picker_up();
delay(2000);
digitalWrite(dirPin1,LOW);
digitalWrite(dirPin2,LOW);
digitalWrite(dirPin3,HIGH);
for(int i=1;i<=400;i++){
  digitalWrite(stepPin1,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  delay(del);
}
for(int i=0;i<=1200;i++){
  digitalWrite(stepPin1,HIGH);
  digitalWrite(stepPin2,HIGH);
  digitalWrite(stepPin3,HIGH);
  delay(del);
  digitalWrite(stepPin1,LOW);
  digitalWrite(stepPin2,LOW);
  digitalWrite(stepPin3,LOW);
  delay(del);
}
delay(2000);
}

I am not getting why this is happening. Or do I need some more electronic components  included in the machine and I know I could have used mosfets to control the motors but I am just way too lazy.
I used uno before this and it used to work fine, so should I just go back to using it?
Also I have modified the code to be compatible with the uno again so please bare with the pin numbers.


texts: Make Arduino send and receive at the same time

texts:
I am working on a project where I connect a GPS module and GPRS SIM900 shield. The location will be sent when it recives a certain character.

Now my question is, can the Arduino receive from GPRS and GPS module data at the same time? The GPS is not given coordinates, however it works properly without receiving a message from the GPRS.

I am using softwareserial  for both. Should/can I use hardware serial and softwareserial?


texts:
Hey so basically I have my Arduino uno r3 setup with my RFID-RC522. I am looking to add this library to so I can use the examples alongside the ones I already have.
https://github.com/BoolLi/RC522_RFID_NFC_Utilities

I haven't been able to add them correctly and hope someone can help me out doing this. I currently have these ones already added and working correctly:
https://github.com/miguelbalboa/rfid


texts:
I want to convert a bitmap into binary array. My bitmap image is 272*208 pixel monochromatic 1bpp image. I'm confused when the width I get from my image is 16 instead of 272, the height is corrected. And when I skip the bitmap header to get bitmap infomation, I got string of meaningless number in my text file.

#include <SPI.h>
#include <SD.h>
#include <TFT.h>

File bmpImage;
File textFile;

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

Serial.print("Initializing SD card...");
if (!SD.begin(53)) {
  Serial.println("initialization failed!");
  return;
}
Serial.println("initialization done.");
int height = 0;
int width = 0;

// Open
bmpImage = SD.open("Circle.bmp", FILE_READ);
textFile = SD.open("test.txt", FILE_WRITE);

bmpImage.seek(0x12);// width in pixel = 16
width = bmpImage.read();
bmpImage.seek(0x16);// height in pixel = 208
height = bmpImage.read();
Serial.println(width);
Serial.println(height);

int imageSize = height*width;

bmpImage.seek(0x36);//skip bitmap header

for(int i = 0; i < height; i ++) {
  for (int j = 0; j < width; j ++) {
    textFile.write(bmpImage.read());
    textFile.write(" ");
  }
  textFile.write("\n");
}

bmpImage.close();
textFile.close();

Serial.println("done write");
}

void loop()
{
  // nothing happens after setup
}


texts: Analogue input 0 staying at 0 when sensing light with Arduino and a photocell

texts:
I am doing a circuit for capturing light intensities.

I followed the tutorial provided by Adil Moujahid

Yet, when I plug the jumper wires on 5V the circuit stops working and when I plug on 3.3V the analog in A0 sent back only a series of zero...

What did I missed? I acknowledge that I tried to be the most economical on the jumper wires...

The sketches, program and circuit given by Adil Mouhajid

My attempt


texts: Is it OK to Serial.print(message), when the USB cable is not connected to a host PC?

texts:
Often I put a bunch of Serial.print( F("debugging messages") ) in my Arduino sketch.

Normally those messages go up a USB cable to a host PC so those messages can be seen on the serial monitor.

I want to install this Arduino as part of a stand-alone system far from any PC and plug the "host" end of the USB cable into a wall-wart USB charger.

Without anything to accept those messages, the buffer on the Arduino eventually fills up, right?
Do I need to do anything to keep the Arduino from overflowing and crashing when it's not connected to a host PC?

Does it make any difference if I'm using a (1) "single-chip" Arduino-compatible where the processor includes on-chip USB, vs. (2) an Arduino-compatible with separate "USB interface chip" and "processor chip"?
(By "single-chip Arduino-compatible", I mean things like the Arduino Leonardo, Arduino Yún, LilyPad Arduino USB, Arduino Micro, the Teensy-LC, etc.)


texts: Interrupts inside a class attaching to the function of the class

texts:
Hello i have a class and i would like to attach an interrupt inside the class and attach it to a function of the class.

class counter{
  public:

  counter(int pin){
    Ipin=pin;
  }
  void startCounting(){
    attachInterrupt(digitalPinToInterrupt(Ipin),this.addCount,CHANGE);
  }
  void stopCounting(){
    detachInterrupt(digitalPinToInterrupt(Ipin));
  }

  void addCount(){
    count++;
  }

  private:
  int Ipin;
  unsigned long count= 0;
};

Some what of the code above. There can be multiple intialization of this class. hopefully depending on the user uses a different pin.

There is a way arround this where the attaching of pin is done in the loop or setup and just calling a public function of the class. But to me that kinda doesn't fit the spirit of classes like a properly made library is done.

Im not very good at programming if you could teach me how it would be greatly appreciated.


texts:
If I am correct, the first two pins (RX/TX) are connected to the USB, and I cannot use the serial monitor and the first RX/TX serial ports at the same time.

But, what about the other 3 auxiliary serial ports? Are they separated? Do each one of them has it's own buffer?

For example: Is it possible to add, let's say, four Bluetooth modules(Let's say HC-05) and use each of them for a different purpose?


texts: How to / is it possible to change Vendor Name in ESP8266-12E?

texts:
I am aware of that it is possible to change hostname for ESP8266 but I want to change vendor name also so that it lists my company/product name in routers/firewalls.

Is it possible?


texts: How to use? ATmega328P Development Board for Arduino UNO R3 Bootloader Project DIY.


texts: Connecting Saleae Logic 8 to MISO (pin 12) on Uno 3 w/ NRF24L01+ halts program

texts:
I have an NRF24L01+ with the base module (regulates voltage) connected to an Arduino Uno 3.  I'm using the tmrh20 NRF24 library and am running one of the example programs.  I'm trying to sniff the SPI bus so I have a Saleae Logic 8 hooked up.  As soon as I connect the clip to the MISO pin the Arduino program stops executing.  I'm able to reproduce this 100% of the time.  It seems it is only the MISO pin that is causing the problem.  For the library I am using MISO uses pin 12 on the Uno 3.

Anybody know what is going on?  It seems as if the Saleae is grounding pin 12 when I hook it up.  Not sure why it is only pin 12 that is an issue though.

I can reproduce the same problem when I manually connecting pin 12 straight to GND as well.

I can collect samples without MISO just fine but that of course only tells me half the story.

Any suggestions?

EDIT:
Here are some links and resources for more information.

I'm basically following the instructions from this article:
http://arduino-info.wikispaces.com/Nrf24L01-2.4GHz-HowTo

The breakout board
http://www.addicore.com/1x-nRF24L01-Adapter-p/ad279.htm

And it's schematic:

Link to the datasheet for the radio itself:
http://www.nordicsemi.com/eng/Products/2.4GHz-RF/nRF24L01

And some photos of how I have it wired up:


texts: Sending data to serial port using Processing IDE (Debug works but run doesn't)

texts:
I'm trying to read a series of numbers in a text file on my PC then send them to my Arduino board via serial port. The numbers are split by commas and dashes so I perform two loops. Sending a number to the serial port should light the equivalent LED on the Arduino board. The problem is that only the first iteration in the first loop doesn't light the equivalent LEDS in run mode though it does in the debug mode.; other iterations and other loops run flawlessly. There aren't any problems with the hardware 100% for sure. Any help would be greatly appreciated.
Here is the code:

import processing.serial.*;
import java.io.*;
int mySwitch=0;
int counter1=0;
int counter2=0;
String [] subtext;
String[] Lines;
Serial myPort;

void setup(){
//Create a switch that will control the frequency of text file reads.
//When mySwitch=1, the program is setup to read the text file.
//This is turned off when mySwitch = 0
 mySwitch=1;

 //Open the serial port for communication with the Arduino
 //Make sure the COM port is correct
 myPort = new Serial(this, "COM36", 9600);
 myPort.bufferUntil('\n');
}

void draw() {
 if (mySwitch>0){
 /*The readData function can be found later in the code.
 This is the call to read a CSV file on the computer hard-drive. */
 readData("Y:/MyTextFile.txt");

 /*The following switch prevents continuous reading of the text file, until
 we are ready to read the file again. */
 mySwitch=0;
 }
 /*Only send new data. This IF statement will allow new data to be sent to
 the arduino. */

  while(counter1<Lines.length){
 subtext = splitTokens(Lines[counter1],",");
 counter2=0;
 while(counter2<subtext.length){
 /* Write the next number to the Serial port and send it to the Arduino
 There will be a delay of half a second before the command is
 sent to turn the LED off : myPort.write('0'); */

 myPort.write(subtext[counter2]);

 //delay(300);

// delay(100);
 //Increment the counter so that the next number is sent to the arduino.

 counter2++;
 }
 delay(2000);
 myPort.write('0');
 delay(2000);
 counter1++;
 }
 //If the text file has run out of numbers, then read the text file again in       5 seconds.
delay(5000);
mySwitch=1;

}

/* The following function will read from a CSV or TXT file */
void readData(String myFileName){

 File file=new File(myFileName);
 BufferedReader br=null;

 try{
 br=new BufferedReader(new FileReader(file));
 String text=null;

 /* keep reading each line until you get to the end of the file */
while((text=br.readLine())!=null){
 /* Spilt each line up into bits and pieces using a comma as a separator */
 Lines = splitTokens(text,"-");
 }
 }catch(FileNotFoundException e){
 e.printStackTrace();
 }catch(IOException e){
 e.printStackTrace();
 }finally{
 try {
 if (br != null){
 br.close();
 }
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
 }

Here is the Arduino code:

void setup() {
 // initialize the digital pins as an output.
 pinMode(2, OUTPUT);
 pinMode(3, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(5, OUTPUT);
 pinMode(6, OUTPUT);

// Turn the Serial Protocol ON
 Serial.begin(9600);
}

void loop() {
 byte byteRead;

 /* check if data has been sent from the computer: */
 if (Serial.available()) {

 /* read the most recent byte */
 byteRead = Serial.read();
 //You have to subtract '0' from the read Byte to convert from text to a    number.
 byteRead=byteRead-'0';

 //Turn off all LEDs if the byte Read = 0
 if(byteRead==0){
 //Turn off all LEDS
 digitalWrite(2, LOW);
 digitalWrite(3, LOW);
 digitalWrite(4, LOW);
 digitalWrite(5, LOW);
 digitalWrite(6, LOW);

 }

 //Turn LED ON depending on the byte Read.
 if(byteRead>0){
 digitalWrite((byteRead+1), HIGH); // set the LED on
   }
  }
 }


texts: Arduino Uno simple LED example with pointers

texts:
I am new to Arduino and I have recently started off by trying to turn on an LED connected to pin 13 on my Arduino Uno using pointers.

I opted to do this with pointers because this would give me a better understanding on what really goes behind when I use predefined Arduino functions.

My simple code looks like this,

uint8_t *data = (uint8_t *) 0x05; //PortB data register ptr (Since pin 13 is PB6)
uint8_t *dir = (uint8_t *) 0x04;  //PortB dir register ptr (Since pin 13 is PB6)

void setup() {
    *dir = 0x40;  //PB6 direction set to O/P
    *data = 0x40; //PB6 data set to 1 to turn on the LED
}

void loop() {
  *data = 0x40;
}

I tried the same program using   pinMode(13, OUTPUT) and digitalWrite(13, LOW) functions and it works fine. But I do not understand what could be wrong with my pointers. If you find anything wrong, kindly let me know.


texts:
I am a beginner with c and arduino and am trying to create a 'whack-a-mole' style game. I am having problems with the 'score' variable. At the moment, I am just trying to get it to print to the Serial Monitor. There are no errors when I verify it but nothing shows up when it is uploaded. Could somebody please help me understand what is going wrong and inform me of how I can fix it. Here's my code:
int led1Pin = 11;
int led2Pin = 10;
int led3Pin = 4;
int led4Pin = 2;
int button1pin = 13;
int button2pin = 8;
int button3pin = 12;
int button4pin = 7;

float highLED = 0;

int score = 0;

int exitSubLoop = 0;

byte leds = 0;

void setup()
{
  pinMode(led1Pin, OUTPUT);
  pinMode(led2Pin, OUTPUT);
  pinMode(led3Pin, OUTPUT);
  pinMode(led4Pin, OUTPUT);
  pinMode(button1pin, INPUT_PULLUP);
  pinMode(button2pin, INPUT_PULLUP);
  pinMode(button3pin, INPUT_PULLUP);
  pinMode(button4pin, INPUT_PULLUP);
  digitalWrite(led1Pin, LOW);
  digitalWrite(led2Pin, LOW);
  digitalWrite(led3Pin, LOW);
  digitalWrite(led4Pin, LOW);
}

void loop()
{
  Serial.println(score, DEC);

  exitSubLoop = 1;

  highLED = random(1, 5);

  if(highLED == 1){
    digitalWrite(led1Pin, HIGH);
  }
  if(highLED == 2){
    digitalWrite(led2Pin, HIGH);
  }
  if(highLED == 3){
    digitalWrite(led3Pin, HIGH);
  }
  if(highLED == 4){
    digitalWrite(led4Pin, HIGH);
  }

  while(exitSubLoop != 0){

  if ((digitalRead(button1pin) == LOW) && (highLED == 1))
  {
    digitalWrite(led1Pin, LOW);
    score++;
    exitSubLoop--;

  }
  if ((digitalRead(button2pin) == LOW) && (highLED == 2))
  {
    digitalWrite(led2Pin, LOW);
    score++;
    exitSubLoop--;

  }
  if ((digitalRead(button3pin) == LOW) && (highLED == 3))
  {
    digitalWrite(led3Pin, LOW);
    score++;
    exitSubLoop--;

  }
  if ((digitalRead(button4pin) == LOW) && (highLED == 4))
  {
    digitalWrite(led4Pin, LOW);
    score++;
    exitSubLoop--;

  }

  if ((digitalRead(button1pin) == LOW) && (highLED != 1))
  {
      score--;
    }
    if ((digitalRead(button2pin) == LOW) && (highLED != 2))
    {
      score--;
    }
    if ((digitalRead(button3pin) == LOW) && (highLED != 3))
    {
      score--;
    }
    if ((digitalRead(button4pin) == LOW) && (highLED != 4))
    {
      score--;
    }
    delay(200);
  }
}

P.S I don't know whether it makes any difference but I am using the Arduino UNO


texts: Arduino reading value from external devices on

texts:
For this device it says:

The PC Interface Option has all the features of the standard DC1100, but also has a COM Port interface that allows you to capture the air quality data to a PC for graphing and analysis. A 9pin serial cable or USB-to-COM Port Adapter (not included) links the DC1100 to your PC or laptop which then captures the data as it samples.

Is it possible to connect such a device directly to an Arduino so that measured data are sent through the Serial Interface and Arduino is able to read them and manipulate them?


texts: Programming arduino using avrdude from command prompt

texts:
Out of curiosity, I am trying to upload a simple hex file to Arduino UNO using avrdude from windows command prompt.

As per this forum, I tried to implement it. But got stuck at

  avrdude: ser_open(): can't open device "COM41": The system cannot find the file
  specified.

This command was directly imported from Arduino IDE verbose, and also it works fine when uploaded with Arduino IDE. I checked both the device and syntax are correct unless I would not be able to generate the hex file by Arduino compiler.

P.S. I have installed Winavr separately although it was pre-installed by Arduino
itself.

Here is a snapshot of the error

What could be the possible reason for it to fail? Please notify, if anything is missing.


texts: exit status 1 error compiling for board arduino/Genuino Uno when tone code is used

texts:
I am just trying to use an ultrasonic sensor with a buzzer but the buzzer doesn't respond to my code. I mean it doesn't make any sound. I tested it to check if by sending 5 volts to it, it will make a sound.. and it did... but using this code below... for some reason, it doesn't make any sound....

#include <NewPing.h>
#define TRIGGER_PIN 11
#define  ECHO_PIN 12
#define buzzer 13

NewPing sonar1 (TRIGGER_PIN, ECHO_PIN);

long inches1;
int sound = 250;

void setup (){

  Serial.begin (9600);

  pinMode (TRIGGER_PIN, OUTPUT);
  pinMode (ECHO_PIN, INPUT);
  pinMode (buzzer, OUTPUT);

}

void loop () {

  inches1 = sonar1.ping_in();
   if (inches1 <= 5 ){
 //   sound = 250;
    tone(buzzer, 1000); // Send 1KHz sound signal...
    delay(1000);        // ...for 1 sec
    noTone(buzzer);     // Stop sound...
    delay(1000);
    Serial.print (inches1);
    Serial.print ('\n');
   }
  delay (200);
}


texts: I'm wondering if I can run Arduino mega on 5V power supply, even though it's recommended for 6-12V. USB has only 5V right, will it be a problem? I expect to draw quite a lot of power from the 5V pin too so could it be a problem?


texts:
I'm trying to detect baud rate of Arduino Mega2560 by using C#. My code is below:

SerialPort SP=new SerialPort();
SP.BaudRate = 115200;

BaudRate is specified as a constant like this, but I would like to automatically detect it.

For instance, if Arduino code includes Serial.begin(xxxx), program should declare SP.BaudRate = xxxx.

How can I do it?


texts: Can I read two PWM signals and output two square waves on an UNO?

texts:
My system requires that I read two independent PWM signals (60hz) and output two corresponding square waves. These output square waves vary in frequency according to their corresponding input duty cycle. The output frequencies will vary between 1-60Hz. (outside of tone() range)

I'm planning out the best way to approach this project.
My initial thought is to use the two available external interrupts set to CHANGE to measure the inputs. I believe I'll also need to reference a timer in this routine, to determine the time since the last change.

Unless I'm mistaken, it looks like I will also need a timer interrupt for each output, to control the frequency properly.

The Arduino UNO has 3 timers. timer0: 8bit (used internally), timer1: 16bit, and timer2: 8bit. In short, can I run all of these interrupts in the same code? Will I run out of timers, or can I multitask the timers between my requirements?

Thanks!


texts: Waveshare 1.54 inch ePaper display requires 5Vs from Arduino Uno

texts:
I have an Arduino Uno and I would like to attach a Waveshare 1.54“ display (red, black & white) to it.

All the specs tell me that it consumes 3.3 V which I have readily available on the Arduino Uno.

I could not get the display to work until I attached the Power pin to 5V instead of 3.3V.

I did try this with two different ePaper displays and the situation was the same.

I also tried to power the display with a Raspberry Pi‘s 3.3V (with the GNDs connected). But this did not work either.

So I am wondering what I am missing here, is it simply a power issue and my Arduino can‘t deliver the necessary current?


texts: Arduino UNO stuck in Setup function when interfacing UNO with ESP8266 module

texts:
Following is my code that i am trying to use it with Arduino Uno with ESP8266 module but my code stucked in setup function why is that.

#include "ESP8266.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12,13);
#define SSID        "abcd"
#define PASSWORD    "87654321"
#define HOST_NAME   "www.baidu.com"
#define HOST_PORT   (80)

ESP8266 wifi(mySerial);

void setup(void)
{
    Serial.begin(9600);
    Serial.print("setup begin\r\n");

    Serial.print("FW Version:");
    Serial.println(wifi.getVersion().c_str());

    if (wifi.setOprToStationSoftAP()) {
        Serial.print("to station + softap ok\r\n");
    } else {
        Serial.print("to station + softap err\r\n");
    }

//    if (wifi.joinAP(SSID, PASSWORD)) {
//        Serial.print("Join AP success\r\n");
//
//        Serial.print("IP:");
//        Serial.println( wifi.getLocalIP().c_str());
//    } else {
//        Serial.print("Join AP failure\r\n");
//    }
    delay(500);
    if (wifi.disableMUX()) {
        Serial.print("single ok\r\n");
    } else {
        Serial.print("single err\r\n");
    }

    Serial.print("setup end\r\n");

}

void loop(void)
{
    uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("create tcp ok\r\n");
    } else {
        Serial.print("create tcp err\r\n");
    }

    char *hello = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
    wifi.send((const uint8_t*)hello, strlen(hello));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n");
    }

    if (wifi.releaseTCP()) {
        Serial.print("release tcp ok\r\n");
    } else {
        Serial.print("release tcp err\r\n");
    }

    while(1);

}

On Serial Monitor i get the following continuously

setup begin
FW Version:0018000902
to station + softap ok
singl

setup begin
    FW Version:0018000902
    to station + softap ok
    singl


texts: cast double to long leads to unexpected results

texts:
I wrote a little program to show my problem:

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

  double K=39.85;
  double a=K*100;
  Serial.print("a= ");
  Serial.println(a);

  long val_long = 0;
  val_long = a;
  Serial.print("val_long= ");
  Serial.println(val_long);
}

void loop() {
}

I get this back from my Arduino uno:

a= 3985.00
val_long=3984

I've been pondering for a long time and can't find the mistake! Why is the long value decremented by one? Can anybody help me please?


texts: Eeprom write function does not seem to write in more than 100 locations

texts:
I am trying log my sensor data (1 byte each) on my Arduino Uno Eeprom. I have an ATmega328 on it, so it should allow me to write up to 1Kb on it, however I've tried the Eeprom write command and it does not seem to write to more than 100 locations on it (the first 100 bytes!)

I am using the Eepromex library.

Any thoughts on what's causing this?

Edit:

These are the excerpts from my code related to Eeprom logging:

int addr1 = 0;
int addr2 = 256;

  // Store Data in EEPROM

  EEPROM.write(addr1,FinalMoisture[0]);

    delay(5);

  EEPROM.write(addr2,FinalMoisture[1]);

    delay(5);
  // advance index pointer to the next location.  There are 256 bytes assigned for each sensor in the EEPROM, so go back to 0 when we hit 255/511.

  addr1 = addr1 + 1;

  if (addr1 == 255)
    addr1 = 0;

  //same for addr 2 :

   addr2 = addr2 + 1;

  if (addr2 == 511)
    addr2 = 256;

  // delay until next measurement (msec)
 Sleepy::loseSomeTime(30000);

PS: As mentioned earlier I've included the EepromEx library. Each sensor stores only first 50 locations. Also, I've noticed that if I run a single loop instead of storing data in two locations, I can write 100 straight entries. In any case it seems that the write function is limited to 100?

Could this be a setting in the library? How to disable/modify it? I tried looking at the info on the lib author's postings but didn't help.


texts: Create own apache web server on Arduino Uno... just like you can on a raspberry pi?

texts:
I was wondering if I could create my own apache web server on my Arduino Uno, just like I did on my raspberry pi - https://www.raspberrypi.org/documentation/remote-access/web-server/apache.md

Anyone have any idea about this? From my research it seems like I cant achieve the same results on an arduino uno.

Thanks


texts: How to loop over objects or pass object to function?

texts:
I'm not sure if this is more of an C++ question, but I've looked up both and still have no idea.

I have a sketch which controls 6 stepper motors using the AccelStepper library and in order to shorten the code, I would like to simply loop over them, or pass them to a function individually. They are all initialised with different parameters and then placed in an array.

However I get the error "conversion from ‘SomeClass()’ to non-scalar type ‘SomeClass’ requested" or "conversion from ‘SomeClass (*)()’ to non-scalar type ‘SomeClass’ requested" depending on what I try.

I've got experience with C and Java, not much C++ and I thought it would be a straightforward array of pointers, but I can't get the right combination.

I've made a cut down version that I try to compile with gcc to demonstrate either approach. I've removed all attempts at pointers with & or * to explain what I want:

SomeClass classA();
SomeClass classB();

// error: conversion from ‘SomeClass()’ to non-scalar type ‘SomeClass’ requested
SomeClass things[2] = {classA, classB};

int init(class SomeClass thing) {
    std::cout << "Setting up thing ";
    thing.setFoo(100);
}

int main() {

    for (int i=0; i < 2; i++) {
        things[i].setFoo(100);
    }

    // could not convert ‘classA’ from ‘SomeClass (*)()’ to ‘SomeClass’
    init(classA);

    return 0;
}

And just for completeness my class files which are simplified versions of the AccelStepper class:

SomeClass.h:

#include <stdlib.h>

class SomeClass
{
public:
    SomeClass();

    void    setFoo(float foo);
};

SomeClass.cpp:

#include <stdlib.h>
#include <string>
#include <iostream>
#include "SomeClass.h"

SomeClass::SomeClass()
{
}

void SomeClass::setFoo(float foo)
{
    std::cout << "foo ";
}

I hope someone doesn't mind explaining what is probably really simple and obvious! :)


texts: Increase or decrease const byte value inside the code with a push button

texts:
I'm kind of new in the Arduino world. I decided to make a self learning project with an Arduino where it controls a conveyor that simply moves from right to left and back again. There is a start and stop button. On each end of the conveyor are inductive sensors to stop the motor when it reaches the end position. After a delay, the conveyer starts again the opposite direction. Inside the code I have a cycle counter that stops the conveyer after a certain number of cycles.
Now my question is, how could I change the value of the cycle counter using two push buttons. One to increase the other to decrease.
If there is somebody who could help I would appreciate.
Thanks already
const byte sensorLinksEnd  =  2;
const byte sensorRechtsEnd =  3;
const byte startPin        =  4;
const byte stopPin         =  5;
const byte relaisLinks     =  6;
const byte relaisRechts    =  7;

enum {relaisAn, relaisAus};
enum {warten, on, rechts, haltrechts, links, haltlinks, off};
byte schritt = warten;
byte zyklus = 20; //cycles
const byte maxzyklus = 20; //max cycles

void setup() {
  Serial.begin(115200);
  Serial.println(F("Start...."));
  pinMode(sensorLinksEnd, INPUT);
  pinMode(sensorRechtsEnd, INPUT);
  pinMode(startPin, INPUT);
  pinMode(stopPin,  INPUT);
  pinMode(relaisLinks, OUTPUT);
  digitalWrite(relaisLinks, relaisAus);
  pinMode(relaisRechts, OUTPUT);
  digitalWrite(relaisRechts, relaisAus);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  schrittkette();
}

void schrittkette()
{
  static unsigned long lastmillis;
  const unsigned long pauseZeit = 5000; // in ms
  if (digitalRead(stopPin))
  {
    schritt = off;
  }
  switch (schritt)
  {
    case warten:
      if (digitalRead(startPin))
      {
        zyklus = 0;
        schritt = on;
      }
      digitalWrite(relaisRechts, relaisAus);
      digitalWrite(relaisLinks, relaisAus);
      break;
    case on:
      digitalWrite(LED_BUILTIN, HIGH);
      schritt = rechts;
      break;
    case rechts:
      digitalWrite(relaisRechts, relaisAn);
      if (digitalRead(sensorRechtsEnd))
      {
        digitalWrite(relaisRechts, relaisAus);
        schritt = haltrechts;
        lastmillis = millis();
      }
      break;
    case haltrechts:
      digitalWrite(relaisRechts, relaisAus);
      digitalWrite(relaisLinks, relaisAus);
      if (millis() - lastmillis > pauseZeit)
      {
        schritt = links;
      }
      break;
    case links:
      digitalWrite(relaisRechts, relaisAus);
      digitalWrite(relaisLinks, relaisAn);
      if (digitalRead(sensorLinksEnd))
      {
        digitalWrite(relaisLinks, relaisAus);
        schritt = haltlinks;
        lastmillis = millis();
      }
      break;
    case haltlinks:
      digitalWrite(relaisRechts, relaisAus);
      digitalWrite(relaisLinks, relaisAus);
      if (millis() - lastmillis > pauseZeit)
      {
        if (zyklus == maxzyklus)
        {
          schritt = off;
        }
        else
        {
          zyklus++;
          schritt = rechts;
        }
      }
      break;
    case off:
      digitalWrite(LED_BUILTIN, LOW);
      schritt = warten;
      break;
  }
}


texts:
I'm trying to print some data to and from an ATtiny85 via serial, using the SoftwareSerial library.  So far I've tried these setups with no results:

1/8MHz clock
baud rates from 9600 to 57600 (library doesn't seem to support higher rates)
printing to a newline or a single one
packing up a char array just as much as a String and then printing it
Txing/Rxing through an Arduino Nano/Uno/Mega or a cheap USB-Serial port

Reading up on the subject seemed to suggest that some values I was passing (such as '1000') might have been erroneously interpreted as EOL characters breaking the code, but attempts with different values (i.e. 845) returned the same failures.

As you might have guessed I'm writing code with the ArduinoIDE, and no errors are returned when compiling and uploading. Many other parts of the project involving serial work just fine, and I can communicate with the ATtiny on pretty much any of the above setups (actually packing up the String or char[] crash the whole thing).
The 'Ready' at the end of the setup is also printed fine, and the loop runs as long as it won't encounter any of the above issues.

Here's the code:

int VALUE = 1000;
int ANOTHER = 12;

#include <SoftwareSerial.h>
SoftwareSerial tSerial(3,4);

void _serialEvent() {
  if (tSerial.available()) {
    char mode = tSerial.read();
    if (mode == '?') {
      tSerial.println("someTextHere 1.23moreText");
      tSerial.print("value:");
      tSerial.print(VALUE);
      tSerial.print(";another:");
      tSerial.println(ANOTHER);
    }
    else if ...
  }
}

void setup() {
  tSerial.begin(57600);
  ...
  tSerial.println("Ready");
}

void loop() {
  ...
  _serialEvent();
}


texts:
I am trying to create an if statement that only runs once, the very first time the void loop is started and switches to another code after that. But the following only executes stepper1a(). Any help would be great. Thx !

int var;
int var2;
bool executed = false;

const int M1dirpin = 4; //Stepper Dir Pin
const int M1steppin = 5; //Stepper Step Pin

void setup() {

pinMode(A2,INPUT);
pinMode(M1dirpin,OUTPUT);
pinMode(M1steppin,OUTPUT);
Serial.begin(9600);

}

void stepper1() {
  int j;
    delayMicroseconds(10);
    digitalWrite(M1dirpin,HIGH);
  for(j=0;j<=200;j++){
    digitalWrite(M1steppin,LOW);
    delayMicroseconds(10);
    digitalWrite(M1steppin,HIGH);
    delay(2);
  }
}

void stepper1a() {
  int j;
    delayMicroseconds(10);
    digitalWrite(M1dirpin,HIGH);
  for(j=0;j<=1600;j++){
    digitalWrite(M1steppin,LOW);
    delayMicroseconds(10);
    digitalWrite(M1steppin,HIGH);
    delay(2);
  }
}

void loop() {

if (executed == false) {
var = analogRead(A2);
delay(10);
if (var > 500) {
  stepper1a();
  delay(2000);
  executed = true;
  Serial.println("turned 1600");
  Serial.println(executed);
  }
else if (executed == true) {
 var2 = analogRead(A2);
delay(10);
if (var > 500) {
  stepper1();
  delay(2000);
  Serial.println("turned 200");
}
}
}
}

Updated void loop:

void loop() {

    static bool yes_we_did_the_one_time_job = false;

    if (yes_we_did_the_one_time_job) {
        var = analogRead(A2);
        delay(10);
        if (var > 500) {
            stepper2();
            delay(2000);
            Serial.println("turned 1600");
        }
    }
    else {
        var2 = analogRead(A2);
        delay(10);
        if (var > 500) {
            stepper1();
            delay(2000);
            Serial.println("turned 200");
            yes_we_did_the_one_time_job = true;
        }
    }
}

This works now, thx !!!:

void loop() {
  static bool yeswedid = false;

  if(yeswedid) {
    if(analogRead(A2) > 500) {
    stepper1();
    stepper2();
    }
  }
  else {
    if(analogRead(A2) > 500) {
    stepper1();
    yeswedid = true;
  }

  }
}


texts: What is the best way to power the ESP32 from a battery?

texts:
I am making a temperature sensor that can go in a freezer and I am trying to figure out what the best method is.
My research has taken me all over the place an I can't seem to find a straight answer. Some sites recommend using LiFePo4, while others say absolutely not, because it needs to be regulated.
One question I have is: could I use more voltage, say 6V from a series of batteries and connect it to the 5V pin since it is regulated, or is it better to go with an external regulator for the 3.3V pin with less voltage?


texts: Arduino Robot. a function-definition is not allowed here before '{' token

texts:
The code is very messy. We have an L293D circuit which has two enable pins always on. We also have an LDR light sensor with two light resistors, one on the left and one on the right.

We are trying to make a line following robot

We are ambitious high school students.

// Use this code to test your motor with the Arduino board:

// if you need PWM, just use the PWM outputs on the Arduino
// and instead of digitalWrite, you should use the digitalWrite command

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

// --------------------------------------------------------------------------- Motors
int motor_left[] = {2, 7};
int motor_right[] = {10, 15};
int LDR = 0;     //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDRValue = 0;      //that’s a variable to store LDR values
int light_sensitivity = 500;    //This is the approx value of light surrounding your LDR
int LDR2 = 0;     //analog pin to which LDR is connected, here we set it to 0 so it means A0
int LDR2Value = 0;      //that’s a variable to store LDR values
int light_sensitivity2 = 500;    //This is the approx value of light surrounding your LDR
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
LDRValue = analogRead(LDR);
    Serial.println(LDRValue);

    if (LDRValue < light_sensitivity);
    Serial.println("wat");

}
// --------------------------------------------------------------------------- Loop

// --------------------------------------------------------------------------- Drive

void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}

void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

void drive_backward(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}

void turn_left(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);

digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}

void turn_right(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);

digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}
void loop() {
drive_forward();
delay(1000);
motor_stop();
Serial.println("1");

drive_backward();
delay(1000);
motor_stop();
Serial.println("2");

turn_left();
delay(1000);
motor_stop();
Serial.println("3");

turn_right();
delay(1000);
motor_stop();
Serial.println("4");

motor_stop();
delay(1000);
motor_stop();
Serial.println("5");
}


texts: Need advice on serial bytes reading optimization

texts:
I am doing some device serial data read and publishing values to MQTT. Using ESP8266 for this.

Currenty I request serial device by sending a command and parse all byte values individually, how to do this in better way ?

each byte parse is done in such way:

float Heat = (float)data[38];

  sprintf(mqtt_topic, "%s/%s", mqtt_topic_base, "Temp"); mqtt_client.publish(mqtt_topic, String(Temp).c_str());

float Power = (float)data[39];
......
..... and etc...


texts: TimedAction.h: No such file or directory

texts: I am new to Arduino and I am trying one of the library TimedAction.h for sudo multithreading on Arduino. However the library is not present in the Arduino. How do I install external library(if it is)?


texts: Burning a bootloader onto my Arduino MEGA 2560 without another arduino board, or isp board

texts: My youtube video explains it. It's starting to get on my nerves.


texts: Help: convert Arduino code to avr-gcc code

texts:
I need to convert Arduino code to avr-gcc code. This is code:

#include <Servo.h>

Servo myservo;

void setup() {
  myservo.attach(11);
}

void loop() {
  myservo.write(67);
}

I use Arduino Mega.


texts:
I'm starting to learn how to use Arduino and I tried to make this code, which is just a simple if else statement; what I want to make is when the input is LOW, LED 1 is HIGH and LEDs 2,3 are LOW, and when the input is HIGH, the LEDs 2,3 are HIGH and LED 1 is LOW. I wrote this code but when I put the switch in LOW, instead having just like what I intended, all the outputs are HIGH.

I try changing the output and I checked all the wiring to the LEDs so my mistake is in the code.

Could you guys tell me what's wrong with the code?

int switchstate = 0;
void setup() {
  pinMode (13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(3,INPUT);
}

void loop() {
  switchstate = digitalRead(3);
  if (switchstate == LOW) {
    digitalWrite(11,HIGH);
    digitalWrite(12,LOW);
    digitalWrite(13,LOW);
  } else {
    digitalWrite(11,LOW);
    digitalWrite(12,HIGH);
    digitalWrite(13,HIGH);
  }
}


texts: Monitoring multi analog ports with ACS712 current sensors

texts:
Making a Auto Blast Gate for dust collection in my wood shop. Arduino Nano using ACS712's to detect when tool is in use.  Using DRV8825 to drive a single Stepper motor that will spin a disk to line up blast gate for the tool in use. Code works as expected with one sensor coded but I can't figure out how to make it work with additional sensor coded in.
Not sure if this is the way the question shows up,  Thanks

/*This one is atarting to work.   When tool is turn on the ACS712 detects it and the stepper moves 90 deg/steps.

When the tool is turned off it remains in position which is desireable as I would use the same tool multiable times in a row.
Need to add sensor A1 and assign different steps to it.
Can I declare the values of each sensor 1 time to be used whenever that analog port read > current Threshold?
Can I have a statement that will check all the analogs and act on the one that is >current Threshold?
Need for the stepper to only move if a different sensor (than the previous analog#) is > current Threshold?
IF/Else
*/

#include <Arduino.h>
#include "BasicStepperDriver.h"
#include "DRV8825.h"

#define MOTOR_STEPS 360 // Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
#define RPM 200
#define MICROSTEPS 1    // Since microstepping is set externally, make sure this matches the selected mode
                        // If it doesn't, the motor will move at a different RPM than chosen
                        // 1=full step, 2=half step etc.
#define DIR 2           // All the wires needed for full functionality
#define STEP 3
#define ENABLE 4        // 2-wire basic config, microstepping is hardwired on the driver
BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, ENABLE);

#define CURRENT_SENSOR_PIN A0 // Current sensor is connected to analog pin A0

#define CURRENT_THRESHOLD 570 // The analog value above which the relay shall be triggered
#define CURRENT_SAMPLE_PERIOD 500 // The number of milliseconds to sample the current reading

int analogValue = 0; // Stores ADC values read in from the current sensor
unsigned long stopwatch = 0; // Used to keep track of elapsed time

void setup() {
  Serial.begin(9600);
  pinMode(DIR, OUTPUT);
  pinMode(STEP, OUTPUT);
  pinMode(ENABLE, OUTPUT);
 // pinMode (A0, INPUT);

    stepper.begin(RPM, MICROSTEPS);
    stepper.setEnableActiveState(LOW);
  }

void loop() {
    analogValue = 0; // Initialize analogValue to a known state
    stopwatch = millis(); // Store a snapshot of the current time since the program started executing

    // Collect the max ADC value from the current sensor for the predetermined sample period
    while (millis() - stopwatch < CURRENT_SAMPLE_PERIOD) {
      analogValue = max(analogValue, analogRead(CURRENT_SENSOR_PIN));
      Serial.println(analogValue);
    }

    // If the max ADC value from the current sensor exceeds the threshold, set the state to LOW
    if (analogValue > CURRENT_THRESHOLD) {
      stepper.enable();  //  energize coils - the motor will hold position
      stepper.rotate(90);  //Moving motor using the degree notation in ()

   }
    while(analogValue > CURRENT_THRESHOLD)
      stepper.disable();  // pause and allow the motor to be moved by hand
}
// need to return to top of loop


texts:
So this is pretty much explanatory.  I am new to arduino, and i am learning the best i can.  I need to sketch a code in which will cycle through 5 different brightness settings of an led.  One push will cycle through the five, another push of the button will turn the led off, and another push will restart the cycle.

const int led =11;
const int BUTTON = 7;
boolean lastButton = LOW;
boolean currentButton = LOW;
int ledLevel = 0;

void setup()
{
  pinMode(led,OUTPUT);
  pinMode(BUTTON,INPUT);
}
boolean debounce(boolean last)
{
  boolean current = digitalRead(BUTTON);
  if (last != current)
{
  delay(5);
  current = digitalRead(BUTTON);
}
return current;
}

void loop()
{
  currentButton = debounce(lastButton);
  if (lastButton == LOW && currentButton == HIGH)
  {
    ledLevel = ledLevel + 51;
  }
  lastButton = currentButton;
  if (ledLevel > 255) ledLevel = 0;
  analogWrite(led, ledLevel);
  analogWrite(led, ledLevel + 51);
  delay(200);
  analogWrite(led, ledLevel + 102);
  delay(200);
  analogWrite(led, ledLevel + 153);
  delay(200);
  analogWrite(led, ledLevel + 204);
  delay(200);
  analogWrite(led, ledLevel + 255);
}

The code above turns the led on and cycles brightness, like it should it however for some reason it does disable the button.  Take the analogWrites out except for the first one, and the button will cycle the led. any suggestions on what i could do?  Im very new at this.


texts: Can I cut the pin holes off of my Arduino board?

texts:
I'm making a project, but my arduino pro micro is just slightly too big to fit in it's case.

What would happen if I cut off the pin holes that I don't need? Would it still work? Or would it be ruined?


texts: Calculate the Li-Po Battery Level in ESP-Wroom-02

texts:
I am very new to micro controller and circuits. I am not at all with this field. But trying to create a home project where I have a device image attached below.

This is 18650 Lipo battery powered device. Here I want to calculate the battery level. After doing some research on google I found that I need to have Voltage Divider which I think I already included in this with 220k ohms and 100k ohms

People are using different ways to calculate it. Which I found in few examples. Which I am not able to understand at all, that what formula or values they are referring to calculate it.

if someone can help to understand that will be helpful. Here is how I am coding it which I saw somewhere on internet itself.

      #include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
//#include "DHTesp.h"

#define DHT_PIN       16

//SSID and Password of your WiFi router
const char* ssid = "Asus";
const char* password = "Xmv02488!!**";

ESP8266WebServer server(80); //Server on port 80

/***************************************************************
 * SETUP
 **************************************************************/
void setup(void){
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);

  WiFi.begin(ssid, password);     //Connect to your WiFi router
  Serial.println("");

  // Wait for connection
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  //If connection successful show IP address in serial monitor
  Serial.println("");
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());  //IP address assigned to your ESP

  server.on("/", handleRoot);      //Which routine to handle at root location

  server.begin();                  //Start server
  Serial.println("HTTP server started");

  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(A0, INPUT);

}
/***************************************************************
 * LOOP
 **************************************************************/
void loop(void){
  server.handleClient();          //Handle client requests

}

/***************************************************************
 * This function converts IPAddress struct to a String
 **************************************************************/
String IpAddress2String(const IPAddress& ipAddress)
{
  return String(ipAddress[0]) + String(".") +\
  String(ipAddress[1]) + String(".") +\
  String(ipAddress[2]) + String(".") +\
  String(ipAddress[3])  ;
}

/***************************************************************
 * This rutine is exicuted when you open its IP in browser
 **************************************************************/
 void handleRoot() {
  IPAddress ip_address = WiFi.localIP();
  String ip_str = IpAddress2String(ip_address);

  int nVoltageRaw = analogRead(A0);
  float fVoltage = (float)nVoltageRaw * 0.00486;

  float fVoltageMatrix[22][2] = {
    {4.2,  100},
    {4.15, 95},
    {4.11, 90},
    {4.08, 85},
    {4.02, 80},
    {3.98, 75},
    {3.95, 70},
    {3.91, 65},
    {3.87, 60},
    {3.85, 55},
    {3.84, 50},
    {3.82, 45},
    {3.80, 40},
    {3.79, 35},
    {3.77, 30},
    {3.75, 25},
    {3.73, 20},
    {3.71, 15},
    {3.69, 10},
    {3.61, 5},
    {3.27, 0},
    {0, 0}
  };

  int i, perc;

  perc = 100;

  for(i=20; i>=0; i--) {
    if(fVoltageMatrix[i][0] >= fVoltage) {
      perc = fVoltageMatrix[i + 1][1];
      break;
    }
  }

  server.send(200, "text/plain", "Hello from esp8266!\n\rIP: " + ip_str +
    ".\n\rTemp: " + "NO" +
    ", Hum: " + "NO" +
    "\n\r" + "NO" +
    "\n\r" + "Voltage: " + fVoltage +
    "\n\r" + "Charge: " + perc + '%');
}

This is a copied code. Where I am not sure about where they got the this formula and how they got the value of 0.00486

I copied this code from different source references. But I hope this will help you to understand the issue.

Any suggestions will be helpful!

Thank you! (In advance)


texts: EPS8266 ESP-01 Blue led stays lit unless 3.3v logic divider is bypassed, works when reconnected

texts:
I am having a very weird and frustrating issue with this ESP01. I am creating a shield on protoboard, and everything checks out as far as I can tell. I am using a 3.3v voltage divider (1k and 2.2k) from arduino TX to ESP RX.

When I connect the ESP straight to the arduino Mega 2560, it works fine. When I connect the ESP to my protoboard, the blue led stays lit. Now here's he weird part.

I broke out the protoboard header with jumpers to the ESP, 3.3v to vcc and ch_pd, gnd to gnd in my header. Bypassing the logic voltage divider on my protoboard results in a working ESP8266.

While still powered up, I moved the Tx/Rx to the header, through the voltage divider, and it still works! But when I disconnect USB from the Arduino, then reconnect, the blue led stays lit, until I bypass the voltage divider, connect to the ESP, then connect back to the divider.

I am currently testing my code with a simple serial relay sketch, ESP on Serial3.
I have nothing else connected to ESP besides vcc, ch_pd, gnd, tx and Rx.
I am connecting to the arduino and ESP on 115200 baud. The ESP replies without garbage on 115200 when connected straight to Serial3 rx/tx

I thought insufficient power may have been an issue, using the mega's 3.3v for vcc, so I built a voltage regulator circuit converting a 9v battery to 3.3v (well 3.75, using an LM317T with R1=330ohm/R2=660ohm because it's what I had on hand) and there was no change in performance, besides the LEDs being slightly brighter. The ESP still functioned with RX/TX straight to the mega while connected to the 3.75v supply.

I know pics would help a lot, and I can post some later tonight after work. My wife, sensing my frustration, told me to set everything down and go to work so I wouldn't break anything, so I am asking around for possible fixes for when I get home.

I appreciate any and all replies, and will provide any necessary clarification.

Thanks,
Vl4d


texts:
I have a system where an RFID tag can be checked and Its individual 4byte UID will be printed. My task is to check if subsequent tags have the same UID and if not, print “access denied”. I'm assuming i need to use const char but I'm not sure. I get an error at if (myrfid.serNum[i] == ID) saying comparison between pointers and integers are forbidden.
Any sort of clarity would be appreciated, thanks!

(Code is only a section from the for loop)

void loop()
{
    int i;
    const char ID[] = "111 11 11 11";

    cardpresent = myrfid.isCard();

    if (cardpresent && ! lastcardpresent)
    {
        if (myrfid.readCardSerial())
        {
            for (i = 0; i < 4; i++)
            {
                if (myrfid.serNum[i] == ID)
                {
                    Serial.print("Acess granted ");
                }
                else
                {
                    Serial.print("Acess not granted ");
                }
            }
        }
        Serial.printf("%3d ", myrfid.serNum[i]);
    }
    Serial.print("\n");

    // ...
}


texts: What are the units of output of soil moisture sensor?

texts:
I want to use a soil moisture sensor using arduino uno R3. I am using the analog output. The values are in the range of 100 to 1300 as in the readings mention in this question.

May I know what exactly these numbers mean? I read in a website that:

  Most soil moisture sensors are designed to estimate soil volumetric water content based on the dielectric constant (soil bulk permittivity) of the soil.

So what are the units? Basically I want to base an estimate for the normal amount of soil moisture for typical loamy soil and I don't understand how to base this threshold based on the readings given by the sensor. It would be greater help if someone actually knows what an appropriate soil moisture threshold is for loamy soil.

I searched on the internet but the closest i could come to answers was this table and this particular entry:

  Table 1.1. Typical field capacity and wilting point values (m^3
   m^(–3)) for different soil textures

  Soil texture| Field capacity| Wilting point| Available water

  Loam    |0.27| 0.12| 0.15|

I am so sorry if I seem confused but I am very new to the whole of sensors and electronics
This is the sensor that I am making use of


texts:
I am a bit confused. So I want to send messages between two arduinos over RS485, but these are not fixed length, naturally, I have to send the length of the message or add a delimiter to understand that my message has ended.

Suppose, now I create a placeholder for the message, and both ends communicating are receiving the placeholder, rather than the message itself. This placeholder is x bytes long always, and each arduino can look it up from its memory what message corresponds to the placeholder.

Lets say I create a message.h file with contents like this

#define A "First Message"
#define B "Second Message"

When the two devices are communicating, they send each other A or B, and the Arduino looks it up in its .h file what A and B mean.

My question is when the Arduino recieves the A, it recieves a character 'A', but how can I use this to fetch the value assigned to variable A in memory?


texts: Can a 433mhz receiver receive data from a 433mhz tag/fob?

texts:
If I use a 433mhz receiver on an Arduino Nano, will it detect a 433mhz tag? I'm not talking about the transmitter that is shown below but a tag/key fob.

Example of 433mhz tag


texts:
I just brought the camera OV7670 with fifo but I am unable to get the wiring of board with arduino and also I do not find any arduino library for OV7670 with fifo.

It will great if you can help to find some link which can help me.

Thanks,
Somnath


texts: Cannot upload program to Arduino Duemilanove w/ Atmega328

texts:
This is the error I receive while trying to upload to the Arduino.
I have installed FTDI drivers for mac. (http://www.ftdichip.com/Drivers/VCP/MacOSX/FTDIUSBSerialDriver_v2_2_18.dmg)

The board is part of a quadcopter: https://www.hobbyking.com/hobbyking/store/uh_viewItem.asp?idProduct=50460

The processor is an Atmel 328P. Do I have the correct drivers?

What else could be the issue?