texts: Wirelessly (but fast) transfer STEP and DIR output from Arduino to stepper driver

texts:
Very short version:
Looking for a way to wirelessly get STEP and DIR signals (only those two signals) from an Arduino to a DRV8825 stepper driver about a meter away:
Arduino -> STEP and DIR IO pins -> transmitter ) ) ( ( receiver -> DRV8825

Long version:
For a project I've mounted an Arduino to a wooden board. The Arduino has a GRBL shield (basically a breakout board to four motor drivers for stepper motors (in my case the DRV8825)). Connected to this setup is a stepper motor. The power supply (NOT on the wooden board) for the motor is 24v, and I'm using a buck converter to take it down to 5v for the Arduino.
This whole board is rotating and the 24v gets passed to it using a custom sliding-contact with two contacts (24v and gnd).
Now this all works fine, but the problem is this: I have a second motor which I want to control from the same GRBL shield. But this motor is NOT on the rotating board.
If I place the motor driver next to this motor and power it from the same power supply (parallel to the sliding-contact) I have everything I need, except for the STEP and DIR signals from the Arduino.
Because there is no way I can add 2 more contacts to the sliding-contact (plus the signal would probably be too noisy anyway) I'm looking for a way to basically add a wireless bridge between the STEP and DIR output pins on the Arduino, and the STEP and DIR input pins on the motor driver. The motor and driver are about a meter away from the Arduino, so signal strength shouldn't be a problem.
I believe those well known 433Mhz transmitters are too slow for something like this, but I read most nRF24L01 modules are faster. Before I order some for a test setup, I was wondering if anyone already knows if this could work or not, knows a useful alternative, or has some suggestions for keywords to search for when trying to find another solution. I can find a lot of 'wireless' motor drivers online, but most are completely standalone units where the microcontroller is on the board, it's just controllable over wifi/bluetooth.


texts: Different questions regarding Arduino C++ library coding style

texts:
I'm reading the two wire library in Arduino libraries and in the C++ source  code I found different methods which I don't know what they mean, in the following:

// Initialize Class Variables //////////////////////////////////////////////////

uint8_t TwoWire::rxBuffer[BUFFER_LENGTH];
uint8_t TwoWire::rxBufferIndex = 0;
uint8_t TwoWire::rxBufferLength = 0;

uint8_t TwoWire::txAddress = 0;
uint8_t TwoWire::txBuffer[BUFFER_LENGTH];
uint8_t TwoWire::txBufferIndex = 0;
uint8_t TwoWire::txBufferLength = 0;

uint8_t TwoWire::transmitting = 0;
void (*TwoWire::user_onRequest)(void);
void (*TwoWire::user_onReceive)(int);

// Public Methods //////////////////////////////////////////////////////////////
void TwoWire::begin(void)
{
  rxBufferIndex = 0;
  rxBufferLength = 0;

  txBufferIndex = 0;
  txBufferLength = 0;

  twi_init();
}

void TwoWire::begin(uint8_t address)
{
  twi_setAddress(address);
  twi_attachSlaveTxEvent(onRequestService);
  twi_attachSlaveRxEvent(onReceiveService);
  begin();
}

void TwoWire::begin(int address)
{
  begin((uint8_t)address);
}

My first question, regarding to class variables:

Why has the author connected the variables to the class with scope-resolution operator "::"?
I want to understand the last two lines of class variables, I know they are function pointers, but I want to know more details and benefits of function pointers?

My second question, regarding to public methods:

There are three versions of the "begin" function, can someone explain why?
Why is begin(); called inside the second function declaration?


texts: Should I use motor driver or Motor driver shield?

texts: I want to run 4 microgear motor for an RC car with Arduino. Should I use L293d motor driver/L298n motor driver/L293d motor driver shield?? I am using N20 microgear motor with following rating: 6 V, 200 RPM and 120 mA with no load, 40 oz-in (2.9 kg-cm) and 1.6 A at stall.


texts:
I'm design a custom PCB based around the Arduino Zero/Adafruit Feather M0. The plan is to use a few I2C devices. I just had a few questions about whether I've designed the board correctly.

You'll see that I've used 10k resistors on each devices's SDA and SCL lines, but is this necessary? I've seen it mentioned on a few online documents for certain breakout boards etc...

Also, are the devices just connected in parallel? Are there any considerations I need to make when using 3 I2C devices like this?


texts:
I want to skip all '\r' and '\n' chars and I have IF statment:

char c = Serial.read();
if (c != '\r' || c != '\n') { // <- This line interesting
   mAnswer[mAnswerLength] = c;
   mAnswerLength++;
}

VS

char c = Serial.read();
if (c != '\r' && c != '\n') { // <- This line interesting
   mAnswer[mAnswerLength] = c;
   mAnswerLength++;
}

What is better and what is the difference?


texts: Is there by any chance a shield that can take an 4G LTE compatible SIM card activated by a carrier and establish a connection?


texts: How can I stop my Arduino UNO rev 3 from briefly turning on digital output pins on startup or reset?

texts: I am using my Arduino UNO rev 3 to control other devices via the digital output pins. On startup or reset, I find that these pins are all briefly turned on (perhaps as part of a self test). This interferes with my application. How can I suppress this?


texts: Arduino serial plotter with independent Y axis, is it possible?

texts:
The Arduino IDE has a built in functionality that allows the user to plot a value (such as temperature) over time.

I would like to plot two variables with different ranges on the y-axis (pressure in the range of thousands and temperature which varies from 20°C to 40°C).

I could make it work to have both being plotted, but the range differences does not allow me to see small changes in one/both quantities. Is there a way to two, or more, Y axis each one with its own scale?


texts: L298N Dual Motor Controller Enable Pin has power but motors not working

texts:
I am trying to get the L298N to work with a simple DC motor.

For now, I have simplified the setup and the code to the basics to try to get it to work. I am using the following wiring setup with no button or pot:

Only 1 motor, I am using a 2S lipo which I measured the voltage to be 7.8V which should be enough. The DC motor works when directly powered from the battery and when power with ~5V from an Arduino so I know it is not the issue.

My code, simplified from this tutorial: https://howtomechatronics.com/tutorials/arduino/arduino-dc-motor-control-tutorial-l298n-pwm-h-bridge/

#define enA 9
#define in1 6
#define in2 7

void setup() {
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);
  // Set initial rotation direction
  digitalWrite(in1, LOW);
  digitalWrite(in2, HIGH);
}
void loop() {
  analogWrite(enA, 255); // Send PWM signal to L298N Enable pin
}

I can measure the voltage at the input, it is good 7.8V. No voltage on motor output pins. In1 has voltage of 3.0V and In2 has 0V which corresponds to the code. However, Enable1 has 0V which doesn't make sense. So I attached the jumper for Enable 1 to give it the 5V, measured to confirm and still the motor is not working. I also tried a 2nd L298N with the exact same setup it and does not work. So I suspect it is something in my code or setup.

I feel like I am doing something stupid but I do not know what else to check. I checked continuity on the back of the board and it seems okay.


texts: I am running 1.6.5, but the folder says 1.6.3?

texts:
I just downloaded the latest version of the Arduino software (1.6.5). However, when I look into the Application Support folder under Library (I have a mac), I find that I have a folder named 1.6.3:

Library ▸ Arduino15 ▸ packages ▸ arduino ▸ hardware ▸ sam ▸ 1.6.3

Does this mean there is a hidden 1.6.5 folder that I am not seeing?

BTW, this issue surfaced, because I am trying to fiddle around with the ADC clock speed, but it seems that nothing is happening:

void setup() {
  #define ADC_FREQ_MAX = 1;
  Serial.begin(9600);
  Serial.println(ADC_FREQ_MAX);
}

void loop() {
}

gives me:

opamp.ino: In function 'void setup()':
opamp:2: error: expected primary-expression before '=' token
opamp.ino:4:18: note: in expansion of macro 'ADC_FREQ_MAX'
opamp:4: error: expected primary-expression before ')' token
opamp:4: error: expected ';' before ')' token
expected primary-expression before '=' token


texts: EEPROM bytes preset to 255 while programming

texts:
I'm working on a program with Arduino Uno which involves writing and reading EEPROM. I'm using a basic EEPROM library. My problem is: EEPROM values are preset to 255 whenever I burn my program. And there is nothing in my code which will write 255 in these bytes.

I even tried EEPROM_read example from the EEPROM library and got same result. I used EEPROM_clear code before EEPROM_read to set all values to 0. But when I read those values using EEPROM_read, they are 255.

Please help explain what is happening.


texts: Library LiquidCrystal_I2C don't work in other class (Composition)

texts:
Good afternoon, I'm trying to use a class to streamline the writing on the LCD. In this class I have an private attribute (it's a pointer, do not know how I call him) called  LiquidCrystal_I2C* _lcd, I instantiate it in the constructor, so far so good, but when I call the _lcd-> begin (20, 4) the code below is not executed, but no error is displayed.

Display.h:

class Display{
    public:
        Display();
        ...
    private:
        LiquidCrystal_I2C* _lcd;
        ...
}

Display.cpp:

...
Display::Display() {
    _lcd = new LiquidCrystal_I2C(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
    _lcd->begin (20, 4);
}
...

Program.ino

#include "Display.h"

Display lcd;

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

void loop() {
    Serial.println("test");
    delay(3000);
}

Just I noticed the error when I saw that Serial.println ("test"); was not running. If I comment the _lcd->begin (20, 4); everything works.

I tested writing everything in Program.ino and worked, has nothing to do with connections or something, just do not apply the concept of composition with this class.

Can someone help me? And sorry for the English, i'm from Brazil. Thanks.


texts: Fingerprint sensor code won't work correctly with LCD 16x2

texts:
I am doing a fingerprint sensor that works with a 16x2 LCD. The code works correctly for the fingerprint sensor, but when I enter LCD code, the LCD works but the fingerprint stops working.

I am using an Arduino Uno and an Adafruit fingerprint sensor. Both the fingerprint and LCD are wired correctly and work separately. I have enrolled and tested fingerprints and it worked perfectly until I added LCD code.

#include <Adafruit_Fingerprint.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int getFingerprintIDez();
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

void setup() {
 // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
  Serial.begin(9600);
  Serial.println("fingertest");
  // set the data rate for the sensor serial port
  finger.begin(57600);
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1);
  }
  Serial.println("Waiting for valid finger...");
}

void loop() {
  getFingerprintIDez();
}

