texts:
I am unable to get the MAX30100 sensor to work
It keeps throwing the following error:
16:06:32.936 -> Initializing...
16:06:32.936 -> MAX30105 was not found. Please check wiring/power.

I am using the Sparkfun library Example sketch "Example5_HeartRate"
As far as I understand the breakout board for the MAX30100 is a bit buggy -
By which I mean the internal pullup resistors are connected to 1.8V for some reason instead of 5V
I have used MAX30100 before and had faced the same issue. However, after scouring the internet for hours  I found this helpful article: https://reedpaper.wordpress.com/2018/08/22/pulse-oximeter-max30100-max30102-how-to-fix-wrong-board/
I want to use another MAX30100 sensor and have followed the above article again and have done the said changes to my sensor which resulted in the board being detected at address 0x57 when I run the i2c scanner. However, unlike the previous time, the Example sketch did not run as expected.
I even tried this solution:
https://github.com/oxullo/Arduino-MAX30100/issues/51#issuecomment-391193292
But kept receiving the same error message.
The pin connections are:
ARDUINO -> MAX30100/MAX300102
3V3     ->    VIN
SDA (A4)->    SDA\
SCL (A5)->    SCL
GND     ->    GND
I need help asap.
Thank you in advance!
I hope the links mentioned are helpful for someone else.


texts: Best way to measure liquid level of a 10 meter high tank?

texts:
I would like to measure the height at which the liquid inside a 10 meter high tank, what is the best way to achieve it?

What sensor should i use? I have seen ultrasound sensors but I have not found one that covers 10 meters. In context, I need to measure the volume of the liquid.

I don't know whether to measure the distance between the bottom and the height of the liquid, or measure the vacuum.

Example: If a 10 meter tank has 4 meters of liquid, you could calculate its volume by:

1) The maximum height at which the liquid reaches from the bottom to the top. Thus, it is estimated that from the bottom to the top there are 4 meters of liquid.

2) The distance at which the mouth of the tank touches the water. Thus, it is estimated that the tank is empty 6 meters and the rest is liquid. Could you instruct me a little? Thank you.

Edit: I add that the tank is fuel and that my budget does not exceed $ 20. Besides that I can not make modifications to the tank at my whim. Currently, to measure the height, a measuring tape attached to a lead is used so that it falls to the bottom of the tank, when the measuring tape is raised, the height at which the liquid wets the tape is seen. Hence the fuel level is obtained.


texts: How to bring WiFi back up if woken from deepSleep(WAKE_RF_DISABLED)

texts:
I'm trying to build a sensor that should update an MQTT broker only if something changes. So every few seconds it's supposed to wake up just enough to check a few inputs, compare them with the last time it woke up, and only if there has been a change should it connect to the broker and write the updates. I don't expect many updates per day, but if I sleep more than 10 seconds, I might miss them.
I'm using WiFi.forceSleepBegin() and WiFi.forceSleepWake(), mainly based on these articles. But there is this tempting option of ESP.deepSleep(n, WAKE_RF_DISABLED)
The API that I found only mentions this:

If you implement deep sleep with WAKE_RF_DISABLED and require WiFi functionality on wake up, you will need to implement an additional WAKE_RF_DEFAULT before WiFi functionality is available.

Do I read this correct if I understand that I would need to make another deepSleep just to wake up again with WiFi back active? Or is there an easier way to boot up the WiFi after such a sleep?
Thank you


texts:
I want to connect Arduino to my Home Wifi and make it serve as a server to access GPIO pins on Arduino from remote (like controlling LED connected to Arduino from remote).
I am using ESP8266 to connect to my wifi network.
I am facing some issues like:

sometimes it doesn't connect to my wifi router.
not connecting to my mobile Hotspot.
not able to serve default and AP mode.

I am following tutorial from http://allaboutee.com/2014/12/30/esp8266-and-arduino-webserver/
Here is my code:

#include <SoftwareSerial.h>
#define DEBUG true

SoftwareSerial esp8266(2,3); // 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(115200); // your esp's baud rate might be different

  sendData("AT+RST\r\n",2000,DEBUG); // reset module
//  sendData("AT",2000,DEBUG); // send AT command
//  sendData("AT+GMR\r\n",2000,DEBUG); // returns firmware
//  Serial.println("checking mode");
//  sendData("AT+CWMODE=?\r\n",5000,DEBUG); // check supported modes
//
//  Serial.println("scanning APs");
//  sendData("AT+CWLAP\r\n",21000,DEBUG); // scan list of access points

  Serial.println("set mode 1");
  sendData("AT+CWMODE=1\r\n",5000,DEBUG); // configure as both mode

//  Serial.println("joining AP");
  sendData("AT+CWJAP=\"<MY_WIFI_SSID>\",\"<WIFI_PASSWORD>\"\r\n", 16000, DEBUG); // connect to wifi

  Serial.println("Testing CIFSR");
  sendData("AT+CIFSR\r\n",7000,DEBUG); // get ip address

  Serial.println("setting for multiple connection");
  sendData("AT+CIPMUX=1",2000,DEBUG); // configure for multiple connections

  Serial.println("print MAC address");
  sendData("AT+CIPSTAMAC?\r\n",2000,DEBUG); // print current MAC address

  Serial.println("set port 80 for server");
  sendData("AT+CIPSERVER=1\r\n,80",2000,DEBUG); // turn on server on port 80
}

void loop()
{
  if(esp8266.available()) // check if the esp is sending a message
  {

    if(esp8266.find("+IPD,"))
    {
     delay(2000);

     int connectionId = esp8266.read()-48; // subtract 48 because the read() function returns
                                           // the ASCII decimal value and 0 (the first decimal number) starts at 48

     String webpage = "
Tyagi IoT
<button>LED1</button>";

     String cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";

     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);

     webpage="<button>LED2</button>";

     cipSend = "AT+CIPSEND=";
     cipSend += connectionId;
     cipSend += ",";
     cipSend +=webpage.length();
     cipSend +="\r\n";

     sendData(cipSend,1000,DEBUG);
     sendData(webpage,1000,DEBUG);

     String closeCommand = "AT+CIPCLOSE=";
     closeCommand+=connectionId; // append connection id
     closeCommand+="\r\n";

     sendData(closeCommand,3000,DEBUG);
    }
  }
}

void sendData(String command, const int timeout, boolean debug)
{
    esp8266.print(command); // send the read character to the esp8266
    long int time = millis();

    while( (time+timeout) > millis())
    {
      while(esp8266.available())
      {
        // The esp has data so display its output to the serial window
        Serial.write(esp8266.read());
      }
    }
}


texts:
I have a little personal project involving an Arduino Uno and an amp board from Sure Electronics. The amp has contacts for a mute function that involves shorting the contact to ground. I would like to control this muting with the Arduino which I was planning to do with a relay. However I think I might be complicating things and I thought it might be possible to do it directly with the pins.

Can I use the Arduino to directly short a circuit to ground? Or would I need something more complicated to be safe?


texts: How to implement server.on() without any libraries?

texts:
I was trying to setup a web server with Arduino and ESP32, without using the ESP32 libraries.
Currently I'm able to display a webpage(a form with single submit button) from the server, with only using AT commands.
But how can I receive GET/POST requests send buy the form fields?
In the WebServer.h library this is done by the method
    server.on("/actionPage", HTTP_GET, []() {
        server.sendHeader("Connection", "close");
        server.send(200, "text/html", "This is actionPage");
    })

I was wondering if there is a way to do this without libraries, I searched a lot, but didn't found a solution for this..
Thanks in advance!


texts: Arduino & ARM - Replacement for avr-libc?

texts: There is very cool avr-libc library that provides direct access for all functions of AVR microcontrollers. I'm writing a project for Arduino Due and I want to use timers and ISRs directly. Is there a library like avr-libc for ARM Cortex M3?


texts: Serial monitor in Arduino IDE for RobotDyn ESP8266-Pro via CP2102

texts:
I bought a couple of "ESP8266-Pro" micro-controllers from a Chinese company named RobotDyn.  There's no real documentation with them, but I've bought a lot of other stuff from them in the past that worked out really well, so I took a chance.

After some work, I am finally able to program the board with the Arduino IDE 1.8.1.

The problem is that I am unable to get the serial monitor working to see what's going on with the code.

What do I need to do to get this to work, or is it simply not possible?  In order to program the board, I need to connect EN to VIN, and both IO0 and IO15 to GND.  I assume I have to disconnect that to actually run the board after programming, but I don't know and haven't gotten anything to work yet.

Here's a photo of the board hooked up for programming.  What do I need to do to restart it with the serial monitor working?


texts:
I have a 28BYJ 48, 5V stepper motor. After some trial and error I got it working with the all the sample examples in Arduino IDE.

However when I increase the speed of the motor using setSpeed() beyond 15, the motor stopped rotating. Following is the configuration in which I am running the motor.

const int stepsPerRevolution = 2048;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
myStepper.setSpeed(15);

I wanted to understand what factors limit the speed. And how fast can I rotate this motor?

Thanks,

Manish


texts:
I'm trying Project 15 from the Arduino Uno Projects book (optocoupler).

I manage to turn on and off a LED in a separate circuit using my Arduino-driven optocoupler.

