texts:
I have been trying to set up the BMA421 motion sensor in a nrf52 based smart watch, using the datasheet for the BMA423, which has the same interface. I had got the sensor working well with the original source code, but I was trying to set it up myself. It is connected via I2C, address 0x18.
I made some mistakes in my original code. I was trying to initialise the chip with a 6Kb byte stream (as in the original source), in chunks of 64 bytes. I didn't resend the register at the start of each data chunk, so ended up writing bytes to random registers.
Unfortunately, I have managed to get the sensor into an unrecoverable state - it now returns 0xFF to all reads, and doesn't respond to a soft-reset code (register 0x7E=0xB6). Even exhausting the watch battery to power cycle the chip doesn't seem to help.
I have found someone with a similar issue on the Borsch Sensortec forum, so I am hoping that a complete battery discharge works.
Does anyone have any other suggestions?


texts:
I've tried this code on an LCD, and instead of displaying "Hello World!" it displays what is shown on the picture.

Code:

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  lcd.begin(16, 2);
}

void loop() {
  lcd.print("Hello World!");
  delay(500);
  lcd.clear();
  delay(500);
}


texts: Can I set the Arduino board type in code

texts:
When I've come back to Arduino programming after a spell doing other things, I keep forgetting that I last experimented with a different type of board and get a "avrdude: stk500_getsync(): not in sync: resp=0x00" error.

I have one sketch which will always be compiled and uploaded against a specific piece of hardware. Therefore, I would like to specify the board type and preferably COM port as well, in my sketch.

Can it be done?


texts:
For my code I use a couple of static variables.
But when I search the internet, they seem "evil".

For example: I have a function which will be executed every loop (5ms looptime).
to increase the speed I added some static variables to it.
Is the way I am doing this bad? Are there simple solutions for it?

Code:

int ProgFormula() {
  static int StartPosition;
  static int DeltaPosition;
  static int LoopTime = 5;
  static int AccelerationLoops;
  static int TotalLoops;
  static int EndOne;

  static float VelocityLoop;
  static float VelocityFactor;

  int Setpoint;

  if (Iteration == -1) {
    StartPosition = PID.ActualPosition;
    DeltaPosition = abs(SetPosition - StartPosition);
    VelocityLoop = Velocity / (1000 / LoopTime);
    TotalLoops = DeltaPosition / VelocityLoop;
    if (TotalLoops <= (AccelerationLoops * 2)) {
      AccelerationLoops = (TotalLoops / 2);
      VelocityFactor = (VelocityLoop * 0.5 / AccelerationLoops) / 2;
    }
    else {
      AccelerationLoops = 70;

      VelocityFactor = VelocityLoop * 0.5 / AccelerationLoops;
    }
    TotalLoops = DeltaPosition / VelocityLoop + AccelerationLoops;
    EndOne = (VelocityFactor * pow(AccelerationLoops, 2));
  }
  else if (Iteration >= 0 && Iteration <= AccelerationLoops) {
    if (StartPosition < SetPosition) {
      Setpoint = VelocityFactor * pow(Iteration, 2) + StartPosition;
    }
    else {
      Setpoint = -VelocityFactor * pow(Iteration, 2) + StartPosition;
    }
  }
  else if (Iteration > AccelerationLoops && Iteration <= (TotalLoops - AccelerationLoops)) {
    if (StartPosition < SetPosition) {
      Setpoint = VelocityLoop * Iteration - EndOne + StartPosition;
    }
    else {
      Setpoint = -VelocityLoop * Iteration + EndOne + StartPosition;
    }
  }
  else if (Iteration >= (TotalLoops - AccelerationLoops) && Iteration <= TotalLoops) {
    if (StartPosition < SetPosition) {
      Setpoint = -VelocityFactor * pow((TotalLoops - Iteration), 2) + DeltaPosition + StartPosition;
    }
    else {
      Setpoint = VelocityFactor * pow((TotalLoops - Iteration), 2) - DeltaPosition + StartPosition;
    }
  }
  else {
    Setpoint = Setpoint;
  }
  return(Setpoint);
}

Is it better to avoid statics? If so why?

Thanks in advance,
Koen


texts:
I'm using mthreads (https://github.com/jlamothe/mthread) for my arduino. But now as the project is getting bigger, it would make sense to break it up in several files.

I successfully outsourced already a part which is not threaded. But somehow I cannot make up my mind how to use mthread in conjunction with several header files.

here is what I got:

main: call header:

#include "tcan.h"

tcan.h:

#ifndef tcan_h
#define tcan_h

#include "Arduino.h"

class tcan : public Thread {
  public: tcan();
  protected: bool loop();
  private:
};
#endif

tcan.cpp

#include "Arduino.h"
#include "tcan.h"
#include <mcp_can.h>

bool tcan::loop() {
  // lala
  return true;
}

