texts: Problem with receiving data from Arduino via HC05 sent by Java

texts:
I want to both send some sensor data via Bluetooth (HC05) and Arduino to Java and I also want to send some command data via the same Bluetooth and serial port to Arduino.
I've managed to do the first part (arduino to java) successfully with this code:

hc05SerialEx.printf("^%d,%7.3f,%d,%7.3f,%d,%7.3f\n", s1, ss1, s2, ss2, s3, ss3);

^ is the character I devised in my simple protocol and it means the starting point of data.
@ means starting point of command packet.

The problem is whenever I want to write a char packet via the same HC05 connection to arduino, it sometimes works. In fact, whenever I click the button firing the write method, I see the packet received correctly but when I click the button again or click it rapidly, it sometimes outputs garbage in arduino side.
I do have delay in my main loop in arduino side and I'm using it to control the sampling rate of sensors. I've timed arduino side's calculation time (except delay of course) and it takes about 52 milliseconds.
I suspect whenever I fire the write method while arduino is busy in main loop, the received data becomes gibberish. So here are the questions:

1- What is the cause of this problem?
2- How can I achieve the goal I mentioned?

Here is java-side code sending the command packet:

String message = String.format("@%5.3f,%5.3f,%5.3f\n", rmR1, rmR2, rmR3);
System.out.println(message);
rightHC05Port.write(message);

Here is arduino-side code receiving and mirroring the received packet in arduino's own serial port (for me to see):

void loop() {
  serialEventHC05();
  //fetching sensor data and some math operations...
  hc05SerialEx.printf("^%d,%7.3f,%d,%7.3f,%d,%7.3f\n", s1, ss1, s2, ss2, s3, ss3);
  delay(loopTime);

int numOfReceivedBytes = 0;

void serialEventHC05() {
  while (hc05Serial.available() > 0) {
    numOfReceivedBytes = hc05Serial.available();
    String s = hc05Serial.readStringUntil('\n');
    arduinoSerialEx.println(numOfReceivedBytes);
    if (s.charAt(0) == '@') {
      arduinoSerialEx.println(s);
    }
  }
}

For example, here is the string I'm sending from Java via HC05 to Arduino:

@10.000,10.000,10.000

And here is the result of Arduino's behavior caused by me sending the same packet multiple times:

Any help is appreciated.


texts: Send out a short signal every 10 seconds to an arduino

texts:
In order to reduce power consumption, I want to resume my Arduino from standby mode every 10 seconds. For this a hardware interrupt is necessary.

Is there such a device that can create a quick impulse to trigger that interrupt? It can be anything from 10ms to 2 seconds; doesn't matter. My first thought was to use a 555 timer, but this one can only be on for 10 seconds and off for the same amount of time.

The best solution for me would be an already assembled device that I just have to wire with my Arduino since my knowledge in electronics is very low. Or a detailed assembly plan, then I would be able to build it myself I guess?

UPDATE: I was now able to put the Arduino into standby-mode using the Low-Power library. At first it seemed like it didn't work, because I wanted to print out a text over the serial connection. Instead, I tried to let the internal LED blink every 8 seconds, and this works perfectly.


texts:
Can I send data using nRF24L01 with Arduino through multiple pipes?
As by using the RF24 library, I can send data through just one pipe and receive on the 6 pipes that nRF24L01 has.


texts: Can I emulate Arduino in a headless CI/CD setup?

texts:
6 years ago, there has been a question "How to emulate Arduino on PC".

Since then, probably many more Arduino emulators have been introduces.

With this question, I would like to narrow the search scope down to the following criteria:

Linux compatible
headless operation mode without UI/IDE possible to run in a CI/CD (continuous integration/delivery) system in collaborative environment where many code versions need to be merged and tested.

Do such setups exist already?


texts: Sketch stops printing after writing a few times

texts:
I am trying to build a random horoscope printer. I have a series of strings in an array which I am storing in program memory. I then pick a random number and print that index concatenated with a title. But it often (but not always) only runs 4 or 5 times.

#include <avr/pgmspace.h>

const char string_0[] PROGMEM = "You have a great need for other people to like and admire you. ";
const char string_1[] PROGMEM = "You have a tendency to be critical of yourself. ";
const char string_2[] PROGMEM = "You have a great deal of unused capacity which you have not turned to your advantage. ";
const char string_3[] PROGMEM = "While you have some personality weaknesses, you are generally able to compensate for them. ";
const char string_4[] PROGMEM = "Your sexual adjustment has presented problems for you. ";
const char string_5[] PROGMEM = "Disciplined and self-controlled outside, you tend to be worrisome and insecure inside. ";
const char string_6[] PROGMEM = "At times you have serious doubts as to whether you have made the right decision or done the right thing. ";
const char string_7[] PROGMEM = "You prefer a certain amount of change and variety and become dissatisfied when hemmed in by restrictions and limitations. ";
const char string_8[] PROGMEM =  "You pride yourself as an independent thinker and do not accept others' statements without satisfactory proof. ";
const char string_9[] PROGMEM = "You have found it unwise to be too frank in revealing yourself to others. ";
const char string_10[] PROGMEM = "At times you are extroverted, affable, sociable, while at other times you are introverted, wary, reserved. ";
const char string_11[] PROGMEM = "Some of your aspirations tend to be pretty unrealistic. ";
const char string_12[] PROGMEM = "Security is one of your major goals in life. ";

const char* const string_table[] PROGMEM = {string_0, string_1, string_2, string_3, string_4, string_5, string_6, string_7, string_8, string_9, string_10, string_11, string_12};

void setup() {
  Serial.begin(9600);
  randomSeed(analogRead(2));
}

void loop() {
    Serial.println("WE GOING TO LOOP NOW");
    char buffer[50];
    int rand = random(0,12);
    Serial.println(rand);
    strcpy_P(buffer, (char*)pgm_read_word(&(string_table[rand]))); // Necessary casts and dereferencing, just copy.
    char text[15] = "Your horoscope";
    String output;
    output = strcat(text, buffer);
    Serial.println(output);
    delay(1000);
}

I also sometimes don't seem to get very clean results, but I'm not sure why. I.e. printing WWWW... and missing the first part of the string in the serial monitor.

WWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWE GWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWE GOING TO LOOP NOW
1
Your horoscopeYou have a tendency to be critical of yourself.
WE GOING TO LOOP NOW
3
or them. While you have some personality weaknesses, you are generally able to compensate for them.
WE GOING TO LOOP NOW
4
Your horoscopeYour sexual adjustment has presented problems for you.
WE GOING TO LOOP NOW
2
ge. You have a great deal of unused capacity which you have not turned to your advantage.


texts: Arduino: Digitally Muti-Switch - What is the proper term for hardware?

texts:
I have recently purchased a RoboMower. Like most of the automated mowers these use electric-fence wiring to mark the borders of the property and keep a small charge on those wires so that the mower can tell where the borders are. The  RoboMower I purchased is rated for 3/4 of an acre and I have 2.25 acres to mow.

As a result I was thinking of breaking my yard into multiple 3/4 or less acre zones and using an Arduino to shift which zone is active/has current in it so that the mower would follow those boundaries. The base station would be in a place where all zones overlapped slightly. Based on what day of the week it was, the Arduino would activate the proper zone, and the mower would go out and mow in that zone because it was active. I'd clearly have to schedule this so that the switch did not happen when the RoboMower was actively mowing or it would cause all sorts of issues.

In any case, my question is: What is the hardware called that I would need in order to activate one zone or the other? Is that called a digital switch or something else? Is there such a thing of one switch that would be able to switch multiple zones, or would I basically need a bunch of switches to individually control each zone?

Each zone is a loop of wire and therefore there would not be any shared wires between the zones.


texts: How do functions outside of void loop work?

texts:
I am used to Arduino sketches with a void setup() part that runs once, and a void loop() part that keeps looping. What happens when you have void functions outside of the main void loop()? Will these all keep looping in parallel or do they run one after the other? Or do certain void functions only run once certain criteria has been met (like a while loop)?

For example in the code below, when will the void receiveData(int byteCount) and the void sendData() functions run?

//I2C_test

//This code demonstrates communication via an I2C bus between a raspberry pi and an arduino.
//When the Raspberry pi (master) sends data to the Arduino (slave), the Arduino uses this
//data to control a motor. After the Arduino has recieved data from the master, it then collects
//data from the external environment via a sensor and sends this data back to the Raspberry pi.

#include <Wire.h>
int number = 0; //Declare variables
int val = 0;

void setup() {
  //Anything between the curly brackets runs once when the arduino is turned on or reset
  pinMode(0, INPUT);
  //Set pin 0 as input and 3 as output
  pinMode(3, OUTPUT);
  Serial.begin(9600);
  //Set the data rate for serial transmission at 9600bps
  Wire.begin(0x04);
  //Initiate the Wire library, join the Arduino as a slave, and specify its 7 bit slave address
  Wire.onReceive(receiveData);
  //Define callbacks for i2c communication
  Wire.onRequest(sendData);
}

void loop() {
  //The code between the curly brackets keeps repeating
  delay(100);
}

void receiveData(int byteCount) {
  while(Wire.available()) {
    number = Wire.read();
    //Set the variable "number" to the data sent by the master
    analogWrite(3, number);
    //Write this number to pin 3 (PWM). This controls the motor speed
  }
  val = analogRead(0);
  //Read the voltage on pin 0 (connected to the sensor). Map input voltages between 0 and 5 volts into integer values between 0 and 1023
}

void sendData() {
  Wire.write(val);
  //Send the data read from the sensor to the master.
}


texts: Communication with two XBee's and Arduinos over serial

texts:
I have two XBee's connected to two Arduino Uno boards (one for each XBee). I connected each XBee to the X-CTU software, and have set the following:

XBee 1

Pan ID = 4270
DL = 10
MY = 20

XBee 2

Pan ID = 4270
DL = 20
MY = 10

Both

DD = 10000
IC = FF
IR = 32

Therefore, they should be on the same network and see each other as the 'other person' each is talking to. I'm using the TX and RX pins of the arduino and the XBee to communicate over the serial port.

When testing if each can hear the other, I loaded one arduino with this code:

#include <SPI.h>

void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
  Serial.print('x');
  delay(1000);
}

Then another with this:

#include <SPI.h>

void setup() {
// put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(7,OUTPUT);
  digitalWrite(7,LOW);
}
void loop() {
// put your main code here, to run repeatedly:
  if(Serial.available())
  {
    char getData = Serial.read();
    if(getData == 'x')
    {
      digitalWrite(7,HIGH);
      delay(500);
      digitalWrite(7,LOW);
      delay(500);
    }
  Serial.print(getData);
  getData = ' ';
  }
}

This works perfectly. One LED will light up on the correct arduino in half second intervals. However, when I try to make them both communicate at the same time to each other, nothing happens. Neither LED will light up. The code for both arduino's is:

#include <SPI.h>

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

void loop() {
  // put your main code here, to run repeatedly:
  Serial.print('x');
  delay(1000);
  if(Serial.available())
  {
      char getData = Serial.read();
      if(getData == 'y')
      {
        digitalWrite(7,HIGH);
        delay(500);
        digitalWrite(7,LOW);
        delay(500);
      }
      Serial.print(getData);
      getData = ' ';
    }
}

But for one arduino I change the code to Serial.print('y') and if(getData == 'x') to listen for the other one. I also have tried delaying one arduino in the setup by one second to offset the sending and recieving, but that also doesn't help.

I need them to be able to listen and talk to each other, maybe even at the same time like this example. I'm trying to create a proximity sensor in, lets say the 'back', area communicate with the 'front' area, and an accelerometer and two switches from the 'front' communicate with the 'back'.