Now I tried to also turn on some real device (battery-driven toy from my kid that she doesn't used anymore). Replacing the toy's original switch with jumper wire leaves it running, so I'm confident that it basically works. But putting my optocoupler in between, it just won't fire up.

Measuring resistance on the 4N35's output bins as advised here, I obtain -15k Ohm (and 1 when measuring the other way round, i.e., as if there were no connection at all). Switching wires also exactly switches the measurement, i.e., I never obtain any positive resistance measurement.

What can go wrong here? What else can I try to find out what's wrong? Thank you!


texts: Error when using USART with Arduino Mega 2560

texts:
I use the Arduino IDE 1.6.9

What I want is a DMX Receiver which receives 1 channel and displays it on the serial monitor. When I try to compile the code, I get the following error:

C:\Users\Helyx\AppData\Local\Temp\build25a76891c667e0896ec10beb77bd0478.tmp/core\core.a(HardwareSerial0.cpp.o): In function `__vector_25':

D:\Programme\Arduino\hardware\arduino\avr\cores\arduino/HardwareSerial0.cpp:48: multiple definition of `__vector_25'

sketch\DmxReceive.ino.cpp.o:C:\Users\Helyx\Documents\Arduino\DmxReceive/DmxReceive.ino:26: first defined here

d:/programme/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.8.1/../../../../avr/bin/ld.exe: Disabling relaxation: it will not work with multiple definitions

collect2.exe: error: ld returned 1 exit status

exit status 1
Fehler beim Kompilieren.

Any ideas?
Here is my code:

#include <avr/interrupt.h>
#include <avr/io.h>
#include <stdio.h>

#define F_CPU 16000000

#define DMX_BAUD 250000
#define DMX_LOST_TIMEOUT 8000

volatile unsigned char dmx_buffer[10];
volatile unsigned int dmx_lost = DMX_LOST_TIMEOUT;

volatile unsigned int dmx_adresse = 1;

ISR (USART0_RX_vect)

{
static unsigned int dmx_channel_rx_count = 0;
static unsigned char dmx_valid = 0;
unsigned char tmp = 0;

tmp =  UDR0;

if(UCSR0A&(1<<FE0))
{
 if(dmx_channel_rx_count > 1)
 {
   dmx_lost = 0;
 }
 dmx_channel_rx_count = 0;
 dmx_buffer[0] = tmp;
 if(dmx_buffer[0] == 0)
 {
   dmx_valid = 1;
   dmx_channel_rx_count++;
 }
 else
 {
   dmx_valid = 0;
 }
 return;
}

if(dmx_valid)
{
 dmx_buffer[dmx_channel_rx_count] = tmp;
 if(dmx_channel_rx_count < 514)
 {
   dmx_channel_rx_count++;
 }
 return;
}
}

ISR (TIMER2_COMPA_vect)

{
 if(dmx_lost<DMX_LOST_TIMEOUT)
 {
   dmx_lost++;
 }
}

void setup()
{

EICRA |= (1<<ISC11)|(1<<ISC10); //The rising edge of INT1 generates an interrupt request
EIMSK |= (1<<INT1); //External interrupt request 1 enable

//Init usart DMX-BUS
UBRR0   = (F_CPU / (DMX_BAUD * 16L) - 1);
UCSR0B|=(1 << RXEN0 | 1<< RXCIE0);
UCSR0C|=(1<<USBS0); //USBS0 2 Stop bits
sei();//Globale Interrupts Enable

TCCR2A |= (1<<WGM21);
TCCR2B |= (1<<CS22|1<<CS21|1<<CS20);
TIMSK2 |= (1<<OCIE2A);
OCR2A = F_CPU/1024/1000 - 1; //Tick 1ms
Serial.begin(57600);

DDRC = (1<<PE3);
PORTB |= 0x3F;
PORTC |= 0xFF;
PORTC &=~(1<<PE3);

}

void loop()
{

if(dmx_lost==DMX_LOST_TIMEOUT)
{
  dmx_buffer[dmx_adresse] = 0;

}
Serial.print(dmx_buffer[dmx_adresse]);
}


texts: ATtiny85 serial communication, bootloader and setting up fuses

texts:
I have been reading some articles about ATtiny and how to burn the bootloader. And I have two questions which I can't figure out.

Do I need to manually setup fuses to run 8 MHz on my ATtiny when I'm using my Arduino board as my ISP (there we can select the internal clock and that confuses me)?
For the SoftwareSerial.h library, do I need to setup my ATtiny to 8 Mhz in order to work?


texts:
When using C/C++ on other platforms, the int type is typically 4 bytes (or potentially more). However, on Arduino, it's only 2 bytes.

Why is it different? Does it affect performance if I always use the 4 byte long instead?


texts: Can analog pins be defined as either their analog name (A0) or their digital pin number?

texts:
Can analog pins be defined by their digital pin number, and be used for analog purposes?
For example, instead of defining A0 for a pinout with the Uno, it could be 14?
Where is this documented? Is there a PDF type manual related to this, but not so low level to get into the ATmega chip?

https://www.arduino.cc/en/Hacking/PinMapping2560


texts: Sending binary data to Matlab via serial

texts:
I would like to exchange data via Xbee. I've set up a communication based on strings between the Arduino and a Matlab software.
Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the binary communication.

The problem:

I'm not able to send binary data from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is 0x11 in hex if we receive 16 from Matlab.

[...]
SoftwareSerial xbee(pinRx, pinTx);
void setup()
{
  Serial.begin(BaudRateSerial);
  xbee.begin( BaudRateXbee );
}
[...]
void loop()
{
 while(xbee.available())
  {
    getData = xbee.read();
    Serial.println();
    Serial.print("Received: ");
    Serial.print(getData,HEX);
    Serial.println();
    if(getData == 16)
    {
      // First attempt
      //uint8_t s = 17;
      //xbee.write(s);  -> Fail
      // Second attempt
      //xbee.write(0x11);  -> Fail
      // Third attempt
      byte message[] = {0x11, 0x11};
      xbee.write(message, sizeof(message));
    }
  }
}

In the third attempt I tried sending an array of bytes and noticed that the received values were different.

byte message[] = {0x11, 0x11};

xbee.write(message, sizeof(message));

The Matlab software sends data correctly. I used the fwrite function as follows fwrite(xbee,hex2dec('10')); and the fread function to receive the ack which:

  reads binary data from the device connected to the serial port object,
  obj, and returns the data

Matlab relevant code:

fwrite(xbee,hex2dec('10'));
disp('Ack Requested...')
ack = fread(xbee);
disp(ack);
if (ack == 17)
     % communication established
end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?


texts:
I recently bought a Wemos D1 board and tried to connect a relay and test its connection.

I got an example server from here and executed. I connected D5 to a Relay's data and 5v and GND from Wemos board.

But this does not change the state of relay, it always remains high. I connected a LED for D5, it works perfectly with client's response.

Then I powered relay using an external 5v and ground connection, but the same result.

I have checked for possible solution, but coulnt find an answer.

The relay I am using is this one


texts:
I have Arduino Nano with powered over USB. I have the request for external (physical) slide switch acting as power on/off for Arduino even if USB is always connected.

Looking at documentation and various posts, it seems the RST button could do just that. So when the "power" switch is on, RST is disconnected (= pulled high) and everything runs like normal. When the "power" switch is switched, it will pull RST low. As long as RST is pulled low, the board is stopped (the PWR led is lit, which is true and okay). Once released, the board will boot again.

Even though I agree this is not terribly elegant, is it going to work? I tried manually with the reset switch. Any side-effects I am overlooking?


texts:
In a similar way to the question  "best way to determine if a 5 gallon water jug is getting empty", I'm looking for a way to measure water in a container. This is so it can be connected to an Arduino for logging and reporting.  But it's a very different container.

I have a home with the household water supplied from an underground concrete tank (around 3000 US gallons, 11000 litres).  Although there is a float switch cutout when it gets empty (to protect the pump), I'd like to know it's gettting low long before that (as it takes a while before a tanker delivers a fresh load).  Ideally something that measures exactly or in steps (at least in eights of a load), so software can predict when it'll run out based on average usage, and it can be monitored online when away.

The tank has a heavy concrete hatch, and a small hole that has an existing primitive dipstick, so access is limited.  It's in a harsh desert environment, but the pump room and power are only a few feet away.

Some ideas I had:

suspend an array of float switches with strings of different lengths from a bar inside the tank, and wire them all back to a controller.  Hard to install, ugly, low tech. Or something similar on a vertical pole.
contacts (like a US 2 pin plug) on a vertical pole that again are connected back to a controller (probably using a ribbon cable).  Corrosion/anodes might be a problem, although power could just be a short pulse at times.  Condensation, spiders webs and dead bugs may give false readings.
run a fully insulated cable vertically down it, and use as an antenna to send a pulse through, and use the difference between how it works as an antenna in air, and in water, (like an SWR meter) to calculate how far down the water is.
ultrasonic (or light?) distance finder mounted under the hatch.  Range needs to be up to 2 metres (6 feet).
depth finder (sonar) on a float.  Biggest challenge here is getting the signal out (long cable might get tangled when the tank fills).

The last two would be even better if they were wireless (to save running a cable that might get damaged) but I don't think I'd get the battery life I'd like (1 year or more).

Any other ideas?  Has anybody ever done this?


texts: Reconnect to I2C with a different address (ATTiny85)

texts:
My project requires to reconnect to an I2C bus as a slave. I can't reset my ATTiny physically because I2C + my project + a pin to trigger the reset isn't possible due to the limited amount of pins available on the ATTiny85. I searched the reference and different forums. If there was an answer to my question, I couldn't find one.

Thanks in advance.

(I want to try to make a plug-and-play kind of experience with a product. I want the chip to join with a defined address (100 or so), get a new address from the master and then reconnect to the I2C bus).


texts: Mega attachInterrupt on pins 18 or 19 require EIFR bit set first (to clear it)?

texts:
Experimenting with external interrupts on a Mega. Pins 2 and 3 work with standard

attachInterrupt(digitalPinToInterrupt(iPin),ISR,FALLING);

coding and call my ISR. With pins 18 and 19 I had to add

EIFR = 4;

for pin 19, and

EIFR = 8;

for pin 18 before calling attachInterrupt(...) to get them to work. Why?

BTW, I'll add this table that I filled in by trial and error for anyone interested in Atmel (AVR) external interrupt numbers to Arduino external interrupt numbers (I won't list the AVR chip pin numbers)

AVR INT      5 .  4 .  3 .  2 .  1 .  0
EIFR (Dec)  32 . 16 .  8 .  4 .  2 .  1
Arduino Pin  3 .  2 . 18 . 19 . 20 . 21
Arduino INT  1 .  0 .  5 .  4 .  3 .  2