but I get an error when compiling:

  tcan.h:6:28: error: expected class-name before '{' token  class tcan :
  public Thread {

Thanks in advance


texts: How to fix this code so instead of having to hold button to change led, you can press?

texts:
const int buttonPin = 1; // the pin number of the pushbutton input pin
const int ledPins[] = {2, 3, 4, 5, 10, 11, 12, 13};    // variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonPressCount = 0;
int numberOfLED = 8;

void setup() {    // initialize the LED pin as an output:
  for (int i = 0; i < numberOfLED; i++) {
    pinMode(ledPins[i], OUTPUT);
  }
  pinMode(buttonPin, INPUT);
}

void loop() {    // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);    // check if the pushbutton is pressed.    // if it is, the buttonState is HIGH:
  if (buttonState  == HIGH) {
    for (int i = 0; i < numberOfLED; i++) {
      if (buttonPressCount % numberOfLED == i)
        digitalWrite(ledPins[i], HIGH);  // turn LED on
      else
        digitalWrite(ledPins[i], LOW);   // turn LED off
    }
  }
  buttonPressCount++;
  delay(300);
}


texts: How can I concatenate these two values as a string?

texts:
I've tried all the supposed solutions for the exact error, pasted into google, that I could find on every forum including this one and no matter the alleged solution I will either get the error about unsigned int to char*, the error below, or invalid pointers.

Why is this platform so completely unfriendly in data type conversion? It's almost as if the creator/s never wanted any data types to be able convert.

Here's my code that is apparently useless:

  char* DeviceName = "Device-" +  ESP.getChipId();
  wifiManager.autoConnect(DeviceName);

Error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
   char* DeviceName = "Device-" +  ESP.getChipId();

Then I tried to use the pointers, but I have no idea what I'm doing and I keep getting invalid pointer errors, and/or invalid conversion errors.


texts: Error:expected declaration before { token. (Havent i already declared it?)

texts:
I'm getting the error message:

sketch_dec31d.ino: In function 'void setup()':
sketch_dec31d:20: error: expected unqualified-id before '.' token
sketch_dec31d.ino: In function 'void loop()':
sketch_dec31d:29: error: expected primary-expression before '.' token
sketch_dec31d:31: error: expected primary-expression before '.' token
sketch_dec31d:33: error: expected primary-expression before '.' token
sketch_dec31d:43: error: expected primary-expression before '.' token

This is the code:

#include <dht.h>     // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11
#define DHT11_PIN 2

// Initialize DHT sensor for normal 16mhz Arduino

String TextForSms ;
String humidity = " Humidity: %";
String temperature = "   Temperature";
String sign = " *C";

char fromc; // character from computer

void setup() {
  Serial.begin(9600);
 // Serial.println("DHT11 test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  int h = dht.readHumidity();
  // Read temperature as Celsius
  int t = dht.readTemperature();
  // Read temperature as Fahrenheit
  int f = dht.readTemperature(true);

  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

  // Compute heat index
  // Must send in temp in Fahrenheit!
  int hi = dht.computeHeatIndex(f, h);

   TextForSms = TextForSms + t + "," + h + ",";
Serial.println(TextForSms);
     TextForSms = "";
   delay(1000);

}


texts: Creating Sine wave with DAC and feeding it back

texts:
I want to produce Digital Sine wave send it to DAC0 and then receive it back as input on A0 and plot the graph. I am using Arduino Due. I wrote the following code:

#define maxSamplesNum 120
#define Sample 50000000/maxSamplesNum  // sample for the 50Hz signal expressed in microseconds

static int Table[maxSamplesNum] =                        // lookup table  for sine wave table

  {
    0x7ff, 0x86a, 0x8d5, 0x93f, 0x9a9, 0xa11, 0xa78, 0xadd, 0xb40, 0xba1,
    0xbff, 0xc5a, 0xcb2, 0xd08, 0xd59, 0xda7, 0xdf1, 0xe36, 0xe77, 0xeb4,
    0xeec, 0xf1f, 0xf4d, 0xf77, 0xf9a, 0xfb9, 0xfd2, 0xfe5, 0xff3, 0xffc,
    0xfff, 0xffc, 0xff3, 0xfe5, 0xfd2, 0xfb9, 0xf9a, 0xf77, 0xf4d, 0xf1f,
    0xeec, 0xeb4, 0xe77, 0xe36, 0xdf1, 0xda7, 0xd59, 0xd08, 0xcb2, 0xc5a,
    0xbff, 0xba1, 0xb40, 0xadd, 0xa78, 0xa11, 0x9a9, 0x93f, 0x8d5, 0x86a,
    0x7ff, 0x794, 0x729, 0x6bf, 0x655, 0x5ed, 0x586, 0x521, 0x4be, 0x45d,
    0x3ff, 0x3a4, 0x34c, 0x2f6, 0x2a5, 0x257, 0x20d, 0x1c8, 0x187, 0x14a,
    0x112, 0xdf, 0xb1, 0x87, 0x64, 0x45, 0x2c, 0x19, 0xb, 0x2,
    0x0, 0x2, 0xb, 0x19, 0x2c, 0x45, 0x64, 0x87, 0xb1, 0xdf,
    0x112, 0x14a, 0x187, 0x1c8, 0x20d, 0x257, 0x2a5, 0x2f6, 0x34c, 0x3a4,
    0x3ff, 0x45d, 0x4be, 0x521, 0x586, 0x5ed, 0x655, 0x6bf, 0x729, 0x794
  };

int i = 0;
int sample;
int sensorPin = A0;
int sensorValue = 0;

void setup() {
  Serial.begin(9600);
  analogWriteResolution(12);  // set the analog output resolution to 12 bit (4096 levels)
  analogReadResolution(12);   // set the analog input resolution to 12 bit

}

void loop() {

  sample = 50;

  analogWrite(DAC0, Table[i]);  // write the selected waveform on DAC0

  i++;
  if(i == maxSamplesNum)  // Reset the counter to repeat the wave
    i = 0;

  delayMicroseconds(sample);  // Hold the sample value for the sample time
  sensorValue = analogRead(sensorPin);
}

I want to create 3.3V (P-P) sine wave but I don't how to set the amplitude in this wave.

Also I would like to redirect the sine wave output from DAC0 to A0 Pin and plot the graph to check if the sine wave generated was successful.
How do I plot the graph ?

Update : I uploaded the program but there was no result. I tried to read data from A0 but there wasn't any output. What am I doing wrong ?


texts: 3v3 ESP one way communication with 5 V Arduino?

texts:
Perhaps I'm not fully understanding a difference between logic level and the function of the TX and RX pins? I'm just wondering if an ESP can send, one-way, data to an Arduino. (I found that two-way communication would need a logic level converter.)
ESP32 Datasheet

https://www.espressif.com/sites/default/files/documentation/esp32_datasheet_en.pdf#page=42

Arduino datasheets do not appear to specify logic level tolerances. It appears from this Arduino Forum post, it would work.
Is it universally assumed that 3v3 will be in tolerance for logic high?

https://learn.sparkfun.com/tutorials/logic-levels/all


texts: I have a tv remote that I want to connect to an Arduino so that I can send a series of commands to the TV using the remote.  I would like to open the remote and solder transistors or a Transistor Array in place of the buttons.  I have never done this before, so what do I need to be aware of?  I think that I will need to power the remote using the Arduino's power supply, but I am a bit foggy on the details.


texts: Digital Potentiometer (TPL0501) Control Issues

texts:
I'm using SPI library in my code for controlling a digital potentiometer (TPL0501) with Arduino Mega.

The code I have is:

#include <SPI.h>
byte address = 0x80;
const int CS = 53;
int SCLK = 52;
int i=0;

void setup()
{
  SPI.begin();
  pinMode (CS, OUTPUT);
  pinMode (SCLK, OUTPUT);
  SPI.setBitOrder(MSBFIRST);

}

void loop()
{

     for (i = 0; i < 256; i++)
    {
      digitalPotWrite(i);
      delay(100);
    }

    delay(5000);
    for (i = 255; i >= 0; --i)
    {
      digitalPotWrite(i);
      delay(100);
    }
}

int digitalPotWrite(int value)
{
  digitalWrite(CS, LOW);
  delay(100);
  SPI.transfer(address);
  SPI.transfer(value);
  delay(100);
  digitalWrite(CS, HIGH);

}

Following the datasheet, I think the code is correct because this is what the datasheet says:

Can someone help me identify the error in my code, if any, because when I try to read the resistance with an ohmeter, I do not get the expected values.


texts: Unplanned behavior with two power sources

texts:
I'm trying to control this servo, and whenever I leave the Uno connected, via USB, to the PC, most of the time the servo barely moves, and sometimes jitters.

simulate this circuit – Schematic created using CircuitLab

I connected the oscilloscope to try to understand / solve my problem, and I see that the signal I send is the same whether or not the USB is connected. I measured the voltage over the 5V/GND and it's constant at 5V and doesn't dip/spikes. I tried with a pull-down resistor on the signal pin (don't know if it's a good idea) and it doesn't change anything.

If I unplug the battery, but keep the USB connected, the servo stays immobile, but I figure that's because the Arduino can't feed a servo, hence why I wanted to use an external power for it. The second power source is a PowerBoost 1000C with a LiPo battery.

As soon as I unplug the USB port, the servo just starts moving properly, so I figured it must be interference of some kind. I saw the accepted answer to this question and it has me doubt whether I should use a battery while it's plugged in, but surely there is a way. Would I kind of need to connect the GND of my circuit to the GND wire of the USB before it actually enters the Arduino?

I didn't post the code as it's basically just the swipe demo from the website, and because it works when on battery only.

Regards


texts: If Arduino connected to computer and opened up Serial Monitor, will Tx and Rx pin still be working?

texts: Suppose one connected two of the Arduino Uno boards through Rx and Tx pins. Then, if one or both of the Arduino boards were connected to computer, and possibly opened up Serial Monitors, will Tx and Rx pin still be working? i.e. will Arduino still communicate through Rx and Tx pin when it's communicating to computer? If not how to make them working while connect to computer?


texts: Ultrasonic sensor and ledstrip color problem

texts:
So I've made a parking sensor with the Ultrasonic sensor and a ledstrip. But the ledstrip doesn't turn yellow or green. I think it has to do with the Thresholds. Can anyone help me to set this up? I also want a longer distance greater than 1 meter. This is my code:

#include "FastLED.h"
 #include <math.h>

    #define NUM_LEDS 32
    #define BRIGHTNESS 10
    #define DATA_PIN 4

    // Define the array of leds
    CRGB leds[NUM_LEDS];

    // Module Pins
    #define trigPin 11
    #define echoPin 12

    // Thresholds (in CM)
    long SECTION_SIZE = 80;
    long STOP_DISTANCE = 60;
    long WARNING_THRESHOLD = 50;
    long MAX_THRESHOLD = 375;

    long RED_THRESHOLD = STOP_DISTANCE;
    long YELLOW_THRESHOLD = RED_THRESHOLD + SECTION_SIZE;
    long GREEN_THRESHOLD = YELLOW_THRESHOLD + SECTION_SIZE;

    const int numReadings = 5;

    int readings[numReadings];      // the readings from the analog input
    int readIndex = 0;              // the index of the current reading
    int total = 0;                  // the running total
    int average = 0;                // the average

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

      FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
      FastLED.setBrightness(10);

      // HC-SR04 Setup
      pinMode(trigPin, OUTPUT);
      pinMode(echoPin, INPUT);

      // initialize all the readings to 0:
      for (int thisReading = 0; thisReading < numReadings; thisReading++) {
        readings[thisReading] = 0;
      }
    }

    void loop() {
      long distance, lastRun;
      bool red, yellow, green;
      total = total - readings[readIndex];
      readings[readIndex] = calculateDistance();
      total = total + readings[readIndex];

      readIndex++;
      if (readIndex >= numReadings) readIndex = 0;

      distance = abs(total / numReadings);

      yellow = distance <= YELLOW_THRESHOLD && distance > RED_THRESHOLD;
      red = distance <= RED_THRESHOLD;
      green = distance > YELLOW_THRESHOLD && distance <= GREEN_THRESHOLD;

      if (red) {
        setRed();
      } else if (yellow) {
        setYellow(distance);
      } else if (green) {
        setGreen(distance);
      } else {
        setGreenStandby();
      }

      Serial.print(distance);
      Serial.println(" cm");
      FastLED.show();
      delay(1);
    }

    void lightItUp(const CRGB& pColor, const CRGB& sColor, uint16_t travel) {
      uint16_t travelFix = travel * (NUM_LEDS/SECTION_SIZE);
      uint16_t leftStop = travelFix/2;
      uint16_t rightStop = NUM_LEDS - leftStop;
      for (int i = 0; i < NUM_LEDS; i++) {
        if (i < leftStop || i > rightStop) {
          leds[i] = pColor;
        } else {
          leds[i] = sColor;
        }
      }

      FastLED.show();
    }

    long calculateDistance() {
      long duration;
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);

      duration = pulseIn(echoPin, HIGH);
      return (duration/2) / 29.1;
    }

    void setGreenStandby() {
      return fill_solid(leds, NUM_LEDS, CRGB::Black);
    }

    void setRed() {
      return fill_solid(leds, NUM_LEDS, CRGB::Red);
    }

    void setGreen(long distance) {
      long travel = GREEN_THRESHOLD - distance;
      return lightItUp(CRGB::Yellow, CRGB::Green, travel);
    }

    void setYellow(long distance) {
      long travel = YELLOW_THRESHOLD - distance;
      return lightItUp(CRGB::Red, CRGB::Yellow, travel);
    }


texts: Using Rx and Tx pins(0 and 1) on Arduino Uno for GSM

texts: I am using a GSM module sim800. My module responds to the output given by my PIR sensor and sends sms according to it. My module has got +5V, GND, Rx and Tx pins. What are the pin connections that I have to make?


texts: My ESP8266 01 is saying at espcomm_sync failed, espcomm_open failed, and (2x) espcomm_upload_mem failed. OS X

texts:
I'm extremely frustrated at my ESP8266 right now, with the Arduino. I am using a 6v DC battery power supply (4xAA batteries), and a 3.3v voltage regulator (NTE1904). I have the connections as shown:

Vcc - 3.3v rail
CH_PD - 3.3v rail
RST - 3.3v rail (I put it into GND when I need to reset)
GPIO 0 - GND (I momentarily put the reset in ground after)
TXD - Rx
RXD - Tx

I have the 6V from the 4xAA batteries into the Vin of the 3.3V voltage reulgator, it's ground to the ground of batteries (and therefore connected to Arduino), and the output connected to the 3.3v rail.

I had the circuit working before, and I had it not receiving a packet header, but when I resembled the circuit fully I am now getting these errors when uploading my code:

Sketch uses 232778 bytes (53%) of program storage space. Maximum is 434160 bytes.
Global variables use 31981 bytes (39%) of dynamic memory, leaving 49939 bytes for local variables. Maximum is 81920 bytes.
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
error: espcomm_upload_mem failed

I've tried a bunch, and I am not sure where my problem is. Note:

I have changed my platform.txt (Arduino15/packages/.../esp8266/2.2.0/platform.txt)'s tools.esptool.upload.pattern to: tools.esptool.upload.pattern="{path}/{cmd}" {upload.verbose} -cd {upload.resetmethod} -cb {upload.speed} -cp "{serial.port}" -ca 0x00000 -cf "{build.path}/{build.project_name}.bin" (or have I? It seems quite unorganized I've changed it in the past from a tutorial saying that esptool doesn't work properly on OS X, but the page is quite hard to locate again. Please tell me what you use currently)

Again, I am on OS X (10.11.4)

Thank you for any help. It is extremely frustrating trying to get this, and I cannot seem to find any up-to-date tutorials with my problem. If you know anything I could try, that would be great.


texts: Can you save data to heap section in Arduino memory?

texts: On normal computers, heap will be cleaned as you close the program, but can I save data to Arduino's heap with malloc function. And will it be cleaned after I power off the Arduino?


texts: Attiny85 with 433 mhz rf, worked fine nano to nano, not attiny85 to nano

texts:
Before downvoting or discarding the question, I have checked other questions which are of similar nature, but they use different library.
So I am creating a signal message using rf module 433mhz. I know you guys might have seen similar post.
I have read many posts but cant make things working.
receiver code on arduino nano :
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
// driver(speed not to mess with that , receive pin , transmit pin , push to talk )
RH_ASK driver(2000, 2,4,5);
// RH_ASK driver(2000, 4, 5, 0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS

void setup()
{
#ifdef RH_HAVE_SERIAL
    Serial.begin(9600);   // Debugging only
#endif
    if (!driver.init())
#ifdef RH_HAVE_SERIAL
         Serial.println("init failed");
#else
    ;
#endif
}

void loop()
{
    uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
    uint8_t buflen = sizeof(buf);

    if (driver.recv(buf, &buflen)) // Non-blocking
    {
//  int i;

    // Message with a good checksum received, dump it.
//  driver.printBuffer("Got:", buf, buflen);

    String rcv;

    for (int i =0; i < buflen; i++) {
        rcv += (char)buf[i];
    }
    Serial.println(rcv);
    } else {
    Serial.println("else");
    Serial.println((char)buf[0],buflen);
    delay(1000);
    }
}

transmitter code :
#include <RH_ASK.h>
#ifdef RH_HAVE_HARDWARE_SPI
#include <SPI.h> // Not actually used but needed to compile
#endif
// driver(speed not to mess with that , receive pin , transmit pin , push to talk )
RH_ASK driver(2000, 5,3,0); // ESP8266 or ESP32: do not use pin 11 or 2
// RH_ASK driver(2000, 3, 4, 0); // ATTiny, RX on D3 (pin 2 on attiny85) TX on D4 (pin 3 on attiny85),
// RH_ASK driver(2000, PD14, PD13, 0); STM32F4 Discovery: see tx and rx on Orange and Red LEDS

void setup()
{

#ifdef RH_HAVE_SERIAL
    Serial.begin(9600);    // Debugging only
#endif
    if (!driver.init())
#ifdef RH_HAVE_SERIAL
         Serial.println("init failed");
#else
  ;
#endif
//pinMode(4, OUTPUT);
}