uint8_t getFingerprintID() {
  uint8_t p = finger.getImage();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println("No finger detected");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK success!
  p = finger.image2Tz();
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  p = finger.fingerFastSearch();
  if (p == FINGERPRINT_OK) {
    Serial.println("Found a print match!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    return p;
  } else {
   Serial.println("Unknown error");
    return p;
  }

  // found a match!
  Serial.print("Found ID #");
  Serial.print(finger.fingerID);
  Serial.print(" with confidence of ");
  Serial.println(finger.confidence);
}

// returns -1 if failed, otherwise returns ID #
int getFingerprintIDez() {
  uint8_t p = finger.getImage();
  if (p != FINGERPRINT_OK)  return -1;
  p = finger.image2Tz();
  if (p != FINGERPRINT_OK)  return -1;
  p = finger.fingerFastSearch();
  if (p != FINGERPRINT_OK)  return -1;
  // found a match!
  Serial.print("Found ID #");
  Serial.println(finger.fingerID);
  Serial.print("This Finger print related to : ");
  switch(finger.fingerID){
   case 0:
     Serial.println("Subhy Mesmar");
     break;
   case 1 :
     Serial.println("Amjad Mesmar");
     break;
  }
  return finger.fingerID;
}

In this image the fingerprint sensor works without LCD code:

And in this one the LCD works after adding code but the fingerprint sensor stopped working:


texts:
So let's say I use a store-bought TENS unit for liability. I want to make a challenge where you need to hold on to the TENS unit for 10 seconds before it activates a solenoid. How can I have an Arduino detect if someone is touching some metal posts connected to the unit? Would I need to measure the current for the tens unit or something? Any ideas/suggestions? Thanks!
Edit- Not sure if this should be in Arduino or Electrical Engineering, feel free to move it.


texts:
I have created an API in Ruby on Rails and it send the following JSON response:

{"sun_position":{"altitude":"32.46","azimuth":"223.93"}}

I'm able to successfully hit the API and store the response. But when I try to parse it and store data it gives me an error. I have used the Arduino JSON library.

The code for parsing the JSON is as follows:

bool parseSunPosData(char* content, SunPosData* sunPos) {
  StaticJsonBuffer<JSONBUFFER_SIZE> jsonBuffer;
  JsonObject& root = jsonBuffer.parseObject(content);
  Serial.println("In parse fuc");
  Serial.println(content);
  Serial.println("==============");
  if (!root.success()) {
    Serial.println("JSON parsing failed!");
    return false;
  }

And the output on the serial monitor is as follows:

  In parse fuc 38

  {"sun_position":{"altitude":"32.46","azimuth":"223.93"}} 0

  ==============

  JSON parsing failed! Disconnect

My guess is it can't parse the data due to the numbers 38 and zero printing... I don't know what that is and what it is.

PS: New to Arduino coding.


texts: Arduino code for turning an led on by one clap and then off by one clap

texts:
I want my Arduino to turn on a LED when sound sensor detects a clap (noise) and keeps the LED on until the sound sensor detects another clap (noise) which turns the LED off.

int Sensor = A0;
boolean status_lights = false;

void setup() {
  pinMode(Sensor, INPUT);
  pinMode(13, OUTPUT);
}

void loop() {
  int status_sensor = digitalRead(Sensor);
  if (status_sensor == 0)
  {
    if (status_lights == true)
    {
      status_lights = false;
      digitalWrite(13, LOW);
    }
    else {
      status_lights = true;
      digitalWrite(13, HIGH);
    }
  }
}

My sound sensor has 3 pins.
sound sensor details

EDIT: My code only turns on the led but dosen't turn it off when I clap.


texts: What is the proper way to implement PID?

texts:
I'm having some trouble conceptualizing how to go about implementing PID into my drone. There are a few ways I'm thinking about implementing the pipeline:

Having one PID Object for each of the six motors.
Having one PID Object for each axis.

How I would implement PIDs on a per-motor basis?

How I would implement PIDs on a per-axis basis?

I'm guessing that the second one will be the best course of action, as it can all be put into its own loop, where the PID data will be available on-demand, as opposed to calculating it on the spot. It is object-oriented, and runs in the background.

The first one has its appeals, too. It eliminates some of the calculations needed in order to find the actual value. It is procedural, and very straightforward and performs on the spot.

What do you guys think?


texts: invalid conversion from 'byte {aka unsigned char}' to 'void (*)()' [-fpermissive]

texts:
char auth [ ] = "8439"; // Wi-Fi credentials .
char ssid [ ] = "";
char pass [ ] = "chan";
const int SENSOR_PIN = A0;
const int RS = 0.5;
const int VOLTAGE_REF = 32;
const byte ButtonPress = 2;
const byte tweetOnButtonPress = 3;
volatile byte state = LOW;
float sensorValue;
float current;
float power;
float sValue;

void tweetUptime ()
{
  long uptime = millis () / 60000L;
  Blynk.tweet ( String ("Voltage is") + sValue + " V");
}

void setup () {
  Serial . begin (115200);
  Blynk . begin (auth , ssid , pass );
  Blynk . tweet ( String (" Voltage is") + sValue + " V");
  timer.setInterval (5L * 60000L, tweetUptime );
  pinMode(2 , INPUT_PULLUP);
  attachInterrupt ( digitalPinToInterrupt (2) , ButtonPress , CHANGE);
  pinMode(3 , INPUT_PULLUP);
  attachInterrupt ( digitalPinToInterrupt (3) , tweetOnButtonPress , CHANGE);
}

Image


texts: Arduino - ServoMotor Control and SoftwareSerial

texts:
My two arduino communicating serially with XBee. The receiver arduino also controls the servo motor. Servo works stably when there is no xBee connection. But when Arduino's serial communication, there is a problem in the operation of the servo motor. Servo motor stuttering while rotate, so stuttering occurs.
Can you help me?
My Coordinator Code:
#include <SoftwareSerial.h>
#define xBeeRxPin 10
#define xBeeTxPin 9
int deger3;
int deger4;
String d1,d2,d3;
SoftwareSerial xBeeSerial(xBeeRxPin, xBeeTxPin);

void setup() {
  Serial.begin(38400);
  xBeeSerial.begin(38400);
}void loop() {

  deger3 = analogRead(A0);
  deger4 = analogRead(A2);

  String deger5 =  (String)deger3 + ";" + (String)deger4 ;

  xBeeSerial.println(deger5);

  delay(50);
}

My Receiver Code:
#include <SoftwareSerial.h>
#include <Servo.h>
#define xBeeRxPin 10
#define xBeeTxPin 9
SoftwareSerial xBeeSerial(xBeeRxPin, xBeeTxPin);
String d1,d2,d3;

const int trigPin = 4;
const int echoPin = 3;
long duration;
int distance;
Servo myServo;

void setup() {
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  xBeeSerial.begin(38400);
  Serial.begin(38400);
  myServo.attach(11);
}
void loop() {
  for(int i=15;i<=165;i++){
    myServo.write(i);
     delay(10);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, 11200);
    distance= duration*0.034/2;

    if(xBeeSerial.available()>0){
      d1=xBeeSerial.readString();
    }
  }

  for(int i=165;i>15;i--){
    myServo.write(i);
     delay(10);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, 11200);
    distance= duration*0.034/2;

    if(xBeeSerial.available()>0){
      d1=xBeeSerial.readString();
  }
 }
}


texts: On extending scrolling 8x8 bitmap to 32x32 or 32x64 (see clip)

texts:
I am using an Adafruit 64x32 RGB LED panel with my Arduino Mega 2560. I tried to find/construct working examples of a 32x32 or wider scrolling text/bitmap but have failed.

The smaller version is working and is calling two functions for it to implement:

loadSprite(IMAGES2,60);
bildmittig_sprite(data,dpink,300);

IMAGES2 is of type const PROGMEM byte IMAGES2[][8] and is an array
of several 8x8 bitmaps
data is a buffer data array element,    containing the dynamic
movement of bitmaps, called in the void loop()

For the whole code here. For the video clip smaller scroller here.

For the video clip to what I would like to extend to:

   Russian Letters: http://dropbox.com/s/n2ilxqgubn83ii9/MOV_0056.mp4?dl=0
 Or Chinese Letters: http://dropbox.com/s/9rad116adc575u1/MOV_0057.mp4?dl=0

loadSprite() looks like this:

void loadSprite(const PROGMEM byte bild[][8],int anzahl) {
  for(int row=0; row < 8; row++) {
    //iterate through each row
    data[row] = 0;
    //reset the row we're working on
    for(int column=0; column < 8; column++) {
      //iterate through each column
      data[row] = data[row] + ((powers[column] & (pgm_read_byte(&(bild[index][row])) << offset)));
      //loads the current charachter offset by offset pixels
      data[row] = data[row] + (powers[column] & (pgm_read_byte(&(bild[index+1][row])) >> (8-offset)));
      //loads the next charachter offset by offset pixels
    }
  }
  offset++;
  //increment the offset by one row
  if(offset==8){offset = 0; index++; if(index==anzahl){index=0;}}
  //if offset is 8 load the next character pair for the next time through
}

The displaying function (places it i the middle of 32x32 panel) like this:

void bildmittig_sprite (byte bild[8],word cchsv, int duration) {
  for(int i = 0; i <8; i++) {
    for(int ii = 0; ii<8; ii++) {
      int bit = (bild[i] >> ii) & 1;
      if(bit == 0) {
        matrix.drawPixel(7-ii+12, 12+i, black);
      } else {
        matrix.drawPixel(7-ii+12, 12+i, cchsv);
      }
    }
  }
  delay(duration);
}

Working for 8x8 bitmaps, It eludes me how I could possible extend the coding (scrolling) for bitmaps like this:

const PROGMEM unsigned char rus5[] = {
  0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xff, 0x03,
  0x00, 0x00, 0x78, 0x00,
  0x00, 0x00, 0x38, 0x00,
  0x00, 0x00, 0x3c, 0x00,
  0x00, 0x00, 0x1c, 0x00,
  0x00, 0x00, 0x1c, 0x00,
  0x00, 0x00, 0x1e, 0x00,
  0x00, 0xfc, 0xde, 0x0f,
  0x00, 0x8f, 0xef, 0x1f,
  0x80, 0x07, 0x3f, 0x3c,
  0xc0, 0x03, 0x0f, 0x3c,
  0xe0, 0x01, 0x0f, 0x3c,
  0xe0, 0x01, 0x07, 0x3c,
  0xf0, 0x80, 0x07, 0x3c,
  0xf0, 0x80, 0x03, 0x3c,
  0x70, 0x80, 0x03, 0x1e,
  0x78, 0xc0, 0x03, 0x1e,
  0x78, 0xc0, 0x03, 0x0f,
  0x78, 0xe0, 0x01, 0x0f,
  0x78, 0xf0, 0x81, 0x07,
  0xf0, 0xf8, 0xc3, 0x03,
  0xf0, 0xef, 0xf6, 0x01,
  0xe0, 0xf7, 0x7c, 0x00,
  0x00, 0xf0, 0x00, 0x00,
  0x00, 0x70, 0x00, 0x00,
  0x00, 0x70, 0x00, 0x00,
  0x00, 0x78, 0x00, 0x00,
  0x00, 0x78, 0x00, 0x00,
  0x00, 0x7c, 0x00, 0x00,
  0x80, 0xff, 0x03, 0x00,
  0x00, 0x00, 0x00, 0x00
};

I tried variants of concatenation, like:

4 bytes as a row, stitching together several with beforehand created
data (data1 ... data4) elements (also adjust coherence for vertical elements).
And then have them displayed at the correct place to be able to use
the existing code but so far only vertical concatenation seemed to
work briefly.

I am at the end of my wits for this project, but maybe somebody else sees a better way.


texts:
TL;DR: is it safe to power a MPU 6050 module through its AD0 pin instead of VCC?

We managed to have two MPU 6050 modules on the same I2C buffer by changing the address of one of them by connecting its AD0 pin to the same current origin used for VCC.

We found out that we can get the same result if we just switch the power cable which goes to the VCC pin to the AD0 pin: the module changes its address and we are able to read its data normally.

This would be a better configuration for us because, if the AD0 cable ever got disconnected, we wouldn't get anything from the second module but we would still get uncorrupted data from the first one. In the other case (cable to both VCC and AD0), if the AD0 cable got disconnected, we would get corrupted data.

So the final configuration would be: GND, SCL, SDA pins connected normally, power to AD0, pin VCC left unconnected.

The question is: is this a safe configuration or is it better to just leave the VCC pin connected normally and get another cable to the AD0?

From empirical tests it looks like it works fine, but we couldn't find any confirmation and are not experts on the matter.