I know writing a 1 to the EIFR bit for the appropriate interrupt clears the interrupt. When I reset the Arduino without clearing interrupts on pins 2 and 3 it's fine. If I don't clear 18 and 19 after a reset, it throws the interrupt right away. (Yes, I should OR the EIFR with the bit I want to change but I'm just playing) Didn't try 20 and 21 because I'm using them for comm.


texts: analogRead returning 0 constantly when connected to joystick

texts:
What reasons could there be for a joystick to return 0 when using analogRead?

X-pin is connected to AO and y-pin is connected to A1.

VCC is connected to 5V and GRND is connected to GRND.

By default (as in when not using the joystick) the value should be approximately 500, right? Well why is the value then 0? Can this only be a wiring issue?


texts:
I am trying to reduce current consumption on my project. Right now it is using ~1.28mAh, it should be possible to get it much lower (I am using AA batteries as the power source).

The ATtiny85 has its fuses set to run at 1MHZ, with BOD disabled.

I am using this board to mount the CPU. I desoldered the power LED and the regulator, feeding power directly from the batteries to the 5V input.

Nothing was connected to any other pins while measuring, just 5V and GND. The code was running in debug mode, so every 8 seconds it flashed a debug LED. I don't know for how much this could account.

Full code:

#include <avr/sleep.h>
#include <avr/power.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>

#define DEBUG (true)
#define INT_PIN (0)
#define OUT_PIN (2)
#define LED_PIN (1)

/***************************************************
 *  Name:        ISR(WDT_vect)
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Watchdog Interrupt Service. This
 *               is executed when watchdog timed out.
 *
 ***************************************************/
EMPTY_INTERRUPT(WDT_vect);
EMPTY_INTERRUPT(PCINT0_vect);

/***************************************************
 *  Name:        enterSleep
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Enters the arduino into sleep mode.
 *
 ***************************************************/
void enterSleep() {
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
  sleep_disable(); /* First thing to do is disable sleep. */

  #if DEBUG
    digitalWrite(LED_PIN, HIGH);
    for (uint16_t dbg = 0; dbg < 65535; dbg++);
    digitalWrite(LED_PIN, LOW);
  #endif
}

/***************************************************
 *  Name:        setup
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Setup for the serial comms and the
 *                Watch dog timeout.
 *
 ***************************************************/
void setup() {
  pinMode(INT_PIN,INPUT);
  pinMode(OUT_PIN,OUTPUT);
  pinMode(LED_PIN,OUTPUT);
  ADCSRA &= ~_BV(ADEN); // ADC off
  power_all_disable();
}

/***************************************************
 *  Name:        enterSleep
 *
 *  Returns:     Nothing.
 *
 *  Parameters:  None.
 *
 *  Description: Main application loop.
 *
 ***************************************************/
void loop() {
  digitalWrite(OUT_PIN, LOW);
  digitalWrite(LED_PIN, LOW);
  /*** Setup the WDT ***/
  wdt_reset();
  /* In order to change WDE or the prescaler, we need to
   * set WDCE (This will allow updates for 4 clock cycles).
   * WDTCR on ATTINY85 / WDTCSR on ATMEGA
   */
  WDTCR |= (1<<WDCE) | (1<<WDE);
  /* set new watchdog timeout prescaler value */
  WDTCR = 1<<WDP0 | 1<<WDP3; /* 8.0 seconds */
  /* Enable the WD interrupt (note no reset). */
  WDTCR |= _BV(WDIE);
  // sleep for 8 seconds x 43200 = 96 hours = 4 days
  for (uint16_t i = 0; i < 43200; i++)
    enterSleep();
  wdt_reset();
  wdt_disable();
  GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
  PCMSK |= _BV(PCINT0); // Use PB0 as interrupt pin
  enterSleep();

  #if DEBUG
    digitalWrite(LED_PIN, HIGH);
  #else
    digitalWrite(OUT_PIN, HIGH);
  #endif
  enterSleep();
  PCMSK &= ~_BV(PCINT0); // Turn off PB0 as interrupt pin
}


texts: Problem with transmitting 2 byte data in correct way

texts:
I'm using Atmel Studio with Atmega328P.

I'm trying to send the decimal number 876 continuously from the micro-controller. This was just to learn.

To send 876 I need two bytes which is:

0x036C = 00000011 01101100

So I manipulated a code and here is what I use now:

#include <avr/io.h>
#define F_CPU 16000000
#define USART_BAUDRATE 9600
#define UBRR_VALUE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

void USART0Init(void)
{
    // Set baud rate
    UBRR0H = (uint8_t)(UBRR_VALUE>>8);
    UBRR0L = (uint8_t)UBRR_VALUE;
    // Set frame format to 8 data bits, no parity, 1 stop bit
    UCSR0C |= (1<<UCSZ01)|(1<<UCSZ00);
    //enable transmission and reception
    UCSR0B |= (1<<TXEN0);
}

int main (void)
{
    //Initialize USART0
    USART0Init();

    while(1)
    {

        UDR0 = 0b00000011;
        UDR0 = 0b01101100;

    }

}

The problem is at the receiving side the data comes as:

01101100
00000011
00000011
.
.
.

Here is the screen shot of the binary data at the receiving end:

However it should be received correctly as two byte chunks 00000011 01101100.

And here you can see the problem of the data being received as uint16(not only 876 as desired):

How can I fix this and receive the data properly as two bytes with correct order as 876?


texts: Arduino and WS2812 RGB LED Strip "freezing"

texts:
I have been working on a project as a gift for my girlfriend for Christmas which involves some a bunch of standard "white" LEDs controlled by shift registers and darlington arrays, and also some RGB LED strips (WS2812B strip, 29 LEDs on strip). Everything is going fine with the white LEDs, but not so much with the RGB ones.

If I leave the RGB leds running for a while all of the LEDs on the strip turn red, except for the first one, which continues to change color. I am not sure how long "a while" is because in "short term" testing, approximately running continuously for an hour, it works fine and all of the LEDs change appropriately, but if I leave it running overnight I wake up with the issue of all red and one single RGB "working". I then have to reset to get it working again. These RGB LEDSs need to be run for long periods (24 hours) of time without "freezing". The rest of the program (with the normal LEDs) continues to work fine despite the RGB ones not.

Let me explain how I am controlling them. V_rgb is 5V (5V - 8A power supply), which it is also grounded to. Then the data line, C, is connected to an Arduino Uno, on pin 12, which is a PWM pin.

In software, I am using a Adafruit Neopixel Library to control the RGB LEDs and write their respective colors, based off the examples given in their git repo and the tutorial here.

I have pasted my code below in case that may help, but honestly I am not sure if it is software or hardware related. (unrelated code has been removed)

#include <Adafruit_NeoPixel.h>
#define rgbPin 11
#define numRGBleds 29

Adafruit_NeoPixel strip = Adafruit_NeoPixel(numRGBleds, rgbPin, NEO_GRB + NEO_KHZ800);
int colorStep = 0;
int rgbIndex = 0;

void shiftColor() {
  int i = 0;
  for (i = 0; i < numRGBleds; i++) {
    int idx = (rgbIndex + i) % numRGBleds;
    int colorVal = round(i * colorStep);
    strip.setPixelColor(idx, Wheel(colorVal & 255));
  }
  strip.show();
  rgbIndex++;
}

uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if (WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } if (WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

void setup()
{
  strip.begin();
  strip.show();
  rgbIndex = 0;
  colorStep = 255 / (numRGBleds - 1);
}

void loop()
{
  shiftColor();
  delay(1000); // Redo every second
}

My thoughts of what it could be are the following, let me know if any make any sense or are known issues:

Having issues with micros() value rollover
Overheating
Noisy power supply
Defective LED strip
black magic?

Thanks in advance for any help.

UPDATE

My current solution to the problem is to just reset the board using the watchdog functionality. It reboots in a few milliseconds and sometimes flashes in the process, but I would like to figure out the real problem.

UPDATE #2

So with the reset solution, I left it running overnight and it did not freeze which leads me to think it is definitely a software, not hardware, issue. I have changed some of the wiring and coding to make sure the watchdog reset is not noticeable. It resets every half hour or so. This will make sure all of the memory is cleaned, except stuff I store in the EEPROM (which I do use to make the reset less noticeable). This reset delays processing by a few milliseconds, but time is not critical, so it is not a big deal.

I still however, would like to know a more elegant way of doing this. The software reset is a bit "hacky"


texts: Stuck making multi, many button, joysticks

texts:
I'm stuck, I figured I'd ask here for some help... Note I'm a newb and this is essentially my first Arduino project beyond blink...

I'm creating Virtual cockpit panels for DCS World, using an Arduino Leonardo as an HID device. I'm using three SN74HC165 Shift-In registers for multi-buttons (24) - as it seemed the easiest - and all in all it does work...

So I figured that I'm using only 4 pins on the Leonardo, so why not try to setup 3 of these "shift-in clusters" (12 pins) to appear as 3 separate joysticks?

I got the one working and I got 2 more joysticks showing up in Windows10... now my problem is: how would I setup 2 more "shiftIn Clusters", I've tried many things but I must defer to outside help (cause I really don't know what I'm doing)

Edit to clarify: So each joystick need 3 or 4 shift registers making 24-32 buttons on each joystick

Shift In Lib: https://github.com/…/Ardu…/blob/master/ShiftIn/src/ShiftIn.h

Joy2 Lib: https://github.com/MHeironimus/ArduinoJoystickLibrary

Here's an image of the Layout I want: https://i.imgur.com/eZfMMzI.png

... any help would relieve a great headache, Thank for your time

#include <ShiftIn.h>
#include <Joystick.h>

// use <n> shift registers
ShiftIn<3> shift;             // use three shift register

// Create joystick
// TESTING MULTI JOYSTICKS
// 1/3 Works!!!
// 3/3 Appear in Windows
// ????? must add shiftIn sections for 2nd and 3rd joysticks????
// (add pin usage + modify line 77-79 stuff)

#define JOYSTICK_COUNT 3
Joystick_ Joystick[JOYSTICK_COUNT] = {
  Joystick_(0x03, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, false, false, false, false, false, false, false, false, false),
  Joystick_(0x04, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, false, false, false, false, false, false, false, false, false),
  Joystick_(0x05, JOYSTICK_TYPE_GAMEPAD, 32, 0, false, false, false, false, false, false, false, false, false, false, false),
};

// Set to true to test "Auto Send" mode or false to test "Manual Send" mode.
//const bool testAutoSendMode = true;
const bool testAutoSendMode = false;

const unsigned long gcCycleDelta = 1000;
const unsigned long gcAnalogDelta = 25;
const unsigned long gcButtonDelta = 500;
unsigned long gNextTime = 0;
unsigned int gCurrentStep = 0;
int gJoystickId = 0;

/*
// WORKING SECTION Single Joystick with Shift Reg
Joystick_ Joystick(JOYSTICK_DEFAULT_REPORT_ID, JOYSTICK_TYPE_GAMEPAD,
  32, 0,                        // Button Count, Hat Switch Count
  false, false, false,          // X and Y, but no Z Axis
  false, false, false,          // No Rx, Ry, or Rz
  false, false,                 // No rudder or throttle
  false, false, false);         // No accelerator, brake, or steering
*/

void setup() {

  shift.begin(8, 9, 11, 12);  // set pins of the shift register
//  shift[1].begin(7, 6, 5, 4);  // set pins of the shift register
//  shift[2].begin(3, 2, 1, 0);  // set pins of the shift register

 Joystick[0].begin();
 Joystick[1].begin();
 Joystick[2].begin();
}

void loop() {

  if (shift.update()) {
    for (int i = 0; i < shift.getDataWidth(); i++)
    Joystick[0].setButton(i, shift.state(i));            // just press or release the button
  }
/*if (shift[1].update()) {
    for (int i = 0; i < shift[1].getDataWidth(); i++)
    Joystick[0].setButton(i, shift[1].state(i));            // just press or release the button
  }
if (shift[2].update()) {
    for (int i = 0; i < shift[2].getDataWidth(); i++)
    Joystick[0].setButton(i, shift[2].state(i));            // just press or release the button
  }
  delay(10);
*/
}


texts:
I have an Arduino and I am building a space satellite, just for fun. I'm not going to launch it obviously.

I have built all the sensors and everything works. I was looking into communication because if a satellite is in space it needs to send down the data.

Is it possible to have radio communication between two Arduino or an Arduino and something else that are 100km apart, it doesn't need to particle, I'm just wondering if it is possible and how it works. Is it possible without going out to buy shields?


texts: Good day. Anyone that could help me. I need to generate a frequency greater than 40 khz using arduino uno. What coding do I use? Or do I need to put another citcuitry? Please help me. This is my first time on arduino. Thanks!


texts:
I'm making a simple Infrared detector using a thermopile. I have a few extra capacitors than what that schematic says. I'm currently following another, but this is the gist.

Schematic and Breadboard-

I can add breadboard picture if needed. I don't have 10 points in this Stack so I can't post more than 2.

I'm using a 9V battery through a 24v - 5v regulator (had one around) to power my op amp and schematic. The signal from the OPAMP will be between 0-5V so voltage hasn't damaged the Arduino Uno. The final project will be something like: output > A then power green, A < output < B power yellow, B < output red.

The issue is that I'm getting an oscillating value from my Serial Monitor that goes from 0 to 1023 (or I have a conversion to change it back to output voltage. So 0V to 5V. See code).

It does this oscillation when I have the board connected to any of the AX pins (X=0-5) or nothing plugged in at all (I understand it will output weird numbers with the pin floating).

I had a picture of the serial monitor but I don't have 10 points to add more than 2 pictures. Please see image below

I know that the output from the OPAMP works because when I use a VoltMeter to read the output, it works fine. 0.3XXV when no flame, 5V when flame is directly on top of my theromopile.

Would anyone happen to have a suggestion to why the Arduino is acting this way? The volt meter reading is directly out of the Op amp pin 1. no more than 2 links. AD822 op amp

Here's my code before adding if statements for the LED's. It was incorrect.

int TP=A2; // Assign Thermopile to pin A2
int val; // Declare readValue Variable
float Voltage; // Declare real world voltage variable - Float = in between variable
int ledG = 11;
int ledY = 12;
int ledR = 13;

void setup() {
 pinMode(TP,INPUT); // Declare Thermopile pin as input
 pinMode(ledG, OUTPUT);
 pinMode(ledR, OUTPUT);
 pinMode(ledY, OUTPUT);
 Serial.begin(9600); // Start your Serial Port
}

void loop() {
  val = analogRead(TP); // Read Thermopile pin and place value into readValue

  Voltage = (5./1023.)*val; // To do "floating point math" have a "." //after the number. If not, it will return real number (5/1023 = 0) according to Arduino

Serial.println(Voltage); // Print readValue to Serial Monitor
  delay(100); // Delayed output to 1/4 a second
}


texts: I am aware that you can programmatically reset the board either with an expiring watchdog or using the CMSIS method NVIC_SystemReset(). Are there any other ways to do so? Also are there any caveats with any of the above?


texts:
HI I am a newbie and need some suggestions
Is there a possibility to do this?? I am trying to send MIDI data through a button using Arduino and bluetooth module HM10. Can someone help me write the loop part or am going the right way.

#include <MIDI.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial (2, 3);
char c = ' ';
int pushButton7 = 7;
int buttonState7 = 0;
int note7 = 0;
void setup() {
  MIDI.begin(4);
  // 115200 hairless MIDI
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(pushButton7, INPUT);
}

  void loop() {

   int buttonState7 = digitalRead(pushButton7);

 // Button 7

  // when button pressed:
  if (buttonState7 == HIGH) {
    // if note not playing
    if (note7 == 0) {
      // play note (note number, velocity, channel)
      // more info: http://arduinomidilib.sourceforge.net/a00001.html
      // MIDI notes chart http://www.phys.unsw.edu.au/jw/notes.html
      // 55 = G3, 127 = trigger note with max volume
      MIDI.sendNoteOn(55,127,1);
      // note is playing
      note7 = 1;
    }
  // when button released
  } else {
    // if note playing
    if (note7 == 1) {
      // if playing - stop
      MIDI.sendNoteOff(55,0,1);
    }
    // if button released note is off
    note7 = 0;
  }

  delay(1);

  }


texts: Issues with Arduino UNO printing repeated "double" on serial monitor

texts:
A weird is happening which i can't figure out why. First I had issue communicating with SIM800L.
So i tried checking the USART Hardware to see what UNO sends to SIM800 using small piece attached below.
The sketch is to compares what i send from serial monitor with strings "Hello", "heLLo" and "Hello" expecting to get Found .... or No match found.
each line string i send, the serial monitor prints twice WHY?,
The first says not found and the second say Received == ........ WHY?
**See the output of serial terminal
when i typed "Hello" with quotes.
12:03:46.536 -> Buffer Received= "  No match found
12:03:46.569 ->
12:03:46.569 -> Buffer Received= Hello"
12:03:46.603 ->     Found Hello
when i typed "HELLO" with quotes.
12:03:55.855 -> Buffer Received= "  No match found
12:03:55.888 ->
12:03:55.888 -> Buffer Received= HELLO"
12:03:55.921 ->     Found HELLO**

****when i typed "heLLo" with quotes.
12:04:04.016 -> Buffer Received= "  No match found
12:04:04.049 ->
12:04:04.049 -> Buffer Received= heLLo"
12:04:04.082 ->     Found heLLo
12:04:04.115 ->****

When i typed without quotes, all i get No match found
char buffer[100];
uint8_t index=0;

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

void loop()
{
  if(Serial.available()>0)
  {
    index=0;
    while(Serial.available())
    {
      buffer[index++]=Serial.read();
    }

    buffer[index]='\0';
    Serial.println(' ');
    Serial.print("Buffer Received");
    Serial.print(buffer);
    Serial.print('\t');
    if(strstr(buffer, "Hello")!=NULL) Serial.println("Found Hello");
    else if(strstr(buffer, "HELLO")!=NULL) Serial.println("Found HELLO");
    else if(strstr(buffer, "heLLo")!=NULL) Serial.println("Found heLLo");
    else Serial.println("No match found");
    Serial.flush();
  }
}

Note: Suspecting my PC hardware and serial driver,
so I tried it in my Ubuntu 20.04 and window 10 installed with Arduino IDE 1.8.13
suspecting it may be crystal, i tried two different boards and used even Atmega328P core.
I also suspected my keyboard "ENTER" key, so i tried the serial monitor "send" button.
with no difference.
I seems to run short is ideas so i am posting to the community. Let me have your advice and experience too.
Thanks.


texts: Can you query the current serial port's speed?

texts: Is there some code I can use to find out what the a chosen serial port's speed is running at ?


texts: Controlling a servo motor with a touch sensor

texts:
I want to modify my code to move a servo motor only for the duration of time that the sensor is touched and stop moving immediately when the sensor is no longer touched. The code I have moves the sensor from 0 to 90 and back.  That motion is completed even when you remove your finger. I want it to be such that if you remove your finger before the servo reaches 90 degrees the servo stops.  And the servo starts up again toward 90 when touch resumes. This is the code I currently have:

//when signal output is high the sensor is being pressed

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
int pos = 0;    // variable to store the servo position
int sensor=11; //initialises component to arduino digital pins
led=13;

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

void loop() {

        int value=digitalRead(sensor);
        if(value == HIGH){
                digitalWrite(led, HIGH);
                for (pos = 0; pos <= 90; pos += 1) {
                        myservo.write(pos);              // tell servo to go to position in
                        variable 'pos'
                                delay(15);                       // waits 15ms for the servo to reach the
                        position
                }
                for (pos = 90; pos >= 0; pos -= 1) { // goes from 90 degrees to 0 degrees
                        myservo.write(pos);              // tell servo to go to position in
                        variable 'pos'
                                delay(15);
                }
                Serial.println("TOUCHED ");
        }else{
                digitalWrite(led, LOW);

                Serial.println("NOT TOUCHED ");
                delay(500);
        }
}


texts: Start / Stop Motor Run with Button State Change

texts:
I'm trying to understand Arduino with push buttons. But I can't get the test project I'm working on to work as how I want it to do.

Basically what I'm trying to do with the codes below is to make the push button either start or stop the servo motor. But so far, I couldn't get it to work. I'm also wondering why the servo motor won't run on loop? I tried several approach, but I couldn't get it working.

What am I missing here? Thanks.

By the way, I'm a beginner.

#include <Servo.h> //Servo Library.

int servoPin = 3; //Servo to Pin 2.
int led = 4; // LED to Pin 4.
int buttonState = 0;
int lastButtonState = 0;

Servo ServoOne; //Servo object created.

void setup() {
  Serial.begin(9600);
  ServoOne.attach(servoPin);
  pinMode(led, OUTPUT);
  pinMode(2, INPUT);
}

void loop() {
  buttonState = digitalRead(2);
  if (buttonState != lastButtonState) {
    servoRun();
  }
  lastButtonState = buttonState;
}

void servoRun() {
  if (buttonState != lastButtonState) {
    if (buttonState == HIGH) {
      Serial.println("Running.");
      ServoOne.write(0); //Servo resets to 0 degrees.
      digitalWrite(led, LOW); //LED turns on.
      delay (1000);
      ServoOne.write(90); //Servo turns to 90 degrees.
      digitalWrite(led, HIGH); //LED turns on.
      delay (1000);
      ServoOne.write(180); //Servo turns to 180 degrees.
      digitalWrite(led, LOW); //LED turns on.
      delay (1000);
      ServoOne.write(90); //Servo turns to 90 degrees.
      digitalWrite(led, HIGH); //LED turns on.
      delay (1000);
      ServoOne.write(0); //Servo resets to 0 degrees.
      digitalWrite(led, LOW); //LED turns on.
    } else {
      Serial.println("Off.");
      ServoOne.write(0);
      digitalWrite(led, LOW);
    }
  }
}

Edit:
I tried this new approach, but I can't get the button state change saved.

#include <Servo.h> //Servo Library.

//Constant.
const int pswitch = 2; //Switch to Pin 2.

//Variables.
int servoPin = 3; //Servo to Pin 3.
int led = 4; //LED to Pin 4.
int newState; //Current switch state.
int oldState = LOW; //Previous switch state.

Servo ServoOne; //Servo object created.

void setup() {
  Serial.begin(9600);
  ServoOne.attach(servoPin);
  pinMode(led, OUTPUT);
  pinMode(pswitch, INPUT_PULLUP);
}

void loop() {
  newState = digitalRead(pswitch);

  if (oldState == LOW && newState == HIGH) {
    Serial.println("ON and running.");
    ServoOne.write(90);
    digitalWrite(led, HIGH);
    delay(1000);
    ServoOne.write(0);
    digitalWrite(led, LOW);
    delay(1000);
    ServoOne.write(90);
    digitalWrite(led, HIGH);
    delay(1000);
    ServoOne.write(180);
    digitalWrite(led, LOW);
    delay(1000);
    ServoOne.write(90);
    digitalWrite(led, HIGH);
    delay(1000);
  } else {
    Serial.println("OFF.");
    delay(1000);
  }
  oldState = newState;
}


texts: How to connect capacitive touch sensor to Arduino?

texts:
The capacitive touch sensor has 3 pinouts: Vin, GND, and OUT and emits an active high signal when the pad is touched. I should be routing the OUT pin to any one of the digital input pins on my Arduino Micro, correct?

Also, I need to power 2 of these capacitive touch sensors along with an IMU. How do you power multiple sensors on the Arduino Micro? There is only one GND pin and one 5 V pin. I would prefer if it could be done without a breadboard as this entire setup will be placed in a stylus.


texts:
I generally use sockets for AVRs in standalone circuits, but sometimes I sell my items and therefore I soldier the chip on the circuit. As you guess I can upgrade the code inside the chip with socket simply putting the chip out and putting it into the programmer board, but It doesn't work the same way with the ones which are soldiered on the circuit.

I know there are some ISP devices like USBtinyISP etc., but I want to be more professional and know exactly how an in system programmer work.

Do I have to use Avrdude If I design my own In system programmer? Isn't there any way that is more universal?

I searched the internet for a long time and I found only hobbyist stuff. Can anyone explain or simply direct me to a good source that explains this topic? Thank you in advance.


texts: File Size Problem with EyeFi SD Card and Arduino Mega

texts:
I've been writing to an EyeFi SD card with an Arduino Mega.  I've managed to get the files to upload wirelessly, but I noticed that my data gets cut off when the file reaches a size of 24 kb.  If I use a normal SD card, the file is able to keep logging past 24 kb.  The EyeFi card is able to upload large images, so I'm not sure what is limiting my file size for the EyeFi card.  Can I get some advice?

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

  // initialize the SD card
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT); // make sure that the default chip select pin is set to

  // see if the card is present and can be initialized:
  if (!SD.begin(10,11,12,13))
  {
    error("Card failed, or not present");
  }
  Serial.println("Card initialized");

  // see if the directory exists, create it if not.
  if( !SD.exists(directory) && !SD.mkdir(directory) )
    error("File directory not created");

  newFile();

  Serial1.begin(115200);

  while (Serial1.peek() != '!' )
    Serial1.read();

  i = 0;
}