void loop()
{
    const char *msg = "higgh";
    driver.send((uint8_t *)msg, strlen(msg));
    driver.waitPacketSent();
    delay(1000);
//    digitalWrite(4, HIGH);   // turn the LED on (HIGH is the voltage level)
//    delay(1000);                       // wait for a second
//    digitalWrite(4, LOW);
}

Its working if i use another arduino nano as transmitter but not with attiny85.
I am able to make blink successfully run with attiny85 . so adding code to attiny85 is fine i guess.
Also i am using 3 , which is pin 2 for attiny85
I even changed 5v to attiny85 to 3 v ish still didnt work


texts: Saving Arduino output to a text file in append mode

texts:
I used the code below to save output from an Arduino Uno to a text file.

The problem is whenever I run the code the old data in the text file is deleted.

I don't want the old data to be deleted, what should I change?

import processing.serial.*;
Serial mySerial;
PrintWriter output;
void setup() {
   mySerial = new Serial( this, Serial.list()[0], 9600 );
   output = createWriter( "data.txt" );
}
void draw() {
    if (mySerial.available() > 0 ) {
         String value = mySerial.readString();
         if ( value != null ) {
              output.println( value );
         }
    }
}

void keyPressed() {
    output.flush();  // Writes the remaining data to the file
    output.close();  // Finishes the file
    exit();  // Stops the program
}


texts: Arduino pro mini not compiling after changing fuse to 128khz

texts:
I used Arduino UNO as ISP to change the fuse setting of Arduino Pro Mini. Using avrdude cmd, I successfully changed it to 8MHz setting. Due to curiosity, I decided to try changing it to 128kHz. But that ends up me being unable to further program it. The Pro Mini still works but just cant change fuse through avrdude cmd, burn bootloader and upload. Does 128kHz really leave atmega328p like that?

On one computer, the below error appears.

avrdude: stk500_recv(): programmer is not responding

On another computer, the below error appears

avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check
Wrong microcontroller found. Did you select the right board from the Tools > Board menu?

There are actually more errors because I trial and error different ways to solve it, i.e Nick Rammon's Atmega_Board_Programmer, cmd command with varying parameters (baud rate, programmer), inserting capacitor on UNO. But I dont remember every one of them because the not in sync:resp=0x.. differs from time to time

There is one method which I have not try, high voltage programming mode. I would try it out if it was detachable but atmega328p on Pro Mini is SMD. Is it possible to high voltage program on Pro Mini? Ultimately I am stuck.

Ignoring what I have done, I would once again like to try out every method you guys recommend. Hopefully everything can be step by step and the thing I want to know most is the setting of 'Board', 'Processor' and 'Programmer' in Tools.

I would give my best response possible to you guys who is willing to help me out. Thank you


texts:
I am trying to use the CMDmessanger library on my Arduino uno, and am facing an issue.

My issue starts right from the ArduinoController.ino example.

When i send the frequency command

3,1;

The led starts blinking correctly, once per second.

But when I send a wrong command (basically a command without an argument)

3;

The led just stops blinking. The state of the led depends on which state it was in when I sent the command.

I realised that, when I send the wrongly formatted command, it takes the frequency as 0.

Is there any method by which I can make sure that the command is received in the right format, before it is executed? Ideally I would love it if there is a method to know how many arguments were received, and I could call the readBoolArg, or other equivalent functions to retrieve the argument data.

I am planning on using this library for quite a few projects, and I don't want to be in a situation where things went wrong because there was not formatting check.

Thanks in advance.


texts: Adafruit v2.3 Motor Shield Initialization Failure

texts:
I would appreciate any help solving this as I have spent several hours trying to debug. My code seems to stop when I get to the initialization of the motor shield.

motorShield.begin();

#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <LiquidCrystal.h>

//CREATE LCD OBJECTm
LiquidCrystal lcd = LiquidCrystal(2, 3, 4, 5, 6, 7);

//CREATE MOTOR SHIELD OBJECT
Adafruit_MotorShield motorShield = Adafruit_MotorShield();

//SET MOTOR VALUES
Adafruit_DCMotor *frontRight = motorShield.getMotor(1);
/*Adafruit_DCMotor *rearRight = motorShield.getMotor(2);
Adafruit_DCMotor *frontLeft = motorShield.getMotor(3);
Adafruit_DCMotor *rearLeft = motorShield.getMotor(4);*/

//DEFINE SENSORS
#define centerTrigPin A2
#define centerEchoPin A3