Is there any settings I can change in X-CTU, such as the baud rate or the amount of packets re-sent, to overcome this problem? Or is this merely a code issue?

I do have the power connected to the 3.3V pin of the arduino, and I'm using 470/220 Ohm resistors as voltage dividers for the output pins from the arduino to the XBee, so I don't think voltage is an issue here.

Also, I have disconnected the arduino from the computer. I'm powering it via the USB-A to USB-B cord -> 13000 mAh 5V DC rechargeable battery, so there should be no interference with the serial data lines. Pin 2 (RX) of the XBee is connected to pin D0 (RX) of the arduino, and pin 3 (TX) of the XBee is connected to pin D1 (TX) of the arduino.

Thanks for your help.


texts: Strange things happening with Arduino PROGMEM

texts:
I am currently working on a display library. The font should be stored in PROGMEM. The code looks something like this:

unsigned int i = 0;
Serial.println(pgm_read_byte(&font[1]),HEX);
unsigned char width = pgm_read_byte(&font[0]);
unsigned char height = pgm_read_byte(&font[1]);
unsigned char spacing = pgm_read_byte(&font[2]);

The strange thing is that the code breaks (Serial spits out random characters, OLED displays only noise or nothing) when I remove the

Serial.println(pgm_read_byte(&font[1]),HEX);

If I replace it with something like

Serial.println("Hello World!");

the code breaks as well, but in a different way. I think pgm_read_byte() returns different things with different Strings in the Serial.println() function.

Is there something going on with the compiler? Are there some optimization options that I should change? Or am I doing it completely wrong?

Here is the whole function:

/**
 *
 * Displays text using a predefined sprite in PROGMEM
 * Only fonts with a uniform letter spacing are supported
 * The font must have the following format
 * Byte   Description
 *  0.    X width of one letter in pixel
 *  1.    Y height of one letter in bytes (8 pixel)
 *  2.    letter spacing in pixels
 *  3.    data
 *  .      .
 *  .      .
 *  .      .
 *  N.    data
 *
 * The data is arranged like this
 *    | 0 | 1 | 2 | 3 | 4 | ... |126|127
 *     b0  b1  b2
 *     b3  b4  b5
 *    LSB D0
 * In each byte the data is displayed like this
 *    .
 *    .
 *    .
 *    MSB D7
 *
 * A font starts with the symbol "!" (ASCII 33) and ends with the symbol "~" (ASCII 126).
 * Each symbol in between has to be present. The letters have to be arranged like this
 * Letter     A       B       C
 * Bytes    b0 b1   b2 b3   b4 b5
 *          b6 b7   b8 b9  b10 b11
 *
 * @param unsigned char disp[]          the display buffer where the text should be shown
 * @param const unsigned char font[]    the font in PROGMEM
 * @param const char *string            the string to display
 * @param unsigned char X               x location
 * @param unsigned char Y               y location
 * @param int mode                      blend mode
 */
void gfx::text(unsigned char disp[], unsigned char *font, const char *string, unsigned char X, unsigned char Y, int mode){
  unsigned int i = 0;
  Serial.println(pgm_read_byte(&font[1]),HEX);
  unsigned char width = pgm_read_byte(&font[0]);
  unsigned char height = pgm_read_byte(&font[1]);
  unsigned char spacing = pgm_read_byte(&font[2]);
  while(string[i])
  {
    if(string[i] > 32 && string[i] < 127){  //only display valid characters, otherwise leave a blank spot
      unsigned char s[width*height];
      unsigned char c = string[i] - 33;
      //transfer pixel with and height to the sprite
      s[0] = width;
      s[1] = height;
      //copy the other bytes
      for(int y = 0; y < height; y++){
        for(int x = 0; x < width; x++){
          unsigned int sprite_pointer = 2 + width*y + x;
          unsigned int font_pointer = 3 + c*width + x + y*width*93;
          s[sprite_pointer] = pgm_read_byte(&font[font_pointer]);
        }
      }
      sprite(disp,s,X+i*(width + spacing),Y,mode);
    }
    i++;
  }
}


texts: Read encoder output by using an optocoupler

texts:
I have a 512 pulses encoder with four wires: +5V, ChannelA, ChannelB, GND and I'm using it as feedback for my motor position (max 80 RPM) on Arduino UNO. Everything works fine, but I need also to generate a +5V signal everytime ChannelA is HIGH since I need to use it to trigger further actions.
I was thinking to read ChannelA by using an optocoupler in order to split the signal and use it both for feedback and for the +5V signal. Is it possible?
Is there any other easier solution to do that?
EDIT: I try to explain better what the additional device must do.
The device is a video camera system that takes a +5V signal from the encoder to trigger some actions by software (create key frames or more) and we need it for our computer vision system. I just need to use the encoders both for the motor feedback and to trigger the video camera. The signal is always +5V so I do not have problems with voltage levels. What do you suggest? I do not have to drive loads from channelA output, I just need the +5V signal to trigger the video camera.
Can I split the channelA output and use it both for the motor controller and the video camera inputs?
EDIT2:
Following the useful suggestions of @st2000 I tried to think to a solution like this:

Do you think it can work?
EDIT3: I changed swapped the motor controller and the video system positions in the circuit and I changed the voltage source from +12VDC to +5VDC for the motor controller since it accepts only +5V signals as input.

EDIT4: Following the suggestions of @st2000, I changed the circuit design by placing in parallel both devices (motor controller and video system) by using the optocoupler (6N136) only for the video output to isolate it from the whole system.


texts: Arduino loses communication with bluetooth when sending commands to nodemcu esp8266

texts:
i've been working on a project using an Arduino UNO, Bluetooth Module HC-06 and NodeMCU esp8266, the project consists on turning leds on via bluetooth and telling the esp8266 that the leds were turned ON, so then we can display some particular webpage data, everything that is not related to the serial communication works perfectly fine.

#include <NewPing.h>
#include <Servo.h>
#include <SoftwareSerial.h>
#define TRIGGER_PIN 2
#define ECHO_PIN 3
#define MAX_DISTANCE 200

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);

SoftwareSerial Serial1(5, 4);

Servo myservo;

int ledazul = 8; // LED RED
int scLed1 = 9; // LED 1
int scLed2 = 10; // LED 2
int scLed3 = 11; // LED 3
int scLed4 = 12; // LED 4
int scLed5 = 13;
int fan = 6;
bool br = false;
bool bra = false;
bool porta = false;
int pos = 0;

char val;
void setup() {

  Serial1.begin(115200);
  Serial.begin(9600);
  myservo.attach(7);
  pinMode(ledazul, OUTPUT);
  pinMode(scLed1, OUTPUT);
  pinMode(scLed2, OUTPUT);
  pinMode(scLed3, OUTPUT);
  pinMode(scLed4, OUTPUT);
  pinMode(scLed5, OUTPUT);
  pinMode(fan, OUTPUT);

}
void loop() {
  if (Serial.available() > 0)
  {
    val = Serial.read();

    Serial.print("Ping: ");
    int dist = sonar.ping();
    Serial.print(sonar.convert_cm(dist));
    Serial.println("cm");

  } else {
    //Serial.println("");
  }
  bool ledState = false;

  if (val == '1' && Serial1.available() > 0)
  {

    Serial1.print(val);
    Serial.print("SENT");
  }

  if (val == '0' && Serial1.available() > 0)
  {

    Serial1.print(val);
    Serial.print("SENT");
  }

  if (val == 'A')
  {
    digitalWrite(ledazul, !digitalRead(ledazul));
    ledState = true;
  }
  if (val == 'B')
  {
    Serial.print("Ping: ");
    int dist = sonar.ping();
    Serial.print(sonar.convert_cm(dist));
    Serial.println("cm");
  }
  if (val == 'C')
  {
    digitalWrite(scLed1, HIGH);
    ledState = true;
  }
  if (val == 'D')
  {
    digitalWrite(scLed2, HIGH);
    ledState = true;
  }
  if (val == 'E')
  {
    digitalWrite(scLed3, HIGH);
    ledState = true;
  }
  if (val == 'F')
  {
    digitalWrite(scLed4, HIGH);
    ledState = true;
  }

  if (val == 'G')
  {
    digitalWrite(scLed5, HIGH);
  }
  if (val == 'S')
  {
    digitalWrite(fan, HIGH);
  }
  if (val == 'O')
  {
    switch (porta)
    {
        if (pos < 90)
        {
        case false:
          porta = true;
          for (int x = 0; x < 90; x++)
          {
            myservo.write(x);
            delay(15);
          }
        }
        break;
    }
  }
  if (val == 'P')
  {
    switch (porta)
    {
        if (pos >= 90)
        {
        case true:
          porta = false;
          for (int y = 90; y > 0; y--)
          {
            myservo.write(y);
            delay(15);
          }
        }
        break;
    }
  }
}

What happens is, i can toggle ESP led on or off as long as i dont use commands that uses bluetooth module, it works perfectly fine. Now, if i do use bluetooth commands and then esp commands, it'll lose connection with the bluetooth module.

What im looking for is a workaround for the baudrates, because i have a 9600baudrate for the HC-06 and 115200 for the nodemcu, how do i do to fix it?


texts: how to get esp32 ip address ,which is being connected to local network

texts: I need to know the IP address of ESP32 on the local network(without printing ip on serial monitor ). The idea is to do mDNS or UDP broadcast to send the IP to the android application. The app will then use that IP to do the communication. Is there someone who has already done it?


texts: How to identify pinout of ATmega 2560 derivative board?

texts:
My 3d printer, Creality Ender 4, has an ATmega 2560 chip based card, and I need to identify the number associated with a particular Pin.
I read, on the official Arduino website, a simple tutorial in which through a small led connected to two pins of the card, you wrote a code (sketch) that made it turn on, but you had to know the Pin number.
I would like to do this on my board, I unplug all cables (power supply, motors, etc.) and connect it to the PC via USB and from Arduino IDE, I execute the code, connecting the LED on the ground and on the signal (see image).
To identify the Pin number I thought I would go to exclusion, because I know all the PIN numers of the chip, until the LED lights up.
So I ask, is that correct? is there a chance of damaging the card? or is there a better method?
Thanks in advance


texts: Can a shift register be used to extend the Arduino pins when an ethernet shield is mounted on the Arduino?

texts: I am currently working on a wireless home automation system. The system is connected to a wireless network in the home via the ethernet cable connected the ethernet shield and router. Hence, I need more pins on the Arduino to connect the appliances to be controlled in the home.


texts: Are there any Wi-Fi modules for the Arduino Uno that may connect to an external Wi-Fi Antenna?

texts:
I have an Arduino Uno I need to connect to Wi-Fi to make HTTP POST Requests to a Raspberry Pi Web Server.

The Arduino is located only about 30 feet from the AP, but there is a brick wall in the line of sight, and it is in a metal outdoor enclosure. For that reason, I wanted to attach an external Wi-Fi Antenna which would stick out a sealed hole in the enclosure.

I was contemplating using an ESP8266 Wi-Fi module, but it does not look like there is an easy way to attach the antenna.

What would be the best Wi-Fi module to which I could attach an external antenna for an Arduino Uno?


texts: Expected Unqualified-ID Before 'do'(and 'while')

texts:
I am getting the error "error: expected unqualified-id before 'do'" multiple times for every do{
}while(); loop I have... Any help?

Pastebin:http://pastebin.com/DubuAEUs


texts: How can I have two Arduino Uno's communicate wirelessly?