/*************** MAIN LOOP ***************/
void loop(void)
{
  if (Serial1.available())
  {
    logfile.print( (char)Serial1.read() );
    i++;
  }

  if (i >= SOFT_BUFFER_SIZE)
  {
    logfile.flush();

    if( logfile.size() > 20480 && logfile.size() < (20480 + SOFT_BUFFER_SIZE) )
      Serial.println("Minimum File Size Achieved.");

    i = 0;
  }
}


texts: Arduino Uno synthesizer - Line Level (audio) output to mixer/amplifier

texts:
Is using PWM tones from Arduino amplified by a HiFi amplifier safe? Can I damage the amplifier or speakers because the PWM signal is not a "real" audio signal? Taken in consideration that I do not clip the signal and using a RC Low Pass Filter to filter out inaudible frequencies and using a LM386 amplifier chip to amplify and control the volume?
I am developing a synth/sampler project based on the Arduino Uno r3. This is my first electronics project ever and because of that reason I have some questions which I can't find a definite answer for on internet.
The synth has two function. It has a tone generator using the ToneAC library. With code I have mimicked LFO and VCO functions, using potentiometers I can adjust the frequency and LFO speed realtime. The other function is that I can trigger samples stored on a SD card using the TMRpcm library. The lowest frequency which can be played is 100hz and the highest 3100hz.
The device will be used in nightclubs on high end sound-systems and PA. I am afraid I will damage the equipment with my device because I do not send a pure audio (AC?) signal.
Currently the flow is like this:
PWM output (pin 9, 10) -> voltage divider to 2.5v -> RC Low Pass Filter 15Khz -> LM386 amp with volume control -> mono jack output -> mixing desk -> amplifier -> speakers
(the TMRpcm and ToneAC library share the same pin (9), I have fixed this by disabling the TMRpcm when the ToneAC is playing and vice versa. The mono jack is wired as follow. pin 9 goes to plus side of mono jack output, pin 10 to negative side. The TMRpcm pin 9 also needs to go to plus side of mono jack output, and mono jack negative needs to go to ground. Because I disable the ToneAC at that time I consider port 10 grounded because it not generating any sound so there is no signal/voltage running out of it, aka the IO pin is set to LOW)
I am hoping that using the voltage divider I am within range of the Audio Line levels of a default mixers Line-IN (like Pioneer, Behringer, etc). The RC Low Pass Filter is used to filter of inaudible frequencies and clean up the sound a bit, the LM386 audio amp is used to amplify the signal and (hopefully) make it a real audio signal.
Because I lack a lot of knowledge in this field and because I do not own a oscilloscope I can't say for sure if my output signal is harmful for the equipment and was hoping to get some guidance on my project on this forum.