//DEFINE SENSOR VALUES
long centerDuration; // Variable for the duration of sound wave travel
int centerDistance; // Variable for the distance measurement

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

  lcd.begin(16, 2); //Set LCD dimensions

  //motorShield.begin();

  //frontRight->setSpeed(50);
  /*rearRight->setSpeed(50);
  frontLeft->setSpeed(50);
  rearLeft->setSpeed(50);*/

  //frontRight->run(RELEASE);
  /*rearRight->run(RELEASE);
  frontLeft->run(RELEASE);
  rearLeft->run(RELEASE);*/

  pinMode(centerEchoPin, INPUT);
  pinMode(centerTrigPin, OUTPUT);
}
void loop() {
  //GET CENTER SENSOR
  digitalWrite(centerTrigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(centerTrigPin, HIGH);
  delayMicroseconds(10);
  centerDuration = pulseIn(centerEchoPin, HIGH);
  centerDistance = centerDuration * 0.034 / 2;

  if (centerDistance <= 10){
    //SERIAL OUTPUT
    Serial.print("OBJECT: ");
    Serial.print(centerDistance);
    Serial.println(" cm");

    //LCD OUTPUT
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("OBJECT");
  }else{
    //SERIAL OUTPUT
    Serial.print("DRIVE: ");
    Serial.print(centerDistance);
    Serial.println(" cm");

    //LCD OUTPUT
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("DRIVE");
  }//End Forward/Reverse Check
}//End loop


texts: How can I power an ESP8266 using a 9V 1A barrel connector power supply?

texts:
I have a Huzzah Feather ESP8266 (pinout) and due to the requirements of my project, I need to supply it with a 9V power adapter with a barrel connector, such as this one.  I'm REALLY new to all of this, so I am trying to figure out how to do this and understand reading dev board specs.

It looks like this development board has a regulator that will adjust a power source down to the appropriate voltage...  but how do I know what parameters it allows?

If I'm understanding correctly, on the pinout sheet above it looks like I would connect a power supply to the "VBUS" and "GND" (right?) pins.  It also says "500mA Max", so does that mean a 1A power supply won't work?  Also, why wouldn't it specify a maximum voltage?

If just connecting a barrel connector to those pins will not work, what am I missing that would get me there?


texts: Noise on piezo analog read due to Arduino power supply

texts:
I am making a device that measures temperature and vibrations and records the values onto an SD card. It will be a standalone device.

The hardware used:
- Arduino Uno
- PCF8523 RTC clock
- MAX3186 + PT100 RTD temperature sensor
- Adafruit data logger shield
- Typical bare piezo sensor

For the vibrations, a piezo sensor is used. Because it can produce a signal in two directions, I decided to use a voltage divider to offset the signal from GND. Two 5.1K resistors are connected from the piezo negative terminal to 5V and GND. A 1M resistor is placed in parallel with the piezo sensor. The positive terminal is connector to analog input 0.

The sensor is read 100 times per data point, the maximum and minimum values are stored and the final value is set to be the difference between the two (two times the amplitude).

USB

9V wall adapter

When the system is powered via a laptop USB port, the resting value has a jitter of a few bits. When a 9V wall adapter powers the arduino, the jitter is +/- 30 bits. Any small vibrations disappear in the noise.

USB with piezo

9V with piezo

9V without piezo

I would like some help to find the best way forward.

edit 29-10 17:53 Added better plots

edit 30-10 17:53 Added plots for 2.5V and 3.3V lines


texts:
The following code operates in a way that LED starts to flash only if the pushbutton is pushed for one second. I want to change this and make the LED flash for 5 times, immediately on push, regardless if the button is held "long" or released immediately. Can anyone help me out with this? I'm using the LC_baseTools library btw. I managed to do this with another library with doFlash(5) but I have to work with LC basetools in this scenario and I can't figure out how to do it.
#include <mechButton.h>
#include <blinker.h>

#define BUTTON_PIN   11
#define LED_PIN      13
#define BLINK_MS     500.0
#define HOLD_MS      1000

mechButton  theButton(BUTTON_PIN);                    // A debounced button object. (Hook button between pin & ground)
blinker     theBlinker(LED_PIN,BLINK_MS/2,BLINK_MS);  // A fire and forget blinker object.
timeObj     pushTimer(HOLD_MS);                       // A timer object

void setup(void) {
   theBlinker.setOnOff(false);            // Make sure the blinker is acutally off.
   theButton.setCallback(btnClicked);     // Set the callback for the button.
}

// This gets called when the button is clicked.
void btnClicked(void) {
   if (!theButton.trueFalse()) {    // If it has been grounded..
      pushTimer.start();            // Start the timer.
      theBlinker.setPercent(100);   // Set the blinker to full on.
      theBlinker.setOnOff(true);    // Fire it up.
   } else {                         // Else, button released..
      theBlinker.setOnOff(false);   // SHut off the blinker.
   }
}

void loop(void) {
   idle();                             // idle runs the stuff in the background (button & binker)
   if (!theButton.trueFalse()) {       // If the button is currently pressed..
      if (pushTimer.ding()) {          // If the timer has expired..
         theBlinker.setPercent(50);    // Start blinking!
      }
   }
}


texts: How do you send data via I2C without the wire library?

texts:
I have the following digital potentiometer: DS1803-100 which, according to the datasheet, can be controlled using a two-wire serial interface. I have managed to get it working using Wire, however I can't seem to get it working using only digitalWrite (link to code). Can somebody tell me why? For reference, 0x50 is the address + r/!w bit, 0xA9 is the command (write to pot 0 in my case) and the next 0xA9 is the value to write. I know there's something wrong with the code, however I cannot figure out what. Thank you in advance!

EDIT: Here is the code

int PIN_SCK = 12;
int PIN_SDA = 11;

const int delayvalue = 10;

void setup(){
    digitalWrite(PIN_SCK, 1); // I can first declare the state
    digitalWrite(PIN_SDA, 1);
    pinMode(PIN_SCK, OUTPUT); // then turn them on
    pinMode(PIN_SDA, OUTPUT);

    delay(1000);

    digitalWrite(PIN_SDA, 0); // start bit

    shift_out(PIN_SDA, PIN_SCK, 0x50);
    shift_out(PIN_SDA, PIN_SCK, 0xA9);
    shift_out(PIN_SDA, PIN_SCK, 0xA9);

    digitalWrite(PIN_SDA, 1); // stop bit

}

void loop(){

}
// uint8_t is the same as 8 bits aka one byte
void shift_out(uint8_t datapin, uint8_t clockpin, uint8_t val){
    uint8_t i;

    for (i = 0; i < 8; i++)  {
        digitalWrite(datapin, !!(val & (1 << (7 - i))));
        delay(1);
        digitalWrite(clockpin, 0);
        delay(delayvalue);
        digitalWrite(clockpin, 1);
        delay(delayvalue);
    }

    digitalWrite(datapin, 0); // to enable stop bit
    delay(100); // wait fro aknowledgement

}


texts: Arduino Smoothing does not work as expected

texts:
I using the standard example of smoothing:

/*
  Smoothing

  Reads repeatedly from an analog input, calculating a running average and
  printing it to the computer. Keeps ten readings in an array and continually
  averages them.

  The circuit:
  - analog sensor (potentiometer will do) attached to analog input 0

  created 22 Apr 2007
  by David A. Mellis  <dam@mellis.org>
  modified 9 Apr 2012
  by Tom Igoe

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/Smoothing
*/

// Define the number of samples to keep track of. The higher the number, the
// more the readings will be smoothed, but the slower the output will respond to
// the input. Using a constant rather than a normal variable lets us use this
// value to determine the size of the readings array.
const int numReadings = 10;

int readings[numReadings];      // the readings from the analog input
int readIndex = 0;              // the index of the current reading
int total = 0;                  // the running total
int average = 0;                // the average

int inputPin = A0;

void setup() {
  // initialize serial communication with computer:
  Serial.begin(9600);
  // initialize all the readings to 0:
  for (int thisReading = 0; thisReading < numReadings; thisReading++) {
    readings[thisReading] = 0;
  }
}

void loop() {
  // subtract the last reading:
  total = total - readings[readIndex];
  // read from the sensor:
  readings[readIndex] = analogRead(inputPin);
  // add the reading to the total:
  total = total + readings[readIndex];
  // advance to the next position in the array:
  readIndex = readIndex + 1;

  // if we're at the end of the array...
  if (readIndex >= numReadings) {
    // ...wrap around to the beginning:
    readIndex = 0;
  }

  // calculate the average:
  average = total / numReadings;
  // send it to the computer as ASCII digits
  Serial.println(average);
  delay(1);        // delay in between reads for stability
}

to calculate power consumption for a load which changes it's value frequently (sometimes it stops and the consumption goes down to couple of watts).

My only modification of the above code is to pass a calculated power (V*I) value to it instead of the analogRead(inputPin);. The input value for the power calculation works fine because without this code I get the exact good values for power. I have also increased the numreadings from 10->100 and probably will needed to be increased a lot more since I need the average for 1 minute.

There are 2 major issues with this code:

1, When a constant load is attached, which let's say draws 500W the value generated by the code is floating around 312W and never reaches 500.

2, When the load is disconnected it and the current power consumption is 1-2watts standby this code jumps to -312W. I could cast it to be an unsigned integer on the first place but that's not really a good solution.

Anyone knows how to fix this?

Thanks


texts: Split up Arduino code into multiple files using Arduino IDE

texts:
I am working on a very long code that requires multiple functions defined. I want to split the code into two files as main code ("Feeder_Control" in the screenshot) and functions ("connections" in the screenshot) How to import the second file into main code to use its functions?

PS: In C/C++ same thing is done with #include "connections.h". How is it done in Arduino IDE.

.


texts: How to build a high-frequency (>20kHz) driver for LEDs?

texts:
I'd like to build a LED lighting for my house. I've made preliminary tests and I've realized that my 12V transformer emits a considerable electric hum at the Arduino's PWM frequency range (PWM signal from Arduino gets amplified by external amplifier powered by the transformer).

I know, that I can reduce the audible noise if I will drive the PWM at higher frequency, beyond the human ear's audible range.

AFAIK Arduino itself is not able to give me 8-bit PWM at the >20kHz range. Do you know any feasible hardware high frequency PWMs that will work with the Arduino?


texts: Removing Element From Array While Keeping Order

texts:
I'm building a wireless mechanical keyboard. There is an array of 6 elements that stores the keys pressed by the user (since 6 is the max number of keys you can send at once over Bluetooth). An example would be 02-05-03-00-00-00. Notice the "00" at the end, these are just "placeholders" and don't have a meaning other than to indicate that there are no more keys pressed. When the user releases key 05 for example, the array should become this 02-03-00-00-00-00. I don't know how to do this however, since you can't just remove and item from an array and there doesn't seem to be a polished option for lists in Arduino.

Does anyone have any idea for an algorithm that finds the 0's in an array, places them at the end of the array and keeps the order of the other elements?


texts:
Last night I had my arduino connected to pc and mc connected to 9 volts in the same time then today I tried to connect my arduino to pc and i removed any connection i just wanted to display a string it i used this code

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

   void loop() {

    Serial.print("NO FORMAT");
     }

its not showing anything in serial montor I tried to blink led no output still

And  i have another arduino i used the same code it showing the message in serial monitor is my previous board broken ? thank you for help when i tried to click the reset button in arduino the orang led built in is not blinking


texts: Error compiling for board Arduino Uno SIM7000

texts:
I'm using  botletics / SIM7000-LTE-Shield with Arduino Uno, I selected all examples but all end up with the same Error
C:\Users\lenovo\Documents\Arduino\libraries\SIM7000\Adafruit_FONA.cpp: In member function 'boolean Adafruit_FONA::postData(const char*, uint16_t, const char*, const char*, const char*)':
C:\Users\lenovo\Documents\Arduino\libraries\SIM7000\Adafruit_FONA.cpp:2045:3: error: expected ';' before 'readline'
readline(10000);
^~~~~~~~
exit status 1
Error compiling for board Arduino Uno.


texts: How to send string over bluetooth LE from Arduino

texts:
How do you send a string over BLE from Arduino? (and is it any different for an Adafruit Feather 32u4?)

Background: I have force sensitive resistor (fsr) sending an Int value. I would like to convert it to a string (or char or whatever it needs to be) and send it via BLE to an app.

Update:
I was able to successfully send the string via BLE by simply using ble.println(); on my Adafruit Feather 32u4. I have learned that the ble. method inherits commands similar to the Serial.print methods. I used ble.println() to send a string, as opposed to using ble.write() which send data as bytes. I also learned that different hardware devices have different names for this method, such as BTLEserial.write, as well as other names specific to each device. Hopefully, this info helps other people figuring this out, too.


texts: Store value in EEPROM to perform different actions on reset?

texts:
I want the same button to wake up (reset) and put it to sleep but this is hard if the button is tied directly to the rst pin. My thought was to read and store a value in EEPROM so tell the chip what mode we were in so it can perform the counter action. For example, on RST if the value is 0 the chip should wake up and do things. It would then set the value to 1. If the button is pressed again, the chip resets, reads there is a 1 and now just puts the chip into deep sleep after setting the value back to 0. Rinse, repeat.

Does this make sense? Will this work? Is there a better/easier way?


texts: How to properly construct objects on ATmega2056?

texts:
I was wondering the correct method to construct objects for use in the setup and loop scopes. I tried working constructing in the global scope, but I get garbage values printed to serial (probably from misusing pointers)? If I use the new keyword, then it works, but I heard that that is not best practice.

I is there a better way I should do this?

// navigator.cpp

#include "navigator.h"

Navigator::begin(Waypoint* w, int count) {
  waypoints = w;
  pointCount = count;
  next = 0;                               // start with first waypoint
  course = 90;                          // Notice that initial course is due East

  Serial.println('here');
}

-

// navigator.h

#define _navigator_h

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
#endif

struct Waypoint {
  double lat, lon;
};

class Navigator {
public:
  begin(Waypoint* w, int);
};

#endif

-

// TransAt.ino

#include "navigator.h"

Waypoint w = { 43.36, -75.1 };  // These objects must be accessible in both setup() and loop(), but we can't use the new keyword
Navigator nav();                    // That means we have to do a lot of the heavy lifting here

uint32_t timer = millis();

void setup() {
  nav.begin(&w, 1);
}

void loop()
{

}


texts: Adafruit RTC begin() not returning false

texts:
I am programming my arduino with the capability to keep time with the DS3231 from Adafruit. I do not have the module yet, but am trying to figure out the rest of the build without it.

However, it seems like the way to determine RTC is working does not work, as it returns true, even without the module.

Example code from the Adafruit RTC library for using this module:

// Date and time functions using a DS3231 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

RTC_DS3231 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(9600);

  delay(3000); // wait for console opening

  if (! rtc.begin()) { // part that fails. begin() returns true when should return false
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 21, 2014 at 3am you would call:
    // rtc.adjust(DateTime(2014, 1, 21, 3, 0, 0));
  }
}
....


texts: Arduino Stepper Motor Standing Desk help!

texts:
I currently have a standing desk at work, and I thought a fun way to learn Arduino would be to automate it, as it currently uses a hand crank.

I would love some help determining what I would need for this task.

What kind of motor should I use?
  -Stepper motor?
  -High/low rpm?
  -High/low torque?

What sort of power would I need?

Looking forward to hearing people's suggestions!


texts: Mega code not compiling on Wemos Mega board

texts:
Hi I have some code that I'm trying to port from a Mega 2560 R3 to a Wemos Mega.

#include "SoftPWM.h"
#include ESP8266WiFi.h

// Outputs to PWM & H bridge direction
// PWMs:
// DC_pwm, left_pwm, right_pwm = 3, 4, 5
int pwm_out[] = {3, 4, 5};
const int num_pwm = sizeof(pwm_out) / sizeof(pwm_out[0]);

// H bridge direction control:
// dc_1, dc_2, left_1, left_2, right_1, right_2 = 6, 7, 8, 9, 10, 11
int dir_pins[] = {6, 7, 8, 9, 10, 11};
const int num_dir_pins = sizeof(dir_pins) / sizeof(dir_pins[0]);

// Variable for reading pin inputs
int from_r_pi_pwm = 0;
int from_r_pi_dir = 0;

void setup() {

  // Inputs from Raspberry Pi
  Serial.begin(38400);

  // Set up PWM pins
  SoftPWMBegin();
  for (int i = 0; i < num_pwm; i++)
  {
    SoftPWMSet(pwm_out[i], 0);
  }

  // Set up H bridge direction pins
  for (int i = 0; i < num_dir_pins; i++)
  {
    pinMode(dir_pins[i], OUTPUT);
    digitalWrite(dir_pins[i], LOW);
  }
}

void loop() {

  // Check input from R Pi & send it to the H bridges
  while (Serial.available() < 2){}

  if (Serial.available()) {
      // read the incoming bytes:
      from_r_pi_dir = Serial.read();
      from_r_pi_pwm = Serial.read();
      Serial.print("Serial in: directions - ");
      Serial.print(from_r_pi_dir);
      Serial.print(" PWM - ");
      Serial.print(from_r_pi_pwm);
      Serial.println();
  }

  // Set direcions on H bridges
  for (int i = 0; i < num_dir_pins; i++)
  {
    digitalWrite(dir_pins[i], bitRead(from_r_pi_dir, i));
    Serial.print("pin ");
    Serial.print(dir_pins[i]);
    Serial.print(" : ");
    Serial.print(digitalRead(dir_pins[i]));
    Serial.println();
  }

  // PWM to motors
  for (int i = 0; i < num_pwm; i++)
  {
    analogWrite(pwm_out[i], from_r_pi_pwm);
    Serial.print("pin ");
    Serial.print(pwm_out[i]);
    Serial.print(" : ");
    Serial.print(digitalRead(pwm_out[i]));
    Serial.println();
  }
}

This compiles and runs fine on a Mega & is my go to code for setting up pwm & h bridges.

So when I was playing with WiFi I selected the Wemos R1 board from the programmer & everything worked fine but if I try that with this code I get,

#include <avr/io.h>
                    ^
compilation terminated.

exit status 1 Error compiling for board WeMos D1 R1.

So after a bit of searching I found that I should be selecting Arduino/Genuino Mega 2560 but now the upload keeps timing out,

avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_ReceiveMessage(): timeout
avrdude: stk500v2_getsync(): timeout communicating with programmer
An error occurred while uploading the sketch

Anybody come across this before?

Edit #1:  As per the comment below I tried setting DIP switches 1 & 2 ON and all the rest OFF (I also tried 1, 2, 3 & 4 ON and the rest OFF) but still the same compliation error if I select Wemos board.

If I select the Mega 2560 I get ESP8266WiFi.h: No such file or directory which is a new error!


texts: Connecting Seeeduino XIAO 3.3 V out to dual H-bridge driver module (L298N) with TTL compatible inputs

texts:
The H-bridge module uses TTL compatible logic, but the chip allows these values (based on the L298N data sheet):

Symbol
Parameter
Min.
Max.

ViL
Input Low Voltage (pin 5, 7, 10, and 12)
-0.3 V
1.5 V

ViH
Input High Voltage (pin 5, 7, 10, and 12)
2.3 V
VSS

Am I correct to assume that I do not need to step-up the logic signal (from 3.3 V to 5 V) for this to work, but can I connect straight to the input?
Schematic in mind:


texts: LCD from Arduino Starter Kit not displaying text

texts:
I've been tinkering with my new Arduino a bit and I was adding an LCD from the starter kit, using information from the eleventh project in the project book, "Crystal Ball." When I connect the Arduino to my computer, the LCD lights up, but no text is displayed on the screen.

Here are some screenshots of my connections:

Finally, here's the code that I uploaded to the Arduino:

#include <LiquidCrystal.h>

// Create this display with the pins that I wired
LiquidCrystal lcd(12, 11, 2, 3, 4, 5);

void setup()
{
    // This is a 16x2 display
    lcd.begin(16, 2);

    lcd.print("hello!");
}

void loop()
{
}

edit: Additionally, I tried adding a potentiometer to control the display, but to no avail. Below is the wiring for this (back pin goes to the third to last pin for the LCD).


texts:
I have connected arduino nano every to my lcd display. It works perfect when i put all my code in setup() part. But when i put the code in loop() it does werid things. I have to put my code in loop(), because i am reading from load cell and displaying the values that are constantly changing. The delay can't be more than 250 ms.
This works well.
#include <LiquidCrystal.h>
int Contrast=30;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
    analogWrite(6,Contrast);
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);
    lcd.print("testing");
}

void loop(){

 }

When I do this next thing it works well for few seconds and then it starts to display random weird characters and stops displaying anything after some time.
#include <LiquidCrystal.h>
int Contrast=30;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup(){
    analogWrite(6,Contrast);
    lcd.begin(16, 2);
    lcd.setCursor(0, 0);

}

void loop(){

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(millis()/1000);
  delay(250);
 }

I have tried removing lcd.clear() it didn't help.
I thought it was a problem with wiring first, but it's not.
What am I doing wrong?
Any help would be great, thanks.


texts:
I'm an intermediate Arduino progammer, and I'm making an electronic braille display for my friend. You can think of this display as an array of 28x3 LEDs(one braille character contains a maximum of six (2x3 for one letter) dots so there can be 14 characters displayed at a time, including spaces) but actually instead of LEDs, there will be electrical braille cells. This will be the algorithm:

Read string (English alphabet) files from SD card
Count the letters, including spaces, until it becomes 14. Convert them into braille (2x3 for one letter) and then display them (as we will be able to display only 14 letters at a time )
When the user presses the button for the next row/page do the same process(step 2) for the next string.

So this is the complete process I want to do.

I have 5 months deadline to make it. The main problem is how I can make the code to convert and then display it. I know there are already a lot of Arduino libraries out there for displaying stranded English characters, but this is different, because I'm new to Arduino and 'C'.

Instead of losing your mind and saying this site is not for fool people like you, please guide this 17yr old what should I learn in order to make this for my friend who lost his eyesight in an accident(consider I have time of 5 months).

Do I have to build entire new Library for converting alphabet and multiplexing braille? Or is there existing code that will work.


texts:
I have a SG90. I just want it to spin 360° and stop, that's about it. This seems impossible.
I have tried the sweep example:
 by BARRAGAN <http://barraganstudio.com>
 This example code is in the public domain.

 modified 8 Nov 2013
 by Scott Fitzgerald
 http://www.arduino.cc/en/Tutorial/Sweep
*/

#include <Servo.h>

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

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

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

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

This works fine.
I read somewhere that for 360 motors the variable in myservo.write() is actually just the speed. So I tried:
void loop() {
    myservo.write(0);              // tell servo to go to position in variable 'pos'
    delay(2000);                       // waits 15ms for the servo to reach the position
    myservo.write(180);              // tell servo to go to position in variable 'pos'
    delay(2000);
    myservo.write(0);              // tell servo to go to position in variable 'pos'
}

The motor rotates several times then spins the other direction and repeats doing this.
What do I need to do to make it complete 1 rotation and stop?


texts: Accessing struct's variable parametrically on ESP8266

texts:
I have 2 instances of a struct. One has def values stored and second stores values read from a file on SPIFFS.
I'm trying to use a for loop over all struct's variables - if file was read OK and key was found, store its value in final_par else get value from def_par.
For that, I've created keys array - but I can't find a way to iterate, in a for loop
as final_par.keys[i] = def_par.keys[i] - but this is not possible.
How can it be done ?
struct parameters
{
  bool ext_inputs;
  bool auto_relay_off;
  bool useSerial;
  bool useWDT;
  bool useOTA;
  bool useResetKeeper;
  bool useFailNTP;
  bool useDebugLog;
  char deviceTopic[20];
  char groupTopic[20];
  char prefixTopic[20];
  int inputUpPin;
  int inputDownPin;
  int outputUpPin;
  int outputDownPin;
  int inputUpExtPin;
  int inputDownExtPin;
  int auto_relay_off_timeout;
};
char *keys[] = {"ext_inputs", "auto_relay_off", "useSerial", "useWDT", "useOTA", "useResetKeeper",
                "useFailNTP", "useDebugLog", "deviceTopic", "groupTopic", "prefixTopic", "inputUpPin",
                "inputDownPin", "outputUpPin", "outputDownPin", "inputUpExtPin", "inputDownExtPin",
                "auto_relay_off_timeout"};

parameters def_par{false, false, false, true, true, false, true, "devTopic", "noGroup", "myHome", 2, 1, 14, 12, 0, 2, 60};

parameters final_par;


texts: Combining code for multiple sensors in a single program

texts:
I need to operate 3 different sensors (taken 6 sensors of each type) by Arduino Mega2560 :-

DHT11 (temperature-Humidity sensor)
MQ5 (gas sensor) and
Soil Moisture sensor
{taken 6 of each type (total=18).}

I have managed to run each one of them separately and I don't know how to manipulate the code so they could work all together. My background in coding is basic, so it would be great help if someone can help me for combining these codes.

Here are the sketches:

MQ5 Code:

int sensor=7;
int gas_value;
void setup()
{

pinMode(sensor,INPUT);
Serial.begin(9600);

}

void loop()
{

gas_value=digitalRead(sensor);
Serial.println(gas_value);
}

{other digital pins to be used: D6,D5,D4,D3,D2}

DHT11 Code:

#include <dht.h>
#include <dht.h>
#include "dht.h"
#define dht_apin A0 // Analog Pin sensor is connected to
dht DHT;

void setup(){

  Serial.begin(9600);
  delay(500);//Delay to let system boot
  Serial.println("DHT11 Humidity & temperature Sensor\n\n");
  delay(1000);//Wait before accessing Sensor

}//end "setup()"

void loop(){
  //Start of Program

    DHT.read11(dht_apin);

    Serial.print("Current humidity = ");
    Serial.print(DHT.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(DHT.temperature);
    Serial.println("C  ");

    delay(5000);//Wait 5 seconds before accessing sensor again.

  //Fastest should be once every two seconds.

}// end loop()

{analog pins for other sensors: A1,A2,A3,A4,A5}

Soil_Moisture Sensor Code:

int sensor_pin = A6;
int output_value ;

void setup() {

   Serial.begin(9600);
   Serial.println("Reading From the Sensor ...");
   delay(2000);

   }

void loop() {

   output_value= analogRead(sensor_pin);
   output_value = map(output_value,550,0,0,100);
   Serial.print("Mositure : ");
   Serial.print(output_value);
   Serial.println("%");
   delay(1000);
   }

{Analog pins for other sensors to be used: A6,A7,A8,A9,A10}


texts: Simple ESP to ESP reading blink program not reading input voltage

texts:
One ESP32's 3v3 is connected to GPIO 26 of another ESP32.
The program is uploaded. The built-in LED lights for two seconds as expected. Then, it turns off. No matter what GPIO pin the 3v3 is connected to (besides 2), the LED remains off.
/*
 * ON Board LED GPIO 2
 */

#define LED 2
#define inPin 26

void setup()
{
  Serial.begin(9600);
  // Pins 34, 35, 36, 39 are input only
  pinMode(LED, OUTPUT);

  // Sanity check LED works
  digitalWrite(LED, HIGH);
  delay(2000);
}

void loop()
{
  Serial.println(digitalRead(inPin));
  digitalWrite(LED, digitalRead(inPin));
}

Any reason this is happening? Grounds are connected. Simply trying to turn LED on/off if external voltage occurs at any GPIO pin (e.g., 26).


texts: Connect BotBoarduino with servos and Ultrasonic sensor HC-SR04

texts:
I am new to Arduino and I am making a Walking Quadruped using BotBoarduino as microcontroller.
I want to install an Ultrasonic Sensor HC-SR04 so that it will stop when an obstacle is detected.
I have connected the sensor to Arduino UNO. RX-TX of both the boards are cross-connected. Now I have written this code for UNO:

const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;

void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}

void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(100);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance= duration*0.034/2;
  // Prints the distance on the Serial Monitor
  Serial.println(distance);

  delay(200);
}

And I am doing this on BotBoarduino:

int byteRead;

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

void loop() {
  while (Serial.available())
  {
    byteRead = Serial.read();
  }

  if(byteRead >= 10)
  {
    walk();
  }
  else
  {
    stand();
  }
}

Whenever distance = 10 or above, let it walk. Else stop.

But it's not working. It's not stopping on obstacles. Sensor is doing its work perfectly, but I think Botboarduino is not getting the values.

Any idea guyz?


texts: Unable to compare two integer values in Arduino Mega

texts:
I wrote Arduino code (code is given at the end) to compare two integer values. The steps I took was:

Give input to DC motor to rotate it using serial port. Input was: G254
Then I store it in XX string and using XX.remove(0,1); I removed G from G254. XX now become 254
Then I used Serial1.println("P"); to get position of motor after rotation. I stored this value in ZZ string using String  ZZ = Serial1.readString();. ZZ will be P254.
And using XX.remove(0,1); I removed P from P254. ZZ now become 254.
Now, I convert both XX and ZZ into integer from string using  XX.toInt(); ZZ.toInt(); .
After that, I compare both values using:

if (XX == ZZ)
{
    Serial.println("BOTH ARE EQUAL");
}
else
{
    Serial.println("BOTH ARE NOT EQUAL");
}

But it shows BOTH ARE NOT EQUAL which is not true. I want to know where I'm making a mistake?

Code I used:

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

    pinMode(13, OUTPUT);
}