texts: PROGMEM doesn't cause Sketch size to change

texts:
I'm trying to pinpoint some strange behaviour involving the use of PROGMEM and the size of a Sketch.

I've written a library that contains a number of functions, in addition to several large global byte arrays and 32-bit uint arrays. These arrays are stored in PROGMEM using the pgmspace library. The library compiles fine, and all code works properly when uploaded to an Arduino.

I'm performing testing on the functions using a testing sketch that in turn uses my library. In order to test the performance, I've been switching between using PROGMEM and not using PROGMEM in the library (all arrays are under 2KB). When using PROGMEM, it drops the Global Variable dynamic memory count by the expected amount... but the the sketch program size remains either constant, or seems to arbitrarily increase or decrease by a very small amount, depending on the function. For example, a uint8_t byte[256] array, when moved to the PROGMEM, causes the Global Variable size to go down by about 256 bytes... but the sketch size only increases by about 12 bytes.

Each entry in the array is unique and is accessed, so the compiler shouldn't be optimizing it away. I tried just using avr-size directly on the ELF file, but the sketch size was the same. I can't tell if the data is being stored in PROGMEM all the time (even when not declared as PROGMEM, due to some sort of issue with PROGMEM in libraries?), or if PROGMEM data simply isn't being counted as part of the sketch size, or ??? I have tried moving the functions directly out of the library into the sketch, changing data types, adding/removing static and const declarations... but the lack of change in sketch size continues to confuse me. Any help would be greatly appreciated.


texts: cannot convert 'bool' to 'PinStatus' for argument '2' to 'void digitalWrite(pin_size_t, PinStatus) on Arduino Uno Rev 2 Wifi not working

texts:
I am a newbie to micro controllers and struggling to figure out how to fix this issue. When using an older Arduino micro controller it works fine, but when I use a new board (Arduino Uno Rev 2 Wifi) it gives me this error:

cannot convert 'bool' to 'PinStatus' for argument '2' to 'void digitalWrite(pin_size_t, PinStatus)'

At this line :

digitalWrite(pin_enable_line, !digitalRead(pin_enable_line));

Library I am using is: ReceiveOnlySoftwareSerial.


texts:
I have connected to EL wire, 12v EL Inverter to SparkFun EL Sequencer but it does not work (no battery is connected). The connections are the same like in Hookup Guide (https://cdn.sparkfun.com/assets/learn_tutorials/3/6/9/ELSequencerHookUp_bb.png). Furthermore, there is no light indicating that it works but I hear a noise/whistle from the Inverter.

Do I have to program the EL Sequencer or does it automatically turn the EL wire on?


texts: What is the difference between file.print() and file.write()

texts: From here I think I understand the difference between Serial.write and Serial.print, but is it the same when writing to a file in a SD card for example. Does it mean that File.write saves bytes in the file instead of text?


texts:
I'm getting JSON data using HTTP methods in Arduino and storing in String Object. The data is:

{
  "item": {
    "Identity": {
      "Id": "327681",
      "ItemId": "64006A962B71A1E7B3A0428637DA997C.327681",
      "Level": 1,
      "EntityType": "64006A962B71A1E7B3A0428637DA997C",
      "ItemStatus": 1
    },
    "Properties": {
      "AssetName": "PHE-1001",
      "Category": "Electrical Appliance",
      "RegistrationTime": "2017-12-14Z",
      "Activated": true,
      "Status": "Offline",
      "Manufacturer": "Philips",
      "ModelNumber": "1E-S00ER11",
      "SerialNumber": "YGTJGJK458545",
      "sample_property": null,
      "AssetLocation": null,
      "AssetType": null,
      "ActivationTime": "2017-12-24T05:44:38Z",
      "Country": "India",
      "PostalAddress": "500081",
      "dummy": null,
      "TotalHours": 16,
      "TotalWorkingHoursFromInstallation": 38,
      "TotalLifeTime": 62,
      "AssetSensorDistance": null
    }
  }
}

Arduino code:

HTTPClient http;
http.begin("URL");
int httpCode = http.GET(); //  //Send the request
if (httpCode == 200) {
  String payload = http.getString();
  Serial.println(payload);
}

Now I want to get only AssetName, Status and AssetSensorDistance. I have tried payload["Status"] but it prints nothing.

Can anyone help me with this? Thanks in advance.


texts:
I have a project where I'm looking to power 120 RGB LEDs in a strip (WS2812B).

Obviously an Arduino Micro cannot supply this amount of current so I'm looking to use an external 5V/4A switching power supply (wall-wart) to power the LED's as well as the Arduino.

My question is, can I just split the power from the wall-wart providing 5v_reg directly to the 5V pin on the Arduino Micro and 5v_reg to the LEDs Vss?

It it necessary to use extra bypass capacitors in this case?


texts: Sending string over serial to nodejs app. Why does it get chunked?

texts:
I'm sending a string from my sketch over Serial port as follows:

Serial.println(F("Found ILI9341 LCD driver"));

On the other side, I have a nodejs app using the serialport npm module, with something like this:

var SerialPort = require('serialport')
var serialPort = new SerialPort('/dev/ttyACM1', {
  baudrate: 9600
})

// it opens the connection and register an event 'data'
serialPort.on('open', function () {
  console.log('Communication is on!')
})

// when your app receives data, this event is fired
// so you can capture the data and do what you need
serialPort.on('data', function (data) {
  console.log('data received: ' + data)
})

Communication works, but on nodejs side I get the output chunked, as if it had line breaks, like this:

Communication is on!
data received: Pa
data received: int!
data received:

data received: Fou
data received: nd I
data received: LI93
data received: 41 L
data received: CD d
data received: rive
data received: r

Why does this happen?


texts: How to randomize the delay in Arduino Stepper code?

texts:
How does one add a random DELAY between 10 and 20 seconds?

For example in the following stepper logic I have a delay of 11 seconds - expressed in milliseconds as: delay(11000).

What would I need to add (or modify) so this is randomized between 10 and 20 seconds?

//#define IN1  8
//#define IN2  9
//#define IN3  10
//#define IN4  11

int Steps = 0;
boolean Direction = true;
unsigned long last_time;
unsigned long currentMillis ;
int steps_left=4095;
long time;

void setup()
{
Serial.begin(115200);
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);

}
void loop()
{
  while(steps_left>0){
  currentMillis = micros();
  if(currentMillis-last_time>=1000){
  stepper(1);
  time=time+micros()-last_time;
  last_time=micros();
  steps_left--;
  }
  }
   Serial.println(time);
  Serial.println("Wait...!");
  delay(11000);                     // delay timing
  Direction=!Direction;
  steps_left=4095;
}

Forgive the appearance of the code.  Everytime I post it gets butchered.  Hopefully it's understandable.


texts: The code fails to generate the values I want, when both trigger pins 2, 3 are high or low. Why?

texts:
/*aim of the program is to generate 2 different varying frequency from the
same output which is controlled by 2 triggers*/
void setup()
{
    pinMode(2,INPUT); //setting the trigger pins 2,3
    pinMode(3,INPUT);
    pinMode(6,OUTPUT); //output pin
}

void loop()
{
    if(digitalRead(2)==HIGH && digitalRead(3)==LOW) { //trigger conditions
        infra();
    }
    else if(digitalRead(2)==LOW && digitalRead(3)==HIGH) {
        red();
    }
    else if((digitalRead(2)==HIGH && digitalRead(3)==HIGH) || (digitalRead(2)==LOW && digitalRead(3)==LOW)) {
        Serial.println('help');
    }
}

void infra() //function varies sinosoidaly (working)
{
    float f;

    for(f=16000; f<=20525; f+=4.525) {
        tone(6,f);
    }

    for(f=20525; f>=16000; f=f-4.525) {
        tone(6,f);
    }
}

void red() //function varies sinosoidaly (working)
{
    float p;

    for(p=25000; p<=32071; p+=7.071) {
        tone(6,p);
    }

    for(p=32071; p>=25000; p=p-7.071) {
        tone(6,p);
    }
}


texts:
I have an embarrassingly simple question.

My experience to date has been limited to Arduino Uno + Wifi101.  I bought an ESP8266 and noticed that the GPIO pins don't match the printed numbers on the board.

When programming and defining pins, does #define <pin name> 16 call the pin with the printed designation D0?

I can't find a straight answer to this anywhere.

Image credit: http://crufti.com/content/images/2015/11/nodemcudevkit_v1-0_io.jpg


texts: Arduino: Read frequency of input from audio jack

texts:
I want to trigger an arduino from a sound from an audio jack from a mobile phone. The audio is a 1 Khz sound that the mobile will play. I want to avoid accidental triggering of the audio by testing for specifically that frequency.

I've found several tutorials using analog read, but the output is not in hertz.

How do i get the output in Hertz?

int incomingAudio;

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

void loop(){
  incomingAudio = analogRead(A0);//read voltage at A0
  incomingAudio = (incomingAudio+1)/4 - 1;//scale from 10 bit (0-1023) to 8 bit (0-255)
  if (incomingAudio<0){//deal with negative numbers
    incomingAudio = 0;
  }
  PORTD = incomingAudio;
  Serial.println(PORTD);

}


texts: When installing the IDE there are many "Unable to open *.DLL", errors. I check "ignore errors" and the IDE installed. Now when selecting the correct port and  board the blink sketch is uploaded and several ATK 500 errors result. I have uninstalled and reinstalled the IDE several time, with repeated results.


texts: Bizarre transistor behavior and voltage with DC motor in simple circuit

texts:
I started a new motor related project recently with a new Arduino Uno, beginning with several tutorial circuits included in the Vilros Arduino guide. The circuit in question is #10, a simple DC motor circuit with a transistor switch (http://imgur.com/a/vaqUA). The Arduino is being powered for the moment via USB.

The circuit, completed according to the diagram/common sense, does not work. The voltage across the transistor base is clearly not sufficient to activate the switch with the motor in the circuit. 5V (more like 4.6V) from Pin 13 is running across a 330 ohm resistor to the transistor base, but there is no current between the collector and the base. Bypassing the collector/base gap with a piece of metal will complete the circuit and activate the motor.

For some reason, the transistor will switch properly when the motor is replaced by a simple LED. AND, switching the cable from Pin 13 to the +5V out is enough to activate the transistor switch. I was under the impression that the transistor should only require .7V above the common grounded element.