texts: Using Arduino to control a 12v car light system?

texts:
I am new, but I am wondering what options I may have to control a 12v line that connects to a light with Arduino i/o.

Given the voltage limitations of an arduino, I am thinking using some kind of 5v relay to switch a 12v line on/off ( if it exists )

Though I was also hoping to be able to utilize the PWM pins in conjunction with a 12v line to 'reduce' it to 6v without using a resistor.  (though I would have no idea how to go about this, or if it is even possible).

Any help appreciated.


texts: Set PWM by period? And have it variable?

texts:
In this other stack QA I'm asking about generating a pulse signal with a period ranging from 63 ms to 6.5 ms. There is a popular PWM library however it doesn't compile and also since 63 ms is 15.8 Hz, that library's integer Hz setting isn't of help.

Is there a definitive process that isn't waving incense bundles in the corners of the room? There is an over abundance of "how tos" on the internet, however, none seemed to get me to a solution.

I've got a Mega and am using TIMER5. It's "just like" TIMER1 in that it is a 16 bit timer.


texts: Why After instancing TinyGPS , serial stop working?

texts:
I have GSM shield (and Arduino UNO) works fine with this code :

#include <GPRS_Shield_Arduino.h>
#include <SoftwareSerial.h>
#include <Wire.h>
#include <Suli.h>

#define PIN_TX    7
#define PIN_RX    8
#define BAUDRATE  9600

#define MESSAGE_LENGTH 160
char message[MESSAGE_LENGTH];
int messageIndex = 0;

char phone[16];
char datetime[24];

GPRS gprsTest(PIN_TX,PIN_RX,BAUDRATE);//RX,TX,PWR,BaudRate

void setup() {
  Serial.begin(9600);
  while(0 != gprsTest.init()) {
      delay(1000);
      Serial.print("init error\r\n");
  }
  delay(3000);
  Serial.println("Init Success, please send SMS message to me!");
}

void loop() {
   messageIndex = gprsTest.isSMSunread();
   if (messageIndex > 0) { //At least, there is one UNREAD SMS
      gprsTest.readSMS(messageIndex, message, MESSAGE_LENGTH, phone, datetime);
      //In order not to full SIM Memory, is better to delete it
      gprsTest.deleteSMS(messageIndex);
      Serial.print("From number: ");
      Serial.println(phone);
      Serial.print("Datetime: ");
      Serial.println(datetime);
      Serial.print("Recieved Message: ");
      Serial.println(message);
      String msassages = message;
        if(msassages == "Hello"){
          gprsTest.sendSMS(phone,"hello to you");
        }
   }
}

After adding #include <TinyGPS.h> ;  it works fine too but after adding TinyGPS gps; (and nothing else) to the code header, everything stop working and i can't see anything in terminal and the program stop sending SMS back. I should mention , TinyGPS works fine individually.

Why this happen ?


texts: New to Arduino and looking for direction to research for a project idea

texts:
I'm fairy new to python, learning for about 5 months by myself, and found out later that arduino is coded in C/C##. Transferring general python knowledge to Arduino im sort of able to figure out how to rewrite code for basic things.
My goal is to have just 2 buttons and lcd essentially be the main things. When you push one button it will track at what time it was pushed. When you push the other button it will delete the last saved click. At the end of the day I can just connect it to my computer and save the data.
I have a diagram of what I have so far, but im not sure where to start to looking to start coding. feeling a bit new and overwhelmed with so much new information, a general point in the right direction would be amazing.
*my rtc module is DS1307 in case that is important.


texts: Sense distance with Bare Conductive's Touch Board

texts:
How can I sense distance with Bare Conductive's Touch Board, like they suggest in their product video?

I know how I can set the touch and release thresholds, so my Touch Board is more sensitive and triggers before I touch a sensor. What I want to do is get the information how near I am. Not in centimeters or so, but a simple value telling me when I'm nearer to or farther from the sensor like in the video.


texts: Ardiuno DUE board. Sketch uploading Error

texts:
I am working on Arduino UDE board in Ubuntu 18.04. I've followed following link tutorial.
https://www.arduino.cc/en/Guide/ArduinoDue#:~:text=Use%20your%20Arduino%20Due%20on%20the%20Arduino%20Desktop%20IDE,the%20Arduino%20Boards%20Manager%20page.
In Ardiuno IDE I am getting as /dev/ttyS4. Also, I've gone with follwing procedure :
sudo usermod -a -G dialout username
sudo chmod a+rw /dev/ttyS4
ls -l /dev/ttyS4

This gave the following outpit
crw-rw-rw- 1 root dialout 4, 68 Jun 17 17:26 /dev/ttyS4

And I am getting following error while uploading sketch though Ardiuno IDE :
Sketch uses 11092 bytes (2%) of program storage space. Maximum is 524288 bytes.
Forcing reset using 1200bps open/close on port /dev/ttyS4
/home/user/.arduino15/packages/arduino/tools/bossac/1.6.1-arduino/bossac -i -d --port=ttyS4 -U false -e -w -v -b /tmp/arduino_build_718911/ardiuno_to_python.ino.bin -R
Send auto-baud
No device found on ttyS4
An error occurred while uploading the sketch
Set binary mode

I've tried following solution of decreasing baudrate to 1200 by following command line mulitple times till I get output as 1200 :
stty -F /dev/ttyS4 speed 1200 cs8 -cstopb -parenb

Still I am facing the error while uploading sketch. I've tried pressing reset and erase buttons few seconds but still not getting anything. Can anyone please help


texts:
I want to open notepad by my Digispark. I use this code:
/*  * Generated with <3 by Dckuino.js, an open source project !  */

#include <avr/pgmspace.h>
#include "DigiKeyboard.h"

const char line1[] PROGMEM = "notepad.exe";
const char line2[] PROGMEM = "Hello World!";

char buffer[256];

#define GetPsz(x) (strncpy_P(buffer, (char*)x, 256))
#define KEY_UP_ARROW      0x52
#define KEY_DOWN_ARROW    0x51
#define KEY_LEFT_ARROW        0x50
#define KEY_RIGHT_ARROW       0x4F
#define KEY_LEFT_GUI          0xE3
#define KEY_ESC               0x29
#define KEY_TAB               0x2B

void digiBegin() {
  DigiKeyboard.sendKeyStroke(0,0);
  DigiKeyboard.delay(50);
}

void digiEnd() {
  const int led=1;
  pinMode(led, OUTPUT);
  while (1) {
    digitalWrite(led, !digitalRead(led));
    DigiKeyboard.delay(1000);
  }
}

void printText(char *txt) {
  DigiKeyboard.print(txt);
  DigiKeyboard.update();
}

void setup() {
  digiBegin();

  DigiKeyboard.sendKeyStroke(KEY_R,MOD_GUI_LEFT);

  DigiKeyboard.delay(50);

  // notepad.exe   printText(GetPsz(line1));

  DigiKeyboard.sendKeyStroke(KEY_ENTER);

  DigiKeyboard.delay(100);

  // Hello World!   printText(GetPsz(line2));

  digiEnd();
} /* Unused endless loop */ void loop() {}

My program opened RUN Windows, but instead of typing "notepad.exe" it types "fgl]hY&]p]" and I don't know where am I am making mistakes. Please help me.
I have to write my code similar this:
#include "DigiKeyboard.h"

int pinled = 1;

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

    digitalWrite(3, HIGH);
}

void loop()
{
    DigiKeyboard.sendKeyStroke(0);

    if(digitalRead(3) == LOW)
    {
        DigiKeyboard.sendKeyPress(KEY_R, MOD_GUI_LEFT);
        DigiKeyboard.delay(10);

        DigiKeyboard.sendKeyStroke(0, 0);

        DigiKeyboard.sendKeyStroke(KEY_C);
        DigiKeyboard.sendKeyStroke(KEY_M);
        DigiKeyboard.sendKeyStroke(KEY_D);
        DigiKeyboard.sendKeyStroke(KEY_ENTER);

        DigiKeyboard.delay(500);

        DigiKeyboard.sendKeyStroke(KEY_I);
        DigiKeyboard.sendKeyStroke(KEY_P);
        DigiKeyboard.sendKeyStroke(KEY_C);
        DigiKeyboard.sendKeyStroke(KEY_O);
        DigiKeyboard.sendKeyStroke(KEY_N);
        DigiKeyboard.sendKeyStroke(KEY_F);
        DigiKeyboard.sendKeyStroke(KEY_I);
        DigiKeyboard.sendKeyStroke(KEY_G);
        DigiKeyboard.sendKeyStroke(KEY_ENTER);
    }
}


texts: Connect my Arduinos to central server, despite different IP adresses

texts:
Community,

A team of friends just built, with an Arduino UNO, a system where one can open a door lock from the internet.
The Arduino UNO has an Ethernet Module (ENC28J60). When the command prompts, the Arduino will let a solenoid receive 5v, which will open it and, therefore, open the door.

The novel thing is, this door-opening-arduino connects via the Internet to a central server, a webpage that 'centralizes' the door-opening process. So, in a certain URL, we'll get a screen which goes:

All these doors are in remote locations, connected to very different routers. Some of these routers will go 192.168.1.1, whereas others will go with the 0.1 ending.

So far, my friend has hard-coded the internal IP address 192.168.1.143 for identifying the Arduino, so, he's given up on DHCP.
Afterwards, he's chosen port 6560 to be the open port and connect the door to the Internet. (VPN is not a option).

So the public IP address and port 6560 are our way in into the door. This info is shared with his webpage, where commands can be given: 'open it'.

But with these hard-coding of the 1.143 IP and the router's different default addresses, we've had trouble. You know what I mean: sometimes, the whole code must be changed for our Arduino to connect to the router. Not even close to 'plug-n-play'.

My questions seems natural: how can we ensure the Arduino connects each time to the router, without any problems?
Most devices just connect: an IP camera in these routers will connect, and will never care which IP address the router has given it. If the router resets, things will be fine, and connection will restart.