void loop() {
    // put your main code here, to run repeatedly:
    if (Serial.available() > 0)
    {
        Serial1.println(Serial.readString());

        String  XX = Serial1.readString();
        XX.remove(0,1);

        Serial1.println("P");

        String  ZZ = Serial1.readString();
        ZZ.remove(0,1);

        XX.toInt();
        ZZ.toInt();
        Serial.println(ZZ);
        Serial.println(XX);
        Serial.println(typeof(XX));

        if (XX == ZZ)
        {
            Serial.println("BOTH ARE EQUAL");
        }
        else
        {
             Serial.println("BOTH ARE NOT EQUAL");
        }
    }
}

Thanks.


texts: How do I read addresses on multiple DS2413 1-Wire GPIO Breakouts, using the Adafruit sketch?

texts:
I am using three DS2413 1-Wire GPIO Breakouts from Adafruit connected to an ESP8266.  I tested the DS2413
 breakouts using their example sketch and it works fine for just one DS2413.  But I cannot get it to work when 2 or more DS2413s are connected.

Adafruit DS2413 Example Sketch
 https://github.com/adafruit/Adafruit_DS2413/blob/master/DS2413.pde

Adafruit DS2413 Overview
https://learn.adafruit.com/adafruit-1-wire-gpio-breakout-ds2413?view=all

When I connect 2 or more DS2413s, it only blinks the LEDs connected to the 1st breakout and doesn't read the other addresses.

I made some changes to the void setup section and now I am getting the following in the serial monitor. It sees all the addresses, but it is duplicating them and the first set have "No device found on the bus!" at the end. How can I get the sketch to read all the addresses without these errors?

Serial monitor

Looking for a DS2413 on the bus
3A B2 C2 39 00 00 00 8C No device found on the bus!
3A 8E AE 39 00 00 00 2C No device found on the bus!
3A E5 B6 39 00 00 00 55 No device found on the bus!
Found a DS2413: 3A B2 C2 39 00 00 00 8C
Found a DS2413: 3A 8E AE 39 00 00 00 2C
Found a DS2413: 3A E5 B6 39 00 00 00 55

Here is what the code with my changes.

#include <OneWire.h>

#define DS2413_ONEWIRE_PIN  (4)

#define DS2413_FAMILY_ID    0x3A
#define DS2413_ACCESS_READ  0xF5
#define DS2413_ACCESS_WRITE 0x5A
#define DS2413_ACK_SUCCESS  0xAA
#define DS2413_ACK_ERROR    0xFF

OneWire oneWire(DS2413_ONEWIRE_PIN);
uint8_t address[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };

void printBytes(uint8_t* addr, uint8_t count, bool newline=0)
{
  for (uint8_t i = 0; i < count; i++)
  {
    Serial.print(addr[i]>>4, HEX);
    Serial.print(addr[i]&0x0f, HEX);
    Serial.print(" ");
  }
  if (newline)
  {
    Serial.println();
  }
}

byte read(void)
{
  bool ok = false;
  uint8_t results;

  oneWire.reset();
  oneWire.select(address);
  oneWire.write(DS2413_ACCESS_READ);

  results = oneWire.read();                 /* Get the register results   */
  ok = (!results & 0x0F) == (results >> 4); /* Compare nibbles            */
  results &= 0x0F;                          /* Clear inverted values      */

  oneWire.reset();

  // return ok ? results : -1;
  return results;
}

bool write(uint8_t state)
{
  uint8_t ack = 0;

  /* Top six bits must '1' */
  state |= 0xFC;

  oneWire.reset();
  oneWire.select(address);
  oneWire.write(DS2413_ACCESS_WRITE);
  oneWire.write(state);
  oneWire.write(~state);                    /* Invert data and resend     */
  ack = oneWire.read();                     /* 0xAA=success, 0xFF=failure */
  if (ack == DS2413_ACK_SUCCESS)
  {
    oneWire.read();                          /* Read the status byte      */
  }
  oneWire.reset();

  return (ack == DS2413_ACK_SUCCESS ? true : false);
}

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

  Serial.println(F("Looking for a DS2413 on the bus"));

  /* Try to find a device on the bus */
  oneWire.reset_search();
  delay(250);
  while (oneWire.search(address)) {
       printBytes(address, 8);
       Serial.println(F("No device found on the bus!"));
}
  /* Check the CRC in the device address */
  if (OneWire::crc8(address, 7) != address[7])
  {
    Serial.println(F("Invalid CRC!"));
    return;
  }

  /* Make sure we have a DS2413 */
  if (address[0] != DS2413_FAMILY_ID)
  {
    printBytes(address, 8);
    Serial.println(F(" is not a DS2413!"));
    return;
  }

  while (oneWire.search(address)) {
  Serial.print(F("Found a DS2413: "));
  printBytes(address, 8);
  Serial.println(F(""));
}
}

void loop(void)
{
  /* Read */
  /*
  uint8_t state = read();
  if (state == -1)
    Serial.println(F("Failed reading the DS2413"));
  else
    Serial.println(state, BIN);
  */

  /* Write */
  bool ok = false;
  ok = write(0x3);
  if (!ok) Serial.println(F("Wire failed"));
  delay(1000);
  ok = write(0x0);
  if (!ok) Serial.println(F("Wire failed"));
  delay(1000);
}


texts: Do I need to solder wires to my tilt sensor?

texts:
I am using the Arduino Starter Kit and I am on project 8. The picture of the sketch in the book is not clear because it shows the tilt sensor seemingly resting sideways, which is not the way that it connects. If you insert the pins into the board the sensor will always be standing and there will be no way to turn it. I was thinking you might have to solder wires to the pins. Does anyone know?
-Thanks
Edit: Perhaps this picture will help:


texts:
Can anybody tell me how the Particle (Photon/Core) WiFi setup works?

I am looking to mimic this WiFi configuration format for my own device.

The basic steps are as follows:

Power device on; put in "listening mode" if not already active;
Connect smartphone to the wireless network that you want to connect your device to;
Open the Tinker/Spark/whatever-it's-called App on your smartphone; choose "Add New Device";
Enter wireless password;
Wait for device to be discovered by the App; device is now connected to WiFi.

How is the information (SSID, password) transferred from the smartphone to the device?

Thanks in advance.


texts:
I had a problem when installing the esp32 core. I couldn't do it through the board manager procedure because I can't find esp32 for installation in the board manager even though I put the link correctly in the preferences section so I had to download a zip file and unzip it in hardware/espressif/esp32 folder. Now whenever I try to upload the code(a simple LED blinking code) it says error compiling for board with the following error message
exec: "C:\Users\ABDUL\Documents\Arduino\hardware\espressif\esp32/tools/xtensa-esp32-elf/bin/xtensa-esp32-elf-g++: file does not exist
Please help me. I don't know what to do anymore


texts: Can you tell me if this circuit will work?

texts:
Here's an image of my circuit diagram. There are 8 9g servos connected to the arduino gpio pins. The servos have an external power supply of 3 volts (may vary depending on the voltage requirement of the 9g) and the arduino is powered through an adaptor. Is this a convenient way of doing it? Have I gone wrong somewhere? I am new to circuit designing so I am confused.

Thank you! :)


texts: Arduino New Optiboot Bootloader on custom ATMega328p board, ATMEL Studio and AVRdude

texts:
I am about to ask a kind of complex question due to the number of system parts involved and the system architecture I am planning to use.

First of all I have a tiny bit of experience with the Arduino Nano and a professional experience with C microcontroller programming.

What I would like is to create a custom ATMega328p board that does something and be able to update whatever firmware is running on it using the UART port.

1) Firmware updating

Since I am not so familiar with bootloaders, I would skip for now writing my own, so I would like to use the newest Arduino Bootloader for ATMega328p to support the firmware updates.

2) Custom program compilation

What I definitely do NOT want is use Arduino Sketch IDE to compile whatever application code. I am using Atmel Studio up to now for whatever bootloaderless applications I was doing and I would like to keep using that with my own project and code structure. The question here is, do I need to make any linker modifications or modifications in the code in Atmel Studio projects in order to be able to "transform" my code into application code so that can coexist with the bootloader?

3) Updated firmware programming

After the board is on the field running with the Optiboot bootloader and an outdated firmware, I would like to use a thirdparty software to communicate with the bootloader and update the application code. Since the optiboot bootloader used by Arduino uses the STK500 communication protocol and functionality, could I use AVRdude to communicate with the bootloader and flash the applications code only through UART?

Do you think this concept could work?

Thank you in advance.
polylogic


texts:
I have a project using the RC522 RFID module with my Arduino Uno board and miguelbalboa's rfid library. The example code and every other code I find on the internet work pooling the device in order to know if there is a new card present, but I intend to work with a interrupt-driven approach. I have the proper knowledge to do the hardware/arduino part, but I'm having trouble generating an interrupt in the IRQ pin when the card is present. Have anyone succeded on this?

Edit:
Connection:
RST -> 8

SS-> 9

MOSI -> 11

MISO -> 12

SCK -> 13

IRQ -> 2

Code:

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

#define RST_PIN     8
#define SS_PIN      9

MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance

void setup()
{
  Serial.begin(9600);       // Initialize serial communications with the PC
  while (!Serial);      // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
  SPI.begin();          // Init SPI bus
  mfrc522.PCD_Init();       // Init MFRC522
  mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
  mfrc522.PCD_WriteRegister(MFRC522::ComIEnReg, 0x7F); //Enable all interrupts
  mfrc522.PCD_WriteRegister(MFRC522::DivIEnReg, 0x14);
  Serial.println(F("Ready..."));
  attachInterrupt(0, isr, RISING);
}

void loop()
{
}

void isr()
{
  Serial.println(F("Interrupt"));
  mfrc522.PCD_WriteRegister(MFRC522::ComIrqReg, 0x80); //Clear interrupts
}

Result:
I only get the "Ready..." on the Serial Monitor, no matter if there is a card present or not.


texts: Recover from wrong Wi-Fi password on Arduino Yún

texts:
I'm trying to customize my Arduino Yún to work as an access-point (or hotspot) for providing services to clients directly connected and, alternatively, to work as a client on a wireless network for downloading resources from the Internet.

The access to such a wireless network is gained after the user submits a network SSID and password in the web control panel provided by Yún.

How can I recover from a user submitting a wrong password? At the moment the Yún stays stuck without any connection, and thus is unreachable via SSH to attempt any recover.


texts: How to pass variables to custom callback functions

texts:
I want to use the Ticker library of the ESP8266 Arduino core to (asynchronously) delay the switch of a pin to a desired state like below. I am not sure about the "here is" function definitions and I am having a hard time to find some documentation. Please have a look at what I tried so far:

#include <Ticker.h>

Ticker change_pin;

...

    uint8_t desired_state = 1;
    ...
    change_pin.attach_ms(100, [](uint8_t state_to_change_to){
        if( digitalRead(PIN) != state_to_change_to ) {
            digitalWrite(PIN, state_to_change_to);
        }
        else {
            change_pin.detach();
        }
    }, desired_state);

But the compiler's yelling:

espIKEA:145: error: no matching function for call to 'Ticker::attach_ms(int, toogle_light(uint8_t)::__lambda0, uint8_t&)'

   }, des_state);

               ^

...

C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:45:7: note:   candidate expects 2 arguments, 3 provided

C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:62:7: note: template<class TArg> void Ticker::attach_ms(uint32_t, void (*)(TArg), TArg)

  void attach_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)

       ^

C:\Users\USER\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.3.0\libraries\Ticker/Ticker.h:62:7: note:   template argument deduction/substitution failed:

C:\Users\USER\Documents\Arduino\Scratch\pintest\pintest.ino:145:15: note:   mismatched types 'void (*)(TArg)' and 'toogle_light(u8)::__lambda0'

   }, des_state);

               ^

So, I am having too few knowledge to understand what to do about it. I really would like to avoid having a separate function for the callback body.

PS: Important source file can be found here: Ticker.h


texts:
Hey folks … I was hoping some of you might cast your eye over my code.

It splits up a string read from EEprom into an array of separate strings. Based on String length information stored in a separate array. (tempArray[])

It reads fine … and also seems to process fine (ie. it does turn one long string into separate array items)      for some reason it stops working no the 8th array item?

The splitting code (problem) starts on line 80 and i have included the output above it in comments.

http://pastebin.com/Ax4R6t6J   << Full code also available here.

void reJigFromMemory(){

  Serial.print("Eeprom read 1 :");
  Serial.println(eepromReadOne);
  Serial.print("EEprom read 2 :");
  Serial.println(eepromReadTwo);
  String tempArray[10];

  int charLength=eepromReadOne.length()+1;
  char charBuff[charLength];
  eepromReadOne.toCharArray(charBuff, charLength);

  //// GET MEMORY LOCATIONS
  /*
converts long string of numbers:
   13161717171717252533
   into separate strings:
   13
   16
   17
   17
   17
   17
   17
   25
   25
   33

   And stores them in an array.
   */
  for (int i = 0; i <10 ; i++){
    tempArray[i]+=charBuff[i*2];
    tempArray[i]+=charBuff[(i*2)+1];
    Serial.print("I just translated :");
    Serial.println(tempArray[i]);
  }
  /// GET THE STRINGS USING THE ABOVE ARRAYS
  /*
converts long list of data ie:
   |0|Bingo#999#|1|Retest2#9222#|2|Retest3#92299#|3|Retest4#99339#|4|Retest5#95599#|5|Retest6#96699#|6|Retest7#99119#|7|User Defined eighth#0#|8|User Defined ninth #0#|9|User Defined tenth (last) .#0#

   into individual array strings:

   From Number = :0
   To number : 13
   Record 0 :          |0|Bingo#999#
   From Number = :13
   To number : 29
   Record 1 :          |1|Retest2#9222#
   From Number = :29
   To number : 46
   Record 2 :          |2|Retest3#92299#
   From Number = :46
   To number : 63
   Record 3:           |3|Retest4#99339#
   From Number = :63
   To number : 80
   Record 4:           |4|Retest5#95599#
   From Number = :80
   To number : 97
   Record 5:           |5|Retest6#96699#
   From Number = :97
   To number : 114
   Record 6 :          |6|Retest7#99119#
   From Number = :114
   To number : 139
   Record 7 :               <<<<<< THIS ONE IS MISSING ? WHY?
   From Number = :139
   To number : 164
   Record 8 :               <<<<<< THIS ONE IS MISSING ? WHY?
   From Number = :164
   To number : 197
   Record 9 :               <<<<<< THIS ONE IS MISSING ? WHY?

   */
  String tempArray2[10];
  int fromLocation = 0;
  int toLocation=0;

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

    toLocation += tempArray[i].toInt();

    fromLocation += tempArray[i-1].toInt();
    tempArray2[i]=eepromReadTwo.substring(fromLocation,toLocation);
    Serial.print("From Number = :");
    Serial.println(fromLocation);
    Serial.print("To number : ");
    Serial.println(toLocation);
    Serial.print("I just translated :");
    Serial.println(tempArray2[i]);

  }
}


texts: I have a char* array which looks like this "T 20" and I'd like to extract the "20" and convert it in to an integer. I was thinking of using atoi() but it seems that function will operate on the entire string, not just the bits I want. Memory is a bit tight so is there a function similar to atoi() which allows you to specify which charters to operate on?


texts:
I want to exchange some date between arduino and beaglebone, as far as I know, most arduinos works with 5v levels, so I need to convert 5v into 3.3v beaglebone in order to communicate with it.
Unfortunatly I have no pro mini 3.3v now, only 5v arduinos.
So I need to convert levels.
I have several questions.

I have UART TTL CP2102 converter, I am using it to programm my Arduino pro mini, can I use it directly with beagle bone without converter ? http://ecx.images-amazon.com/images/I/410n8%2BHhdNL.SY300.jpg like this.
I can buy this cable with pl2303 inside http://i01.i.aliimg.com/wsphoto/v0/32250361345/Free-postage-1pcs-PL2303-PL2303HX-USB-to-UART-TTL-Cable-module-4p-4-pin-RS232-Converter.jpg
Is it possible to power my arduino pro mini 5v with 3.3v supply and use it directly with beaglebone

Can you provide simple level converter schematic to solder it quickly

All in all I need just to communicate with beaglebone via uart from pc with USB-UART converter or from arduino it doesn't matter, just to communicate and send some data.

Please suggest what is the best way to follow.


texts: I am working on an Asset locator using Arduino and nrf24l01. I want one of the nrf24l01 to track another which is attached to an object. How can it be done?


texts:
I am using arduino pro micro 5v 16Mhz. I have built a simple IR transmitter circuit as shown.

The code i am using is
https://github.com/z3t0/Arduino-IRremote/blob/master/examples/IRsendDemo/IRsendDemo.ino

Although this worked yesterday, it doesn't seem to work now. I was able to turn on and off my TV yesterday but the led is not even blinking now. I checked led, its working.

After hours of trying to make it work I tried different library.
https://github.com/cyborg5/IRLib2/blob/master/IRLib2/examples/send/send.ino

Surprisingly this seems to work but the code is a bit complicated for receiver.

I want to use the first library. Any help is appreciated. Thank you.


texts: How do we connect 2 FSR sensors to an Arduino Mega?

texts: One can connect an FSR sensor (a force-sensitive resistor) to an Arduino via 5V, Gnd,  and A0 port (as below, according to an adafruit.com page), but how will it work for two of them instead of one?


texts: ArchLinux avrdude not in sync (resp changes everytime) but it works on Windows?

texts:
I have some nano clones (ch340) which are driving me crazy! I have followed every possible advice (including wiping out arduino, avr and related configs, using another board, using another pc running ArchLinux as well) for about 6 hours and I am still getting the same error:

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x84
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x8c
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x44
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x04
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0xfc
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x94
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x44
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x04
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x44

Note that resp is changing every time, if I try again, I get different resps.

Then I launched a VM with Win10, installed and setup the ide to use the nano board with the old 328 bootloader, and from there I was able to upload the sketch with no issue.

Something is going bad with within ArchLinux, but I cannot figure out what:

$ lsusb
Bus 002 Device 005: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter
$
$ lsmod | grep ch
ch341                  20480  0
$
$ ll /dev/ttyUSB0
crw-rw---- 1 root uucp 188, 0 20 feb 14.43 /dev/ttyUSB0
$
$ groups me
uucp lock ...

I also tried this AUR package i2c-ch341-dkms (according to the ArchWiki), but DKMS fails to build the kernel module...

Here is the avrdude command that the IDE produces under Linux (not working):

//bin/avrdude -C//etc/avrdude.conf -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/arduino_build_381688/20200220.ino.hex:i

while this one is produced in the Windows virtual machine (working):

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware\tools\avr/bin/avrdude -CC:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.33.0_x86__mdqgnx93n4wtt\hardware\tools\avr/etc/avrdude.conf -v -patmega328p -carduino -PCOM3 -b57600 -D -Uflash:w:C:\Users\JD\AppData\Local\Temp\arduino_build_73565/sketch_feb20a.ino.hex:i

Apart from the paths and the ports they are basically the same command. I wonder if something is going on with /dev/ttyUSB0...

Potentially the same issue: Arduino Nano clone doesn't upload Linux


texts: No valid serial ports for Arduino UNO on Mac

texts:
UPDATE: The issue turned out to be with my work laptop. Our IT department has them configured in such a way that the assignment of serial ports is different somehow. When I plugged in on my personal Macbook Pro it all worked perfectly.

I just got my first Arduino. Its an UNO R3. I'm running OS X 10.8.5 (Mountain Lion) and the Arduino IDE 1.0.5

Under Tools>Board I have Arduino Uno selected

Under Tools>Serial Port my options are:

/dev/tty.Bluetooth-Serial-1
/dev/cu.Bluetooth-Serial-1
/dev/tty.Bluetooth-Serial-2
/dev/cu.Bluetooth-Serial-2
/dev/tty.Bluetooth-Modem
/dev/cu.Bluetooth-Modem
/dev/tty.Bluetooth-PDA-Sync
/dev/cu.Bluetooth-PDA-Sync

I've tried all of them, but when I try to upload a sketch it fails. Most give the following error:

avrdude: stk500_recv(): programmer is not responding

The two "modem" options return this message:

Serial port '/dev/tty.Bluetooth-Modem' already in use. Try quitting any programs that may be using it.

I'm at a loss. None of these serial ports seems correct but there aren't any other options.

Also under Tools>Programmer which option should I be using?


texts:
I have a bench supply which I can use to power a breadboard at 5 V. Is it a bad idea to power the the Arduino by going directly to the 5 V pin? It sounds like both this method, and the USB are unregulated, so there would be no difference. Is it safe? Are there any caveats to this?

  5V.This pin outputs a regulated 5V from the regulator on the board. The board can be supplied with power either from the DC power jack (7 - 12V), the USB connector (5V), or the VIN pin of the board (7-12V). Supplying voltage via the 5V or 3.3V pins bypasses the regulator, and can damage your board. We don't advise it.

They say they "don't advise it", but why?


texts: Connecting MPU6050 to Arduino Due but using Jeff Rowbergs Library

texts:
I am working on a personal project in which I need to collect accurate data from the MPU6050 using an Arduino Due.
I can interface and read data from the MPU using the SLC and SDA pins and the "Adafruit Library" or the "MPU6050_Light" library. However I have been told that the Jeff Rowberg library combines both accelerometer data and gyroscope data to get a more accurate measurement of roll, yaw, and pitch. Every time I've tried using the library I get the error below:
Arduino: 1.8.13 (Windows 10), Board: "Arduino Due (Programming Port)"
...
exit status 1
Is there anything I can do to get this to work on the Due's processor (which I know has a different architecture). If not what can I do to get accurate reading on the Due. I should note that the code works perfectly fine on the Uno.


texts: What background do I need to have before starting Arduino?

texts:
Like: basics of electrical circuits, etc..

In order to go far in Arduino and electronics.


texts: Using an Arduino as an LED controller for an arcade stick

texts:
I'm attempting what seemed to be a rather simple problem at first glance, but due to my limited knowledge of Arduino workings I need some help. I'm trying to use button outputs from a PS360+ arcade controller. Each of the button terminals output +5V, and is meant to be connected through a button to the grounds on the PS360+.
  What I want to do is have an Arduino somewhere in between the button output and ground on the PS360+, to control and animate LEDs. What I've done so far is connect the VCC of the PS360+ to the Arduino's VIN and the ground of the Arduino to the PS360+'s button ground, which powers the Arduino. I then have a button output from the PS360+ going into the button, and the button's ground is connected to an Arduino pin. That Arduino pin's mode is set to INPUT. I then have another pin with an LED which is set to the value of the input pin.
  For some reason, the Arduino seems to get random input from the button(Though it does seem to react somewhat to buttons presses), and the PS360+ does not recognize the button press. Setting the input pin to pullup mode has even less result, and never reads low.