But, even more bizarrely, with a cable running from +5V to the transistor base (through a resistor), a voltmeter across the DC motor is reading a potential difference of anywhere from 9V to 1702V (see http://imgur.com/a/08I3W, yes, with 4 digits). The multimeter is otherwise working normally, so I don't see a good explanation. Is the Arduino pin just incapable of providing sufficient current/voltage to activate the transistor, or am I missing something obvious. And does anyone have some idea why the voltmeter is reading so high and fluctuating so wildly? It is curious that the Arduino disconnects from the PC whenever the circuit is completed with the motor in it, so the Arduino likely is overdrawing from the USB.

The transistor included was not the one listed, but a common MPS2222A.

Thanks


texts:
i just bought a hobby telescope, it works well for being nothing much than a toy, the very problem is that the gesrs that should keep it stable are all plastic and very hard to tighten while keeping it steady.
So I thought to let the gears wide open and move it with arduino: you point the object manually then with 4 buttons move it by small steps.
I've tried to use a couple of servos i had at home, mg90s 2kg 180°; while 180° is enough for the purpose, first i don't think 2kg is enough for the X axis motor, second one is not very precise (using the default library).
I know I can achieve better results calibrating the pulse manually, but maybe is better if I use better motors.
What motors (and why) would you reccomand?
Servo or stepper?
Being for a hobby the budget is low, so very max 50$?


texts: Invoke a method in the main sketch from within a library

texts:
I need to use a specific library that issues error messages in the form of String texts. The library uses the Serial.println() function to send the messages to the Arduino IDE's serial monitor.

The problem is that I have the Serial lines from the Arduino linked to another device, therefore I can't use the Serial Monitor to see the messages. I have a method in the Main Arduino sketch that sends any String text msg generated to another device using Udp commands (wireless). This device is connected to a serial monitor unit.

My question is: How can I invoke the Udp method inside the main sketch of the Arduino program from within the aforementioned library? This would help me to convert the Serial.print() text messages from the library directly into Udp messages to be able to visualize them.

The Udp method I'm using is declared as void UdpSend(String msg) in the Arduino sketch. I'd like to use something similar inside the library to wrap the text msg and send it over to the method on the main program.

Any example or link to get this information will help.

EDIT1:

@Majenko,

On the target library, added:  void libUdpSend(const char *libMsg);
On the sketch, I added this method (Udp comm handler):

 void libUdpSend(const char *libMsg)
 {
   Udp.begin(localPort);
   Udp.beginPacket(Udp.remoteIP(), localPort);
   Udp.write(libMsg);
   Udp.endPacket();
   delay(40);
 }

Added this line on the library (right after the declaration on 1.) to test through the remote serial interface:

libUdpSend("String wrapper has been implemented SUCCESSFULLY!");

When trying to compile linking the library, the following exception occurrs:

  error: expected constructor, destructor, or type conversion before '(' token
  libUdpSend("String wrapper has been implemented SUCCESSFULLY!");

I then switched to String as this is the type I want to wrap, Same steps:

On the target library, added:  void libUdpSend(String *libMsg);
On the sketch:

void libUdpSend(String *libMsg)
{
  Udp.begin(localPort);
  Udp.beginPacket(Udp.remoteIP(), localPort);
  Udp.write(libMsg.c_str());
  Udp.endPacket();
  delay(40);
}

Now the error message says:

  request for member 'c_str' in 'libMsg', which is of pointer type 'String*' (maybe you meant to use '->' ?)

I am not an expert on pointers so I'd need some help on how to assign the pointer as argument on the UdpWrite function using the '->' command proposed by the compliler?

Let me know your thoughts on this.


texts: L293D motorshield with batteries doesn't power Arduino

texts:
Recently I came across a video about a guy building a remote Bluetooth-controlled Arduino car and I was quite amazed. So I decided I wanted to build it too. I have no Arduino or electronics experience at all other than being an IT professional.
So I bought the parts he used in the video (he advised a knockoff Arduino in the description).
After putting it all together the motors work through Bluetooth (yay!). But the issue is that the batteries connected to the motorshield don't give power to the Arduino at all (because the lights don't turn on).
When plugged in the laptop with the USB cable the Arduino gets powered and the motorshield light turns on just a bit, but not enough to make the motors and Bluetooth work.
So in short:
USB powered: Arduino works, motorshield light barely turns on, motors don't work, Bluetooth lights go on, but is not emitting a signal.
2x 18650 battery powered: motorshield light shines bright, Arduino doesn't work, Bluetooth lights don't flicker.
Both: everything works.
So for some reason, the batteries connected to the motorshield don't power the Arduino.
Video used:
https://youtu.be/Q36NbjPMV5k
Circuit diagram:

Knockoff arduino:

L293D motor shield (I'm aware that the ground of the power isn't plugged in)

Parts used:

Geekcreit UNO r3 ATmega16U2 AVR
L293D motor shield
Geekcreit HC-05 bluetooth
4 TT motor
2x 18650 3,7-4.2v 2200mah batteries

I really don't know what I did wrong, since I followed the video and did exactly what the person did. Maybe the batteries aren't powerful enough?


texts:
Does anyone know how to wrap and or text using the U8G2 Libary?   I know there are other libraries that do this for you, but I'd like to use U8G2.

Thank you!

my code's here for reference.  It's not clean, but it works for now https://create.arduino.cc/editor/shaiss/0a2736f4-fb79-4e12-b9d7-fb15ff6757b7/preview


texts: How to save a hex file into Arduino Flash to send it via Serial?

texts:
I have a text file with hex values formatted in the following style:

A0 3F 55 01 00 C7 55 01 00 C7 AA 29 71 11 00 0B
00 C7 AA 29 71 1F AA 29 71 11 55 01 A0 3F 55 DC
...

How can I save this data into my Arduino's Flash (to save RAM)? What libraries are needed? Is there any tool that can automatically create code for this purpose?

After I save this data into the Arduino's Flash, I want to send the data via Serial. I have to send it as binary.

A solution without saving it into the Flash would be also OK.

I am using an Arduino Due.


texts: No ttyACM0 with Pro Micro on Ubuntu 18.04

texts:
I am trying to determine the dev path of a USB keyboard running an Arduino Pro Micro on my Ubuntu 18.04 system. The files /dev/ttyACM0 and /dev/ttyUSB0 do not exist.

When I run dmesg I get:

[  410.770931] usb 3-3: new full-speed USB device number 3 using xhci_hcd
[  410.962180] usb 3-3: New USB device found, idVendor=feed, idProduct=3060, bcdDevice= 0.01
[  410.962184] usb 3-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[  410.962187] usb 3-3: Product: Dactyl-Manuform (5x6)
[  410.962189] usb 3-3: Manufacturer: tshort
[  410.962191] usb 3-3: SerialNumber: 0
[  411.006440] input: tshort Dactyl-Manuform (5x6) as /devices/pci0000:00/0000:00:07.1/0000:11:00.3/usb3/3-3/3-3:1.0/0003:FEED:3060.0008/input/input27
[  411.063192] hid-generic 0003:FEED:3060.0008: input,hidraw0: USB HID v1.11 Keyboard [tshort Dactyl-Manuform (5x6)] on usb-0000:11:00.3-3/input0
[  411.089097] input: tshort Dactyl-Manuform (5x6) Mouse as /devices/pci0000:00/0000:00:07.1/0000:11:00.3/usb3/3-3/3-3:1.1/0003:FEED:3060.0009/input/input28
[  411.147172] input: tshort Dactyl-Manuform (5x6) System Control as /devices/pci0000:00/0000:00:07.1/0000:11:00.3/usb3/3-3/3-3:1.1/0003:FEED:3060.0009/input/input29
[  411.147297] input: tshort Dactyl-Manuform (5x6) Consumer Control as /devices/pci0000:00/0000:00:07.1/0000:11:00.3/usb3/3-3/3-3:1.1/0003:FEED:3060.0009/input/input30
[  411.147395] hid-generic 0003:FEED:3060.0009: input,hidraw1: USB HID v1.11 Mouse [tshort Dactyl-Manuform (5x6)] on usb-0000:11:00.3-3/input1

Dactyl-Manuform is the keyboard so it seems to recognize the device. The command lsusb returns several usb devices. The entry with no title is the keyboard (based on doing watch lsusb):

Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 003: ID feed:3060
Bus 003 Device 002: ID 045e:02d1 Microsoft Corp. XBOX One Controller for Windows
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 002: ID 1e7d:2c2e ROCCAT
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

I have installed arduino and arduino-core from the official repos.

However, I still cannot get a ttyACM0 or ttyUSB0 to appear, and in the Arduino IDE the "Serial Port" option is greyed out (even when using sudo).

What can I check for to either 1) get the ttyACM0 file to exist for my Arduino device or 2) find some other dev port to use as the serial port?


texts: ESP8266 working as station while in AP mode

texts:
I'm programming an ESP8266 via the Arduino IDE with Arduino libraries.  I explicitly set the WiFi mode to WIFI_AP, but then, as described below, I'm still able to use it as both AP and station.  That leaves me unclear what's meant by the three modes available (WIFI_AP, WIFI_STA, and WIFI_AP_STA) since it seems that I've set to WIFI_AP explicitly but am getting behavior consistent with WIFI_AP_STA.

I have read various documents online about these modes. I think I'm clear on the conceptual difference between them.  What concerns / confuses me is that the actual behavior does not appear to match the specified behavior.

More detail:

Near the beginning of my setup function, I have this code

WiFi.mode(WIFI_AP);
WiFi.softAP(ssid, key);

server.begin();

where ssid and key are strings defined with appropriate values, and server is a global variable of type WiFiServer that has been initialized outside of setup.  When run, I see the network with the given name on my phone and can connect to it with the given password.  I can then browse to the IP address assigned by the ESP8266 and set the webpage sent by the server that's been defined in code.  So far so good.

At some point later, inside my loop, a condition triggers the ESP8266 to connect to my router.  Specifically, I have this sequence of code that runs once that trigger occurs:

WiFi.disconnect();
WiFi.begin(router_ssid, router_key);
auto status = WiFi.status();
while ( (status != WL_CONNECTED) && (status != WL_CONNECT_FAILED) ) {
    delay(500);
    status = WiFi.status();
}

As before, router_ssid and router_key are variables declared elsewhere with the proper values for my router.  I can verify from subsequent print statements, that the connection succeeds and get the IP address as assigned by my router. It is clear that the new IP is assigned by the router because it is on the subnet used by my router, which is different than the subnet the ESP8266 is defining in AP mode.

The ESP8266 is configured to serve a small webpage, as noted above. I can now reach that page using my phone, which is connected directly to the ESP8266 via the IP address assigned initially by the ESP8266 in AP mode, and I can also reach the same page from my laptop (connect to my router) using the IP address assigned by my router.  It would seem that I'm effectively in "AP+STA" mode now, despite having explicitly set to "AP" mode at the beginning.

So what's happening here?  Did I automatically switch to "AP+STA" mode when I called WiFi.begin?  If yes, what's the point (if any) of calling WiFi.mode?  If no, then why am I able to operate as if in "AP+STA" mode given the explicit setting of "AP" mode?


texts: I am trying to simulate a 12V LED strip as per this tutorial. However the schematic I tried to make on EasyEDA looks quite different from the images on the website. I wanted to know if what I did is correct.


texts:
I'm trying to make AC current (50Hz) with an Arduino Uno. It seems to be not working (or wrong code).