So, why not DHCP? As far as my understanding goes, a problem my friend mentioned that would happen if he chose to use DHCP would be the communication between his Arduino and his online server: 'how can I know which IP I should speak with in order to open the door? By choosing the .143, I know which would should be'.
Another problem comes in with port forwarding. Apparently, by choosing the .143 and then using port 6560, we ensure that we can access via the Internet, because there's a standarized procedure: 'please open port 6560 for this IP'.

This is a bit cumbersome. Most devices just don't work this way. We want to be able to just plug it in, let our Arduino and the router get any IP, and by just opening port 6560, we're in. Pretty simple.

How can we ensure that:

Our Arduino just connects to the router, and
that communication between our Arduino and the centralized server
just flows?

Another friend suggested configuring each router so that a device with a certain MAC address (our Arduino) gets this IP* and this port forwarding. But what if the default address is 192.168.0.1 (instead of 1.1), for example? wouldn't we be facing a problem?

We're seeking a kind of plug-n-play thing, like most access control systems work. Hardware's ok, it's connection the thing that bugs us.

Any suggestions, advice, or plain responses are really welcome. I think we're just a step away from our commit, which is creating a reliable connection for these doors. It may be just a line of code, or a config trick. Thank you for your time.

(you'll soon notice we're not that savvy on routing and switching, so If we got our premises completely wrong, don't hesitate to correct us)


texts: CH340 Nano avrdude: stk500_getsync() not in sync resp=0xa4

texts:
I'm trying to upload some code to an non-arduino nano with the CH340G chip, and the avrdude refuses to let me upload. The error I'm getting is:

Using Port                    : COM4
Using Programmer              : arduino
Overriding Baud Rate          : 115200

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0xf6
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0xf6

avrdude done.  Thank you.

I've tried installing the drivers for the CH340 chip following this guide but have had no luck. I've also tried uploading to my arduino uno and my arduino micro (both are arduino brand) with no problems. I'm running Windows 10, Arduino IDE 1.8.5

Any ideas?


texts: What image formats are accepted for displays?

texts:
Sorry if there is information missing, im new to the topic.

I have an ESP32 connected to a Waveshare 7,5" RWB display, and i can display images by converting them to .xbm and including the hex code in the sketch.
So far, so good.

But heres my question: What exactly are the requirements? Because when looking at the .xbm image code, i see that its a pattern like this:

0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00,0X00

But when i used a python script

import binascii
filename = 'test.png'
with open(filename, 'rb') as f:
    content = f.read()
print(binascii.hexlify(content))

to convert an image to hex code, i got this:
b'89504e470d0a1a0a0000000d4948445200000280000001800802000000b2...'(continues for thousands of characters, didnt want to paste all of that here

However, when trying to run the sketch that successfully displayed the first hex code with the second image code, i got this error(cut out the big string clutter again):

...0000000049454e44ae426082};

^

C:\Users\Administrator\Desktop\SPI_test_example\SPI_test_example.ino: In function 'void loop()':

SPI_test_example:167:21: error: 'showBitmapExample' was not declared in this scope

   showBitmapExample();

                     ^

SPI_test_example:171:51: error: 'showFont' was not declared in this scope

   showFont("FreeMonoBold9pt7b", &FreeMonoBold9pt7b);

                                                   ^

exit status 1
'showBitmapExample' was not declared in this scope

So, i would like to know - does the image code have to have exactly the format i mentioned first? This is very important for me because i want to automate the process from inputting any image to using the resulting code to feed the display.

Thanks in advance!

EDIT: As far as my understanding goes, both formats are the same data, just that the first one is displaying a white pixel as 0xFF,0xFF,0xFF and the second one as FFFFFF.


texts:
I am trying to send analog data, from a LM35, using an XBee (series 1 - XB24).

My setup:

Transmitting Module: XBee with USB explorer+Arduino+LM35 (temperature sensor)
Receiving Module: XBee with XBee shield+Arduino

I read analog data using the Arduino and send it through the XBee in the USB explorer, then the receiving XBee module receives it and shows it in the serial monitor of the Arduino.

I have tried many ways but I can't reach it and I have figured out that my problem lies in the Arduino code.

So, please can anyone help with some demo code for this project?


texts: No connection with XBee radios on Arduino board

texts: I have two Arduino boards which I've attached XBee radio boards to. One is to send data via Serial.write(num), where num is an integer. The other is receiving that integer via Serial.read. However, when I have both units running, nothing is ever received by the receiving unit. I've tried switching the receiving unit radio board to the USB mode so that I can use the serial monitor to send data to the unit. I've tried sending bytes 01111110, as well as integers such as 77. Nothing ever gets read from the serial monitor. I've downloaded XCTU, but it cannot find either of the radios. What can I do?


texts: Telit GPRS Module never returning and never timing out for command AT#FTPOPEN

texts:
Howdie!  I trying to run a GPRS modem on an Arduino. My full stack is Nimbelink's NL-SW-GPRS Modem (containing Telit GE910-QUAD GPRS module) with the Nimbelink Arduino Development Shield on an Arduino UNO R3.

My goal is to connect to an FTP server and upload a file. I am following this guide from Nimbelink and section 3.3 from Telit's user guide.

I am stuck because the AT#FTPOPEN command doesn't seem to ever timeout nor does it return any result (ERROR or OKAY).

Here is the AT commands I am running:

AT
> OK

AT+CGREG?
> +CGREG: 0,1
> OK

AT#SIMDET=1
> OK

AT+CGDCONT=1,"IP","internet.com","0.0.0.0",0,0
> OK

AT#SCFG=1,1,300,90,600,200
> OK

AT#SGACTAUTH=0
> OK

AT#SGACT=1,1
> <My IP Address>
> OK

AT#FTPTO=100
> OK

AT#FTPOPEN="209.86.62.76","anonymous","anonymous",0

Where 209.86.62.76 is the IP address of ftp.earthlink.net which I am just using for testing purposes, but I have tried several others. I have tried with FTP mode 0 (active) and 1 (passive) with no change in behavior.

The AT#FTPOPEN just never returns anything (no ERROR and no OK). I've waited up to 5 minutes. The command does returns "ERROR" if I deliberately mess up the syntax of the command (eg. AT#FTPOPEN="") but for any valid format it just seems to hang.

Is this a known problem or something I can easy work around? Am I doing something crazy with my timeout values? Is there an easy way to test the context that I activated with the SGACT?

This is more of a question for an M2M forum, but I'm on an Arduino and it seems like there are many people using GSM modules on Arduino - so I thought I'd post here because I am a bit desperate. Thanks :)


texts:
When I bought my Arduino Uno and connected it to my computer, I tried to make the simple blink circuit (before programming the Arduino) and suddenly the LED started blinking. Is the blink example the default Arduino sketch?

I am sure that I didn't uploaded anything to the board.


texts: Stacking adc's when making an midi controller ( lots of potmeters)

texts: I'm making a midi controller with the Arduino uno. It contains approximately 50 analog inputs with potentiometers. I have enough MCP3008 adc's here but I have no idea how I connect 2 or more adc's to the Arduino so that I can read 50. How do you stack adc's?


texts: Is it possible to use two encoders with Arduino Uno?

texts:
I would like to control 2 motors with the Arduino Uno board, which provides only two interrupt pins on digital 2 and 3.

I've set one encoder using these pins, and it works. What do you think about the following approaches:

Timer Interrupt:

Create a Timer Interrupt.
Connect the seconder encoder to an analog pin.
Set an analog read function in the interrupt service routine.
Change the prescaler of the ADC and increase the acquisition time.

PinChangeInt

Use PinChangeInt to capture the pin change interrupt rather than an external interrupt.

  This should allow you to use almost any I/O pins on the Uno for the
  encoder.

  as Ignacio Vazquez-Abrams suggested here


texts: Limiting Data Output Frequency from ADXL345

texts: I have a working ADXL345 connected to an Arduino UNO, I need to limit the rate at which the ADXL345 takes in readings. I am using the SparkFun library for this sensor. I have read about the delay function and it works in the loop function but I was wondering if there might be a better way that is much more efficient?


texts: Sending data to a webserver with GPRS/GPS Shield (U-blox Sara G-350)

texts:
I am working on a project for tracking cars. I am using an Arduino UNO to receive the position from GPS/GPRS shield. I am OK on obtaining the coordinates position.
Now I need to send the position to a webserver and then show it on a webpage using the Google Maps API. Which accepts it in a POST or GET method.
Here is the shield model:
U-blox Sara G-350
and this is its manual here

Here is my approach:

#include <SoftwareSerial.h>
#include <String.h>

SoftwareSerial gprsSerial(7 ,8);

void setup() {
  // put your setup code here, to run once:
  gprsSerial.begin(19200);
  Serial.begin(19200);
  delay(2000);

 gprsSerial.println("AT+CGDCONT=3,\"IP\",\"weborange\"");
 toSerial();
 delay(2000);

 gprsSerial.println("AT+UHTTP=0");
 toSerial();
 delay(2000);
 gprsSerial.println("AT+UHTTP=2,1,\"www.navtec.16mb.com\"");
                   //AT+UHTTP=<profile_id>,<op_code>,<HTTP_server_name>
 toSerial();
 delay(2000);

 gprsSerial.println("AT+UHTTP=0,5,80");
 toSerial();
 delay(2000);

}

void loop() {

 //gprsSerial.println("AT+UHTTP=2,1,\"submit\"");
                    //AT+UHTTP=<profile_id>,<op_code>,<param_val>[,<param_val1>]
 //toSerial();
 //delay(2000);

 gprsSerial.println("AT+UHTTPC=2,1,\"/add.php\",\"filename\"");  //Problem here!!!!!!!!
                   //AT+UHTTPC=<profile_id>,<http_command>,<path>,<filename>[,<param1>[,<param2>[,<param3>]]]
 toSerial();
 delay(2000);
}

void toSerial()
{
  while(gprsSerial.available()!=0)
  {
    Serial.write(gprsSerial.read());
  }

}

This is what I get:

  +CGDCONT=3,"IP","weborange"

  OK
  +UHTTP=0

  OK
  +UHTTP=2,1,"www.navtec.16mb.com"

  OK
  +UHTTP=0,5,80

  OK
  +UHTTPC=2,1,/add.php,filename

  ERROR
  +UHTTPC=2,1,/add.php,filename

  ERROR
  +UHTTPC=2,1,/add.php,filename

  ERROR
  +UHTTPC=2,1,/add.php,filename

  ERROR ...

Thanks for your time, I am waiting for your support, any ideas could help. Sorry for my bad English


texts: Irrecvdemo program in or remote library gives fatal error #include

texts:
Whenever I compile irrecvdemo of or remote library it gives error saying that fatal error saying

  no file or directory exists #include <WProgram.h>

#include <IRremote.h>

int RECV_PIN = 11;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
}

void loop() {
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
  }
}


texts:
I'm using an Atmega168 in a project that involve using the ISRs from multiple sources. I have an ISR hooked up to an external button and a timer, to use it as a reset button after a predetermined hold time.

I'm also using an ISR hooked upto UART. The UART is connected to an external Linux based SoC. Upon receiving specific commands from the linux machine, the atmel will perform certain functions.

In very rare occasions, the linux hangs up during tranmission and is always sending out the UART commands. This saturates the ISR and it also prevents the reset button ISR to function.

Although this happens rarely, I would like to take measures for this. As far as I know, there are no way to set priority in avr ISRs. So what can I do if the UART ISR is always called and prevents the rest of the board from functioning?

EDIT:
I think the problem arises when the linux machine sends an empty string to the atmel.
the UART_receive() on the atmel gets stuck at: while ( !(UCSR0A & (1<<RXC0)) );

Any way I can avoid this?