Anybody got any ideas? Here's my current circuit diagram. 1P is a +5V output. I think that it's an internal pull-up pin like the Arduino's, but I am not certain.

And my current code:

int buttonlisten = 22;
int led = 53;
int val = 0;

void setup() {
  pinMode(led, OUTPUT);
  pinMode(buttonlisten, INPUT);
}

void loop() {
  val = digitalRead(buttonlisten);
  digitalWrite(led, val);
}

Thanks!


texts: Sound localization using two mics, Arduino Uno on MATLAB

texts:
I have been trying to achieve this for a long time using the ITD method and have gone through various articles on the net.
I want to know if its possible to actually achieve sound localization using an Arduino Uno and two MEMS mics with a high gain (https://www.sparkfun.com/products/9868).
I have been trying this on MATLAB using the a=arduino() command and readVoltage command but the main issue I face is that for a particular sound (clapping for instance) the time difference between the two mics is not always the same which results in different direction predictions.
We managed to increase the low resolution of the Arduino by removing unnecessary operations. Now we are able to get an array of size 750 for 10 secs giving a resolution of 0.01 secs. I am not sure if that is enough.
I basically have 3 arrays, one storing the sampling times, and the other two storing the amplitudes of the two analog inputs at that particular time in the first array.
Now I look for a peak in one and then the corresponding near peak in the second one and then compute the time difference. After this I can compute the angle using the speed of sound and the distance between the mics.
Please let me know how I can make this work or where I am going wrong.


texts: What does a tilde (~) mean as annotation for a data pin?

texts:
When I examine the datasheet for the Arduino Micro (couldn't find the Pro Micro on their site, btw) then I see some data pins annotated with a ~ character, and some are not.

For instance, D9 has a ~ annotation, D8 does not.

What does this annotation mean?


texts: Arduino reading string sent from Rpi multiple times

texts:
1.Reading strings sent from Arduino on RPI

Below you can see that I am communicating between a rpi and arduino serially. I am sending "start", then move_played to the rpi. The readline() reads until a newline so, first start gets read then the move_played string(it's like read the move played only after encountering the string start)

Python code on RPI

s1 = serial.Serial('/dev/ttyACM1', 9600)
stockfish = Stockfish('/usr/games/stockfish')
while 1 :
    if str(s1.readline(),'UTF-8').strip('\n\r') == 'start' :
           move_played = str(s1.readline(),'UTF-8').strip('\n\r')
           print(move_played)

Code on Arduino

void SendMove();
String movePlayed ="e2e4";
void setup()
{
  Serial.begin(9600);
}
void loop()
{
  SendMove();
  exit(0);
}
void SendMove()
{
  Serial.println("start");
  Serial.println(movePlayed);
}

2.Reading strings send from RPI on Arduino

The  goal for the arduino is to read the bestMove string after it reads "Rstart". But when I run the code on the rpi(sending the strings). The lcd prints "Rstart" and not the bestMove string. So from what I can see is that once the "Rstart" string is sent , the first readString() in the if condition , reads " Rstart" and the the second readString() in the print statement reads "Rstart".

Why is the string"Rstart" stll in the serial Buffer even after being read once?

Python Code on RPI

bestMove = "b3c7"
s1 = serial.Serial('/dev/ttyACM1', 9600)
s1.write(bytes("Rstart","ascii"))
s1.write(bytes(bestMove,"ascii"))

Code on Arduino

#include "LiquidCrystal.h"
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // 4 bit mode
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
void setup()
{
  lcd.begin(16,2);
  Serial.begin(9600);
}
void loop()
{
  if (Serial.available()>0)
  {
    if(Serial.readString() == "Rstart")
    {
      lcd.setCursor(0,0);
      lcd.print(Serial.readString());
      delay(10000);
      exit(0);
    }
  }
}


texts: Send data from computer to phone through bluetooth - Bluetooth SeeedStudio Shield V2.1

texts:
So I bought a Bluetooth Shield from SeeedStudio lately (V2 model) and goofed around with it a little bit. I'm using my HTC One M8 to communicate with it just to send some dummy words. Whenever I send something from my phone to the Android, it works great and I'm pleased to see it's fast too.

The code is fairly simple. I just send data from my phone, gets received to my arduino, prints it on the Arduino IDE terminal. Same thing for communication in the other way. Write something in the terminal, send it to the arduino and then, the phone. The last on doesn't work and I've tried a couple of things in the past 36 hours. Now, I'm just banging my head against the wall (literally). Here's my code (I'm sure you've seen it a couple of times before):

#include <SoftwareSerial.h>   //Software Serial Port
#define RxD 6
#define TxD 7

#define DEBUG_ENABLED  1

SoftwareSerial blueToothSerial(RxD,TxD);

void setup()
{
  Serial.begin(9600);
  pinMode(RxD, INPUT);
  pinMode(TxD, OUTPUT);
  setupBlueToothConnection();

}

void loop()
{
  char recvChar;
  while(1){
    if(blueToothSerial.available()){//check if there's any data sent from the remote bluetooth shield
      recvChar = blueToothSerial.read();
      Serial.print(recvChar);
    }
    if(Serial.available()){//check if there's any data sent from the local serial terminal, you can add the other applications here
      recvChar  = Serial.read();
      blueToothSerial.print(recvChar);
    }
  }
}

void setupBlueToothConnection()
{
  blueToothSerial.begin(9600); //Set BluetoothBee BaudRate to default baud rate 38400
  blueToothSerial.print("\r\n+STWMOD=0\r\n"); //set the bluetooth work in slave mode
  blueToothSerial.print("\r\n+STNA=SeeedBTSlave\r\n"); //set the bluetooth name as "SeeedBTSlave"
  blueToothSerial.print("\r\n+STOAUT=1\r\n"); // Permit Paired device to connect me
  blueToothSerial.print("\r\n+STAUTO=0\r\n"); // Auto-connection should be forbidden here
  delay(2000); // This delay is required.
  blueToothSerial.print("\r\n+INQ=1\r\n"); //make the slave bluetooth inquirable
  Serial.println("The slave bluetooth is inquirable!");
  delay(2000); // This delay is required.
  blueToothSerial.flush();
}

On my phone, I use a simple Bluetooth SSP to pair and communicate. Btw, something odd: I can't change the name of the bluetooth device. When I try to connect it, it shows the same name in the SSP.

Note: When I upload my code, I make sure I reset the arduino everytime. Oh and I changed the jumpers on my board to make sure it was set on the right one.

Note 2: I tried to see if the pins on the Shield (for RdX and TdX) were not starting with 0 by moving the jumpers.

Still, it's pretty odd.

Thanks in advance for any help and don't hesitate to ask me question! It's my first time here!


texts: Creating a timer using a Real Time Clock with start and stop times

texts:
I have an Arduino Uno with a motor shield, as well as a DS1307 RTC that I am using to control 2 pumps.

Ideally I would like to set a start time (startHour + startMinute) and end time (endHour + endMinute) for each pump.

I have had luck using if statements to control my timer like below (adapted from Iain Foulds):

byte startHour=8
byte startMinute=15
byte endHour= 14
byte endMinute= 20

byte startHour2=22
byte startMinute2=30
byte endHour2= 2
byte endMinute2= 45

void loop() {
  byte checkStartTime1() {
    DateTime now = RTC.now();
    // Read in what our current datestamp is from RTC
    if (now.hour() == startHour && now.minute() == startMinute) {
      validStart1 = 1;
    } else {
      validStart1 = 0;
    }
    return validStart1;
    // Return the status for powering up
  }
}

But my concern is that this only checks for equivalency at the moment, and if I lost power when my start time came up my pump would not come on. So I was hoping to set up an if statement that can deal with ">=" as opposed to just "==".

Which I can use if I only deal with the hour section:

if (now.hour() >= startHour && <= endHour)

But things get complicated when I try to add in minutes to the control structure. I end up with a series of nested for loops that do not work.

I'm hoping someone can help me write an if statement (or switch case) that can accommodate hours and minutes. So that any time between 8:15-14:20

validStart1=1

and anytime other time

validStart1=0

And please note the addition of the second set for this timer (StartHour2)- which I threw as my second pump will need to deal with the switch over past midnight.


texts:
I'm trying to read all the available access points nearby with an ESP8266 module.

Whenever I try to read all the available data from the ESP module and write it to the Monitor Serial it truncates text. Text often also a bit messed up.

I'm using an Arduino Uno with the following scheme (I'm using pins 2 & 3 NOT 1 & 0):

#include <SoftwareSerial.h>

SoftwareSerial esp8266(2, 3);

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);

  esp8266.begin(115200);
}

void loop() {
  while(esp8266.available()) {
     Serial.write(esp8266.read());
  }

  while(Serial.available()) {
    esp8266.write(Serial.read());
  }
}

The code prints something like the following:

AT+CWLAP

+CWLAP:(3,#SBanaan",-73,"4c:09:d4:d5:d6:f2",1,,2,0)
+CWLAP:(3,"UPC24923"CH7"0,L5-:d6Ai0:,
,,f5
44"f"CZ7f1
4-"6:0:4-95
,5-3d0


texts: Arduino Pro Micro clone not recognized, flickering RX LED

texts:
I have an Arduino Pro Micro clone that seems to be in some sort of reset loop. The RX LED is flickering very fast and very dim. The power LED also seems to flicker at the same frequency but has normal brightness.

The Arduino is not recognized by the PC at all anymore. It was working fine before. It doesn't matter if I try to go into the bootloader, by pressing reset twice, or not. Nothing happens. It feels like it is constantly resetting. The flickering stops if the reset pin stays connected to GND.

Another clone from the same shipment is still working fine. Both running the blink sketch. Just this one started to malfunction all of the sudden - after probing the pin I set in the blink sketch with my multimeter to see if the flashing was a success.


texts: Which Protocol to use to control WiFi (esp 32) enabled Led Light

texts:
I am developing a Wifi based Led light (for learning purpose). I have little knowledge about web server, clients, Web protocols. I will be using ESP32 as Controller cum WiFi module.

There are two ways to control Led light over WiFi.

Locally
Remotely // as of now am focusing on locally

Android/iOS app will be handling all the control part (Flutter app)

Which protocols can I use to control Led light, locally?
will set up multiple esp32 at that time its hard to control the device both devices will have different ip

Kindly help!
if anyone give good example it would be helpful


texts:
I want to build some small wireless temperature measurement boards, to sprinkle around the house. I'd like to power these from a single coin cell battery (CR2032).

For these I'd like to use the DS18B20 sensor. These sensor require a minimal voltage of 3v. A coin cell will however only provide 3v when it's full, and will drop to around 2.6v when 90% discharged.

From what I've read the DS18B20 will give some strange results when the supply voltage is below 3v. Also the precision can be off, when the supply voltage isn't regulated.

(The ATMega328p and NRF24L01, I plan to use, will work just fine at voltages down to 2v, so only the DS18B20 requires 3.3v.)

So I've come up with the following solutions:

Use two coin cells, and a (low quiescent current) voltage regulator. (Disadvantage: takes more space, more batteries, slightly more expensive.)
Use a boost regulator. (Disadvantage: even more expensive, and a lot more complex (for me at least).)
Implement a voltage doubler to power the DS18B20 when needed (every 15 minutes). To regulate the voltage I'd add a 3.3v zener diode to the output. (dirt cheap to implement)

I tend to lean toward option 3, but my question is, could it even work?

Is there something to look out for?

Or is there an even better solution?

edit I was planning to use the Dickson doubler circuit.