int up;
int down;
int out = 11;
void setup() {
  pinMode(out, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  for (up = 0; up <= 255; up++) {
    analogWrite(out, up);
    delay(1);
  }
  for (down = 255; down >= 0; down--) {
    analogWrite(out, down);
    delay(1);
  }
}

Update:

Now the code above is giving output voltage of 0-5V (getting increased from 0 to 5 and then decreased) not giving a negative cycle (-5V).
After setting the minimum delay of 1, the output wave is still half wave rectifier with frequency 2Hz.
Without delay LED is blinking so fast I don't know what's its frequency.

How do I make make 50Hz AC current a with negative cycle?


texts: How can I use an MPU6050 with Arduino to measure linear speed?

texts: I need to measure linear speed of a body which travels 1000 m forward and backward recursively. How can I use an MPU6050 with Arduino Nano to measure the linear speed of a moving object? (the object does not have any rotation). I tried my best, but I was not able to measure linear speed, can I get sample source code?


texts: Problem sending string with Python to Arduino through serial port

texts:
I want to send string 50 to Arduino through serial port, the Arduino UNO seems it communicates with port COM25 but it doesnt receive the string properly:

import serial # if you have not already done so

ser = serial.Serial('COM25')
ser.baudrate = 9600
ser.write(b'50')
ser.close()

Btw Arduino code is correct I checked it with other serial com programs. How can I fix the above code?


texts:
When I assign a global var to a certain value inside an if-block it has been changed to another value in the next statement. Somehow the address of the var is overwritten by some other process. It also does not stop at 1 value, this happens to the next vars that are assigned another value too. The vars are not defined in a row but should be close.
I already installed a newer version of Arduino IDE, no change.
Example:

menuActive=1;
Serial.print(menuActive);

gives results in the range 40 to 57 as far as I have seen till now. Further actions assign always the SAME value to next vars I assign after this.
Anyone some idea what could cause this? Am I low on memory for local vars?
This is compile message:

Sketch uses 21790 bytes (70%) of program storage space. Maximum is 30720 bytes.
Global variables use 1454 bytes (70%) of dynamic memory, leaving 594 bytes for local variables. Maximum is 2048 bytes.

edit:

As I already said, it is 21k of code. But I show you the part of the code that mishaves:

while ((digitalRead(rotSwPin) == 0) && lpress <= 200) {
    delay(10);
    lpress++;
    if (lpress > 200) {
        menuActive++;
        menuLvl=0;
        menuPos=0;
        subPos=0;
    }
}

Normally I use menuActive=1. Within the braces, it is still 1, out of that it changes. Maybe change from byte to bool.


texts:
SparkFun BasicAHRS_I2C giving unstable readings.

I am using the SparkFun Arduino Sketch from here.

It is giving me these results:

X-acceleration: 91.43 mg Y-acceleration: 249.51 mg Z-acceleration: 1042.05 mg
X-gyro rate: -0.549 degrees/sec Y-gyro rate: 0.557 degrees/sec Z-gyro rate: 1.595 degrees/sec
X-mag field: -164.35 mG Y-mag field: -240.16 mG Z-mag field: -20.73 mG
Temperature is 27.9 degrees C

and then the next result (when MPU9250 is still) is:

X-acceleration: 91.49 mg Y-acceleration: 252.75 mg Z-acceleration: 1039.49 mg
X-gyro rate: -0.076 degrees/sec Y-gyro rate: -0.130 degrees/sec Z-gyro rate: -0.008 degrees/sec
X-mag field: -175.07 mG Y-mag field: -222.24 mG Z-mag field: -27.64 mG
Temperature is 27.9 degrees C

Notice how the temperature has remained constant, acceleration has remained constant (although im not why there is a reading if the MPU9250 is stationary) and the mag field is fairly close. However, the Gyro values are not close.

Could I have a bad MPU9250?

I am using the Mega.

Edit: Added a complementary filter from here, however they have not added a comp filter for the z value as can be seen from my screenshot of the serial monitor:

I think this is because they have the MPU6050 and not the MPU9250. I believe the MPU9250 has the magnetometer which can be used to 'help' the drift?

How could I use the magnetometer to help counter the drift?

End goal: rotate a gameobject in unity with the MPU9250 with minimal drift and maximum accuracy.


texts:
const uint8_t OUTPUT_PIN = 3;  // = OC2B
const uint8_t PERIOD = 9;      // 9 CPU cycles ~ 1.778 MHz

void setup()
{
    pinMode(OUTPUT_PIN, OUTPUT);
    TCCR2B = 0;           // stop timer
    TCNT2  = 0;           // reset timer
    TCCR2A = _BV(COM2B1)  // non-inverting PWM on OC2B
           | _BV(WGM20)   // fast PWM mode, TOP = OCR2A
           | _BV(WGM21);  // ...ditto
    TCCR2B = _BV(WGM22);  // ...ditto
    OCR2A = PERIOD - 1;
    OCR2B = PERIOD/2 - 1;
}

void soundBuzzer() {
    TCCR2B |= _BV(CS20);  // F_CPU / 1
}

void silenceBuzzer() {
    TCCR2B &= ~_BV(CS20);
    TCNT2 = 0;
}

I got it from here, look down to the answers

This program supposed to generate a square-wave of frequency around 1.7MHz but it is not working for me. I have tried the simulation on Proteus 8 and there is no output. Only one error shows during the compilation which is the 'loop' function is missing, I have added one and still there is no output. Please somebody help me.


texts: Counter on my coin acceptor goes up without a coin input, any advice?

texts:
I'm working on a project that makes use of a CH926 coin acceptor. The problem we're having is that when I read the serial monitor, the coin value is continuously going up and adding credits when it's supposed to remain at 0 until a coin Is fed into the acceptor.

We've tried a different coin acceptor, different codes, arduinos, wiring, resistors, breadboards, the lot. nothing seems to be solving this problem and we can't determine why, it had been working fine until we tried to tidy up our wiring and untangle it.

we're using a basic code that had worked fine up until we had the issue of the counter value no longer remaining at 0:

const int coinpin = 2;
const int ledpin = 3;
const int targetcents = 100;

// Variables
volatile int cents = 0;
int credits = 0;

// Setup
void setup() {

  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(coinpin), coinInterrupt, RISING);
  pinMode(ledpin, OUTPUT);

}

// Main loop
void loop() {

  // If we've hit our target amount of coins, increment our credits and reset the cents counter
  if (cents >= targetcents) {
    credits = credits + 1;
    cents = cents - targetcents;
  }

  // If we haven't reached our target, keep waiting...
  else {
  }

  // Debugging zone
  Serial.print(cents);
  Serial.print(" cents toward current credit and ");
  Serial.print(credits);
  Serial.println(" credit(s) earned so far.");
  delay(1000);

  // Turn off LED
  digitalWrite(ledpin, LOW);

  // Now, write your own cool code here that triggers an event when the player has credits!
  if (credits > 0) {
    // Play music?
    // Spin up a motor?
    // Start a game?
    // It's up to you!
  }

}

// Interrupt
void coinInterrupt(){

  // Each time a pulse is sent from the coin acceptor, interrupt main loop to add 1 cent and flip on the LED
  cents = cents + 1;
  digitalWrite(ledpin, HIGH);

}

any advice on what may be causing this problem?

cheers


texts: How to save data in arduino when it's power goes off

texts:
I am doing a project 'arduino based switch operation'. Here the user needs to set a time to turn on relay and set time to turn it off. The problem is that I want to supply power to arduino using adapter connected to the ac supply (where the relay will also be connected). When the on time is set and if power goes off for some time then this system doesn't work. I want to save the data in arduino so that it will retain the data if power comes back.. So that my relay is operated on time..
How to do it guys???


texts:
I have a few TFT LCD displays lying around which I salvaged from old phones. I would really like to use them with my Arduino. I didn't get anything about making a shield on the net but only links to eBay and Amazon. Please help.
It is a 36 pin tft for which adapters can be found.
But I don't know the wiring or the pins concerned.
Here is the supposed pin data sheet for my lcd for ur help


texts: Is there a way to update Arduino uno Over The Air

texts:
I have the Arduino uno with a Ethernet W5100 Shield and would like to remotely sketches.  Is there a way to update Arduino uno over the air?  If not, is there a wired network arduino solution that will allow update over the air.

I've done this on the esp8266 using there tools but I can't find one for the Uno.

Thanks


texts: Would someone provide an example of extracting data from a char array?

texts:
I have tried so many things now that I am just confused.
I am not understanding the way char arrays work.
I can't get the date and names extracted.  And when I use just strings, I jam up the memory.

Below was my last attempt, before asking the question.
while (f.available()) {
  String line = f.readStringUntil('\n');

  if (line.startsWith("04-23")) {
    currentDay = 1;
    int str_len = line.length() + 1;
    char char_array[str_len];
    line.toCharArray(char_array, str_len);
    Serial.println(char_array);                 // Everything works to here
    for (int j = 0; j < 2; j++) {
      b += char_array[j];
    }
    bMth = b.toInt (); // This should be an int of the birth month in this case: 04
  }
}

Var:
format: MM-DD-YYYY,Name  // this is inside the file
line = "04-23-2020,James"  // This is the output from - Serial.println(char_array);

What I am trying to do is

Extract the month/day so that I can compare it to today.
The year so I can calculate the age.
The name to display on OLED.
Everything else seems to work, but I can't get my head
wrapped around the char array access.

To do this in PowerShell I would do:
$line = "04-23-2020,James"

$dob = ($line.Split(","))[0]
$bMth = ($dob.Split("-"))[0] # This is not used in this example
$bDy = ($dob.Split("-"))[1]  # This is not used in this example
$bYr = ($dob.Split("-"))[2]

$age = $(get-date -UFormat %Y) - $bYr