unsigned char USART_Receive_string(unsigned char *x, unsigned char size)
{
unsigned char i = 0;

if (size == 0) return 0;            // return 0 if no space

while (i < size - 1) {              // check space is available (including additional null char at end)
    unsigned char c;
    while ( !(UCSR0A & (1<<RXC0)) );  // wait for another char - WARNING this will wait forever if nothing is received
    c = UDR0;
    if (c == '\0') break;           // break on NULL character
    x[i] = c;                       // write into the supplied buffer
    i++;
}
x[i] = 0;                           // ensure string is null terminated

return i + 1;                       // return number of characters written
}


texts: Aruino UNO not getting programmed on MAC OSX

texts:
I am using MAC OSX Mojave and trying to program an Arduino UNO board. However, whenever I start the Arduino IDE, I only find one port in the ports section called: /dev/cu.Bluetooth-Incoming-Port.
When I select that, since there is no other option, I get the following error code on pressing 'Upload' button. The error code I receive is given in image.

My programmer is ArduinoISP and the board is Arduino UNO

Kindly help me resolve this issue.

Note
I have reinstalled CH34x drivers (latest version v.5)


texts:
I have already downloaded the arduino package for LabVIEW, MakerHub LINX, NI-Visa, and I've uploaded LIFA_Base to arduino, and it still does not work :(.
My questions are:

1) Do I need to upload the LIFA_Base to arduino every time I want to interface arduino with LabVIEW, or is once enough? (the order I'm following is: upload LIFA_Base -> upload my arduino code -> run the LabVIEW code)

2) I know my arduino UNO is receiving info by the LabVIEW software because the RX led goes on every time I press the ON/OFF buttons, what could be the problem?

The ideia of this humble project is to turn on/off LED through the LabVIEW. The arduino code follows the LebVIEW code.

String c, string;
int led = 2;

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

void loop() {
   if (Serial.available() > 0) string = "";

   while(Serial.available() > 0)
   {
     c = (byte)Serial.read();
       if (c == ":")
       {
         break;
       }else
       {
         string += c;
       }
     delay(1);
   }

   if (string == "LL")
   {
     digitalWrite(led, HIGH);
   }
   if (string == "DL")
   {
     digitalWrite(led, LOW);
   }
}


texts:
Code would not update variable inside drive method. The variable is updated inside the drive method, but it doesn't change in the rest of the class. I wrote a simple similar method in normal C++ and the variable actually updated in the rest of the class.

engine.hpp

#pragma once
#include <Arduino.h>

namespace engine
{
class Engine
{
public:
    Engine(const unsigned char t_motor, const unsigned char t_forward, const unsigned char t_backward);
    void drive(unsigned int t_speed, bool t_isForward = true);
    bool isMovingForward() const;
    void stop();

private:
    const unsigned char m_motor;
    const unsigned char m_forward;
    const unsigned char m_backward;

    // Movements
    bool m_isActive;
    bool m_isForward;
    unsigned int m_speed;
};
} // namespace engine

engine.cpp init list

Engine::Engine(const unsigned char t_motor, const unsigned char t_forward, const unsigned char t_backward)
    : m_motor(t_motor),
      m_forward(t_forward),
      m_backward(t_backward),
      m_isActive(false),
      m_isForward(true),
      m_speed(0U)
{
}

drive method

void Engine::drive(unsigned int t_speed, bool t_isForward)
{

    if (!m_isActive || m_isForward != t_isForward)
    {
        stop();

        // Set direction
        if (t_isForward)
        {
            digitalWrite(m_forward, HIGH);
            digitalWrite(m_backward, LOW);
        }
        else
        {
            digitalWrite(m_forward, LOW);
            digitalWrite(m_backward, HIGH);
        }

        m_isActive = true;
        m_isForward = t_isForward;
    }

    if (m_speed != t_speed)
    {
        m_speed = t_speed; // Updated here
        analogWrite(m_motor, t_speed);
    }
}


texts: How can the sensitivity of capacitive touch sensors be limited?

texts:
I have an Adafruit circuit playground classic, and the touch-pads are so very sensitive. From a centimeter away, they trigger.  I would be happy to just have regular inputs, or to have the sensitivity reduced. How can I do this?

To clarify, here is my code:

//keyboard control for TuxKart power Glove
#include <Adafruit_CircuitPlayground.h>
#include <Keyboard.h>
#include <Mouse.h>
// set pin numbers for the five buttons:
const int Fire = 6;
const int Nitro = 9;
const int Eagle = 10;
const int _Esc = 12;

bool slideSwitch;

void setup() { // initialize the buttons' inputs:
  pinMode(Fire, INPUT_PULLUP);
  pinMode(Nitro, INPUT_PULLUP);
  pinMode(Eagle, INPUT_PULLUP);
  pinMode(_Esc, INPUT_PULLUP);

  Serial.begin(9600);
  // initialize mouse control:
  //Mouse.begin();
  Keyboard.begin();
}

void loop() {
  if (!CircuitPlayground.slideSwitch()) {
    return;
  }

  // use the pushbuttons to control the keyboard:
  if (!digitalRead(Fire) == HIGH) {
    Keyboard.write('KEY_SPACE');
    Serial.println("F");
  }
  if (!digitalRead(Nitro) == HIGH) {
    Keyboard.write('n');
    Serial.println("U");
  }
  if (!digitalRead(Eagle) == HIGH) {
    Keyboard.write(0xB2);
    Serial.println("N");
  }
  if (!digitalRead(_Esc) == HIGH) {
    Keyboard.write(0xB1);
    Serial.println("K");
  }
delay(200);
}

This code or any other, where capacitive touch sensitivity has not been specified, yields pins having extreme sensitivity. I have read the comments, that say the MCU doesn't feature this natively. If that were true, how would the pins remain sensitive?

My solution to this is to set sensitivity so low, that it is negligible. If capacitive touch sensing is not specified, why am I getting that functionality? Why would this code give me capacitive touch sensing?
Ideally, I would disable the touch sensing somehow, or have the pins simply behave normally, like any other Arduino based device that doesn't have touch sense. But what I have guessed, (shown in code) doesn't work. If there is a more explicit way to specify that IO pins should act as normal pins, without capacitive touch sensing, I would surely like to know.


texts: How can I test/demonstrate what the serial input and output buffers are?

texts:
Serial is causing me a lot of pain, and I think there are certain basic principles that I simple have not understood. I hope that by understanding how to test/demonstrate the buffer size, I will come one big step closer to understanding how serial works.

I suspect it is only possible to demonstrate this by writing a piece of software for "the other end"; the pc. I do understand Python, and to some extent how to work with serial on Python, so if possible, please write the pc code in Python.

If you supply an example (piece of code), please explain how the example works.


texts: I made a programmable Arduino that measures an input voltage. The Arduino will close or open an inverter using a relay to prevent the set of batteries from dropping below 50% to keep the batteries healthy. I currently have a set of 8 6V batteries configured to supply a total of 12V to one inverter. I used a set of 10k ohm and 100k ohm to safely measure the 12 volt input from the batteries. In the current configuration the total Amperage provided by the set of batteries is 400 amps. Is it safe to measure the voltage from a 12V/400A input or do I need some kind of protection?


texts: How does Arduino IDE for OSX work without drivers?

texts:
My Arduino IDE works right out of the box without me having to install any USB to UART drivers. I know the Atmega16U2 on the UNO is acting as UART bridge, but this means that OSX recognizes it on a hardware level, which doesn't make sense since no drivers were installed - unless there is some sort of standard here that the Atmega16U2 implements?

The reason why I ask this is that I have a project where I want to connect an ATMega328p to a client mac which may not have access to 3rd party drivers, so having serial work natively with screen would be ideal. If the Arduino IDE can implement serial monitor without any additional drivers then it means I can too.

Does anyone know how this is implemented?

Thanks!


texts: Accuracy of liquid level measurement using sonar sensor

texts:
Is it a good way to measure liquid level in a water tank using a general purpose sonar sensor? How can echoes from the tank walls affect measurement accuracy?

I have a cylinder shaped horizontal 700L water tank, used for emergency water supply. I need to measure the water level with approx. 5% accuracy and display it in my kitchen.

UPDATE! Today I found this helpful page: Home Heating Hacking Part 1 or How to Measure an Oil Tank.
I had no time to realize my idea, but it's exactly what I wanted to do. So take a look.


texts: Motors would make the car go extreme left instead of forward (Self Driving car)

texts:
This is my very first day in the community, please bear me until I make myself comfortable here.
Coming to my question,
I'm making a self Driving car.
My car instead of moving forward it moves on the left rigorously which makes the car go round and round.
Along with my arduino, I'm using the L298 bridge to control my motors.
The motors seem to work fine until put on the ground.
Can you guys help me with what could be the possible solution to this and make my car go forward.

Here's my code :

    const int EnableL= 5;
const int HighL = 6;  //Left side motors
const int LowL = 7;

const int EnableR= 10;
const int HighR = 8;  //Right side motors
const int LowR = 9;

void setup() {
 pinMode(EnableL, OUTPUT);
 pinMode(HighL, OUTPUT);
 pinMode(LowL, OUTPUT);

 pinMode(EnableR,OUTPUT);
 pinMode(HighR, OUTPUT);
 pinMode(LowR, OUTPUT);

}

void Forward()
{
  digitalWrite(HighL,HIGH);
  digitalWrite(LowL,LOW);
  analogWrite(EnableL, 255);

  digitalWrite(HighR,LOW);
  digitalWrite(LowR,HIGH);
  analogWrite(EnableR, 255);
}

void Backward()
{
  digitalWrite(HighL,LOW);
  digitalWrite(LowL,HIGH);
  analogWrite(EnableL, 255);

  digitalWrite(HighR,HIGH);
  digitalWrite(LowR,LOW);
  analogWrite(EnableR, 255);
}

void loop() {
  Forward();

}

Components used :

3 pack lithium ion cells at 12V to power L298 bridge

A 9v cell to power Arduino Uno