texts: I'm an art student, using arduino in an Electronic Arts Class.  I have already created a skateboard speedometer, using a Hall Effect Sensor and a magnet embedded in one of my skateboards wheels.  I've attached a speaker to the arduino that plays a tone, with the pitch depending on the RPM's of the wheel.  (the faster the board is going, the higher pitch the tone being played is).  Currently the speaker is attached to the skateboard and wired directly to the arduino.  My goal is to have a speaker with an arduino wirelessly connected to the arduino on the skateboard.  The arduino on the skateboard record's the RPM's and then wirelessly send that information to the second arduino to play the tone through the speaker.  Is this possible? what hardware would yo recommend? I've been looking at the Bluetooth HC-05 but I'm not sure this will work.  Thanks for any help!


texts: Can I control relays through an Arduino while using USB joystick?

texts:
I was curious if i could control maximum of 9-10 relays with an arduino while using USB joystick?
Id also want to connect a camera to see what my robot is doing, so i had few ideas.
1. Try and do it all through arduino and a small HDMI monitor.
2. Have a camera and joystick connected to a laptop, and laptop connected to arduino which controls the relays?

And bare in mind that im not really a programing nerd, id make simple electric connections with homemade joystick, but id like for this project to be more precise and more 'high tech'. Also im not rich so i cant buy alot of arduinos and 'test it out' or 'start from smaller projects'
Tho id love to hear your advices


texts: Arduino IDE monitor multiple USB ports simultaneously

texts:
Is it possible to monitor multiple USB ports simultaneously in Arduino IDE while running only ONE instance of the IDE?

If not, which solutions come alternatively to mind?


texts:
Due to the results of my previous post (Slower nRF24L01 round trip delay than expected) I found out that it will be quite difficult to reach my latency requirements.

I am thinking about using my own protocol (instead of the 6-1 Multiceiver protocol), but that would involve getting some kind of 'clocked' receive and send times for devices, which will not make it simple probably. The time to change from reading to writing is less than expected (startListening takes max 350 us and stopListening 450 us). However, if I need to do this ever 5 ms and making sure no devices are reading/sending to others, that's quite a bit of downtime.

So I was thinking, would it be a good (or stupid) idea to use TWO nRF24L01's per Arduino, one by default in reading mode, the other on writing mode (thus having bidirectional communication) and using two different channels. This means I never have to switch between reading and writing and can read/write simultaneously without message colliding.

(note: later I want to use multiple Arduinos and one STM32 device).

Does anyone see problems in this idea?

Requirement goals:

Latency: less than 10 ms to send it from device A to B, process it (excluded, takes a few ms) and send back from B to A (or in some cases B to C). Less than 10 ms is better.
Amount of messages: can be theoretically hundreds per second, in practice max 100 (from various devices, but all go through a processor-device).
Payload per message: 16 bytes probably, most are shorter, some are longer but I can split or combine them if needed.
Range: about 10 meters max, but in a music/band stage environments
Channels: I will not use the WIFI channels, but a range of others, also (professional) wireless mics do not work on 2.4 GHz, so I don't expect too many problems.

About channels: I don't expect any problems. I should have enough channels between 2.484 and 2.525 GHz. This gives me about 40 channels for 1 mbps or 20channels for 2 mbps to chose from.

sources:

2.484 GHz: WIFI Channels, first table with red/green items
2.525 GHz: Datasheet, paragraph 6.3.


texts: Error using Crypto Library for Arduino: Speck

texts:
I'm trying to encrypt a string in my Arduino Uno using the following library:

https://github.com/rweather/arduinolibs/tree/master/libraries/Crypto

And I'm getting this error:

  In function 'void setup()':

  TESTING_SPECK_LIB:27: error: request for member 'setKey' in
  '(byte)(& cipher)', which is of non-class type 'byte {aka unsigned
  char}'

  cipher->setKey(*key,keySize);

  exit status 1 request for member 'setKey' in '(byte)(& cipher)',
  which is of non-class type 'byte {aka unsigned char}'

This is the code I'm using:

#include <Crypto.h>
#include <Speck.h>
#include <SpeckSmall.h>
#include <SpeckTiny.h>
#include <string.h>

Speck speck;
SpeckSmall speckSmall;
SpeckTiny speckTiny;

byte buffer[16];
byte cipher[16];
size_t keySize = 32;

void setup() {

  const uint8_t key[32]={0x0f, 0x0e, 0x0d, 0x0c, 0x0b, 0x0a, 0x09, 0x08,
                    0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01, 0x00};
  byte plaintext[16]={0x6c, 0x61, 0x76, 0x69, 0x75, 0x71, 0x65, 0x20,
                    0x74, 0x69, 0x20, 0x65, 0x64, 0x61, 0x6d, 0x20};
  byte ciphertext[16]={0xa6, 0x5d, 0x98, 0x51, 0x79, 0x78, 0x32, 0x65,
                    0x78, 0x60, 0xfe, 0xdf, 0x5c, 0x57, 0x0d, 0x18};

  Serial.begin(9600);

  cipher->setKey(*key,keySize);
  cipher->encryptBlock(buffer, plaintext);

}

void loop() {

}

I know that I'm doing something wrong, but I don't understand what the error means, someone knows what it means and how to fix it?


texts: How can I PWM 4 LEDs from 0 to full brightness using a two axiz resistive joystick?

texts: I am trying to use the Arduino MAP function to allow me to PWM 4 LEDs between 0 and full brightness. I guess the tricky part is that the joystick neutral position is at the venter of the range of the potentiometers so the analog voltage to the inputs is at +2.5V when the joystick at neutral). Ideally I want to make a red LED that is associated with the Y axis to go from 0 to full as the joystick is pushed away. Similarly, I want a blue LED associated with the Y axis to go from 0 to Full on when the joystick is pulled toward me. I want to duplicate that action for the X axis with green and yellow LEDS but I can't seem to be able to figure out how to compensate for the 2.5V offset* I hoped I could just use mapping of the values.


texts:
there is AVR AVR ATmega32 and a board within.
there is outputs for all ports (A, B, C, D) on board, and Vcc.
the problem is - I have no external GND output.
to watch current - I should search for GND pin everytime.
and now I need ground on my solderless board for LEDs and temperature sensor.

let's guess that I have no idea what is current or electricity.
so the question is: where I can find ground to connect it to solderless board?
maybe I can use something else, except MCU? (like my hand or smth :D)


texts:
Still trying to understand the nomenclature of the pins, I am confused of what's the function of the +5V pin, as I read that the 101 should not operate at that tension.

What's it for?


texts: Loading Leonardo bootloader to Atmega32U4 running at 8 MHz

texts:
I am currently using ATMega32U4 running at 16MHz using Leonardo. I can only supply 3.7V (I use LiPo batteries) and everything seems fine but this is not as per specs.

To run at 16 MHz, I have to supply 5V but I can't. I do not want to do any step-up. I am thinking of of using 8 MHz crystal so the processor will require only 3.3V, but I need to use a Leonardo.

Has anyone been successful in doing this?


texts:
How can I make my program so that every half hour LED lights on and work for 5 minutes and than go off and the process should repeat

I made code but it does not works. Can someone help me?

void setup() {
  pinMode(8,OUTPUT);

}
void loop() {
  digitalWrite(8,HIGH);
  delay(300000);
  digitalWrite(8,LOW);
  delay(1800000);

}


texts: ESP32-CAM interfacing with CCS811+HDC1080+BMP280

texts:
I want to measure Temprature, Pressure, Humidity and CO2 in a room with ESP32-CAM & CCS811+HDC1080+BMP280

Since this module is combination of 3 sensors. Can I integrate it with ESP32-CAM over Software SPI ?


texts:
I am working on a project which requires a dozen VL53l0X I2C-TOF sensors to be polled by one master MCU over a few meters of cable.
Thus, I decided to accompany each TOF by an Atmega8 acting as a gateway between the TOF and a Modbus (using a MAX485), which is managed by an ESP32 (the master). Since I require fairly low latency (~10 reads / sensor / second) I am a bit disappointed by the Modbus RTU performance (mostly caused by the forced 1.75ms delay between frames).
My question: Is there any quicker, more suitable, Atmega-bearable bus protocol for long distances? Ethernet is sadly not an option due to the limited slaves computing power and cost...


texts: Can an Arduino be used to read data from a serial port?

texts:
People often use Arduinos to send data over serial to other peripherals (flashing firmware onto modules, etc) by pulling RES to ground,  connecting the TX and RX pins to the device being programmed, and then sending data to the Arduino over serial. As an alternative, one could also remove the ATmega instead of grounding RES.

That being said, there should be no reason why one could not receive data from a connected device in the same way. However, no matter what I try, I never succeed in using an Arduino to relay serial input from another device over USB.

I have even tried setting up a simple echo to no avail (even though the TX and RX LEDs flash):

Is it even possible?


texts: I'm trying to use a pH probe with NodeMCU, the problem is that NodeMCU is 3.3V and the pH analog sensor requires 5V, at first I thought using the VIN pin but didn't work, then I used the VU pin from NodeMCU V3 (by Lolin) but it didn't give me the right values, like if it missed more power. Is there any other way? Or any esp8266 board which supports 5V into it's analog input?