Clear-Host
Write-Host (@'
Name: {0}
Age:  {1}

'@ -f $($line.Split(","))[1], $age)

In Python:
import datetime as dt

line = "04-23-2020,James"

dob = (line.split(',')[0])
bMth = (dob.split("-"))[0] # This is not used in this example
bDy = (dob.split("-"))[1]  # This is not used in this example
bYr = (dob.split("-"))[2]

age = int(dt.datetime.now().year) - int(bYr)

print('Name: ',(line.split(',')[1]))
print('Age: ', age)


texts: Arduino Yun not getting response from Azure API

texts:
I posted this on StackOverflow but figured I'd post it here too. Sorry in advance if thats not allowed.
I'm trying to get my Arduino Yun to talk to an API that I'm hosting on Azure. I would like to do more complex things in the future, but at the moment I'm just trying to make a GET request over wifi with a single integer as a parameter.
I'm basically just using the example found here with the url changed. The example works fine, so as far as I'm aware the issue isn't with my board, its with the interaction with Azure.
HttpClient.get() returns an int as a response (not the regular HTTP response codes, its unique for the library). I got 60 initially, and changing my API to accept http calls (instead of just https) fixed this and made me get a response of 0 instead. 0 is the same response that I get from the working Arduino example, but for some reason I'm not actually getting anything in the body of my response, as the client.available() loop is never entered.
The API works as intended when I go to the url in chrome, so the issue arises somewhere due to how the arduino and azure talk to each other, but I don't know enough about either to figure it out and nowhere that I look seems to point me in the right direction.
Any help would be greatly appreciated, thanks.


texts: Why is this IIR Filter unstable on the Arduino Due?

texts:
I am using an Accelerometer (on the MPU6050) and connected it to the Arduino Due. In order to filter the signal I am using an IIR Filter with the following transfer function:

H(z) = Y(z)/X(z) = B/A

B = 0.00000376 + 0.00001127*z^(-1) + 0.00001127*z^(-2) + 0.00000376*z^(-3)

A = 1 - 2.9372*z^(-1) + 2.8763*z^(-2) - 0.9391*z^(-3)

which is an IIR 3th Order Butterworth, Cutoff Freq: 0.5Hz, Samling Freq: 100Hz. These numbers can be calculated by any IIR calculator.

Thus, then discrete equation is:

y[n] = 0.00000376*x[n] + 0.00001127*x[n-1] + 0.00001127*x[n-2] + 0.00000376*x[n-3] + 2.9372*y[n-1] - 2.8763*y[n-2] + 0.9391*y[n-3]

I first tried it on the Arduino UNO. Then I found out that decimal point precision (float & double) on the UNO is only 6-7 digits. But the therm "B" in the transfer function has for example (0.00000376) 9 digits. I thought this is the porblem, so I switched to Arduino Due and now I am using double (instead of float) which should have enough precision.

It is still unstable. It is not oscillating but getting bigger. I also tried an IIR 4th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz. This one is oscillating.

However, the only IIR that seems to be stable is an IIR 3th Order Butterworth, Cutoff Freq: 1Hz, Samling Freq: 100Hz.

I have no idea so far what the problem is. Could anyone help please?


texts:
I want to transfer image to PC via Arduino leonardo.
OV7670 is non-FIFO, and no SD card connected.

I followed this blog and this youtube video.using this code.
when uplaod, I got errors below:

Arduino: 1.8.5 (Windows 10), Board: "Arduino Leonardo"
error: 'ASSR' was not declared in this scope
error: 'EXCLK' was not declared in this scope
error: 'AS2' was not declared in this scope
error: 'TCCR2A' was not declared in this scope
error: 'COM2A0' was not declared in this scope
error: 'WGM21' was not declared in this scope
error: 'WGM20' was not declared in this scope
error: 'TCCR2B' was not declared in this scope
error: 'WGM22' was not declared in this scope
error: 'CS20' was not declared in this scope
error: 'OCR2A' was not declared in this scope
error: 'UBRR0H' was not declared in this scope
error: 'UBRR0L' was not declared in this scope
error: 'UCSR0A' was not declared in this scope
error: 'UCSR0B' was not declared in this scope
error: 'RXEN0' was not declared in this scope
error: 'TXEN0' was not declared in this scope
error: 'UCSR0C' was not declared in this scope
error: 'UCSR0A' was not declared in this scope

I know that error occurred because this code is only for UNO. But mine is leonardo. Changing settings (Tool->board:uno board) was still compiling error.
I have search this Topic found nothing. I am so confusing, please help.


texts: Communication between Arduino UNO using an ethernet shield and a RF attenuator

texts:
I am relatively new to Arduino and I was wondering if someone could help me with my problem.
I have a RF attenuator that can be programmed in various ways.
For example if I type http://10.10.10.10/:MN? in my browser it returns the model name of the attenuator.
My aim is to do that using an arduino UNO and an ethernet shield and display the result through the serial monitor.
The arduino and the attenuator are both plugged in the same router i.e in the same network.
Can anyone help me with the code please it is urgent.
The link for the RF attenuator's Manual:
https://www.minicircuits.com/softwaredownload/Prog_Manual-6-Programmable_Attenuator.pdf


texts: waiting for a set number of inputs in an array to be reached

texts:
How do i have code wait for an x number of inputs be reached in an array before doing anything else?

int largestindex = 0;
int learnindex=0;

    void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
    learn[learnindex]=pitch;
     learnindex++;
    }

    while(learn[largestindex]==0){
          MIDI.read();
          if (learn[largestindex]!=0){
           break;
              }


texts:
Is it possible to change serial information of arduinos board ?
For example I have an arduino uno with this serial informations :

{
      comName: '/dev/cu.usbmodem1411',
      manufacturer: 'Arduino (www.arduino.cc)',
      serialNumber: '75430333137351804230',
      pnpId: '',
      locationId: '0x14100000',
      vendorId: '0x2341',
      productId: '0x0043'
}

I want to modify for example the manufacturer to be able to automatically detect the device whatever the comName is. I don't want to detect arduino board I want to detect arduino board modify by me without make a serial connection.


texts:
I am having a problem implementing a the digitalRead() function in arduino uno.I want digitalRead to return 0 when nothing is connected and return 1 when it is connected to +5 volt.But seems like digitalRead returns random values when it is not connected to anything.
I have kind of solved the problem by a small piece of code to stabilize the value i'll attach the code here but if any other solution is avalable..Please help.

The function is as follows:-

bool getValue()

{

String k="";

if(digitalRead(3)==HIGH)

k="HIGH";

else

k="LOW";

bool f=true;

for(int i=0;i<1000;i++)

{
String z;

  if(digitalRead(3)==HIGH)

  z="HIGH";

  else

  z="LOW";

  if(k!=z)

  {

    f=false;

    break;

  }

}

if(f==true)

return true;

else

return false;

}


texts:
I know there is a lot on this subject on the net but i cant seem to be able to join the dots together.
I am trying to make sensor system than can run for as long as possible if not indefinitely using an Arduino, and also to do so very cheaply. I have a £1 Arduino Nano clone that is running with sensor and alarm fine, but currently its runs off USB power from PC.

I have followed this guide to minimize power usage code side: https://www.openhomeautomation.net/arduino-battery/

And I have read that the Vin pin needs at least 7 volts to work properly, so 2 volts would be wasted in heat making a 5V level.

I have a 3.7V lithium cell 4300mAh so I thought I would need a step up boost module.

But it looks like the Nano can run using 3V. But the 3.3V rail is apparently made for external sensors, assuming I want a mixture of cheap/simple and high efficiency. Can i just hook a 3.7 lipo into the 5V rail of the Nano and a 5V solar panel (with diode) up to same point? Will this kill my Nano?
If not, is it worth stepping the 3.7V down to the minimum the Nano can run with?

Underclocking is not an issue, it essentially wakes up every hour reads 5 sensors and if all is well (99% of the time) goes back to sleep for an hour.
Linear voltage regulators seem to burn the excess voltage as heat. And then what will happen when the battery dies off and is no longer 3.7 volts? And if my solar panel is around 5V in good light, if its partly shaded and only has 3.5 volts for example it would not charge my lipo to 100% capacity. Should I step up DC/DC boost the panel voltage to charge my cell.

Guidance please.


texts: Temperature sensors TMP36 and LM35 have temperature diff. (offset) in the same circuit

texts:
I am trying to use the two temperature sensors TMP36 (from Sparkfun Inventor's kit) and KEYES LM35.

In read TMP36 Sensor and I convert the result to Celsius using the following code:

// TMP36 input sensor -> degrees Celsius calculation
TM36reading = analogRead(TM36sensor);
TM36voltage = (TM36reading/1024.0)*5.0;
//converting from 10mv per degree with 500 mV offset
//             (TMP36 voltage - 500mV) times 100)
TM36degreesC = (TM36voltage - 0.5) * 100;

In read LM35 Sensor and I convert the result to Celsius using the following code:

// LM35 input sensor -> degrees Celsius calculation
LM35reading=analogRead(LM35sensor);    // reads the LM35 output
LM35voltage = (LM35reading/1024.0)*5.0;
LM35degreesC=LM35voltage*100.0;

I have connected also a LCD display to monitor visually the values of these two sensors. Here is my full code. I use also a serial log. Here is a sample from this serial log (as you can see there is a difference/offset between 0.5 to 0.9 Celsius).

TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.89, LM35: 16.11 diff -> 0.78
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.87, LM35: 16.60 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 17.09 diff -> 0.20
TM36: 17.38, LM35: 17.09 diff -> 0.29
mean difference between sensors: 0.48
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.41, LM35: 17.58 diff -> 1.17
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 16.89, LM35: 17.09 diff -> 0.20
mean difference between sensors: 0.71
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 16.89, LM35: 16.60 diff -> 0.29
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.60 diff -> 0.78
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 16.11 diff -> 1.27
TM36: 17.38, LM35: 17.09 diff -> 0.29
TM36: 16.89, LM35: 16.11 diff -> 0.78
mean difference between sensors: 0.93

I power the Arduino from the computer using the USB cable. When the computer is ON we have the offset that I already demonstrated above. When the computer is turned off (after computer shutdown), immediately the sensor of TMP36 falls around 1 Celsius.. And then both sensors have similar temperature.

Why there is this temperature difference between TMP36 and LM35 sensors? How can we "fine tune" these sensors to monitor the real temperature?


texts: Why can't this C++ program read my arduino's Serial.write()?

texts:
I made a super simple arduino uno sketch to send a serial byte once every second:

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

void loop(){
   Serial.write(12); // send a byte with the value 12
   delay(1000);
}

My arduino is hooked up to com 3.

On the other end of the line, I have a C++ program with the following read function:

int Serial::ReadData(char *buffer, unsigned int nbChar)
{
    //Number of bytes we'll have read
    DWORD bytesRead;
    //Number of bytes we'll really ask to read
    unsigned int toRead;

    //Use the ClearCommError function to get status info on the Serial port
    ClearCommError(this->hSerial, &this->errors, &this->status);

    //Check if there is something to read
    if(this->status.cbInQue>0)
    {
        //If there is we check if there is enough data to read the required number
        //of characters, if not we'll read only the available characters to prevent
        //locking of the application.
        if(this->status.cbInQue>nbChar)
        {
            toRead = nbChar;
        }
        else
        {
            toRead = this->status.cbInQue;
        }

        //Try to read the require number of chars, and return the number of read bytes on success
        if(ReadFile(this->hSerial, buffer, toRead, &bytesRead, NULL) && bytesRead != 0)
        {
            return bytesRead;
        }

    }

    //If nothing has been read, or that an error was detected return -1
    return -1;

}

This seems to check only one time if data is available, so obviously I have to loop through it until data comes in.  I did that in my main program:

#include "Serial.h"
#include <iostream>

using namespace std;

int main(void)
{
    Serial serial("COM3");

    char* c = "";
    int len = strlen(c);
    while(c == "")
    {
        serial.ReadData(c, len);
    }

    cout << "\n\n";
    system("PAUSE");
}

When I do this, my C++ program gets stuck in an infinite loop waiting for data from the arduino, and I cannot figure out why this is happening.  My program never sees the data the arduino is sending.

This Serial class works and is configured properly because I can SEND all the data I want to the arduino without any problems.  My issues are only with reading back from the arduino.

Can someone please help me figure out why this is not working?


texts: Can't replace SoftwareSerial by Serial1 on Mega board

texts:
This sketch runs well with SoftwareSerial define and the monitor displays device modbus values. But now, i want to replace SoftwareSerial by Serial1
and i have no data.

This is the sketch with SoftwareSerial:

#include <SoftwareSerial.h>
#define SSerialRX        10  //Serial Receive pin
#define SSerialTX        11  //Serial Transmit pin
#define SSerialTxControl 40   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

SoftwareSerial RS485Serial(SSerialRX, SSerialTX); // RX, TX
byte byteSend;

void setup()
{
  Serial.begin(9600);
  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Transmit);  // Init Transceiver
  RS485Serial.begin(9600);
}
void loop()
{
  delay(500);
  if (RS485Serial.available())
  { for(int i=0; i<7; i++)
    {
    byteSend = RS485Serial.read();   // Read the byte

    Serial.print(byteSend, HEX);
    Serial.print(" ");
    }
  }
  digitalWrite(SSerialTxControl, RS485Transmit);  // Init Transceiver
  byte request[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
  RS485Serial.write(request, sizeof(request));

  digitalWrite(SSerialTxControl, RS485Receive);
  Serial.println(" ");
}

And the sketch i tried with Serial1 (pin 19(Rx) and 18(Tx)):

#define SSerialTxControl 40   //RS485 Direction control
#define RS485Transmit    HIGH
#define RS485Receive     LOW

byte byteSend;

void setup()
{
  Serial.begin(9600);
  pinMode(SSerialTxControl, OUTPUT);
  digitalWrite(SSerialTxControl, RS485Transmit);  // Init Transceiver
  Serial1.begin(9600);
}
void loop()
{
  delay(500);
  if (Serial1.available())
  { for(int i=0; i<7; i++)
    {
    byteSend = Serial1.read();   // Read the byte

    Serial.print(byteSend, HEX);
    Serial.print(" ");
    }
  }
  digitalWrite(SSerialTxControl, RS485Transmit);  // Init Transceiver
  byte request[] = {0x01, 0x03, 0x00, 0x00, 0x00, 0x01, 0x84, 0x0A};
  Serial1.write(request, sizeof(request));

  digitalWrite(SSerialTxControl, RS485Receive);
  Serial.println(" ");
}

Can you help me to find my mistake ?


texts:
I have a Photo Interrupter which I am using to count the RPM of a motor.

I am incrementing an integer to show the amount of interrupts there have been.

The issue is that there can be several interrupts fired for each time the "beam" of the Photo Interrupter is broken.

I have a 5mm length of plastic which breaks the "beam". If I make the plastic shorter than that, the Photo Interrupter doesn't pick up the break.

I am using the following, very basic code:

int pin = 13;
volatile  int tcnt = 0;
volatile int state = LOW;

void setup() {
  Serial.begin(9600);
  pinMode(pin, OUTPUT);
  attachInterrupt(0, blink, CHANGE);
}

void loop() {
  Serial.println(tcnt);
  digitalWrite(pin, state);
}

void blink() {
  tcnt = tcnt + 1;
  state = !state;
}


texts: Confused between which arduino to use for project?

texts:
I am planning to build a smarthome working model with arduino. I will also need to connet to wifi(not ethernet). So I was wondering which setup would be the best:-

Arduino Uno + ESP8266
Arduino Yun
Arduino Uno + Wifi Shield
Or any other setup/ board(eg-Raspberry Pi 3B, ESP32 etc).

I would be connecting at least few leds, servos, and some sensors, so it should be able to handle that.

My project will be based on this model

http://www.instructables.com/id/Arduino-controlled-Smart-Home/

It will also have a temperature sensor and a rain sensor.


texts: Error while connecting Arduino to Macbook: “serial port already in use. try quitting any programs that may be using it”

texts:
I'm trying to connect to my Arduino board through a macbook pro with mac os x 10.9.3 installed. I'm following the instructions from the arduino guide and in the connection section:

  " Connect the Arduino board to your computer using the USB cable. The green power LED (labelled PWR) should go on.
  If you're using the Arduino Uno or Arduino Mega 2560, a dialog box will appear telling you that a new network interface has been detected. Click "Network Preferences...", and when it opens, simply click "Apply". The Uno or Mega 2560 will show up as "Not Configured", but it's working properly. Quit System Preferences.

I cannot see any ports that hold the USBModem port.

How to setup the connection in the right way?

I read some articles about making a lock folder and I followed them but they didn't work for me, I also tried following this article but the solution there didn't work as well.


texts:
I got the following error:

warning: variable 'b' set but not used.

I think I do a really small thing wrong but I can't figure out what it is.

#define array_size(array) ((int)(sizeof(array) / sizeof((array)[0])))

typedef struct Boid {
  unsigned long start_animate_time;
} Boid;

Boid boids[4];

Boid create_boid() {
  unsigned long start_animate_time = 0L;
  Boid b = {start_animate_time};
  return b;
}

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

  boids[0] = create_boid();
  boids[1] = create_boid();
  boids[2] = create_boid();
  boids[3] = create_boid();

  for (int i = 0; i < array_size(boids); i++) {
    Boid b = boids[i]; // <<<<<<<<<<<<< this line!
    b.start_animate_time = 456;
  }

  for (int i = 0; i < array_size(boids); i++) {
    Boid b = boids[i];
    Serial.println(b.start_animate_time); // BUG always 0
  }
}

void loop() {

}

  flock_01_ino_debug.ino:28:10: warning: variable 'b' set but not used
  [-Wunused-but-set-variable]
       Boid b = boids[i];
            ^


texts:
I am converting a program made for particle photon to a Mega, everything is working except for the interrupt timer. The code that is of concern is (it's a .cpp file being included in the main .ino)

MyClass::MyClassConstructor(){
    messageTimer = new Timer(20, &MyClass::send, *this);
}

The documentation for this method is here.

Does anyone know a way to convert this to Arduino? There is the Timer library, but I can't really use the update method as the timer is in an instance of a class.


texts: Arduino with ESP8266 via serial pass through

texts:
I bought an Arduino Mega 2650 alongside a couple of ESP8266 chips hoping to make a wireless project take off.

Using the basic serial passthrough code

void setup() {
    Serial.begin(9600);
    Serial1.begin(115200);
    Serial.write("Starting");
}

void loop() {
    if (Serial.available()) {      // If anything comes in Serial (USB),
       Serial1.write(Serial.read());   // read it and send it out Serial1 (pins 0 & 1)
    }

    if (Serial1.available()) {     // If anything comes in Serial1 (pins 0 & 1)
       Serial.write(Serial1.read());   // read it and send it out Serial (USB)
    }
}

updated to use a 115200 baud rate which it seems my version of the 8266 is programmed to use, I encounter this problem when trying to issue it commands:

Starting
AT

ERROR

Looking around I found that this could be caused by the chip not getting enough power. So I hooked it up to a small power breakout board
 with a small 12 power supply I used to have connected to something else. After doing that all it does is spit out question marks even when I dont send anything. Weird part is the TX pin on the arduino thats going crazy? As if I am sending it to myself without a prompt from the ESP board. This only happens when I'm connected to that breakout supply.

Other oddity:
If I have all my wires except for VCC/CH_PD connected everything is fine, but the second I connect them to that power supply everything goes crazy and my TX pin starts flashing up a storm (can it be a voltage issue that also transfers to my Arduino board as well?)


texts:
I am new to using serial input. I have an IR emitter and a photo transistor hooked up to my Arduino, I am trying to see which values corresponds to the colored object I put over my IR emitter and phototransistor.

How do I find which values are corresponding to the changing values from my phototransistor?


texts: Arduino Mega reading from external sensor Issue

texts:
I have one external sensor and I want it to be connected with Arduino. The sensor came up with a usb cable and the pin out diagram is also given in the data sheet .
When I simply connect the the cabe which came along the sensor (E322968) with no Arduino board involved, but through Arduino IDE and setting baud rate to 115200 I am able to see the output in serial monitor of the Arduino .

I want to capture this data to some variables for further manipulation. In the data sheet the pinout is specified as

Please help me get the data to Arduino variable .
What I tried is connected,

the RX1 or Arduino mega to the TX1 of the sensor (pin2) and
from Arduino VCC(5v) to VCC of the sensor :: pin(1)
ground to gnd of sensor, (pin5)


texts: SIlly PID question using the PID library

texts:
I'm new to PID.
My goal: control the motor to get it to run a given RPM by a potmeter (which is setpoint).
Sensor is optical (detects white line, reflections), counts 100 round in x amount of time. Small calculation gives detected RPM.
I'm using an Arduino and the PID library.

Now my question.
Let's say I've implemented the PID lib on the arduino. It all calculates and so on, but it gives a PID_value which I don't understand.

Ex:
setpoint = 5000
detected = 4999
received PID value = 40

It's my guess that this (or rather: all) PID-lib I'm using always gives a value between 0 and 255 and I have to map/scale that value to my AC trigger.
Could someone point me in the right direction? Thanks!


texts:
I'm working with an SDS011 particular sensor through its serial interface. The spec sheet (http://inovafitness.com/upload/file/20150311/14261262164716.pdf) indicates that the second to last byte of a serial packet is a checksum equal to sum of all the data bytes.

I am using pyserial to read and interpret the serial data. Here's a snippet of the code:

import serial

def read_sensor(port):
    while True:
        header = port.read(2)
        if header == b'\xAA\xC0':
            data = port.read(6)
            checksum = port.read()
            tail = port.read()
            if tail == b'\xAB':
                return header + data + checksum + tail

port = serial.Serial(port=MY_PORT)
packet = read_sensor(port)
data_sum = sum(packet[2:8])
checksum = packet[8]

if data_sum == checksum:
  print('Ok')
else:
   print('Error')

However, I haven't got a single packet whose checksum hasn't been an error. Is there anything I could be potentially doing wrong?


texts: What are the distances between Arduino Mega connectors?

texts: I am trying to build an Arduino Mega shield. For that, I need to know the exact distances between the different connectors.


texts: Sending serial data to Arduino from Matlab(not using support package)

texts:
I am learning Arduino and trying to understand how integers and strings are sent across the serial port.
I tried a small program in arduino which reads a number as a string and tries to blink led 13 according to that number. Below is the arduino side of code.

const int ledpin = 13;
int value = 0;
int blinkrate;
void setup()
{
   Serial.begin(9600);
   pinMode(ledpin,OUTPUT);

}

void loop()
{
    if (Serial.available())
      {
         char ch = Serial.read();
         if (isDigit(ch))
            {
               value = (value*10) + (ch - '0');
            }
         else if (ch == 10)
            {
               blinkrate = value;
               Serial.println(blinkrate);
               value = 0;
            }
      }
    blinkled(blinkrate);
}

void blinkled(int blinkrate)
 {
   digitalWrite(ledpin,HIGH);
   delay(blinkrate);
   digitalWrite(ledpin,LOW);
   delay(blinkrate);
 }

When i try to send a string from MATLAB, the RX led blinks once indicating something is coming, but the LED on pin 13 is not behaving accordingly(it should blink according to the number i send). Here is the matlab side of code.

pre_open = instrfindall;
delete(pre_open);
serial_port = serial('COM3');
set(serial_port,'Terminator','CR');
set(serial_port,'BaudRate',9600);
set(serial_port,'DataBits',8);
set(serial_port,'StopBits',1);
set(serial_port,'Parity','none');
fopen(serial_port);
num = 200;
fwrite(serial_port,int2str(num));
data = fscanf(serial_port,'%d');
pause(2);
fclose(serial_port);

When i try to read the return string from arduino, MATLAB shows me a timeout error.

I would be grateful if anybody points me to the right solution.
Thank you.


texts: Arduino reads hc-05 device connecting status

texts: Hello I want to get an arduino get status of bluetooth hc 05 if connect with device or not . I'm trying by myself and search on internet website but I can't find useful things.


texts: Arduino PWM Frequency - Pros and Cons of Modifying

texts:
I am interested in using an Arduino Uno to produce an analog signal by running PWM through an RC low-pass filter.

I'll be controlling a highly dynamic object and need a clean voltage signal to avoid instabilities.  Per this calculator on RC designs, it's suggested that one strategy to reducing voltage ripple is to increase the PWM frequency.

With PWM configured to a default of 980Hz for pins 5 and 6, and PWM of 490Hz for the remaining pins, I've decided that this will create too much voltage ripple for my filter.  I've found resources that describe how to configure the registers to increase the PWM frequency rather drastically.

My question is very simple: Are there any disadvantages to using a higher frequency PWM?  Why is the default set to be so slow?

Thank you!


texts:
I've recently purchased an NFC-PN532 module online, which I connected to my arduino board and tried to get working. After connecting the pins and using the PN532 adafruit lib I encountered and error where the board was not being picked up. I was using the 'readMifareClassic' example from the lib and uploaded the example to the board and it resulted in the image below where I would receive a '?' or the first print output which is 'hello' in the code.
I'm not that experienced with NFC atm and so im seeking some guidance on what may be the issue. If you need more information please leave a comment.
Thank you


texts: What is the fastest way to data to another Arduino SAMD21 boards

texts:
Hello I would be needing to transmit data from one arduino to another as fast as possible? how do I achieve this?

Since my application need a lot of pins (its a compact system so mega and due are not suitable) i am going to use 2 arduino nano 33 IOT (basically a SAMD21 uC) and one of them is just going to read from the sensors convert it to binary ( around 32-40 bits long) and send it to the other arduino.

So parameters are:

must be sent via wires
maximum number of pines used is 6
must be able to repeatedly send data ( like this is the only job the arduino does read from sensors and send it to the other one, repeatedly and endlessly)
must be reliable enough

Thank you Very much !


texts: Creating a product with arduino bootloader

texts:
If you have a prototype with arduino and you wish to create a real product can you do it or the fact that it contains the arduino bootloader prevents you?

BTW, i dont have a product ready. I am thinking options though. Or maybe i will have to go find a job


texts: Bluetooth module HC-05 not finding mobile phones, only PC

texts:
I put the HC-05 in the AT mode with arduino and the comands:

AT+CMODE=1
AT+ROLE=1
AT+INQM=0,10,48
AT+CLASS=0
AT+INIT
AT+INC

It responds "OK" after all till AT+INC, and after this, shows only my notebook's adress, but it has many other mobile phones near with bluetooth on (I can find with my cell phone) and they are not found. Why? Someone help me please


texts: How do I change pin assignments for the LUFA AVRISPMkII?

texts:
I just managed to get Dean Camera's LUFA AVRISP clone working on my Arduino Pro Micro, when to my dismay I found that to use PDI for my XMega, I need to have PD5 exposed for the clock source! The Pro Micro has PD5 connected to an LED, so I am not easily able to use it.

If worst comes to worst, I can desolder the LED and wire a jumper, but that would be a pain in the butt. So I am wondering if any of you know if I can change the clock pin assignment from PD5 to PD6 or some other accesible pin. Thank you in advance for your help!

--[[ EDITS ]]--
Sorry for my lack of clarity, I am using the Pro Micro as the programmer, and the AVRISP clone supports PDI to the XMEGA. The 32u4 is actually directly supported by the programmer firmware. Here is what I am doing:

--[[ EDITS II ]]--
There is a schematic.. umm.. draw-o? I don't know but anyway the cathodes of D1 and D3 are NOT connected. That wire is an error.

simulate this circuit – Schematic created using CircuitLab

--Cantos


texts: Where are the implementations of the SdFat BlockDriver methods?

texts:
This is most probably more of a C++ question than an Arduino question; but since this is an Arduino library, I am asking here.

I am using the SdFat library for my project. The library defines a BlockDriver object in one of its header file which only declares the typedef of BaseDriver to some other classes.

#if ENABLE_EXTENDED_TRANSFER_CLASS || ENABLE_SDIO_CLASS
typedef BaseBlockDriver BlockDriver;
#else  // ENABLE_EXTENDED_TRANSFER_CLASS || ENABLE_SDIO_CLASS
typedef SdSpiCard BlockDriver;
#endif  // ENABLE_EXTENDED_TRANSFER_CLASS || ENABLE_SDIO_CLASS
#endif // BlockDriver_h

typedef SdSpiCard BlockDriver; makes sense to me. But if ENABLE_EXTENDED_TRANSFER_CLASS or ENABLE_SDIO_CLASS are defined, BlockDriver is typedeffed into BaseBlockDriver. BaseBlockDriver is an abstract base class (as defined here). An instance of the BlockDriver object is later used directly in the FatVolume class here.

My question is, how does BlockDriver's method get defined when it abstract base class BaseBlockDriver is typedeffed to BlockDriver?


texts: Run function concurrent to server.available()

texts:
I have a Arduino UNO WiFi Rev2 board that runs WiFiServer serving as a web server. The server listens and accepts clients using server.available(). I also want a loop that controls a servo in concurrent of the server.
I looked at ArduinoThread and tried to implement my web server with it.
class WebServer : public Thread
{
private:
    // Some method definition omitted
    WiFiServer server;
    void accept_and_process();

public:
    void run() override;
}

void WebServer::accept_and_process()
{
    Serial.println("Waiting for client");
    // listen for incoming clients
    WiFiClient client = server.available();
    // Process client
}

void WebServer::run()
{
    this->accept_and_process();
    this->runned();
}

But the code does not run in parallel with code in void loop() it only ran code inside loop function and does not accept client as expected
This is the code I ran the server with
void setup()
{
    Serial.begin(9600);
    WebServer webserver = WebServer();;

    webserver.setInterval(100);
    webserver.run();
}

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

How would I run the server concurrent to another function.


texts: Seeedstudio Wifi shield v1.1 Not working with Arduino Mega 2560

texts: I have been trying use the Seeedstudio wifi shield v1.1 with Arduino Mega 2560 as part of my project but I could not make the WiFly library provided on the wiki work with the Mega. I tried to run the example sketch wifly_test but it did not work I tried some troubleshooting and found that the write commands to the shield were not successful. After a few hours of searching on the internet, I found out the problem and was able to solve it. I am posting my solution below. Anyone is welcome to add to my solution.


texts: Detecting a 2.8ms pulse using a Arduino Uno

texts:
I am working on a project for knowing the position of a DC motor which has a hall sensor built into it. I am a newbie into programming using the Arduino Uno R3. After some forum search and self checks, I cannot pass this hurdle. I hope I can frame the questions properly here.

My Problem: The DC motor hall sensor sends out 2 high pulse of 11.3V - 13V with a duration of 2.8ms for each revolution. My Arduino interrupt pin doesn't read the high pulse as it gives me "0" count after motor spin (I run 50 loops and results remain the same).

On my breadboard, I use a voltage divider to reduce hall-effect ouput from max 13V to 5V so that the Arduino pin 2 can read rising voltage when it jumps to 5V (low should be 2.5V).

Couple of things I noted during the motor spin -

a) The millis() function returns 79-81ms per sketch run

b) The same hall sensor output if connected to analog pin reads 580,590,590,1001, 1012, 580, 580.. etc. I cannot gauge position of the motor by using these values as they are inconsistent on the way up Vs. way down.