texts: RC drag strip finish line with mph calculation (using 1" spaced lasers)

texts: My question is: how do I read multiple inputs at the same time without using interrupts on an UNO.  I'm building an RC drag strip with tree and finish line that will calculate run time as well as calculate each run in mph.  I'm using lasers and non modulated laser detectors for the beams and I'm using a 1" beam gap(between 1st beam and 2nd beam) at the finish line(for mph calculation). My concern comes in when two cars come close enough at the finish line for one to break the first beam at set the win flag but the car in the other lane is close enough to cross the 1st beam before the 1st car actually crosses the 2nd beam then the detection loop is going to miss one of them. (just a note: a few of these cars can top 100 mph when crossing the line)


texts: Can I use a GPS from old Garmin with an Arduino?

texts:
I'm working on an Arduino project, and I'd like to add GPS functionality. I could buy a GPS module, but those are expensive. I had an old Garmin Forerunner 305 lying around, so I took it apart and took a peek inside. There are two PCBs - one connected to a screen and one to the GPS. In addition, there was a battery and a small part for charging.

I'd like to know if it is possible to connect this GPS to my Arduino, and if so, how?

Edited:
To make my question more precise,

-I see the pins in the top right of the picture. How do I connect those to my Arduino? Is there any specific kind of wire? Because the pins are too small for standard wires.

-Once I connect it, how do I figure out the voltage requirements and pin layout? I tried googling the  GPS model, but nothing helpful came up. What kind of scope should I put on it?

The two pictures below show only the GPS part of the inside of the watch.


texts:
So I have an application that runs on the Arduino that passes info over serial.
I'm using a ESP2866 to make it wireless.

Arduino->Serial->Esp2866->SocketConn->JavaSocket->Console

I have a working java socket server, that I can connect to with other applications. (Java, c++, ext.) And even across the network.

I just cant seem to get my ESP2866 to connect.

Iv tried several ESP2866 units, no success. Iv tried updating the firmware on each, nope.

AT                      ->  OK
AT+RST                  ->  ready
AT+CWMODE=1             ->  OK
AT+CWJAP="name","pass"  ->  CONNECTED,GOTIP,OK
AT+CIPMUX=0             ->  OK
AT+CIFSR                ->  192.168.0.30
AT+CIPSTART="TCP","192.168.0.9","4160"  ->  ERROR

The lack of debug info is... Aggravating.
Iv Seen other examples of this that worked. So whats the problem?

Additional info:

netstat -tulpn | grep 4160
tcp6       0      0 :::4160          :::*      LISTEN      23058/java

(Edit 1:)Just tried restricting to IPV4 and rebinding the port. Nope.

InetAddress localAddress = Inet4Address.getByAddress(new byte[]{(byte) 192,(byte) 168,0,9});
System.setProperty("java.net.preferIPv4Stack", "true");
ServerSocket listener = new ServerSocket(port,20,localAddress);
//...Code to make socket work.


texts: How to make 2 LEDs flash in a 5/4 Polyrhythm?

texts:
Basically I want one LED to flash 5 times in the same amount of time it takes another LED to flash 4 times. This is what I have, but they are flashing independently and I need them to flash simultaneously.

//Making a 5/4 Polyrhythm with 2 LEDs
const int LED13 = 13;
const int LED7 = 7;
int i = 5;

void setup() {
   pinMode(LED13, OUTPUT);
   pinMode(LED7, OUTPUT);
}

void loop() {

  for(i=0; i<5; i++)
  {
     digitalWrite (LED13, HIGH);
     delay(500);
     digitalWrite (LED13, LOW);
     delay(800);
  }

  for(i=0; i<4; i++)
  {
     digitalWrite (LED7, HIGH);
     delay(500);
     digitalWrite (LED7, LOW);
     delay(1000);
  }

}


texts:
I was trying to do a LED display that turns on a LED at pin 13 that goes on then turns off after a delay then the next pin (which is pin 12 counting down) will turn on and then turn off.

I also put in a potentiometer that can change the delay to make it faster or slower.

Here's the code:

float pinOn = 13;
int outMin = 0;
int outMax = 13;
float delayNum = 1000;

void setup () {
  for (int i=outMin; i<=outMax; i++) {
  pinMode(i, OUTPUT); }
  Serial.begin(9600);
}

void loop () {
  // Reads Potentiometer -- sets delay relative to the Potentiometer input
  int sensorValue = analogRead(A0);
  delayNum = sensorValue;
  // Turns on the Pin designated by 'pinOn'
  digitalWrite(pinOn, HIGH);
  delay(delayNum);
  digitalWrite(pinOn, LOW);
  // Checks if 'pinOn' is 0 which then resets it back to 13 if not 0 then counts down
  if (pinOn = 0) {
    pinOn + 13;
  } else {
    pinOn - 1;
  }
}

All it does is turn on pin 13 for a moment then permanently turns on pin 1 and 0 and it gets stuck like that.


texts: I want to send a file(text document) from PC to Arduino UNO via Bluetooth and store it in EEPROM. How do it? And I want to display this text document on Graphic LCD Nokia 5110. I have tried interfacing Graphic LCD also displayed test programs on Graphic LCD. It worked. But, how to make it work with text document? Document needs to converted?


texts: Button with switch timer and reset time function + LED feedback. What am I doing wrong?

texts:
Beginner here.

I´ve been trying to implement a button function timer working with millis() instead of delay as I want the button to be responsive while the timer is running.

So far I´ve managed to start the counter on the button´s state change and let it time out. Unfortunately all kind of strange behavior is coming out of my sketch and I am yet to understand why.

Help is appreciated.

This is the desired behaviour of the timer:

On startup the Arduino is ready to recieve a button push.
The relay is off (HIGH).
Once the button is pushed:
• The relay state is changed to LOW in order to turn it on
• A green LED switches on.
• A millis() based timer is switched on.
If the user presses the button while the switch is on, the timer is reset to 0 and continues counting.
If the on-time is going to end, a red LED starts blinking. Say in the last minute.
As soon as the timer reaches the specified on-time:
• The green LED switches off
• The relay switches off
• The system returns to step 1. and is awaiting a push.

In my code example the red blinking Led is not implemented yet.
The following code switches the switch and the green LED on but does not switch them off anymore.

//CONSTANTS

#define BUTTON_PIN        2  // Button
int in1 = 7;
int greenLED = 4;
int redLED = 9;

//VARIABLES

int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

//MILLIS
unsigned long previousMillis = 0;
const long interval = 10000;

void setup()
{
  pinMode(BUTTON_PIN, INPUT);
  digitalWrite(BUTTON_PIN, HIGH); // pull-up
  Serial.begin(9600);

  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);

  //SWITCH HANDLERS
  pinMode(in1, OUTPUT);
  digitalWrite(in1, HIGH);

}

void loop(){

    // read the pushbutton input pin:
    buttonState = digitalRead(BUTTON_PIN);
    unsigned long currentMillis = millis();

    // compare the buttonState to its previous state
    if (buttonState != lastButtonState) {

        buttonState = digitalRead(BUTTON_PIN);

        if (currentMillis - previousMillis < interval){
        //SWITCH ON, LED ON
          digitalWrite(in1, LOW);
          digitalWrite(greenLED, HIGH);
        }

        if (currentMillis - previousMillis >= interval) {
            previousMillis = currentMillis;
            digitalWrite(in1, HIGH);
            digitalWrite(greenLED, LOW);
        }

        // Delay a little bit to avoid bouncing
        delay(50);

        // Reset buttonState:
        lastButtonState = buttonState;
   }
}


texts: Arduino not recognized by PC, overheats and L led is always on

texts: I have a problem with my Arduino Uno rev3, which suddenly started to overheat near the small, black, square element next to the circular cable power input port, isn't recognized by Windows 10 (I have the drivers installed, it was working just a while before it broke) and, what is strange, the internal diode (labeled L, next to the digital port 13) is always on. The PC doesn't even notice that any device is plugged in, the arduino IDE doesn't see any active COM ports (the menu option is grayed). The usb cable supports data transfer and is not broken. The arduino was working a while before, I have the drivers and I tried restarting the PC. Now I cannot upload any program to it, neither can I flash the bootloader. What can be wrong and is it possible to fix it?


texts: USB Communication like serial RS232 with an Attiny

texts:
Basically I want to use an Attiny running an Arduino boot loader as an usb device. I'm not sure how to even start or what phrases to search for.

So here's what I ultimately wish to do.

Load a listener like that of an RS232 serial communication program
trigger pin states based on received commands
plug the Attiny directly into a windows environment USB port for
communication.

I understand that this will require some kind of driver to do this but i don't know what. I do have experience with serial port communication using Visual Studio C# as well.

Assuming what I would like to do is possible, im looking for pointers in how to make the Attiny can be seen by windows.


texts: Is there an alternative to soldering to connect boards?

texts:
I know that shields are usually soldered to headers so they can be attached to the board with the Arduino. I have a tremor, which makes soldering impossible. Are there ways of connecting PCBs without soldering?

If a concrete example would be helpful, I would like to connect the Adafruit WINC1500 WiFi Shield to a SparkFun RedBoard.


texts: Cannot convert 'String' to 'uint8_t {aka unsigned char}' in initialization

texts:
Hey all I am trying to convert a string into a uint8_t with the following code:

String data = "#255101987";
String tmp1 = data.substring(1, 3);

uint8_t first  = (String)tmp1;

I am getting the error of:

  cannot convert 'String' to 'uint8_t {aka unsigned char}' in initialization

Any help would be great as I thought adding (String) in front of the varible would solve the issue but it hasn't as you can tell.


texts: High Precision Temperature Sensor LMT70 connection to arduino mega

texts:
How can I connect an LMT70 temperature sensor (4Pins) to Arduino Mega board for atmospheric temperature measurement. LM35 sensor has got only 3 pins and connections are known. But LMT70 high precision sensor got 4 pins. How to connect it to arduino mega board
Please help.
Thank you.


texts:
I just bought This IMU a while ago, and when I reached the point where I wanna connect it, I noticed that one of the capacitors have been removed by accedint, and since it took too long to check the product, I won't get to replace it or get any refund, so my question, how can I replace that SMD capacitor?
P.S. I have some Ultrasonic sensors might have the same SMD capacitors that I can take off and replace with if anyone can help.


texts: Frequency measuring using Arduino (AC analog input)

texts:
What I aim to do:
To measure the frequency of an AC analog signal generated by an electrodynamic shaker, which has a peak voltage of 10V-- using an Arduino Uno.

What I have tried:
Tried using a circuit similar to an optocoupler (using a 2N2222) transistor to take pulse input, using the pulsein() function. However the duration is always returning as 0.

My questions:

Is this method an acceptable way of measuring frequency?
What could I be doing wrong such that the time duration is always returning 0?
Is there an easier way of carrying out this work?

Will put up the code if asked for. However it is basically just defining a few variables (for pins, duration etc), and then using the pulsein function.


texts: How to implement brown out detector arduino ESP32?

texts:
We are using ESP32 with arduino sdk for developing our application. In our application we need to implement BOD to detect with specific voltage level.
Basically we want to set specific voltage level and when device goes to power off it will detect and trigger interrupt. How I can set interrupt for brown out detect?
we have only this code:
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"

void setup() {
  Serial.begin(115200);
  WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1); //enable brownout detector
}

void loop() {
  Serial.println("Start BOD");
  delay(1000);
}


texts: Use an Arduino to "intercept" transparently serial communication to Grbl?

texts:
I need to have an Arduino "spying" on communications between the PC and another Arduino with GRBL. The goal is to intercept a couple of GCode commands and act on them instead of Grbl.

My first step is to attempt to be as transparent as possible, but so far, I am not getting from Grbl the clear answer I expect. For example, I get Grbl 1.1d [?2???B???u5 instead of Grbl 1.1d ['$' for help]

Here is my code so far.

#include <SoftwareSerial.h>

int PortOneTX = 10;
int PortOneRX = 11;

const String USB = "USB";
const String GRBL = "GRBL";

char endOfLine = '\n';

SoftwareSerial portOne(PortOneRX, PortOneTX);

String grblBytes = "";
String USBBytes = "";

void setup()
{
    Serial.begin(115200);
    while (!Serial)
    {
        ; // Do nothing, just wait till we are connected through USB
    }
    portOne.begin(115200);
    portOne.write("\r\n");
    delay(2);       ;
}

String stringtoWrite = "";

void loop()
{
    if (portOne.available() > 0)//while (portOne.available())
    {
        stringtoWrite = portOne.readStringUntil(endOfLine);
        for (int i = 0; i < stringtoWrite.length(); i++)
        {
            Serial.write(stringtoWrite[i]);
        }
        Serial.write(endOfLine);

    }
    if (Serial.available() > 0)//while (Serial.available())
    {
        stringtoWrite = Serial.readStringUntil(endOfLine);
        for (int i = 0; i < stringtoWrite.length(); i++)
        {
            portOne.write(stringtoWrite[i]);
        }
        portOne.write(endOfLine);

    }
}

I feel that I should be using events instead of if (serial.available) in the loop, but I am not sure how to go about it. I thought it would be easy!

Anyway, as I want Grbl-Panel to work totally transparently, I need this first step to be Ok before doing anything else.

Thanks for your help.