texts:
Hi SE (and Majenko in particular, if I'm lucky) -
I have a setup with an SD module (on SPI) and an Elechouse PN532 NFC reader (on I2C). I would like to use a master tag to enter MASTER MODE [sic] to add tags if they are not present in a file on my SD card, or remove tags which are present in the same file. I am currently checking tag UID against a hardcoded master UID, and it works well enough for now. What trips me up is making the tag database in the most arduino-friendly way. How would you advise me to do this in the most spartan way? And when removing existing tags from the database, how would you suggest I update it, to remove unwanted UIDs? I am using a flat text database now, but it could be a binary file - I am just puzzled by what is the best method to remove an entry(line) from a file using SD library.


texts:
I am connecting an ESP8266 to my home network (WiFi). After successful connection, an IP is assigned to it. I am sending commands to the ESP8266 from an Android app.

What can I do to find the ESP8266 on any network where my Android app is also connected? I ask this because whenever I change the network, a new IP is assigned to the ESP8266 and I have to manually change the IP in the Android app.

I just need to find the ESP8266 on the network, get its IP address and send commands to it.

Thanks in advance.


texts: Replace mechanical switch with electrical switch or relay

texts:
I have a remote controller for a portable heater, and working on a small project to be able to control the fan on/off from an arduino with Bluetooh HM-10 module. I thought a solenoid might work by mounting on top of the remote but it doesnt have enough force, I want to remove/desolder the mechanical button and figure out a way to control it without the switch but kind dont really know what circuit
I should use, kind of just learning how to use arduino.

Images of remote and button traces below.

Any idea how I could wire this up to arduino via some switch/relay circuit? Any circuit design / schematic would be helpful


texts: Always 255-response in I2C between ATTiny85 (8MHz) and Arduino Uno

texts:
I tried to set up an I2C conversation between ab ATTiny85 (8MHz) and an Arduino Uno. However I always get a 255 response from my I2C slave. I am using Arduino 1.8.5.

What am I doing wrong?

ATTiny85-Slave Code:

#include "TinyWireS.h"  // wrapper class for I2C slave
routines
#define I2C_SLAVE_ADDR  0x26 // i2c slave address (38)

byte t=10;

void setup() {
  TinyWireS.begin(I2C_SLAVE_ADDR);  // init I2C Slave mode
  TinyWireS.onRequest(requestEvent);
}

void loop() {
}

void requestEvent() {
  TinyWireS.send(t);
}

Arduino Uno-Master Code:

 #include <Wire.h>
 #define I2C_SLAVE_ADDR  0x26 // i2c slave address (38)

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

void loop() {
  byte num;
  // read 1 byte, from address 0x26
  Wire.requestFrom(I2C_SLAVE_ADDR, 1);
  while(Wire.available()) {
    num = Wire.read();
  }
  Serial.print("num = ");
  Serial.println(num,DEC);
}


texts:
Just using the Basic Example AnalogReadSerial.

// the setup routine runs once when you press reset:
  void setup()
{
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop()
{
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}

I have a basic voltage divider set up between two 10K resistors from 5V to GND. I have verified with a DMM that the DC voltage at pin A0 is 2.5V. Grounding the A0 pin has no effect.

It also seems that enabling either ADC channel 7 (Arduino pin AD0) or enabling every channel, putting the ADC in free-running mode, and deliberately setting it to not sleep has no effect:

ADC->ADC_CHDR = 0;
ADC->ADC_CHER |= 0xFF;
ADC->ADC_MR |= 0b10000000;
ADC->ADC_MR &= 0b11011111;

Also, by running the sketch DigitalInputPullup, I can get the LED on pin 13 to toggle and serial communication to work as I tie the pin to ground, demonstrating that the board is being programmed properly.

I guess I'm just stumped. Should be the simplest thing in the world and it's just not working.

EDIT:
This is my attempt at manually controlling the ADC:

volatile unsigned long value;

void setup()
{
  //ADC setup
  ADC->ADC_WPMR &= 0xFFFE; //disable write protect
  ADC->ADC_CHER = 0b100; //Enable AD2     |
  ADC->ADC_MR &= 0b11111111000000001111111100000000;
  ADC->ADC_MR |= 0b00000000000100100000000000000000; //software trigger, hi res, no sleep, not free running
  ADC->ADC_IER = 0b100; //enable interrupt
  ADC->ADC_IMR = 0b100; //enable interrupt in mask

  ADC->ADC_CR |= 0b10; //start first conversion
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop()
{
  ADC->ADC_CR |= 0b10; //start conversion
  while (!(ADC->ADC_ISR & 0b100)); //wait for conversion to end

  for (int i = 0; i <= 15; i++)
 {
    value = ADC->ADC_CDR[i]; //read conversion data for all channels
    Serial.println(value);
 }

 Serial.println();
 Serial.println();
 Serial.println();

 delay(3000);
}

Just doesn't seem to be doing anything. ADC_CHSR (the ADC channel status register) shows channel 2 and only channel 2 enabled and conversions are starting and completing, yet now the conversion data is always 2048. Here's the serial output of all 15 channels, now in 12 bit mode:

0
0
4095
0
0
0
0
0
0
0
0
0
0
0
0
0

0
0
4095
0
0
0
0
0
0
0
0
0
0
0
0
0


texts: Arduino reads string from another Arduino only if the string is in a loop why?

texts:
In my setup I have connected two arduino's Serially. An Arduino Mega is the on that is sending the string and a Arduino Uno is the one receiving it.

Arduino Mega : RX1(19),TX1(18) - Serial1
Arduino Uno : RX(10),TX(11)  - using SoftwareSerial
Gnd is connecetd on both boards

When I send a single string from the mega to Uno multiple times(In void loop)
I receive the string sent infinite number of times on the Uno which is to be expected:

Arduino Mega - Single string sent multiple no. of times

void setup()
{
  Serial1.begin(9600);
}
void loop()
{
  Serial1.println("e2e4");
  delay(100);
}

Now I want to only send the string a single time, so I inserted an exit(0) or an infinite loop after the delay that is always true.

Arduino Mega - Single string sent only one time

void setup()
{
  Serial1.begin(9600);
}
void loop()
{
  Serial1.println("e2e4");
  delay(100);
  while(true);
}

Arduino UNO - code is same for both cases

#include <SoftwareSerial.h>
SoftwareSerial s(10, 11);
void setup()
{
  delay(200);
  Serial.begin(9600);
  s.begin(9600);
  while (!Serial) ;  // wait for Arduino Serial Monitor
}
void loop()
{
  if(s.available()>0)
  {
     Serial.print("\nrec\n");
     delay(100);
     String b = s.readStringUntil('\n');
     delay(100);
     Serial.print(b);
     delay(40);
  }

}

Note : Arduino uno is receiving the string using : readStringUntil('\n')

But when I send the string only once I receive nothing on the Arduino Uno, can anyone help me figure out why this is happening

What I want to know is why the uno receives the string only when it's sent an infinite number of times and not when it is sent 1 time.

EDIT (July 8)

Still haven't got a solution that I'm looking for, if anyone needs any extra information to help me out please mention it to me.

EDIT (July 8-9)

Sorry it's my fault for writing Tx1 as 19  and Rx1 as 18 although I did not make the same mistake in the code.
When I pressed the reset button on the mega the string was received on the uno side.How did this happen?  Until now, after I uploaded the code in both the arduino's I opened the serial monitor of the port connected to Uno and I did not receive the string.

Why do I need to reset the mega in order to send the string , shouldn't it work when the serial monitor is opened?

Also I need the mega to send the string automatically without any forced/physical reset is that possible?

I'm asking this because sending a string is part of a larger code where values get updated as time goes by,and a reset will  reset all the values to their original state which I don't want happening.


texts: Arduino , python , pyfirmata , standard firmata

texts:
Is there a way to change arduino analog reference to EXTERNAL IN PYTHON using pyfirmata or any other library ?
Necessary Links : https://www.arduino.cc/reference/en/language/functions/analog-io/analogreference/
My sensor has a 3.3 volt operating voltage , my arduino has a 5 volt operating voltage.
As such in arduino using C++ and arduino module the scaling can be done using analogReference(External) and providing reference voltage to analog read?
IS there any equivalent to this in python, pyfirmata ?


texts:
My goal is to make a logic controller for a cassette tape mechanism, right now I'm simply trying to get the mechanism to engage and disengage the pinchroller arm which is motorized, spin the reels/capstan to advance the tape for playback; and stop the process by stopping the capstan motor, and retracting the pinchroller arm.

Currently this code doesn't respond to any of the button inputs, and I'm unsure as to why that is. I have another program that allows manual control of the motors, and that works fine, this however does not.

Can someone point out/correct what is the mistake? Because I can't seem to find what is wrong. Thank you in advance!

Here is my current full code:

const int motor1Pin = 5; //If motor1 is HIGH and motor2 is LOW,  the motor will spin one way, if motor1 is LOW and motor2 HIGH then the motor will spin in the opposite direction.
const int motor2Pin = 4;
const int motor3Pin = 2;
const int motor4Pin = 1;
const int enablePin = 6; //turns pinch roller arm motor on or off
const int enablePin2 = 3; //turns capstan motor on or off
const int limitswitch1Pin = 7; // end of top travel limit switch
const int limitswitch2Pin = 9; // end of bottom travel limit switch
const int cyclePin = 8; //switch that cycles the pinch roller arm depending on limit switches
const int reversePin = 10;
const int forwardPin = 11;
const int stopPin = 12;

int state;
int buttonState;
int limit1State;
int lastlimit1State;
int limit2State;
int lastlimit2State;
int reverseState;
int forwardState;
int stopState;

enum State_enum {STOP,PLAY};

bool enableState = false;
bool enable2State = false;

void setup() {

  pinMode(motor1Pin, OUTPUT);
  pinMode(motor2Pin, OUTPUT);
  pinMode(motor3Pin, OUTPUT);
  pinMode(motor4Pin, OUTPUT);
  pinMode(enablePin, OUTPUT);
  pinMode(enablePin2, OUTPUT);
  pinMode(reversePin, INPUT_PULLUP);
  pinMode(forwardPin, INPUT_PULLUP);
  pinMode(stopPin, INPUT_PULLUP);
  pinMode(limitswitch1Pin, INPUT_PULLUP);
  pinMode(limitswitch2Pin, INPUT_PULLUP);
  pinMode(cyclePin, INPUT_PULLUP);
  pinMode(A0, INPUT);

  buttonState = digitalRead(cyclePin);
  limit1State = digitalRead(limitswitch1Pin);
  limit2State = digitalRead(limitswitch2Pin);
  reverseState = digitalRead(reversePin);
  forwardState = digitalRead(forwardPin);
  stopState = digitalRead(stopPin);

}

void loop() {

  if (buttonState == LOW) int state = PLAY;
  if (stopState == LOW) int state = STOP;

  switch (state) {
  case PLAY: //Plays the cassette
    if (stopState == LOW) {
      state = STOP;
    }
    if (limit1State == LOW) { //running the pinchroller arm clockwise from the top to bottom

      digitalWrite(motor1Pin, HIGH); // set leg 1 of the pinchroller motor H-bridge high
      digitalWrite(motor2Pin, LOW); // set leg 2 of the pinchrooler motor H-bridge low
      analogWrite(enablePin, 176); //set pinchroller motor speed

    } else if (limit2State == LOW) { //pinchroller arm is fully down (at bottom)
      digitalWrite(enablePin, LOW); //disable pinch roller motor
      digitalWrite(motor3Pin, LOW); // set leg 3 of the capstan motor H-bridge low
      digitalWrite(motor4Pin, HIGH); // set leg 4 of the capstan motor H-bridge high
      analogWrite(enablePin2, 200); // set capstan motor speed
      digitalWrite(enable2State, true);
    }
    break;

  case STOP: //Stops the cassette
    if (enable2State == true && limit2State == LOW) {
      digitalWrite(enablePin2, LOW);
      digitalWrite(enable2State, false);

    } else if (enable2State == false && limit2State == LOW) {
      //running the pinchroller arm counter-clockwise from the bottom to top

      digitalWrite(motor1Pin, LOW); // set leg 1 of the motor H-bridge high
      digitalWrite(motor2Pin, HIGH); // set leg 2 of the motor H-bridge low
      analogWrite(enablePin, 176); //set pincroller motor speed

      if (limit1State == LOW) {
        digitalWrite(enablePin, LOW);
      }
    }
    break;

  }
}


texts: Serial Monitor appears unreadable characters

texts:
Hello

My serial monitor keep showing these unreadable characters. Anyone know what is going on? Many thanks!


texts: What is the maximum wire length for serial communication between two Arduinos?

texts:
I am building a project in which two Arduinos will be linked by three wires: TX an RX for serial communication and a common GND. What would be the maximum length of the wires here before communication gets affected?

I am using an Arduino Mega R3 on one side and an Arduino Mini on the other one.

I have no particular requirement for the Baud rate, I could use the lowest one if this helps in any way.


texts: Is it possible to program/flash ESP8266MOD(07) With Arduino UNO

texts:
i am new to ESp and yesterday i received my ESP8266MOD, i don't have FTDi connector with me right now(it's on the way).

Is it possible to flash ESP with Arduino UNO?

Regards,
Ben


texts: running a dc motor with a small L298N module and an arduino and the L298N library

texts:
I have a small L298N module which I would like to use to run a couple of dc motors. The module I have is smaller than most of the ones you see on eBay, it looks like this...

I am trying to use the following library :
https://github.com/AndreaLombardo/L298N

I have managed to get the motor going forwards and backwards, but the problem is, this module doesn't have a pin for enable ( EN for PWM from the Arduino) and the library seems to require this; therefore I can't control the speed of the motors.

Does anyone have any experience with these modules? Is there a different technique I should be using? Is there another library that works with these kind of modules?

All help appreciated.


texts: Failed HC-05 Bluetooth sketch upload - (port and board correct)

texts:
I'm running this project with HC-05 https://create.arduino.cc/projecthub/millerman4487/view-serial-monitor-over-bluetooth-fbb0e5 and I am getting connection error. I have ensured my port selected and board is accurate but no such luck. The Arduino uno is powered by 3.7v batt (output ~8v with reg) so it is simply just a battery connection and BT module, but when uploading the sketch, it fails. I am relatively new to arduino, and am not sure where to begin this debug.
I am using PC windows, and using a BT dongle receiver for connection (maybe this affects port comm?)
Thanks in advance
Here us the error message
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Uno"

Sketch uses 1954 bytes (6%) of program storage space. Maximum is 32256 bytes.

Global variables use 250 bytes (12%) of dynamic memory, leaving 1798 bytes for local variables.
Maximum is 2048 bytes.

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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

avrdude: stk500_recv(): programmer is not responding

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


texts: How to Sort Elements of Array in Arduino Code?

texts:
/How Can i Sort this Array with Descending Order? I need Simplest syntax to use in iterative code.

lt[6]={35,15,80,2,40,110};


texts: I am trying to combine a button's coding and servo's coding. But it is still cannot be verified. What have I done wrong?

texts:
include

Servo myservo;

void setup(){
  myservo.attach(8);
   pinMode(buttonPin, INPUT);
}

void loop()
{
  myservo.write(0);
  delay(3);
  myservo.write(90);
  delay(3);
}
 const int inPin=8;
 const int outPin = 9;
 int currentState = LOW;
  currentState = digitalRead (inPin);
  if (currentState== HIGH)
    digitalWrite (outPin,HIGH);
   else
    digitalWrite (outPin,HIGH);
   delay(10);
 }


texts: How do I know if I need to use a resistor in a circuit?

texts: I have been trying to find answers on Google to this question but cannot seem to find any answers that actually pertain to what I am wanting to know.  I would consider myself a beginner in the area of electronics having some experience but not understanding how everything comes together outside of the some of the basics.  What I am wondering is this; How can I tell if I need to use a resistor in a circuit?  More specifically, When I am hooking sensors up to an Arduino, how can I determine if I need resistors in the circuit?  Anywhere I look I typically see the default LED/Resistor example but that is not helpful.  It doesn't explain how Arduino/Raspberry PI modules and sensors fit into the equation.  I know the data sheets for the various modules/sensors explain how much current is needed/used by the device but how do I take that and apply it to an Arduino circuit?  Thanks in advance.


texts: Made a light controller for the holidays

texts: I am a new the world of Arduino. I found on YouTube, how to build a light controller (https://www.youtube.com/watch?v=WvG9c84ApFA&t=39s). I follow every step but it doesn't work. Here are some pictures and a rough schematic. (I don't have a Arduino, it is a Egeloo mega 2560)enter link description here


texts: I2C between Yun Shield (Dragino) and UNO R3 problem

texts:
I am having problems with I2C communications between my Dragino Yun and an Arduino UNO R3.

I can have the Dragino request data (using Wire.onRequest on UNO) from the UNO and it works great, however, when I have the UNO sending and the Dragino using Wire.onReceive it's not picking up any data!?

What are the SDA and SCL pins on the Dragino? Are they the same as the UNO? Are there any specific difficulties involved for this setup?


texts: Task watchdog gets triggered during Bluetooth initialization

texts:
The board ESP32-Dev-WROOM-32D cannot establish a bluetooth connection due to the task watchdog. Here's my code:

#include "BluetoothSerial.h"
//check if Bluetooth is enabled
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

BluetoothSerial SerialBT;

void setup() {
  Serial.begin(115200);
  SerialBT.begin("ESP32test");
  Serial.println("The device started!");
}

The program runs fine until SerialBT.begin("ESP32test"); where it freezes, and does not continue to run. The message The device started! is not printed. Instead, the task watchdog gets triggered after some time: E (24791) task_wdt: Task watchdog got triggered.

Is there any way to turn off the task watchdog? Or is there any other issue?


texts: Arduino Uno - Firmata/Serial Communication in Visual Studio C++

texts:
I need to pass std::vector <double> values from a C++ console program (written in Visual Studio 2015) running on a PC to Arduino in real-time using USB serial communication. Can anyone of you give any advice on how to implement Firmata or something similar into a C++ console application?

I googled everywhere and could not find a decent example for C++. Almost everything can be computed in console app, Arduino needs to work only with LCD display and beside that it can have StandardFirmata uploaded.


texts:
I have a problem similar to these questions:

Wemos D1 doesnt drive Relay

Wemos D1 is not triggering Relay

I got this BC548B transistor from an old apparatus I scratched. The transistor saturation voltage is 0.6V  according to the datasheet:

https://alltransistors.com/pdfdatasheet_fairchild_semi/bc548_bc548a_bc548b_bc548c.pdf

When I set up my circuit the wemos d1 inboard leds dim and the board resets so I guess something is going really wrong. Can someone advise if my design makes sense?

UPDATE

I replaced the 12V relay with a 5V one but still can't get it to work. Basically, the 3.3V signal seems to be too low to activate the solenoid. How can I raise the 3V3 signal to 5V? What was wrong with my idea of using a transistor to do it?


texts:
i'm stuck with a little problem. I need to create a program that can store a number via keypad (this number will be chosen by the user) and then do something with it. To be more specific i will create a temperature control in which the user will be able to input a value of temperature they need and then with this value control a heater, but that's another story, the main point here is that the program needs to be able to store a value via keypad.

i use the keypad library and some of its commands like getKey() and waitForKey() and so on.

thanks for your answers!


texts: Combining ADC IRQ with SPI peripherals results in SPI not working

texts:
I'm working on a pet project that requires ADC, SD card (SPI interface, SdFat library) and a display in the future (also SPI).

I have put together a piece of code that initializes ADC at the highest clock frequency and uses ADC_IER_DRDY interrupt and double buffering.

I have also put together a piece of code based on one of SdFat examples that inits SD card and benchmarks its speed.

On its own, each piece works just fine. But combined together, it breaks if I enable the ADC interrupt. It causes SdFat to stall, not sure where (I don't have a debugger). Simply disabling the interrupt is enough to let SdFat work just fine, but I need both. I have also set ADC IRQ priority to 0 and most other IRQs to 1, but removing NVIC_SetPriority calls does not solve the problem.

Any advice on how to make both ADC and SPI work, with ADC IRQ priority so that I don't miss samples?
I also tried lowering SPI speed from full to 1/16th (SdFat lib has a convenient parameter for this), didn't help.

The code is not long, but a bit too much for inlining into the question, here are Github links.

main.cpp and ADC stuff - just commenting the highlighted line fixes SPI.
SD card stuff. Of note: sometimes it prints "chipselect: 10", sometimes not even that.

Update: making ADC handler empty does not resolve the problem, neither SPI nor printing to Serial works.


texts:
I'm trying to re-use a piece of example code I found here:

https://howtomechatronics.com/tutorials/arduino/how-to-control-ws2812b-individually-addressable-leds-using-arduino/

And I only have 5 LEDs in my strip, so I changed the define NUM_LEDs to 5, but when compiling with that value, I get a compilation error. with the define at 6 it works tho, but the 5th LED wouldn't turn on. Here is my code:

#include <FastLED.h>
#define LED_PIN     7
#define NUM_LEDS    6
CRGB leds[NUM_LEDS];
void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);

}
void loop() {

  leds[0] = CRGB(0, 10, 0);
  leds[1] = CRGB(10, 0, 0);
  leds[2] = CRGB(0, 10, 10);
  leds[3] = CRGB(10, 10, 0);
  leds[4] = CRGB(10, 10, 10);
  FastLED.show();
  delay(500);
  leds[0] = CRGB(0, 0, 0);
  leds[1] = CRGB(0, 0, 0);
  leds[2] = CRGB(0, 0, 0);
  leds[3] = CRGB(0, 0, 0);
  leds[4] = CRGB(0, 0, 0);
  FastLED.show();
  delay(500);

}

So in the code, I've set the first LED to green, seccond one to red, third one to blue, 4th one to yellow, and the 5th one to white. As you can see in the picture they all light up correctly but the 5th one which stays blank, and I don't know why. I have tested this LED individually and it works perfectly well so it's not a hardware problem. I would encourage anyone who wants to test this code on 5 LEDs and let me know if it works for them, I'd be surprised it it did, but if you have a better solution for me, I would appreciate it.

Thanks.


texts: "Active LOW" relay board Pin configuration

texts:
I bought a 5 V Relay Board: LINK (Aliexpress) and just realised it's "Active LOW".
I want to control a water pump via a Arduino Micro.

I tested it and as far as i understand the workings of this relay, putting the pin to LOW activates the little LED on the Relay Board and switches to the NC position where I connected the water pumps ground wire.

I don't feel very comfortable with that because normally those relays are activated by setting the pin to HIGH.
I tried to connect the ground wire of the pump to the normally open position but than, if I disconnect the Arduino to simulate a malfunction the pump keeps running.... this doesn't happen with the first configuration.

So my Question: Is it a problem to use the Relay Board in the way described above (Pin to LOW switches Coil to NC Postion).
Is there a way I'm not seeing to get the Board to switch the Coil if a pin is set to high.


texts:
I am trying to use a program that has been written for  STM32 microprocessor for interfacing with a Time to Digital Converter TDC GP22 via SPI interface. I would like to use the same program and adapt it to suit Arduino Uno for interfacing with TDC GP22. This would really help save a lot of time.

Can someone please suggest me the most effective way to do this ?


texts:
I am working with a MEGA2560 trying to implement velocity ramps for three steppers at the same time. The goal is to move to different positions applying accelerations and decelerations while finishing all of them at the same time.
In order to do so, from the distances to move of each of the motors, I calculate the amount of steps to do and the velocities for each of those steps in order to ensure that all the motors finish at the same time. For so, I use timers 3, 4 and 5 in compare mode. This way, at each interruption, I make the motors do one step and, after that, I set the new compare value for the timer in order to reach the new velocity to move at.
My problem is that, at some point, my interruptions crash and one of the motors stops working. This only happens under one condition: when motor 1 has to do 18 steps and motor 2, 34. In this case, both motors 1 and 3 finish but motor 2 gets stuck and does not move any more. Although, if its motor 1 who has to do 34 steps and motor 2, 18, everything works. Motor 1 is related to timer 3 and motor 2 to timer 4. This makes me think this must be related to the priorities of the interruptions.
In the following code you can see my interruptions:
ISR(TIMER3_COMPA_vect) {
    m1_step();
    m1_steps_done++;
    m1_configure_vel();
}
ISR(TIMER4_COMPA_vect) {
    m2_step();
    m2_steps_done++;
    m2_configure_vel();
}
ISR(TIMER5_COMPA_vect) {
    m3_step();
    m3_steps_done++;
    m3_configure_vel();
}

While, in the velocity configuration I have:

void m1_configure_vel() {

  if (m1_steps_done < m1_acceleration_steps) {
    m1_temp_vel = m1_temp_vel + acceleration;
  }
  else if (m1_steps_done <= (m1_steps - m1_acceleration_steps)) {
    m1_temp_vel = m1_temp_vel;
  }
  else if (m1_steps_done < m1_steps) {
    m1_temp_vel = m1_temp_vel - acceleration;
  }
  else {
    m1_temp_vel = 0;
    m1_finished = true;
  }
  if (m1_temp_vel <=0){
    m1_temp_vel = 0;
  }

  OCR3A = frequency_to_compare_value(m1_temp_vel);
}

As you can see, all I do here is, depending on the steps done by the motor and the amount of steps to do, I increase, maintain or decrease the motor's velocity and set the compare value for the timer.
The whole thing is that this code works fine, the ramps are calculated properly and motors move correctly. The problem is that, under the condition I explained before, interruptions may collide due to their priorities and one of them just stops to happen.
I was wondering if anyone had any idea or have faced something like this before.


texts:
I am new at arduino.
I want to write a sketch that would print the message if the temperature grows greater than 30 C.
Here is my sketch can you please tell me what's wrong with it

#include "DHT.h"
#define DHTTYPE DHT11
#define dht_dpin D3

DHT dht(dht_dpin, DHTTYPE);

void setup()
{
 Serial.begin(9600);
 }
void loop()
{
 float t = dht.readTemperature();
 Serial.print("temp=");
 Serial.println(t);
 attachInterrupt(dht_dpin, IntCallback, CHANGE);
}
void IntCallback()
{
  float t = dht.readTemperature();
  if(t>30)
  {
    Serial.print("Alert");
  }
}


texts:
So in computer engineering I've got to make a arduino based car, I've added a whole bunch of features such as IR tracking, obstacle avoidance(proximity sensor), optical tracking(follow a black line), and remote control through an android based phone.

Since I'm a total newbie to technology I'm having trouble. I would appreciate it if You guys can point me towards resources and arduino libraries(for coding) that will work for me. Right now for coding I've only got basic pseudo-code setup since I do not know what libraries to use. I have searched up many sketches online and looked at them but didn't really understand any of the code.

Here's the basic pseudo-code I got setup on the things that I've got to work on:

DC Motor (4 of em for the wheels) (I also plan to add a stepper motor for turning right and left so if you could direct me on that as well)

//Import necessary library
//Setup the motors and pins

//If signal for forward received
//Code for moving forward
//Set speed

//Else If signal for backward received
//Code for moving backward
//Set speed

//Else If signal for right received (keep turning right till stop signal received)
//Code for moving right
//Set speed

//Else If signal for left received (keep turning left till stop signal received)
//Code for moving left
//Set speed

//Else If signal for stop is received (Should we slow down to a stop or just stop?)
//Code for stop
//Set speed

IR (I've got transmitting and recording diodes)

//Import Library

//Declare Pin for the IR Sensor

//While loop: Move Right
//If IR signal is received
//move forward
//Else
//Jump back to top of loop

Proximity Sensor (obstacle avoidance mode) (I might either use the one from Lego kit or buy a separate one )

//Import Library

//Declare Pin for proximity sensor

//While Loop: Send out sonar(echolocation or whatever) every second
//Is there any obstacle?
  //Yes, turn right so many degrees, and go back to while loop
  //No, move on forward at set speed

//If you’re surrounded and cannot exit send out a message through flashing LED's

I'm not asking for the code or for any of you to do all my stuff for me, I'm just asking for direction and resources.

Thank You


texts: Set up an Arduino Cellular Shield SM5100B

texts:
I'm trying to set up an Arduino Cellular Shield SM5100B to send SMS.

My setup is:

Arduino UNO R2
SM5100B
"Movistar" SIM Card (Chile)

I've uploaded a code similar to the one described here, but when communication is supposed to star it cannot find a network. I suspect the problem is I haven't setup correctly the GSM band. But when I issue the command (AT+SBAND=7, same as in the US), it doesn't respond. How can I check in what band I'm on? And change the band?


texts:
I wish to build a simple headless device, powered by a 9 V battery that allows a person to speak into it upon touch. The device would then capture to allow "speech to text" functionality and, subsequently, have that text sent over Wi-Fi, to my server.

My background is in Android development and I can handle the necessary programming, but I have very little background in the hardware side. In short, I do know I need a microphone, Wi-Fi transmitter, possibly Bluetooth to allow the device to link to mobile device for Wi-Fi login information, and bare bones microcontroller (way less than an Arduino given the specific functionality).

I am very new to this. Can such products be purchased for around $20 total? Or perhaps a unit with all features outlined above aside from the speech-to-text logic? Where?


texts:
I was trying made a gear indicator for my bike, with manually sensing the gear shift.  But failed, cause my bike has no separate "neutral" wire, instead there is gear sensor in-built...!! But not gear-position indicator...!!
The in-built sensor gives different output voltage at every gear.
It sounds good that all I need is just an Pro-mini & OLED.
But, facing problem with the voltage reading on Pro-mini.
When I checking with normal multimeter, the output voltage is very stable.
I tried with the simple voltage reading code.
And added the voltages ranges as shows on multimeter.
Later Checked with Uno, Reading is quite stable (+- 0.02V).

But, Pro-mini voltage reading is too sensitive.
Sometimes, in same gear position getting high voltage difference.
So, in result I doesn't getting a stable voltage reading or gear display.

Need suggestion to make changes, so the pro-mini also read like the multimeter / Uno reads.
(Is this because of Pro-Mini doesn't have the Op-Amp in-built?)

And, also, Why the serial output is around 1.5V, while no input in A0...?

PS: I didn't use voltage divider, because, gear sensor output voltage is below 5V.


texts:
I'm doing a project where i need a live video capture, not taking pictures. Is it possible on arduino? With this cam ? I want to send the stream to my PC over ethernet. Is it possible? Will it work? I am asking is it possible for normal live video, not for code because I've read that arduino could be too slow for processing. Please help.
Thanks, Anerso


texts: Does anyone know the location of the assembler file for strcpy and strcat for the Arduino?  I wish to modify it.


texts: Arduino Leonardo is not recognized by usb cable in Windows 8

texts:
My Arduino Leonardo was working properly but for the last two hours when I connect it to a PC via a USB cable, it is reporting something like USB is not recognized and even in device manager it is not showing. However, when I press the restart button on the Arduino, the PC will detect it as an Arduino Leonardo bootloader(com 7) but after few seconds it disappears. What do I have to do? I tried to restart the PC, changed USB cable but the same issue occurs. I checked the USB by connecting another device - it works fine but the Arduino is not recognised.
I tried other PCs also but the same problem continued. What do I have to do?


texts: ESP-32 Upload Files to SPIFFS via browser

texts:
I am using ESPAsyncWebServer Library in a ESP32 DevKit. I want to make a form in the browser in order to upload files in SPIFFS.
I have to notice that the whole device works perfectly. I connect to Wi-Fi, it uploads files via IDE etc.
Through searching in the net, I found this part of code that does not work.
server.on("/upload-file", HTTP_GET, [](AsyncWebServerRequest* request) {
    String html = "
<form method='post' action='/upload-file'><input type='file'><button>Send</button></form>
";
    request->send(200, "text/html", html);
    });

server.on("/upload-file", HTTP_POST, [](AsyncWebServerRequest* request) {
    AsyncWebServerResponse* response = request->beginResponse(200, "text/html", "hello world");
    response->addHeader("Connection", "close");
    request->send(response);
    }, handleUpload);
server.onFileUpload(handleUpload);

The handleUpload function:
void handleUpload(AsyncWebServerRequest *request, String filename, size_t index, uint8_t *data, size_t len, bool final){
if (!index) {
    request->_tempFile = SPIFFS.open("/" + filename, "w");
}
if (len) {
    request->_tempFile.write(data, len);
}
if (final) {
    request->_tempFile.close();
    request->redirect("/files");
}
}

It shows the form but the file doesn't upload.
Is there any idea on how can I make it work?


texts:
Its my first attempt to work with relay
I tried to test my relay with this simple code

int Relay = 2; void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(Relay,OUTPUT);
}

void loop() {

  digitalWrite(Relay,HIGH);
  delay(1000);
  digitalWrite(Relay,LOW);
  delay(1000);
}

Connected to
IN -> Digital 2
GND -> GND
VCC -> 5V

The only thing is happened is the LED of the relay blinking in every sec. but can not hear the clicking sound from the relay box or testing with a multimeter's diode function the two(NC and COM) OUTs aren't close
I tried to test other relays(from the same type) but does not do anything else.

thank you for your help
What can be wrong?


texts: Custom Arduino board beeps and process freezes while I'm uploading a sketch to it. Why?

texts:
The strangest thing is happening to a standalone Arduino board that I designed and built. The board (whose schematics are below) has the following features:

It has a ATmega328P with a 5V voltage regulator and usual circuitry when set up as a standalone controller.
It controls a scoreboard with several 7-display digits linked through the connectors on the right (JP1 through JP12).
It has cursor buttons decoded using a voltage ladder through ANALOG_0 (A0).
It has a Real Time Clock to keep time when it's turned off.
It has an RF receiver module.
It has a UART header (JP17) so I can program the board using a serial port.
It has a speaker attached to digital pin 3 (D3).

I upload sketches to it using a RS232-to-TTL adapter that I've also built (schematics also below) and a Serial-to-USB cable. When programming it, the board behaves much like a Severino board.

What's strange is that, when I upload a sketch, the process is paused in the middle and then the speaker starts to beep continually. It pauses with the following avrdude messages:

avrdude: Version 5.11, compiled on Sep  2 2011 at 19:38:36
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

     System wide configuration file is "C:\arduino-1.0.3\hardware/tools/avr/etc/avrdude.conf"

     Using Port                    : \\.\COM1
     Using Programmer              : arduino
     Overriding Baud Rate          : 115200

When I press reset on the board, avrdude continues outputting its messages (such as below), the beep stops, the upload continues and the sketch is uploaded successfully to the board.

avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
avrdude: Send: 0 [30]   [20]
... messages and upload continue and completes successfully.

I don't have the rest of the messages handy here, but I hope you get the idea.

So, my questions are:

What is making the upload process pause?
Why is the buzzer beeping when the process pauses?


texts: How to use IRremote library with atmega8a

texts:
A few days ago I tested  a circuit on a  breadboard based on a ATmega8a with 1 MHz internal oscilator. It sould turn on and off a relay based on a IR code that is received and if it matches the programmed in the EEPROM it shoud enable or disable the relay. Now I developed a PCB and soldered everything together but now it isn't working. On an Arduino Nano it is working ok.

#include <IRremote.h>
#include <EEPROM.h>

int RECV_PIN = 11;
int RELAY_PIN = 4;
int setpin = 3;
unsigned long work_at;
unsigned long adres;
unsigned long irbuffer;
IRrecv irrecv(RECV_PIN);
decode_results results;

void dump(decode_results *results) {

    if(digitalRead(setpin) == 0){
      work_at = results->value;
      Serial.println(work_at, HEX);
    }
    irbuffer = results->value;

}

void eeprom_writer(){
  if (irrecv.decode(&results)) {
    if(digitalRead(setpin) == 0 && work_at != 0){
      EEPROM.put(0, work_at); //put walue
      Serial.println(work_at, HEX);
      adres = work_at;
      Serial.println(adres, HEX);
      delay(1000); //wait
   }
  }
}
void setup()
{
  EEPROM.get(0, adres);
  pinMode(setpin, INPUT_PULLUP);
  pinMode(RELAY_PIN, OUTPUT);
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

int on = 0;
unsigned long last = millis();

void loop() {
  if (irrecv.decode(&results)) {
    // If it's been at least 1/4 second since the last
    // IR received, toggle the relay
  //  if(&results == adres){
      dump(&results);
      if (millis() - last > 250) {
        on = !on;
        if(on == true && adres == irbuffer){
          delay(5000);
          digitalWrite(RELAY_PIN, on ? HIGH : LOW);
          dump(&results);
        }else if(on != true  && adres == irbuffer){
          digitalWrite(RELAY_PIN, on ? HIGH : LOW);
          dump(&results);
          delay(5000);
        }
      }
    //}
//    Serial.println(dump(&results));
//    Serial.println(count, DEC);

    eeprom_writer();
    last = millis();
    irrecv.resume(); // Receive the next value
  }
}


texts: Void value not ignored as it ought to be

texts:
im trying to build an rc plane using arduino nano and nrf24l01 as receiver but im having some issues in the code

it has error on the line
done = radio.read(joystick,sizeof(joystick)); which says that void value not ignored as it ought to be

the whole code is below

#include <nRF24L01.h>
#include <RF24.h>
#include <RF24_config.h>
#include <SPI.h>
#include<Servo.h>

Servo Throttle,Rudder,Elevator,LeftAileron,RightAileron ;

const uint64_t pipe = 0xE8E8F0F0E1LL;
RF24 radio(9,10);
int joystick[5];

void setup()
{
  /*Serial.begin(9600);
  delay(1000);
  Serial.println("Starting Rx");*/ //Enable serial for debugging

  attachMotors();

  calibrateMotors();

  radio.begin();

  detachMotors();

  radio.setPALevel(RF24_PA_MAX);
  radio.setPayloadSize(10);
  radio.setDataRate(RF24_250KBPS);
  radio.setRetries(15,15);

  radio.openReadingPipe(1,pipe);
  radio.startListening();;
}

void loop()
{
  detachMotors();

  if(radio.available())
  {
    bool done=false;
    while(!done)
    {
      done=radio.read(joystick,sizeof(joystick));
    }

  attachMotors();

  int a=joystick[0];
  int b= joystick[1]; //stores values from tx
  int c=joystick[2];
  int d=joystick[3];
  int e=joystick[4];

  //Serial.println(a);
  //Serial.println(b);
  //Serial.println(c);
  //Serial.println(d);
  //Serial.println(e);
 // Serial.println(f);

  delay(20);
  Throttle.writeMicroseconds(a);   //write values to motor
  Rudder.write(b);
  Elevator.write(180-c);

  if(d== LOW)
  {
  LeftAileron.write(180); ////to activate right aileron
  RightAileron.write(180);
  delay(15);
  }

  else if(e == LOW)
  {
    LeftAileron.write(0);  //to activate left aileron
    RightAileron.write(0);
    delay(15);
  }
  else
  {
    LeftAileron.write(100);
    RightAileron.write(110); //Ailerons at neutral pos
    delay(15);
  }
    }
  else
  {
    calibrateMotors();
    delay(15);

  }
  }

void attachMotors()
{
  Throttle.attach(3);
  Rudder.attach(4);
  Elevator.attach(5);
  LeftAileron.attach(6);
  RightAileron.attach(7);
}

void calibrateMotors()
{
  Rudder.write(90);
  Elevator.write(90);
  LeftAileron.write(100);
  RightAileron.write(110); //centering servo shafts
}

void detachMotors()
{
  Throttle.detach();
  Rudder.detach();
  Elevator.detach();
  LeftAileron.detach();
  RightAileron.detach();
}


texts:
I am using an Arduino UNO.

On any digital/analog pin, if an LED (with resistor) is connected and we use digitalWrite(pin,HIGH) the LED lights up rather dimly.

On the other hand, if we use pinMode(pin,OUTPUT) and then use digitalWrite, the LED lights up to maximum intensity.

I checked that in both cases, the voltage on the pin is 5V. Any explanation for this ? Thanks.


texts: availableForWrite() function return error when compiling for Arduino nano 33 BLE

texts:
I used availableForWrite() function as below in my code. When I compile it for nano 33 IoT, everything is OK and compiles perfectly. However, when I change the board to nano 33 BLE, I end up with two scenarios:
1. using Arduino IDE as compiler > gives no error but the board doesn't after programming.
2. using the web-based compiler in Arduino website > give the following error:

error: 'class Arduino::USBSerial' has no member named 'availableForWrite'; did you mean 'available'?"

my code:

NoreplyTime=millis();
TimePassed= millis()-NoreplyTime;

         while(!Serial.availableForWrite()){
         TimePassed= millis()-NoreplyTime;
         if (TimePassed>1000){
         return false;
         }
        }

even simply having:

while (!Serial.availableForWrite());

generates error ONLY for nano 33 BLE board!

Thoughts?


texts:
I'm using the same script(and standard wire and serial library only) one uploaded to Arduino nano one uploaded to ESP8266. However, despite ESP8266 running at 160MHz, 10 times faster than nano, it's taking 3.5 ms to complete the loop, compare to 2.5 ms than that of nano.

How could that be?  why ESP8266 was slower?


texts:
I'm trying to shrink the compiled code size, and I have noticed that the compiler inlines functions a lot, even the ones I have not marked "inline", but I can't manage to turn that off.

It looks like the compiler uses the -Os flag by default (optimize for low program size), because when I add it, the resulting program size is the same.

I tried adding "__attribute__((noinline))" to the functions but it makes no difference. Any idea how to prevent function inlining?

I'm using Visualmicro on Visual Studio Community 2017. Arduino 1.8.8. Arduino Uno board.


texts: Wrong Mouse.move() output in Arduino Leonardo

texts:
I'm using my Arduino Leonardo as a Mouse but I'm experimenting a strange behaviour.
I put my mouse at (-1, -1) (absolute) coordinates and then I execute this code:

Move.move(com[curr_cmd_id].x, com[curr_cmd_id].y, 0);

where that point is (334, 180) (relative coords) (and I checked it through Serial console)

Now, the pointer is actually moving to the right but then it stops. Let's say it reaches the point (334, 0).

Then I tried:

Mouse.move(com[curr_cmd_id].x, 0, 0);
delay(500);
Mouse.move(0, com[curr_cmd_id].y, 0);

but still the same behaviour.

Then finally I tried this one (which it actually solves my problem but it's a dirty solution):

int i;
for(i=0; i<com[curr_cmd_id].x; i++){
  Mouse.move(1,0,0);
  delay(1);
}
for(i=0; i<com[curr_cmd_id].y; i++){
  Mouse.move(0,1,0);
  delay(1);
}

Could anybody help me in understanding what's going on here? How can I achieve a simple and direct relative movement for my pointer?
Thanks you in advance!!


texts: Accelerometer Interrupt Meaning - Wakeup Function

texts:
I am working with an LSM9DS1 IMU, and now specifically trying to program a wakeup feature into the system. My idea is to set the accelerometer at the lowest possible read rate, then when the accelerometer value exceeds a predefined level, to have the system wake up.

When programming the sensor, there is a register called INT_GEN_CFG_XL that has a "6-Direction detection for interrupt." I was wondering what this means. Does this perhaps calculate the magnitude of acceleration, and see if that goes above a predefined value? I can see the other interrupt generators are for 1-direction of each of the three axes, but I can't interrupt this one.

Here is a link to the device datasheet


texts: Burn bootloader to Arduino Uno using ARM-USB-OCD

texts:
I have ARM-USB-OCD created by OLIMEX. I am interested in can I use this to burn a bootloader to Arduino Uno. As I know Atmega 328P can be programmed using JTAG protocol which has also ARM-USB-ODC, so if it really can anyone give the circuit or something like this.
Here is my device (ARM-USB-ODC) manual.


texts: Saving a .txt file to SD Card and Reading each content data to txt file then save it to a variable

texts:
I am new to arduino I am trying to create an arduino project that Saving a .txt file to SD Card and Reading the txt file then save it to a variable data type "Long" named 'savednum'. I had successfully can save the txt file and read it, however the problem lies in storing the read txtfile, when I read the txtfile and stored it in savednum and then serial print the savednum it gives different/ random numbers which is not equal to the data in the .txtfile that I store and read. I am wondering what seem to be wrong? Any suggestion is really appreciated. I thank you in advance.

#include <TMRpcm.h>
 #include <SD.h>
 #include <SPI.h>
 #define SD_ChipSelectPin 4 //using digital pin 4 on arduino nano 328

 TMRpcm tmrpcm; // create an object for use in this sketch

File myFile;

char serialData;

int i = 0;
long n1 = 123456789;
long n2 = 245678918;

long savednum =0;

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

 }

Serial.print("Initializing SD card...");

 if (!SD.begin(SD_ChipSelectPin)) {
Serial.println("initialization failed!");
 while (1);
}
Serial.println("initialization done.");

 myFile = SD.open("NEWDATA.txt", FILE_WRITE);

if (myFile) {
Serial.print("Writing to NEWDATA.txt...");
myFile.println(n1);
myFile.println(n2);

myFile.close();
Serial.println("done.");
} else {

Serial.println("error opening NEWDATA.txt");
}

myFile = SD.open("NEWDATA.txt");
if (myFile) {
Serial.println("NEWDATA.txt:");

while (myFile.available()) {
  Serial.write(myFile.read());
// here the code I tried to read .txt file and store it in long
savednum = myFile.read();
Serial.println(savednum);
}

myFile.close();

}

}

void loop()
 {

  }


texts: Playing Melody with Tone() without using delay()

texts:
Is there a method to play a Melody with Tone() without using the delay() function?

tone(8, melody[thisNote], noteDuration);
int pauseBetweenNotes = noteDuration;
**delay(pauseBetweenNotes);**


texts: How to make the motor move after a certain period of time?

texts:
Basically I want my motor to run after let's say 10 seconds passed since the program started up.

The amount of time is determined by user input, and I have already coded for that. The motor is connected to a breadboard and powered by a 9v battery, also connected to the breadboard.

The thing is, the motor runs as soon as I connect it to the breadboard. How can I use the Arduino board to make the motor wait 10 seconds before it moves? I am new to both circuitry and code... Sorry for my cluelessness.

Thanks so much.


texts: I need to purchase the correct bluetooth module for interfacing some simple functionality between an arduino and a motor. The tricky bit is getting the bluetooth radio to play nice with android and apple ios. There are things like MIT App Inventor, but I'd love to hear from someone with experience how to reliably control arduino from tablets/phones. Preferrably in a way that lets me define the control on the arduino. I can build android apps (slowly), not ios apps, but I would then have to either ask users to install untrusted apks or get it out through the google app store, which would take too long. Any help on this would be great.


texts: How to diagnose unresponsive Leonardo serial port?

texts:
I was using an Arduino Leonardo (in the form of an RPI hat) to control a single DC motor via a motor controller. I have it wired to set Phase and Enable to control motor speed and direction, and I read sensors on the motor's encoder to directly measure motor speed.

I triple checked all my wiring, and a test program I wrote to spin the motor at half-speed seemed to work just fine. Then it suddenly stopped working. Now, when I plug the Leonardo into my machine, the ttyACM0 device does not appear, and I seem to have no way to communicate with it anymore.

I've noticed that when I press the reset button, the Leonardo's status light flashes for a few seconds and ttyACM0 does momentarily appear. But as soon as the flashing stops, ttyACM0 disappears again. I tried upload a new sketch when the device reappears, but I get a "broken pipe" error.

What's going on here? Did I somehow fry my Leonardo, or is it possible I just screwed up the serial port? How do I fix it?

Edit: For the host, I've tried Ubuntu 14 running on a Raspberry Pi 2 and a generic 64bit laptop.

Edit: My setup() is simply:

void count_pan_changes(){
    /*
    CW  => 11,00,11,00,...
    CCW => 10,01,10,01,...
    */
    int a = digitalRead(MOTOR_ENCODER_A_PIN);
    int b = digitalRead(MOTOR_ENCODER_B_PIN);
    int direction = (a == b) ? +1 : -1;
    motor_controller.record_direction(direction);
}

void setup(){
    attachInterrupt(digitalPinToInterrupt(MOTOR_ENCODER_A_PIN), count_pan_changes, CHANGE);
}

Edit: I'm not sure why, but when I disconnected the Leonardo from it's 5V UBEC power supply and powered it directly from my laptop via USB, then ttyACM0 suddenly came back. However, when I reconnect it to its own power supply, I again have problems connecting to it. The first upload and serial terminal seem to work, but as soon as I disconnect, further uploads/serial connections seem to fail with a "broken pipe" error. I'm powering it via a UBEC by connecting the 5V and Gnd lines to one of the Leonardo's GVS headers (i.e. it's not going in through any onboard regulator on the Arduino or RPi). Should this work? The motor is behind a separate UBEC.

Edit: Now power cycling isn't even fixing it. I tried erasing the contents using:

avrdude -patmega32u4 -cavr109 -P/dev/ttyACM0 -b57600 -e

as explained here. This keeps /dev/ttyACM0 from disappearing, but if I try and upload a sketch using ano upload, I still get the error:

IOError: [Errno 32] Broken pipe


texts: ATTiny85 and DHT11 - Sensor always returning 0

texts:
Good day.

I am making a small weather station using ATTiny85, DHT11, and an OLED display.

There are many, many tutorials that explain how this works, and various libraries that show you how to get the DHT11 to work with the ATTiny85 and others that are dedicated to the SSD1306 Oled displays, some even show you how to combine them together. Well, for the better part of 2 days nothing worked for me.

My schematics is as follows:

And here is a picture of the actual thing, working with a CR2032 Coin Cell:

The Libraries I am using are:

OLED Libraries for ATTiny85 - Source: http://www.14core.com/wiring-digispark-attiny85-with-096-oled-screen-display/
Rob Tillaart DHT Library - Source: https://github.com/RobTillaart/Arduino/tree/master/libraries

My Code is as follows:

    //OLED Libraries for ATTiny85 - Source: http://www.14core.com/wiring-digispark-attiny85-with-096-oled-screen-display/

#include <font6x8.h>
#include <font8x16.h>
#include <num2str.h>
#include <ssd1306xled.h>
#include <ssd1306xled8x16.h>
#include <SSD1306_minimal.h>
#include <TinyWireM.h>
#include <USI_TWI_Master.h>

#define DEG "\xa7" "C"

SSD1306_Mini oled;

char strHum[4];
char strTemp[4];

#include <dht.h>
dht DHT;
#define DHT11_PIN 1

void setup()
{

  TinyWireM.begin(); // initialize I2C lib - comment this out to use with standard arduinos
  oled.init(0x3c);
  oled.clear();

}

void loop()
{

  //            DHT Code goes here                              //

  DHT.read11(DHT11_PIN); //Calling the read function

  float hu  = (DHT.humidity, 1);
  float te  = (DHT.temperature, 1);

  //            OLED Start -- DO NOT CHANGE ANYTHING            //

  //oled.clear();

  oled.startScreen();
  oled.cursorTo(10, 0);
  oled.printString("ATTiny85 & DHT11");

  oled.startScreen();
  oled.cursorTo(12, 9);
  oled.printString("Temp & Humidity");

  oled.startScreen();
  oled.cursorTo(10, 18);
  oled.printString("www.MDChaara.com");

  oled.startScreen();
  oled.cursorTo(0, 27);
  oled.printString("mdchaara@gmail.com");

  oled.startScreen();
  oled.cursorTo(0, 45);
  oled.printString("Humidity(%): ");

  oled.startScreen();
  oled.cursorTo(110, 45);
  oled.printString( itoa(int(hu), strHum, 10));

  oled.startScreen();
  oled.cursorTo(0, 55);
  oled.printString("Temperature(c): ");

  oled.startScreen();
  oled.cursorTo(110, 55);
  oled.printString( itoa(int(te), strTemp, 10));

  //            OLED End          //

  delay(5000);
}

Now I know that the OLED code works, and it was a very interesting round or research to get it to work. The DHT code is another story. I have tried 6 different libraries and none of them worked. They all either return 0, 1, or blank readings on the screen.

I have checked if the sensor is working with an Uno and a Nano, works well! I checked the connections, and the soldered parts and did continuity tests, but the issue still remains.

I am asking because I am hoping a fresh set of eyes can pin-point the issue that I am facing. Any help will be highly appreciated.

Arduino IDE: 1.8.2
OS: Windows 7 64 bits
Micro controller: ATTiny85-20PU

Sketch is uploaded to the micro controller using Arduino Uno as a programmer.
Sketch is uploaded at Internal 8MHz clock setting.

Thank You.


texts: How to identify Arduino Mini Pro 5v vs 3.3v

texts:
I have many Arduino Mini Pro, every from different seller.
Few are 3.3v and most 5v.

I had to clean table for Xmas and now I do not have any idea how to identify 3.3v Arduinos.

They do not have any marks. I bought them on ebay.

I know 3.3v has 8mhz clock but only one my arduino has big crystal with 16.000-30.


texts: How to upload program to board using Arduino sketch ver 1.6?

texts: I am having problems uploading my program. I have been using the verify button aka the "checkmark" to upload my programs. I assumed that this was the correct button but now I am having problems uploading. When I attempt to use the "upload" button I get the error "can not open device". What am I doing wrong? How can I fix this error code?


texts:
I am able to use AT command from the Serial monitor however when I run the following code nothing is sent or received from the ESP8266. Can someone advise what could be the problem.

#include <SoftwareSerial.h>;

SoftwareSerial esp8266(0,1); // make RX Arduino line is pin 2, make TX Arduino line is pin 3.
                            // This means that you need to connect the TX line from the esp to the Arduino's pin 2
                             // and the RX line from the esp to the Arduino's pin 3
void setup()
{
  Serial.begin(9600);
  esp8266.begin(9600); // your esp's baud rate might be different
}

void loop()
{
 if(esp8266.available()) // check if the esp is sending a message
  {
    while(esp8266.available())
    {
      // The esp has data so display its output to the serial window
      char c = esp8266.read(); // read the next character.
      Serial.write(c);
    }
  }

  if(Serial.available())
  {
    // the following delay is required because otherwise the arduino will read the first letter of the command but not the rest
    // In other words without the delay if you use AT+RST, for example, the Arduino will read the letter A send it, then read the rest and send it
    // but we want to send everything at the same time.
    delay(1000);

    String command="";

    while(Serial.available()) // read the command character by character
    {
        // read one character
     command+=(char)Serial.read();
    }
    esp8266.println(command); // send the read character to the esp8266
  }
}


texts: A class within a class - via an Initialiser Lists: NOT able to update a variable

texts:
My test are based on the blog of http://arduinoetcetera.blogspot.be/2011/01/classes-within-classes-initialiser.html.

Because I would like to use this idea, I tried with a simple idea, after the instance is created just update a value.

But for some reason, the code compiles perfectly and there seems to be no error with the update method, but it DOES NOT UPDATE the variable.

But my output on the serial monitor show that the number (volatile int) doesn't update.

Object of class First has value - Number: 6
Object of class Second has value - Number: 13
Object of class Second has value - Double: 26
Object of class Second has value - Update: [0] - 20  // <--
- -
Object of class First has value - Number: 6
Object of class Second has value - Number: 13        // <--
Object of class Second has value - Double: 26
Object of class Second has value - Update: [1] - 70
- -
Object of class First has value - Number: 6
Object of class Second has value - Number: 13

code - MAIN :  First thing(6, 13);
[edited on request of @Mark Smith]

#include "First.h"
First thing(6, 13);
...
int newValue;
...
int ledPins[] = {
  20, 70, 45, 68, 543, 321
}; // an array of pin numbers to which LEDs are attached
int pinCount = 6; // the number of pins (i.e. the length of the array)
bool plus=true;
int index=-1;
void loop() {
  Serial.print("Object of class First has value - Number: ");
  Serial.println(thing.Number());
  Serial.println();
  Serial.print("Object of class Second has value - Number: ");
  Serial.println(thing.getSecond().Number());
  Serial.print("Object of class Second has value - Double: ");
  Serial.println(thing.getSecond().Double());
  ...
  Serial.print("Object of class Second has value - Update: [");
  if ( plus && index == (pinCount-1) ) {
    plus=!plus;
  }
  if ( !plus && index == 0 ) {
    plus=!plus;
  }
  // change + <--> -
  (plus) ? index++ : index--;
  newValue=ledPins[index];
  Serial.print(index,DEC);
  Serial.print("] - ");
  Serial.println(newValue, DEC);
  thing.getSecond().Update(newValue);
  Serial.println("- - ");

code - FIRST

#include "First.h"
...
First::First(int firstNumber, int secondNumber) : widget(secondNumber) {
  itsNumber = firstNumber;
}
int First::Number() {
  return itsNumber;
}
Second First::getSecond() {
  return widget;
}

code - SECOND : void Second::Update(int newNumber)

#include "Second.h"
...
volatile int itsNumber;
Second::Second(int newNumber) {
  itsNumber = newNumber;
}
void Second::Update(int newNumber) {
  itsNumber = newNumber;
}
int Second::Number() {
  return itsNumber;
}
int Second::Double() {
  return itsNumber*2;
}

For the complete code
https://github.com/droopy4u/ARDUINO
 - https://github.com/droopy4u/ARDUINO/tree/master/ClassWithClasses -


texts: Serial printing from Flash Memory (F() macro, PROGMEM, sprintf_P, SPTR)

texts:
I have been testing on an Arduino UNO various techniques for serial printing from Flash Memory instead of RAM. At the same time, I have been using the freeMemory() function from Adafruit.

I created a program that prints the word "test", with various methods:

Simple print:

Serial.print("test");
Serial.print(freeMemory());

This call reports free RAM = 2267

Using the F() Macro:

Serial.print(F("test"));
Serial.print(freeMemory());

This call reports free RAM = 2299

Using sprintf_P()

char buf[100];
sprintf_P(buf,PSTR("test"));
Serial.print(buf);
Serial.print(freeMemory());

This call reports free RAM = 2267

Using strcpy_P()

 char buf[100];
 strcpy_P(buf, (PGM_P)F("test"));
 Serial.print(buf);
Serial.print(freeMemory());

This call reports free RAM = 2267

Using strcpy_P and const char[] PROGMEM

char buf[100];
const char buff[] PROGMEM = "test";
strcpy_P(buf, buff);
Serial.print(buf);
Serial.print(freeMemory());

This call reports free RAM = 2267

The basic point of this question is to gather all the possible Flash memory printing techniques. Also it would be really useful if you could explain in detail what exactly does each of the keywords F(), (PGM_P)F, PSTR, const PROGMEM.

IMPORTANT EDIT1:
Depending on where and how I use the call Serial.print(freeMemory()); the results change. For example, at the last example (PROGMEM, strcpy_P) when I included another Serial.print(freeMemory()); before the call of the printing functions, then both freeMemory() calls report 2299!

Another interesting problem is that the freeMemory() reports 2299 as freeRam, while the SRAM of my arduino UNO is only 2kbytes.

EDIT2:
Following the suggestion in comments, I changed "test" to "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest". Now all different methods report a free ram of 2299, including the simple Serial.print().

freeMemory():

#ifdef __arm__
// should use uinstd.h to define sbrk but Due causes a conflict
extern "C" char* sbrk(int incr);
#else  // __ARM__
extern char *__brkval;
#endif  // __arm__
int freeMemory() {
  char top;
#ifdef __arm__
  return &top - reinterpret_cast<char*>(sbrk(0));
#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151)
  return &top - __brkval;
#else  // __arm__
  return __brkval ? &top - __brkval : &top - __malloc_heap_start;
#endif  // __arm__
}