I have attached analog readings while going up and down in snap shot below:

2 questions I have:

Why is the pin 2 not detecting a high pulse? will it not be able to read 2.8ms durations because of motor speed (9.5 rev/s or 570rpm)?
Is it possible to gauge anything from Analog read function? Am I missing something?

Thanks in advance for all responses.. Any questions regarding the circuit, I will be more than happy to post them.


texts: I2C Master send reset command to the slave counter

texts:
My name is Gianni, I live in Olbia Sardinia Italy and I have some experience in electronics.

For several years I have been passionate about Arduino.

They are now engaged in a project to counter with hall sensors.

The slave sends data to the master via I2C, for my project. I'm using the sketch of Gammon which uses a structure enum to send a request to the slave.

I have the need to send a reset command from master to slave.

I edited the sketch and I can see the command on the slave but will not let me use it to reset the counter.

Master code section

   void RstCounter()
  {

  Serial.println ("funzione azzera attivata");
   Serial.println (sensor);
  char key = keypad.getKey();
  if (key !='A')
  {

   char cmdrst = 'a';
   //set=key;

     if (sensor==11)
    {
    sendCommand (CMD_WRITE_D2, 1);

    Wire.beginTransmission(SLAVE_ADDRESS); // testiamo questa istruzione
    Wire.write(cmdrst);
    Wire.endTransmission();

    delay(100);
    Serial.println (cmdrst);
    }

   else
  {
  m=0;
  }

   azzera =true;
  }
   else if (key=='A')
    {
   Serial.println("");
   Serial.println("AZZERA close");
   azzera = false;
   }
     delay(100);
    }

SLAVE code section

#include <Wire.h>

const byte MY_ADDRESS = 42; // address in valore esadecimale

/************  VARIABILI SENSORI **********************/

#define Sensor11 2
int lastValueSensor11 =0;
int ValueSensor11=0;
int contatore11=0;
int counter11;

// various commands we might get
/************  VARIABILI ENUMERATORE **********************/
enum {
    CMD_ID = 1,
    CMD_READ_D2  = 2,
    CMD_READ_D3 = 3,
    CMD_READ_D4 = 4,
    CMD_WRITE_D2 = 5
    };

char command;
int sensor;
char cmdrst;

/************  SETUP **********************/
void setup()
  {
  command = 0;

  pinMode (Sensor11, INPUT);
  digitalWrite (Sensor11, HIGH);  // enable pull-up

  Serial.begin(9600);
  Wire.begin (MY_ADDRESS);
  Wire.onReceive (receiveEvent);  // interrupt handler for incoming messages
  Wire.onRequest (requestEvent);  // interrupt handler for when data is wanted

  }  // end of setup

/************  LOOP **********************/
void loop()
  {
        /************************ CONTATORE SENSOR 1 ***********************/
   ValueSensor11  = digitalRead(Sensor11);

            if ( ValueSensor11 != lastValueSensor11)
               { if ( ValueSensor11 == LOW)
                    {
                      contatore11 = contatore11 + 1;

                        }
                     }
   lastValueSensor11 = ValueSensor11;

/************  I2C RECEIVE **********************/
void receiveEvent (int howMany)
  {

  command = Wire.read ();  // remember command for when we get request
  //Serial.println(command);
  switch (command)
     {
     case CMD_WRITE_D2:
     Serial.println("comando 5 ricevuto");
     char cmdrst=Wire.read();
     delay(100);
     Serial.println (cmdrst);
     break;
    }
} // end of receiveEvent

void sendSensor1 (const byte which)
  {
  int val11 = contatore11;
  Serial.println(contatore11);
  byte buf11 [2];

    buf11 [0] = val11 >> 8;
    buf11 [1] = val11 & 0xFF;
    Wire.write (buf11, 2);
  }  // end of sendSensor

void requestEvent ()
  {
  switch (command)
     {
     case CMD_ID:
     Wire.write (0x55);
     break;   // send our ID

     case CMD_READ_D2:
     sendSensor1 (2);
     break;  // send A0 value

     case CMD_READ_D3:
     sendSensor2 (3);
     break;    // send D8 value

     case CMD_READ_D4:
     sendSensor3 (4);
     break;

     }  // end of switch

  }  // end of requestEvent


texts: Arduino Ping sensor with NewPing library

texts: I was trying out the NewPing library (the main example sketch) and when I compile it and check the serial monitor, it seems like it works for about 10 seconds, then instead of giving distance values it just writes out random characters. The only thing I can think of is that my sensor is bad. Any suggestions before I get another Ping sensor? I'm unsure if the same thing will happen.


texts: ESP8266 /ESP12F use flash button as input without using loop()

texts:
I couldn't find a proper answer anywhere on internet.

I want to use the FLASH button as input in the setup() function and do not use the loop() with deepsleep mode (this part comes later).

I tried demos wherein the button events are sometimes failed to be captured. How can I make it 100% sure to get detected as soon as I press reset or along with reset? Because there is a mismatch in the time when reset is clicked and the flash button press gets detected.


texts:
I am currently playing a bit around with the esp32-pico-4d, it does not have an onboard antenna, so an external antenna is needed, tho I don't know a lot about it so a little help would be appreciated.

I found this:

https://www.espressif.com/sites/default/files/documentation/esp32-pico-d4_datasheet_en.pdf

here one says that he literally just connected the antenna to ground and LNA_IN would that work?

and which antennas would you recommend? (as small as possible is only gonna be used for BLE and)

(datasheet: https://www.espressif.com/sites/default/files/documentation/esp32-pico-d4_datasheet_en.pdf)


texts: What is the minimal possible latency between arduino and PC

texts:
Case specifications:

PC OS: Debian 9, x64 arch
Starting time point: i have a 1kb buffer on arduino that i want to send to host PC
Ending time point: i have recieved the buffer in a custom written C\C++ app running on a host PC
I want to send such a buffer once a second

What is the minimal possible latency - time passed between starting and ending points? and with what communication type? (serial?)


texts: I have noticed that when I used a log pot from a guitar amp I found, it gives janky results when using it in a motor PWM sketch, but if I use it in a fade sketch, it works. why does log pots give sketchy results when using them in a PWM control sketch, like when using the map() function?