texts: Arduino IDE does not display examples folder from my custom library

texts:
I have created a custom library for local usage. I call is ABC_node for ESP32 and the structure is as follows:

.
|-- examples
|   |-- bnoCalibStorage
|   |   `-- bnoCalibStorage.ino
|   |-- influxHTTP_write
|   |   `-- influxHTTP_write.ino
|   |-- influxPing
|   |   `-- influxPing.ino
|   |-- influxUDP_write
|   |   `-- influxUDP_write.ino
|   `-- rtcTimestamp
|       `-- rtcTimestamp.ino
|-- keywords.txt
|-- library.properties
|-- README.md
|-- ABC_Node.cpp
`-- ABC_Node.h

I tried following the Adafruit GitHub Repository structure where each example is placed inside a folder named after the sketch.

I am hosting this repository on a private GitLab Server. I used git tag v1.0.0 to create a tag and from GitLab I could download the .zip file for the stable v1.0.0 library.

I manually extracted the files to my <user>\Documents\Arduino\libraries folder and renamed the folder to ABC_Node (since my gitlab repo is named something else)

I restarted my IDE but I could not find the library ABC_Node in

Sketch\Include Library\

library.properties

name=ABC_Node
version=1.0.0
author=Shan Desai
maintainer=Shan Desai
sentence=Firmware to create InfluxDB measurements and send them via HTTP/UDP to Core
paragraph=ABC_Node provides `String` based InfluxDB measurements which can then be sent via HTTP/UDP to a central InfluxDB instance.
category=Data Processing, DAQ
architecture=ESP32
repository=https://[gitlab-address]/node-repo.git

I followed the Libraries Guide from Arduino on local Installation

System

Windows 10

Arduino IDE 1.8.5


texts:
I'm working on alarm clock project using Arduino Nano (v 3.0, clone) and RTC module ZS-042 (containing DS3231 and EEPROM AT24C32).
The intention is to load the hours and minutes from EEPROM on start-up, use current date (to avoid zero-date problems) and compose DateTime object in order to utilize the TimeSpan object, making time calculations easier than using plain integer math. The issue is, the value in DateTime object seems not constructed correctly, although all the components used for its construction seem OK.
With the following code
/* Hardware definitions */
//RTC using I2C, pins 4,5
#include <Wire.h>
#include <RTClib.h>
RTC_DS3231 rtc;

#include <extEEPROM.h>
extEEPROM e2p(kbits_32, 1, 32, 0x57);

DateTime  alarm1Time;

void setup(){
  Wire.begin();
  rtc.begin();
  Serial.begin(115200);
  uint8_t e2pStatus = e2p.begin(extEEPROM::twiClock400kHz);      //go fast!
  DateTime t = rtc.now(); //get current time from RTC
  Serial.print("t.year: ");  Serial.print(t.year());
  Serial.print(" t.month: ");  Serial.print(t.month());
  Serial.print(" t.day: ");  Serial.println(t.day());
  alarm1Time = (t.year(),t.month(),t.day(),e2p.read(1),e2p.read(2),0);
  Serial.print("E2P : ");
  Serial.print(e2p.read(1));
  Serial.print(":");
  Serial.println(e2p.read(2));
  char buf1[] = "YYMMDD-hh:mm:ss";
  Serial.println(alarm1Time.toString(buf1));
}

I get on the serial monitor the following:
t.year: 2021 t.month: 1 t.day: 31
E2P : 7:15
060206-06:28:16

The date components (year, month, date) correspond to current date. As the bytes on address 1 and 2 in EEPROM read 7 and 15, I'd expect the Alarm1Time be 2021-01-31, 07:15, which isn't.
The output is constant, whatever the current date and the EEPROM stored time. Later in my code the alarm1Time parses into 6 hours and 28 minutes, in accordance with last line of the serial monitor output.
What could be (or better - where I'm) wrong? Thanks.
Libraries used:
RTClib (https://github.com/adafruit/RTClib)
extEEPROM (https://github.com/JChristensen/extEEPROM/blob/master/extEEPROM.h)


texts:
I want to split this:

char* value = "12;32;blue";
or
string value = "12;32;blue";

into this vars:

TV = 12;
AR = 32;
LED = "blue";

is it possible?


texts:
I am using this header: http://playground.arduino.cc/Interfacing/CPPWindows

My main:

#include <iostream>
#include <stdio.h>
#include <tchar.h>
#include "SerialClass.h"
#include <string>

int main(int argc, _TCHAR* argv[])
{
    Serial* SP = new Serial("\\\\.\\COM4");

    if (SP->IsConnected())
        printf("We're connected\n");

    std::string tryStr;
    int value;
    DWORD bytesSend;

    /* Loop */
    while(SP->IsConnected())
    {
         /* Take a value from user */
         printf("Value: "); scanf("%d",&value);

         /* Send Arduino */
         BOOL retVal = WriteFile(SP->hSerial, &value, sizeof(value), &bytesSend, NULL);

        /* I have no idea what is this for? (SP->status.cbInQue) */
        ClearCommError(SP->hSerial, &SP->errors, &SP->status);

        /* Read string from arduino */
        DWORD bytesRead;
        tryStr.assign("");
        bool check = true;
        char tempCharacter;
        while (check==true){

            ReadFile(SP->hSerial, &tempCharacter, sizeof(char), &bytesRead, NULL);
            tryStr += tempCharacter;

            if(tempCharacter == '$'){
                check = false;
            }
        }

        /* Print the string */
        std::cout << tryStr  << std::endl << std::endl ;
    }
    return 0;
}

My Arduino Code:

int LedPin= 10;
int value;
String  incomingData = "hello$";

void setup (){
  Serial.begin(9600);
  pinMode(LedPin, OUTPUT);
}

void loop (){

  while(!(Serial.available() > 0)){
    /*Wait until take data */
  }

  value=Serial.read();

  if (value == 20)
  {
      digitalWrite (LedPin, HIGH);
      incomingData.setCharAt(0,'o');
      incomingData.setCharAt(1,'p');
      incomingData.setCharAt(2,'e');
      incomingData.setCharAt(3,'n');
      incomingData.setCharAt(4,'n');

      Serial.print(incomingData);
  }
  else if (value == 15)
  {
      digitalWrite (LedPin, LOW);
      incomingData.setCharAt(0,'c');
      incomingData.setCharAt(1,'l');
      incomingData.setCharAt(2,'o');
      incomingData.setCharAt(3,'s');
      incomingData.setCharAt(4,'e');

      Serial.print(incomingData);
  }

}

This code works perfectly. Output:

  We're connected  Value: 20  openn$

  Value: 15  close$

  Value: 20  openn$

  Value: 20  openn$

  Value: 15  close$

  Value: 15  close$

  Value: 20  openn$

But now I want to add another condition in my Arduino code:

int LedPin= 10;
int value;
String  incomingData = "hello$";

void setup (){
  Serial.begin(9600);
  pinMode(LedPin, OUTPUT);
}

void loop (){

  while(!(Serial.available() > 0)){
    /*Wait until take data */
  }

  value=Serial.read();

  if (value == 20)
  {
      digitalWrite (LedPin, HIGH);
      incomingData.setCharAt(0,'o');
      incomingData.setCharAt(1,'p');
      incomingData.setCharAt(2,'e');
      incomingData.setCharAt(3,'n');
      incomingData.setCharAt(4,'n');

      Serial.print(incomingData);
  }
  else if (value == 15)
  {
      digitalWrite (LedPin, LOW);
      incomingData.setCharAt(0,'c');
      incomingData.setCharAt(1,'l');
      incomingData.setCharAt(2,'o');
      incomingData.setCharAt(3,'s');
      incomingData.setCharAt(4,'e');

      Serial.print(incomingData);
  }
  else{                                      // new line added
                                             // new line added
      incomingData.setCharAt(0,'g');         // new line added
      incomingData.setCharAt(1,'g');         // new line added
      incomingData.setCharAt(2,'g');         // new line added
      incomingData.setCharAt(3,'g');         // new line added
      incomingData.setCharAt(4,'g');         // new line added
                                             // new line added
      Serial.print(incomingData);            // new line added
  }                                          // new line added

}

But it didn't work. ScreenShot:

What went wrong? The led blinked correctly but the output string is wrong.


texts: Quaternion values from BNO055 not available

texts:
I am trying to obtain Quaternion values from a BNO055 connected to ESP32-PoE board by Olimex.

Code

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BNO055.h>
#include <utility/imumaths.h>

Adafruit_BNO055 bno = Adafruit_BNO055(55);

void setup() {
  // put your setup code here, to run once:
  Wire.begin(13, 16, 400000);
  Serial.begin(115200);

  if (!bno.begin()) {
    Serial.println("No BNO055 Detected!");
    while(1);
  }
  delay(100);
  bno.setMode(Adafruit_BNO055::OPERATION_MODE_NDOF_FMC_OFF);
  bno.setExtCrystalUse(true);
}

void loop() {
  // put your main code here, to run repeatedly:
  imu::Quaternion quat = bno.getQuat();
  imu::Vector<3> euler = quat.toEuler();

  Serial.print("W: ");
  Serial.print(quat.w());
  Serial.print(F(" "));

  Serial.print("x: ");
  Serial.print(quat.x());
  Serial.print(F(" "));

  Serial.print("y: ");
  Serial.print(quat.y());
  Serial.print(F(" "));

  Serial.print("z: ");
  Serial.print(quat.z());
  Serial.print(F(" "));

  Serial.print("X: ");
  Serial.print((float)euler.x());
  Serial.print(F(" "));
  Serial.print("Y: ");
  Serial.print((float)euler.y());
  Serial.print(F(" "));
  Serial.print("Z: ");
  Serial.print(float(euler.z()));
  Serial.print(F(" "));
  Serial.println("");
  delay(200);
}

output

W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00
W: 0.00 x: 0.00 y: 0.00 z: 0.00 X: 0.00 Y: nan Z: 0.00

The sensor seems to be working since I tried a simple script and the values are avaiable.

Is there some specific setting missing during setup() in order to obtain Quaternions.

Purpose

For Absolute orientation, the Quaternion values need to be converted to Euler .


texts:
I have a question for you guys. I have some code that triggers an ultra-sonic sensor to measure distance. My code uses the EICRB register and executes in interrupt when it sees a transition on the interrupt pin. The interrupt routine is supposed to calculate the time of the echo pulse that comes from the sensor. The width of the pin is proportional to the distance measured.
I'm not sure why I'm not getting great results. There seems to be a persistent error in my measurement and I'm not sure why. It's probably something stupid. Here's a screenshot of the code I have if anyone can lend some help. Thanks for reading.


texts: Managing configurations via EEPROM by writing it with the hex file

texts:
I've been looking into I2C bootloaders for an ATTINY coprocessor on a board I'm developing, and I ran into a bit of a snag. I have the need to detect what board the main processor's code is running on, since there are a number of write-only peripherals I can't probe for presence or configuration (WS2812-series LEDs and a SSD1306 screen, among a few others), and I was going to manage that via a configuration blob stored on the ATTINY.

Unfortunately, this was coded into the firmware, and pushing out any sort of update for the coprocessor would then require that I build, label, and provide each version, and then have the user choose the correct one.

So, the solution would seemingly be EEPROM, since that can be set to persist over programming attempts (there's even a fuse setting to keep it, although in the other case how the AVR knows if it's been programmed [in the era of bootloaders] I'm not sure).

The issue is now that I need a way to set the EEPROM configuration when I create the original program, and then have future updates not touch it. The existing way is that I add a stub to my code that checks if there's a config and sets it (unfortunately per-unique-board-design, so I'd need lots of different copies again) and then never touches it again. Future firmwares could then just not include any stub at all.

However, this annoys me, especially since if something goes wrong it could mess up the EEPROM.

Does anyone know of a way to use a ICSP programmer to set EEPROM, ideally as part of the firmware upload?

I am using a usbasp with PlatformIO to do the chip programming, so I should have enough access on the first burning to change the EEPROM. Does anyone know how I could add in an EEPROM configuration to go with the flash one?

Some thoughts I have had:

Somehow modify/append the hex file to include data that goes to EEPROM and then burn it
Add a script to PlatformIO that lets me edit/compile/upload/whatever to EEPROM (I do not speak Python, so I'd need help)
Use an existing feature of PlatformIO/the build process/the AVR toolchain to set an EEPROM configuration (I have to suspect there is one, but Googling does not seem to have pointed one out)
Somehow do this with AVRDude


texts: Arduino UNO R3 not detected by Arduino Create Agent

texts:
So I just got my Arduino Uno R3 and tried to use it with Arduino Web IDE. I installed (and reinstalled) Arduino Create Agent and was expecting it autodetect my board, but it did not happen. Below is a picture of my board link. One light is solid and the other is flashing. In device manager I see USB serial with exclamation mark. Do I need to installed any drivers? This page says that I do not need to:
getting started
Any thoughts?
P.S. I also openned debug console, but there is nothing useful, it keeps scrolling: Network Port and Serial Port.
P.P.S. I tried two different USB cables, still no luck
P.P.P.S. I installed desktop IDE, selected Arduino Uno and tried to upload, but got back error message:
Arduino: 1.8.13 (Windows Store 1.8.42.0) (Windows 10), Board: "Arduino Uno"

Sketch uses 444 bytes (1%) of program storage space. Maximum is 32256 bytes.

Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for local variables. Maximum is 2048 bytes.

Serial port not selected.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.


texts: I'm working on an audio player project, I can get the audio to play fine but I'm getting tons of interference. Using a PAM8403, power is to 3.3V on Arduino, GND to GND and D9 to Left In. Heaps of static/white noise and what sounds like radio tuning interference.


texts:
I am currently trying to see the result of a query to a thingspeak field.
This works great when I just use a empty sketch and type the commands manually, but using the following sketch I cannot see the value of +IDP,0,1:1
This means, at field 1, the value 1 is stored. If 0 was stored, it would be +IDP,0,1:0
How it is possible to "ask" if "+IDP,0,1:0" exists at the serial message from the ESP8266? Serial.find does not work....

Here my sketch:

#include<stdlib.h>
#include <SoftwareSerial.h>

SoftwareSerial monitor(2,3); //rx tx
#define SSID "WLAN-0E0265"
#define PASS "2738564673200634"
int ledPin = 13;
String c;
void setup() {
  Serial.begin(9600);
  monitor.begin(9600);
  monitor.println("AT");
  delay(1000);
  monitor.println("AT+CIPMUX=1");
  delay(1000);
  monitor.println("AT+CWJAP=\"WLAN-0E0265\",\"2738564673200634\"");
  delay(5000);
  if(monitor.find("OK"))
    Serial.println("JAP worked");

  monitor.println("AT+CIPSTART=0,\"TCP\",\"api.thingspeak.com\",80");
  delay(2000);
  if(monitor.find("OK"))
    Serial.println("CIPSTART worked");
  monitor.println("AT+CIPSEND=0,110");
  delay(2000);
  if(monitor.find(">"))
    Serial.println("CIPSEND worked");
  monitor.print("GET https://api.thingspeak.com/channels/54209/fields/1/last \r\n");
  delay(10000);
  monitor.println("GET https://api.thingspeak.com/channels/54209/fields/1/last");
  delay(2000);
  String readString;
  ledPin = 13;
  //++++++++++++++++++++++++++++++++++++++++++++++++++++++++
//SEARCH FOR THE :0 or :1                           <-- Here is the problem, rest works fine
  if(Serial.find(":0")){
 //turn pin off
}
  if(Serial.find(":1")){
 //turn pin on
}

}

void loop(){

}


texts: Communicating Arduino with Intel Galileo

texts:
I'm doing a project where I have few sensors on Arduino Uno. Now I am trying to send some data to the internet where i figured using my GSM shield with the Galileo board I have is the best solution.

The problem I am facing is that software serial is not working on Galileo so I have to use the Serial1 of Galileo board (Pin 0 and Pin 1) and I am out of serial ports. I was thinking of using serial communication between Arduino and Galileo but Galileo seems to have only pin0 and pin1 as serial and they are occupied by the GSM shield.

Is there any part I am getting wrong or any suggestions?

(other than using the sensors on Galileo and getting rid of the Arduino Uno :) )


texts: Transmit/Receive data Nodemcu(V3) + Bluetooth Module HC-05

texts:
I am trying to communicate with the HC-05 Bluetooth module for quite long time now, but with no success.

I am using the Nodemcu(V3) ESP8266 module.

I connect the HC-05 to Nodemcu in following sequence:

HC-05             Nodemcu
-----             -----------
RX       -->      Pin 1 (Tx)
TX       -->      Pin 3 (RX)
Vcc      -->      +3.3V
GND      -->      GND

For starters, i want to check if my Nodemcu is communicating properly with my HC-05 module.

I have written the following code to read the response of AT commands:

#include <SoftwareSerial.h>
SoftwareSerial BTserial(3, 1); // RX | TX
char Bluetooth_Name = ' ';

void setup()
{
    // Arduino IDE serial monitor
    Serial.begin(115200);

    // HC-05 default serial speed for AT mode is 38400
    BTserial.begin(38400);

    // Wait for hardware to initialize
    delay(1000);

    // Print debug string
}

void loop()
{

   // Keep reading from HC-05 and send to Arduino Serial Monitor
   if (BTserial.available())
   {
      reading = BTserial.read();
      Serial.println(reading);
   }

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

However, i do not get response for any AT command at all. The serial monitor just shows blank.

Thanks in advance

EDIT:- I connected the "EN" pin on the HC-05 to Vcc. Now, the led on the HC-05 blinks slowly, which means that the HC-05 is configured in command mode. However, i am still not able to receive the response for any AT commands. I have also selected "Both NL & CR" in the serial monitor, configured the baud rate correctly and double-checked the hardware connections.

Everything seems to be correct except that i don't get response for the AT commands.

Please help!!!


texts:
I am relatively new to Arduino and I am trying to code some neo pixels and every time I try to verify my code this error comes up:

Arduino: 1.8.12 (Mac OS X), Board: "Arduino Uno"
loading libs from /Users/erinshankland/Documents/Arduino/libraries: reading dir >/Users/erinshankland/Documents/Arduino/libraries: open >/Users/erinshankland/Documents/Arduino/libraries: operation not permitted
Error compiling for board Arduino Uno.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

this is my code:
#include <Adafruit_NeoPixel.h>

#define PIN        6

#define NUMPIXELS 15

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRBW + NEO_KHZ800);

// this constant won't change:

const int  btnRed = 2;  // the pin that the pushbutton is attached to

const int  btnBlue = 3;  // the pin that the pushbutton is attached to

const int  btnGreen = 4;  // the pin that the pushbutton is attached to

const int  btnPurple = 5;  // the pin that the pushbutton is attached to

void setup() {

  randomSeed(analogRead(A0));

  // put your setup code here, to run once:

  pinMode(btnRed, INPUT);

  pinMode(btnBlue, INPUT);

  pinMode(btnGreen, INPUT);

  pinMode(btnPurple, INPUT);

  // initialize the LED as an output:

  // initialize serial communication:

  Serial.begin(9600);

  pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)

    pixels.clear(); // Set all pixel colors to 'off'

    pixels.show();

    delay(1000);

}

void loop() {

if (digitalRead(btnRed)==HIGH){

    rndRed();

  delay(100);

}

if (digitalRead(btnBlue)==HIGH){

    rndBlue();

  delay(100);

}

if (digitalRead(btnGreen)==HIGH){

    rndGreen();

  delay(100);

}

if (digitalRead(btnPurple)==HIGH){

    rndPurple();

  delay(100);

}

}

void rndRed() {

  int led = random(0, 15);

  pixels.setPixelColor(led, pixels.Color(255, 0, 0,0));

  pixels.show();   // Send the updated pixel colors to the hardware.

  delay(500);

}

void rndBlue() {

  int led = random(0, 9);

  pixels.setPixelColor(led, pixels.Color(0, 0, 255,0));

  pixels.show();   // Send the updated pixel colors to the hardware.

  delay(500);

}

void rndGreen() {

  int led = random(0, 9);

  pixels.setPixelColor(led, pixels.Color(0, 255, 0,0));

  pixels.show();   // Send the updated pixel colors to the hardware.

  delay(500);

}

void rndPurple() {

  int led = random(0, 9);

  pixels.setPixelColor(led, pixels.Color(171, 0, 255, 0));

  pixels.show();   // Send the updated pixel colors to the hardware.

  delay(500);

}

I am using a new library for the neo pixels but this has been downloaded and updated.
Hopefully someone can help me!


texts:
I am trying to control the speed of two motors using L298N. I use "Arduino Nano ATmega 168". I change the analogWrite between 0-255 but I cannot see any difference. When I assign it to something like 120 the motor stops.

The pwm pins of the motor drive is connected to the 7th and 8th pins of the Arduino. My code is like that:

const int in1=9; //motor 1
const int in2=10;//motor 1
const int in3=11;//motor 2
const int in4=12;//motor 2
const int p1=7;//pwm pin for motor 1
const int p2=8; //pwm pin for motor 2

void setup() {
  // put your setup code here, to run once:
pinMode(in1,OUTPUT);
pinMode(in2,OUTPUT);
pinMode(in3,OUTPUT);
pinMode(in4,OUTPUT);
pinMode(p1,OUTPUT);
pinMode(p2,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  analogWrite(p1,255);
  analogWrite(p2,130);
  digitalWrite(in1,HIGH);
  digitalWrite(in2,LOW);
  digitalWrite(in3,HIGH);
  digitalWrite(in4,LOW);

}

PS:

My Arduino and Motor Shield have same the ground
I use a power supply and not a battery.

I would be happy if anyone could help me)


texts: Should I buy Arduino as a Computer Engineering Student?

texts: I'm going to be in the third year of university in a month. I'm satisfied with the software part of my bachelor but I feel like I lack in practice in practical implementation. Would getting an Arduino board and playing around with it worth it and useful for me?


texts: control Arduino board using Android sensors and wifi?

texts:
i am thinking about building a Quadcopter that can be controlled with a computer via Wifi . but the problem is that with a lack of components and limited resources , i have been thinking of using my available components ( Arduino uno + smart phone + quadcopter frame with 4 brush-less motors and 4 speed control )
so i am asking you guys if it is possible to read smartphone sensor values using Arduino usb and control the quadcopter using smartphone wifi ??


texts:
I have a weird problem. again. This time it's the PWM. I have used PWM before and I used to work the way I am doing it now. But now it just wont work. The Fading sketch from example works. When I compile a code with the similar code it doesn't work. Everything with respect to compilation is same.

The code that works:

int ledPin = 3;    // LED connected to digital pin 9

void setup() {
  // nothing happens in setup
}

void loop() {
  for (int fadeValue = 0 ; fadeValue <= 255; fadeValue += 5) {
    analogWrite(ledPin, fadeValue);
    delay(30);
  }
  for (int fadeValue = 255 ; fadeValue >= 0; fadeValue -= 5) {
    analogWrite(ledPin, fadeValue);
    delay(30);
  }
}

The code that doesn't work.

#define FAN1 3
#define FAN2 5

void setup() {
  //EMPTY
}

void loop() {
  int speed1 = 25;
  int speed2 = 127;
  analogWrite(5, speed1);
  analogWrite(3, speed2);
  delay(10000);
}

Why doesn't the second code work?

EDIT 1:

By not working I meant No output on Second Code and Expected Output on First one. Currently I'm using ISIS for simulation and Oscilloscope to view the output along with a L239D with motors attached.

In the first code the motor starts and stops as expected, with the expected PWM Waveform.

In second code, nothing. No waveform, no motor movement.


texts: How to Run Stepper motor through Serial Communication

texts:
I am trying to run a Stepper motor from my c++ application, from which I sent commands but its not running not sure why would it not run, outside serial check it run but inside serial check it not run.

Here is my code, not sure what am doing wrong, my first time with Arduino.

#include <AccelStepper.h>

#define BAUD 9600

// CNC Shield V3  Step and Dir pins on Mega 2560
#define step_pin_x 2
#define dir_pin_x 5
#define MOTOR_X_ENABLE_PIN 8
// Drive A4988
#define motorInterfaceType 1

AccelStepper stepper_X = AccelStepper(motorInterfaceType, step_pin_x, dir_pin_x);

void setup() {
  Serial.begin(BAUD);
  pinMode(53, OUTPUT);   // for red led it pin # 53
  pinMode(MOTOR_X_ENABLE_PIN, OUTPUT);  // for X stepper motor

    stepper_X.setMaxSpeed(1000);
    stepper_X.setSpeed(500);
}

void loop() {
    String input;
  //If any input is detected in arduino
  if(Serial.available() > 0){
    //read the whole string until '\n' delimiter is read
    input = Serial.readStringUntil('\n');

    if (input.equals("ON")){
       digitalWrite(53, HIGH);   // Turn ON RED LED
       stepper_X.runSpeed();      // Suppose to run stepper motor .. but not working
       Serial.println("X Motors:: "+input);

    }else if (input.equals("OFF")){
       stepper_X.stop();
       digitalWrite(53, LOW);    // Turn OFF RED LED
       Serial.println("X Motors:: "+input);
    }

  }else{
  //  stepper_X.runSpeed();      // if uncommented stepper motor will run
  }
}

Update
so it seems its code blocking issues

i update my code according to tut : https://majenko.co.uk/blog/reading-serial-arduino

    char buf[80];

    int readline(int readch, char *buffer, int len) {
        static int pos = 0;
        int rpos;

        if (readch > 0) {
            switch (readch) {
                case '\r': // Ignore CR
                    break;
                case '\n': // Return on new-line
                    rpos = pos;
                    pos = 0;  // Reset position index ready for next time
                    return rpos;
                default:
                    if (pos < len-1) {
                        buffer[pos++] = readch;
                        buffer[pos] = 0;
                    }
            }
        }
        return 0;
    }

void loop() {
   if (readline(Serial.read(), buf, 80) > 0) {
   if(strcmp("n", buf) == 0){
          digitalWrite(53, HIGH);
         stepper_X.setMaxSpeed(1000);
         stepper_X.setSpeed(500);
          stepper_X.runSpeed();
          Serial.print("All Motors:: ");
          Serial.print(buf);

        }
    }
}

now its working ok

Update 2 : c++ sending command via Serial

    std::string input_command = "ON";
    //Creating a c string
     char *c_string = new char[input_command.size() + 1];
     //copying the std::string to c string
     std::copy(input_command.begin(), input_command.end(), c_string);
     //Adding the delimiter
     c_string[input_command.size()] = '\n';

// using this serial lib : https://github.com/manashmndl/SerialPort
   writeSerialPort(c_string, MAX_DATA_LENGTH);


texts: Unable to declare variable in a library that doesn't have a class: multiple definition of the variable

texts:
I have created a library Lib that doesn't have a class. I want this library to have a variable that can be accessed from outside. The way I would go about this is to just declare them in the header file.

However, if I do this like so:

int myVariable = 1;

with the .cpp-file containing only

#include "Lib.h"

I get this error message when compiling an empty sketch that includes this library:

  multiple definition of `myVariable'

and for some weird reason

  Multiple libraries were found for "Lib.h"

on top of that (although, this is something I have encountered before - when there is some error during the compilation, this error may come alongside it, even though there are no multiple libraries; it goes away when the other compilation errors are resolved aswell).

What is causing that error and how to resolve it?


texts: Use command line to upload hex code to teensy.ex

texts:
I need a command line implementation for uploading code to Teensy-LC through Windows 8.1 operating system
I know Paul has not released support for command line for Teensy-LC yet but i would like to know if any work has been done by anybody else in this regard.
I asked this and this. But all these solutions include

sending the hex file to the user.
Asking him to open Teensy.exe
Asking him to upload the hex file into Teensy.ex
Asking him to run teensy_reboot.exe

So is it possible to create an installer of a sort for this purpose which eliminates the user performing all these operations separately and a guided installer simply with Next->Next which does the entire job.
But I suppose that since Command Line installer is not available for windows I don't know if this is possible for impossible.
So if there is any way I can achieve an installer UI for Teensy-LC bootloader that would be perfect
Other viable option
If not that is it possible to make the entire process happen with the person not having direct access to the hex file.
Like sending a packaged installer or something
I am not sure how this would happen but if there is any possible way please help me out


texts:
I'm trying to interface MCP3903. I haven't really don't any SPI interfacing before and I can't seem to find clear enough answer for newbs. Please bare with me.
I'm trying to use this library. http://www.kerrywong.com/2014/05/10/mcp3903-library/
On the website there is the following circuit diagram.

I can see SDI, SDO pins on the ESP module, how do I connect the SCK and CS pins? If they can be any pins how do I declare them on the test program on the website?
Thank you


texts: How to Implement Simple, Quick HMAC on Arduino

texts:
Hi I am a research student working on securing the communications in Controlled Area Networks (CANs), and I am using Arduinos to simulate one of these CANs.

My goal is to use HMAC to implement message authentication of packets, and the algorithm must be very fast (I was originally thinking of using FNV1a). However, there are no Arduino libraries for this (I found one, but it uses SHA which will most likely be too slow for CAN). I don't have a lot of practice with cryptography and hash algorithms, only usage of them.

So basically, I need help writing a FNV or FNV1a function in C. The message for input will be a key (obviously) concatenated with a string (char array). Also, I need the hash to be between 128 and 256 bits for sufficient security.

Just as a side note: A CAN message/packet looks like 7df#02010d and the actual data part, 010d (two bytes) is the char array I will be using. For example, as integers, the array for 010d would be {1, 13}.

--

I also know this message applies more to cryptography than Arduino, but I figured someone from this community might have more experience with my particular task, or even have/know of a library I can use that I hadn't found.

-Thanks

EDIT: I found this FNV1a implementation in C/C++ that might work. But I have not tested it yet.


texts:
Actually, i would like to control   12 motors of AX-12 using Arduino .. I could control just 2 motors. However when i send a command to the 12 motors they don't move and one or 2 of them move randomly!

could you please help me to find solution of that ???

note :

I am using an external power with 12 Volts and 5 amp maximum


texts:
I need to run a  motor to have a harmonic motion with specified amplitude and frequency ( harmonic motion mean that the angular position of the motor is a sine function of the time). I’m Looking to do a specified number of sinusoidal oscillations.
I don't know how to tell the motor that I want the speed to be a sine function of the time. Any ideas?
Also, I’m still beginning of the project?  Hence I’m pretty flexible to choose any motors (DC/servo/stepper/ brushless motor) or any controller but the system has to be precise.
If you guys know what controllers that allow that kind of motion, please let me know! Thank you :)

EDIT:
so what I'm trying to do is making rheometer which measures the rheological properties of a material. Basically, there are two measuring methods available: Rotational tests and oscillatory tests. With rotational measurements, the measuring bob turns in one direction. In an oscillatory test, the measuring bob "oscillates" around the axis.

what my focus is to with oscillatory tests with set sinusoidal oscillation.
The basic principle of an oscillatory rheometer is to induce a sinusoidal shear deformation in the sample and measure the resultant stress response; the time scale probed is determined by the frequency of oscillation, ω, of the shear deformation. In a typical experiment, the sample is placed between two plates, as shown in the below image While the top plate remains stationary, a motor rotates the bottom plate, thereby imposing a time-dependent strain γ(t)=γ ·sin(ωt) on the sample. Simultaneously, the time-dependent stress σ (t) is quantified by measuring the torque that the sample imposes on the top plate.

So to able to do above testing I need to run the motor with sinusoidal oscillation with exact angle.Hope you get it what im trying to say? does anyone know any  motor controllers that allow that kind of motion ? or any hints how do i wet my feet? cheers!!


texts: Assigning an element of a multidimensional array to a second array

texts:
I have two arrays. The first array is a multidimensional array holding color values.

The 2nd array stores an active color from the 1st array.
How can I assign an element from the multidimensional colors array to the 2nd EXCLUSIVE_COLOR array?

int colors[][3] = {
  { 255, 0, 0 },
  { 0, 255, 0 },
  { 0, 0, 255 },
  { 253, 7, 210 }
};
int EXCLUSIVE_COLOR[3] = {0};

I tried the following but neither seemed to work:

    EXCLUSIVE_COLOR = {
      colors[0][0],
      colors[0][1],
      colors[0][2]
    };
    // error: assigning to an array from an initializer list

    EXCLUSIVE_COLOR = colors[0];
    // error: invalid array assignment


texts: Can someone explain the Uno schematics for the RESET via DTR connection?

texts:
I am wondering why did the guys at Arduino connected twice the C5 capacitor to the RESET line and not only once (via the RESET-EN jumper). Why is there a connection bypassing the RESET-EN jumper?
This is taken form the Arduino schematics ..


texts: Making WiFi hotspot for 3G network sharing controlled by Arduino

texts:
I am trying to make a WiFi internet network from 3G using Arduino as access control. I need the Arduino to act as server and control users, consumption, and connection speed. (When users connect to the WiFi, they have to enter a passcode in a webpage to use internet for a limited time,  or limited data.)

So is this possible? I still did not try anything because I can not afford to buy many objects and fail to make it work.

I am thinking of using a 3G shield and a WiFi shield, or a router connected to 3G dongle connected to an Arduino via ethernet, or a 3G shield Arduino to ethernet shield to WiFi router.

I don't know if any of these can work, so I really appreciate any guidance.


texts:
I'm trying to configure my ADC(LM98725) registers through Arduino UNO via SPI but I'm facing a small problem, it would be great if somebody help me out. I have to configure my 16 bit ADC registers which needs 25+ clocks but right now I'm getting 16 SCLK with my 16 bit data output on MOSI pin, there is no SCLK signal without data output. How can I increase the number of SCLK for my ADC?
To write to the serial registers, the timing diagram shown in a diagram. First, SEN is toggled low. The LM98725 assumes control of the SDO pin during the first eight clocks of the command. During this period, data is clocked out of the device at the rising edge of SCLK. At the rising edge of ninth clock,the LM98725 releases control of the SDO pin. At the falling edge of the ninth clock period, the master should assume control of the SDI pin and begin issuing the new command. SDI is clocked into the LM98725 at the rising edge of SCLK. The remaining bits are composed of the "write" command bit (a zero), two device addressbits (00, 01 or 10 for the LM98725), five bit register address to be written, and the eight bit register value to be written.

#include <SPI.h>

int ss=10;
int DATAOUT=11;
int DATAIN=12;
int SCLK=13;

void setup()
{
    SPI.begin();
    pinMode(DATAOUT, OUTPUT);
    pinMode(DATAIN, INPUT);
    pinMode(SCLK, OUTPUT);
    pinMode(ss, OUTPUT);
    digitalWrite(ss, HIGH);
    SPI.beginTransaction(SPISettings(1000000, MSBFIRST, SPI_MODE0));
}

void loop()
{
    digitalWrite(ss, LOW);
    SPI.transfer16(0x02c6);
    digitalWrite(ss, HIGH);
}


texts:
I bought an OBD connector from Sparkfun to try to connect to my vehicle via arduino.

I'm just beginning and am not sure if I can just connect the connector pics to the arduino directly, or if there is some other required hardware?

Does anyone know if I can connect directly and why or why not?


texts: Use Unix terminal instead of the Monitor on Arduino IDE

texts:
I want to make a shell or C script that interprets the Arduino serial input to run commands. For that, I will need to make that script be the Serial monitor for my arduino. Another reason I want to use scripts or the command line as a Serial I/O is because the Arduino monitor function freezes the IDE.

My arduino's serial port is /dev/tty.usbmodem1d112

This is what I have tried so far:

cat /dev/tty.usbmodem1d112 < This returns absolutely nothing
screen /dev/tty.usbmodem1d112 < This Prints output, but has problems with input.
cat < /dev/tty.usbmodem1d112 < Same result as cat without the < symbol.

Sometimes, I also get annoying Resource Busy messages. This makes me re-plug the Arduino board.

OS X (10.9.5) Arduino IDE latest version. Arduino M0 pro board.


texts: .elf and .hex equivalency? (code, eeprom, fuses, and lock bits all in one)

texts:
I have all configurations (eeprom data, fuses, lockbits) of my ATMega168A together with the code in my C files. The compilation creates an elf file that I use as an all-in-one programming file for production.

Just as a tryout, I converted the elf file to hex with avr-objcopy and saw that the code and configurations are still there (why wouldn't they).

My question is, if the two files are equivalent in case of using them for all-in-one programming. Is there any critical data stripping taking place between elf-to-hex conversion that could affect the actual programming?

Also, I tried again to convert the hex file to bin and saw again the same thing but of course with zero-padding. Except for the obvious different of file size, is there any practical difference when using the bin file and the hex file? Does this padding create any problems? (For example trying to write 0 to addresses that do not exist).

Thank you in advance.


texts:
I purchased a half dozen fake Arduinos hoping to build a bunch of projects without paying a fortune. I have all the drivers installed, and the port shows up in the Arduino IDE. The problem is when I try and upload the code I get the following error:

  can't open device "/dev/cu.wch": No such file or directory

I played around a little and tried running:

sudo ln -s cu.wch\ ch341\ USB\=\>RS232\ 1a1220  cu.wch

After running this a new port shows up called cu.wch, and if I select that it works.

The issue is the Arduino's port is cu.wch ch341 USB=>RS232 1a1220, but for some reason the IDE is trying to write to cu.wch. By linking the folders I can fix this but since it is a hack every time I restart my computer I have to rerun the command. Is there a way I can either rename the Arduino port or permanently link the folder?

I am using OSX 10.10 and Arduino IDE v1.6.3


texts:
I have an ATMEGA 2560 platform running HIDUINO and a sketch based on the stock MIDI library. I'm intending to use it to convert Linear Timecode (LTC) to MTC. Got a long way through the project - LTC decoding working fine, timer configuration OK, and Midi output working fine. It's just that as soon as I try and generate MTC messages, they are being dropped before they land on the computer USB interface.

Equipment to hand: Macbook Pro running El Cap/Reaper and Protools., ATMEGA2560 MEGA R3 (With 16u2 for HIDUINO) and small audio interface circuit.

Using Timer 4 for LTC Decoding and Timer 5 for MTC generation (4 messages per LTC Frame).

Midi Monitor on the OSX box.

Sees Note on/Note off packets quite happily, but no MTC messages are registering.

I do note the TX LED is active during MTC Message generation, indicating that the sketch is actually generating messages and sending them to the 16u2 chip.

Specifically, my question is how do I get the MTC messages through HIDUINO into the computer?

https://pastebin.com/pAXyq04s


texts:
I am working with two sets of IR beam, they are to be placed in X distance. My goal is to measure speed. I would like to measure time between the first IR beam to the second beam when the beam breaks.

I am not sure what's going on, I am not getting any time of the serial port but the LEDs are turning on and off the way I wanted.

Please help me with getting the time between two IR beam sensors.

This the sensor that I am using -  Adafruit IR breakbeam sensors
and I am working with a Mega2560.

#define LEDPIN 13
int startPin = 8, finishPin = 5;
unsigned long starttime = 0, finishtime, time_interval;
float distance = 1, Speed; // Speed calculated
int trigger1 = 0; // Sensor 1
int trigger2 = 0; // Sensor 2
int sensor1State; // Sensor 1 status
int sensor2State; // Sensor 2 status

void setup() {
  pinMode(startPin, INPUT_PULLUP); // Sensor 1 as input
  digitalWrite(startPin, HIGH); // Turn on the pullup
  pinMode(finishPin, INPUT_PULLUP); // Sensor 2s input
  //digitalWrite(finishPin, HIGH); // Turn on the pullup

  pinMode(LEDPIN, OUTPUT);
  time_interval = ((finishtime - starttime) / 1000000);
  Serial.println(time_interval);
}

void loop() {
  sensor1State = digitalRead(startPin); // Read the state of the IR sensor 1:
  if (sensor1State == LOW) // See if IR beam of sensor 1 has been broken
  {
    if (trigger1 == 0 && trigger2 == 0) // Check to make sure both sensors have not triggered
    {
      starttime = micros(); // Save time when sensor 1 was triggered
      digitalWrite(LEDPIN, HIGH);
      trigger1 = 1; // Prevent sensor 1 from triggering again
    }
  }
  if (trigger1 == 1) {
    sensor2State = digitalRead(finishPin); // See if IR beam of sensor 2 has been broken
    if (sensor2State == LOW) {
      // Check to make sure sensor 1 has triggered but not sensor2
      if (trigger2 == 0) {
        // Run speed function
        trigger2 = 1;
        finishtime = micros(); // Save time when sensor 2 was triggered
        digitalWrite(LEDPIN, LOW);
        // time takes to travel between 2 IR Beam  // divide by 1000000 to convert microsecond to second
        Serial.println(time_interval);
      }
      // Reset both sensors
      trigger1 = 0;
      trigger2 = 0;
    }
  }
}


texts: How can I move these global variables to be

texts:
I'm taking a sample I found on the web about how to get ROS and arduino to communicated together over serial. I have the sample working and now I'm moving the idea of the sample into my OOP project and am running into some trouble.

My sketch works but when I move a certain global variable to a protected member it breaks my sketch.

How do I declare this global variable

ros::Publisher chatter("chatter", &str_msg);

as a protected variable

protected:
  ros::Publisher chatter("chatter", &str_msg);

without getting this error

expected identifier before string constant

sample .ino

/*
 * rosserial Publisher Example
 * Prints "hello world!"
 */

#include <ros.h>
#include <std_msgs/String.h>

ros::NodeHandle nh;

std_msgs::String str_msg;
ros::Publisher chatter("chatter", &str_msg);

char hello[13] = "hello world!";

void setup()
{
  nh.initNode();
  nh.advertise(chatter);
}

void loop()
{
  str_msg.data = hello;
  chatter.publish( &str_msg );
  nh.spinOnce();
  delay(1000);
}

ROSController class

#include <ros.h>
#include <std_msgs/String.h>

class ROSController {
  protected:
    ros::NodeHandle _nh;
    std_msgs::String str_msg;
//    ros::Publisher chatter("chatter", &str_msg);
    int _throttle;
    bool _is_on = false;
  public:
    void loop();
    ROSController();
    double* getAttitude();
    bool isOn() {
      return this->_is_on;
    }
    int getThrottlePerc() {
      return this->_throttle / ROSController::THR_MAX;
    }

    static const int THR_MAX;
};

const int ROSController::THR_MAX = 100;

ROSController::ROSController() {
  this->_nh.initNode();
//  this->_nh.advertise(chatter);
}

double* ROSController::getAttitude() {
  return new double[3]{0, 0, 0};
}

void ROSController::loop() {
//  str_msg.data = new char[] {"hello"};
//  chatter.publish( str_msg );
  this->_nh.spinOnce();
  delay(1000);
}


texts: Why should I put a 10K resistor with an LDR?

texts:
I am wondering why should I put a 10K resistor with an LDR.

If I put a "stronger" resistor with another resistor (in this case the LDR), I'd get a lower voltage, and then I'd, too, get a lower value in the analogRead(). I'd like to know in what I'm doing wrong. Can someone help me?


texts: save bytes from Serial into ROM (EEPROM)

texts:
I am trying to save an incoming text from serial into the ROM of the Arduino using EEPROM. I found out that you can only save a byte at once. So I thought I could do it like that:

#include <EEPROM.h>

byte c;
int i; // counter for addressing EEPROM

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

void loop(){
  if(Serial.available()){ // check if there is some input form Serial
    while(Serial.available()){ // loops through every character of the Serial input
      c = Serial.read(); // saves current character into variable c in byte form
      EEPROM.write(i, c); // saves c into rom with the address i (counts up after each character)
      i++; // counts c up
    }

    // after all characters are looped through and saved into EEPROM
    Serial.println(i); // print the amount loop runs / amount of characters that are saved
    Serial.println(EEPROM.read(0)); // prints the first character of the input that got saved into EEPROM
    Serial.println("--"); // print cut for overview
    i = 0; // resets counter to 0. That way all values are goint to be overwritten if you type something new into the serial monitor
  }
}

Unfortunately that is not working at all. So what did I do wrong?


texts: Apply patch to library for custom changes in Arduino IDE

texts:
I wish to obtain unix epoch timestamps in millisecond precision. I am using an ESP32 along with DS3231 RTC breakout board from adafruit.

Apparently the Repository is not maintained often but I see a PR which overcomes the rollover for software timer and the developer provided a patch in the comment to use the unix timestamps in ms.

I went to the libraries folder where all the downloaded adafruit repos exist. But when I did  git status it mentions that the library download (from the library manager) is not a git repository.

I wan't to inculcate the changes to the RTClib library by using the patch provided. Should I just change the code directly via the Arduino IDE editor?


texts: How do I view Serial Output on an Android Device?

texts: Within the Arduino IDE Serial.* output can be viewed with Tools / Serial Monitor.  How can I view Serial.* output on an Android?  As a concrete example, how can I view the output from Examples / Communication / ASCIITable?


texts:
What is the simplest way to switch ON/OFF a 60v and 5 mA of current ?
I don't want the common relays for arduinos as they make click noise.


texts: I have a project using a Wemos D1 Mini.  Is there a way for the sketch running on the Wemos to know when it's been pinged?


texts:
I'm trying to use an ESP8266 Node MCU 1.0 (ESP-12E Module) as an ISP to program an Arduino Mega2560 over Wifi with no USB cable. (USB connected to ESP8266 module just for power).

I used the sketch 'Arduino_Wifi_AVRISP' from the Arduino IDE and modified the STASSID & STAPSK to match my wifi settings.

I followed the procedure found in this other post and was able to program the ESP8266 with success:
ESP8266 as ISP program for ATMega16

However, when I run the command line:

"C:\Program Files (x86)\Arduino\hardware\tools\avr/bin/avrdude" -C"C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf" -v -c stk500v2 -p m2560 -P net:192.168.1.246:328 -Uflash:w:C:\Users\dom\AppData\Local\Temp\arduino_build_199262/blink.ino.hex:i

I get the following response:

avrdude: Version 6.3-20171130
     Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
     Copyright (c) 2007-2014 Joerg Wunsch

     System wide configuration file is "C:\Program Files (x86)\Arduino\hardware\tools\avr/etc/avrdude.conf"

     Using Port                    : net:192.168.1.246:328
     Using Programmer              : arduino
avrdude: ser_drain(): read error: The parameter is incorrect.

avrdude: ser_drain(): read error: The parameter is incorrect.

avrdude: ser_drain(): read error: The parameter is incorrect.

     AVR Part                      : ATmega2560
     Chip Erase delay              : 9000 us
     PAGEL                         : PD7
     BS2                           : PA0
     RESET disposition             : dedicated
     RETRY pulse                   : SCK
     serial program mode           : yes
     parallel program mode         : yes
     Timeout                       : 200
     StabDelay                     : 100
     CmdexeDelay                   : 25
     SyncLoops                     : 32
     ByteDelay                     : 0
     PollIndex                     : 3
     PollValue                     : 0x53
     Memory Detail                 :

                              Block Poll               Page                       Polled
       Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
       ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
       eeprom        65    10     8    0 no       4096    8      0  9000  9000 0x00 0x00
       flash         65    10   256    0 yes    262144  256   1024  4500  4500 0x00 0x00
       lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
       calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
       signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

     Programmer Type : Arduino
     Description     : Arduino

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x14

avrdude: stk500_getparm(): (a) protocol error, expect=0x14, resp=0x10
     Hardware Version: 4744608
     Firmware Version: 0.2
     Topcard         : STK502
     Vtarget         : 1.8 V
     Varef           : 0.0 V
     Oscillator      : Off
     SCK period      : 0.1 us

avrdude: stk500_initialize(): (b) protocol error, expect=0x10, resp=0x01
avrdude: initialization failed, rc=-1
     Double check connections and try again, or use -F to override
     this check.

avrdude: stk500_disable(): protocol error, expect=0x14, resp=0x10

avrdude done.  Thank you.

Everything is connected as it is in the post previously mentioned. What could be causing me to get this issue?

Does it not use the "arduino" protocol for Arduino Mega2560?
Are the 3.3v pins just not sufficient to program the 5v Arduino?

As I mentioned, I'm only using USB to power the the ESP8266, not the Arduino so I don't damage the ESP pins.

Thank you.


texts: Arduino receive response from SIM800H to AT+CCLK? command

texts:
I've been trying to make a program that interacts with SIM800H trough AT commands. It worked with the String class, but it was full of "memory leaks" and after a few hours it just hanged. Then I tried to write it again with char arrays, but for some reason I couldn't get it to work properly.

Can someone suggest me a correction to my program and also a way to get char by char with loop and Serial.read();? Serial in this case (Arduino Leonardo) is the USB port and Serial1 is the port to the modem.

Here is my code:

const long interval = 2000;
static long currentMillis;

char wherecclk = 0; //To determine where is the + in +CCLK in the char array

char serialdata[256] = ""; //Array to store the chars before parsing

char rtcy1[3]; //Current year  Format: yy\0
char rtcm1[3]; //Current month  Format: mm\0
char rtcd1[3]; //Current day  Format: dd\0
char rtch1[3]; //Current hour  Format: hh\0
char rtcmm1[3]; //Current minute  Format: mm\0
char rtcs1[3]; //Current second  Format: ss\0

int rdpos = 0;

void setup() {
    Serial.begin(9600); //USB to Computer
    Serial1.begin(9600); //UART to Modem
    Serial1.print("ATE0\r"); //Disable echo
}

void loop() {
    wherecclk = 0;
    if (Serial1.available () > 0) { //when something comes on real serial
        strcpy(serialdata, "OK\n\n+CCLK: \"04/01/01,01:35:31+00\"\n\nOK\n"); //This is a real sample of the response coming from the modem emulated
        while (rdpos < 256) //loop timeout: 256 bytes
        {
            if (serialdata[rdpos] == '+') {
                break; //We have reached the first + char. Stop incrementing it
            }
            rdpos++;
        }
        if (serialdata[rdpos + 1] == 'C' && serialdata[rdpos + 2] == 'C' && serialdata[rdpos + 3] == 'L' && serialdata[rdpos + 4] == 'K') { //If the serial command mathes +CCLK save its position
            wherecclk = rdpos;
        }
        rdpos = 0;

        if (wherecclk != 0) {
            rtcy1[0] = serialdata[wherecclk + 8]; //getting first char with its offset
            rtcy1[1] = serialdata[wherecclk + 9];
            rtcy1[2] = '\0';
            rtcm1[0] = serialdata[wherecclk + 11];
            rtcm1[1] = serialdata[wherecclk + 12];
            rtcm1[2] = '\0';
            rtcd1[0] = serialdata[wherecclk + 14];
            rtcd1[1] = serialdata[wherecclk + 16];
            rtcd1[2] = '\0';
            rtch1[0] = serialdata[wherecclk + 17];
            rtch1[1] = serialdata[wherecclk + 18];
            rtch1[2] = '\0';
            rtcm1[0] = serialdata[wherecclk + 20];
            rtcm1[1] = serialdata[wherecclk + 21];
            rtcm1[2] = '\0';
            rtcs1[0] = serialdata[wherecclk + 23];
            rtcs1[1] = serialdata[wherecclk + 24];
            rtcs1[2] = '\0';
        }

    }

    if (millis() - currentMillis >= interval) //This is done every second
    {
        Serial1.print("AT+CCLK?\r"); //ask for the time
        //delay(50);
        Serial.println("");
        Serial.println("=====");
        Serial.println(millis());

        Serial.println("YEAR: ");
        Serial.print(rtcy1[0]);
        Serial.println(rtcy1[1]);
        Serial.println("MONTH: ");
        Serial.print(rtcm1[0]);
        Serial.println(rtcm1[1]);
        Serial.println("DAY: ");
        Serial.print(rtcd1[0]);
        Serial.println(rtcd1[1]);
        Serial.println("HOUR: ");
        Serial.print(rtch1[0]);
        Serial.println(rtch1[1]);
        Serial.println("MINUTE: ");
        Serial.print(rtcmm1[0]);
        Serial.println(rtcmm1[1]);
        Serial.println("SECOND: ");
        Serial.print(rtcs1[0]);
        Serial.println(rtcs1[1]);

        currentMillis = millis();
    }
}

Here is the output (a screenshot, because serial monitor doesn't give me full code):


texts: SoftwareSerial data being corrupted - looking for suggestions

texts:
I'm having problems running a serial communication between a NodeMCU ESP8266 and an Arduino Uno. I'm using the "standard" SUART setup, i.e. pins D1&D2 on the ESP are hooked up with GPIOs 2&3 on the UNO; the tx from UNO to ESP is fed through a voltage divider to step it down to 3.3V.

The setup used to work fine; suddently - yeah I've read it before, my setup suddently doesn't work, but honestly that's what happened - data is being corrupted.
The devices exchange a json formatted string:

{"action":"position","lat":123,"lon":123}

and it just worked. Now what I receive is something like:

{"⸮⸮⸮⸮⸮⸮":"pos⸮⸮⸮onb,"l⸮tF:0,"lo⸮":0,"⸮⸮s⸮⸮":0⸮

Both SUART are on 115200 baudrate, physical connections have been checked and are fine, both devices are grounded on the same reference level.

I've tried swapping the ESP with another one and changing TX/RX pins on the UNO - no results.

So I'm looking for suggestions what to do next to debug the issue, what to check and what could be wrong. Thank you in advance.

Below are UNO and ESP code snippets.

ESP8266

SoftwareSerial SUART(4, 5);

int16_t last_fetch = 0;
int16_t last_serial = 0;

double azimut, elevation;

#define DATA_FETCH_TIME_INT 3
#define SERIAL_TRASMISSION_TIME_INT 5

void setup() {
  Serial.begin(115200);  //enable Serial Monitor
  SUART.begin(115200);   //enable SUART Port

  WiFi.begin(ssid, password);

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

  Serial.println();
  Serial.println(WiFi.localIP());
}

void loop() {
  if (secs() - last_fetch >= DATA_FETCH_TIME_INT) {
    last_fetch = secs();
    fetchData();
  }

  if (secs() - last_serial >= SERIAL_TRASMISSION_TIME_INT) {
    last_serial = secs();
    sendDataViaSerial();
    }
}

void fetchData() {
  //connects to server and fetches data
}

void sendDataViaSerial() {
  int lat_i = (int) elevation;
  int lon_i = (int) azimut;
  int checksum = lat_i + lon_i;

  const int capacity = 200;
  StaticJsonDocument<capacity> doc;

  doc["action"] = "position";
  doc["lat"] = lat_i;
  doc["lon"] = lon_i;
  doc["cksum"] = checksum;

  Serial.println("Sending data via serial: ");
  serializeJson(doc, Serial);

  //SUART.flush();
  //serializeJson(doc, SUART);
  // works the same

  String outstring;
  serializeJson(doc, outstring);
  SUART.println(outstring);
}

ARDUINO UNO

SoftwareSerial SUART(2, 3);
#define arraySize 150
char inData[arraySize];

void setup() {
  pinMode(STATUS_LED, OUTPUT);
  digitalWrite(STATUS_LED, HIGH);

  Serial.begin(115200);
  SUART.begin(115200);

  Serial.println("Ready to go.\n");
}

void loop() {
  readSerial();
}

void readSerial() {
  short index = 0;
  char inChar;

  if (SUART.available() > 0) {
    while (SUART.available() > 0 && index < arraySize - 1) {
      inChar = SUART.read();
      inData[index] = inChar;

      index++;
      inData[index] = '\0';  // Add a null at the end
    }

    SUART.flush();
    String myData = (String)inData;
    Serial.println(myData);

    // consume data
    //parseIncomingData(inData);
  }
}


texts:
The Arduino I2S reference describes the I2S standard and functions available with the standard I2S library, (Bizarrely it doesn't reference the existing read() function which is used in the examples but that is beside the point). There also exists an ArduinoSound library, however I have the same issue with this.
I would like to record audio from WM8731 connected up to Arduino. I am using an SAMD arduino part.
But, I have a tremendous issue with the I2S.read() function. The I2S.read() function only returns a singular value, however the I2S standard is intrinsically stereo.
This is particularly important for my project as I am only interested in the LEFT channel as the RIGHT channel is muted.
I would expect this to either:

return a pair of values (i.e left /right) samples for that particular point in time , OR
return a singular sample with extra information telling me which channel that is was retrieved from.

However it seems this is not the case. (Github)
I also assume that the I2S is buffered making it impossible to simply read the WS pin state, as I will probably be popping a sample from the buffer that was push into the buffer at some point in the past.
So, is it possible to know which channel the sample was returned from the I2S.read() function or does this mean that the library needs to be modified?
I am more interested in using the samd library as other libraries such as AudioLibrary is limited to 16-bit - I need 32-bit resolution.


texts:
I want to use 4 Push Buttons and 4 leds in my project. What do I need to change in my sketch for multiple input push buttons and multiple outputs of leds? So my sketch is only for one push button and one led. So tell me how I can solve this problem.

Here is the code:

const int buttonPin =2;    // the number of the pushbutton pin
const int ledPin = 13;      // the number of the LED pin

// Variables will change:
int ledState = HIGH;         // the current state of the output pin
int buttonState;             // the current reading from the input pin
int lastButtonState = LOW;   // the previous reading from the input pin
long lastDebounceTime = 0;  // the last time the output pin was toggled
long debounceDelay = 50;
void setup() {
pinMode(buttonPin, INPUT);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);
}

void loop() {
int reading = digitalRead(buttonPin);
if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it's been there for longer
// than the debounce delay, so take it as the actual current state:

// if the button state has changed:
if (reading != buttonState) {
  buttonState = reading;

  // only toggle the LED if the new button state is HIGH
  if (buttonState == HIGH) {
    ledState = !ledState;
  }
  }
  }

  // set the LED:
 digitalWrite(ledPin, ledState);
 lastButtonState = reading;
 }


texts: What is the purpose of '&' while passing bool as a function parameter

texts:
If I use this function without & before change_x (in function parameter), change_x never changes to false and it keeps on printing forever. Why do I need &?

void some_function(bool &change_x, int pin_x) {
 if (change_x == true) {
 delay(time_delay);
 if (digitalRead(pocket_pin_1) == HIGH) {
  Serial.print("State 1");
  }

 else {
  Serial.println("state 2");
 }
 change_x = false;
 }
}


texts: Can multiple xbees send data to one xbee

texts: I am new to xbees. I want to have multiple xbees (up to 400 xbees) send data constantly to one xbee (receiver).This is just simple data like lets say 0 or 1 . Is this possible? Are there any limitations?


texts: Temperature varations using ADS1115 and voltage divider to read 12v

texts:
I have an issue with reading battery voltages of three 12 volt batteries using an ESP-01 and an ADS1115.  I have been graphing the measurements and the all of the graphs have a temperature component to the readings.  As the outside temperature increases, so does the reading from the ADS1115.  I have verified that battery voltages do not change with the temperature.  I have also recreated the problem by heating up my project case and seeing a great increase in the readings.  Both of my voltage divider resistors are made of the same material, so I would have thought that the changes in resistance would affect both components and not change the reading much.  I have replaced the LD1117 with a 3.3v buck converter and the problem still exists.

Details of my project are located here: https://hackaday.io/project/167291-rv-battery-monitor

ThingSpeak data graphs: https://thingspeak.com/channels/870224

Any ideas where the temperature component error is originating?


texts: Xbee can send from arduino to XCTU, but not the other way around

texts:
I have two arduinos that I would like to use to communicate with two xbees. I programmed both xbees with the xbee explorer breakout boards in XCTU, and got them to communicate on XCTU. They are XB24Cs, with the Zigbee function set, both on the same PAN ID, one as a Coordinator and one as a router, not on API mode. When I put the router on an xbee shield on an arduino, I run a program on the arduino that should allow me to communcate both ways, However I can send something through the serial and have it show up on the XCTU, but anything typed in XCTU will not show up in arduino. The arduino shield is the sainsmart xbee pro shield, and I tried it both with the jumpers in USB and XBee mode, however I can only ever upload first when it is on USB mode. How can I make communication possible from the computer to the arduino?

Here is my arduino code:

#include <SoftwareSerial.h>
SoftwareSerial Xbee(2,3);

void setup() {
  Xbee.begin(9600);
  Serial.begin(9600);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
 Serial.println("test");
 delay(1000);
  if(Xbee.available()){
    Serial.println(Xbee.read());
  }
  if(Serial.available()){
    Xbee.write(Serial.read());
  }
}


texts:
Have read a lot of different things online, and I just ain't sure yet.
I'm trying to hook up a NodeMCU to control some relays. And want to power the NodeMCU by the VIN pin.
Anyone know if this setup is possible?
Or should I do it in another way?


texts:
I have a problem collecting data from my accelerometer/gyroscope sensor with a constant sampling rate. Is there a way to program the arduino to collect data from the sensor and store these values in a SD card with a constant frequency of 1kHz without using delay? The sensor that I am using is a MPU6050 gy-521 sensor that uses I2C with arduino. I will be reading 6 different datas from my sensor: acceleration in x,y,z directions and gyration in x,y,z directions. Thank you all in advance for the advice/help.

so my project will be making a device that collects the values from the sensors and saves them to study the data later. First, a LCD display will print out a message without having any data collection to occur. The data collection will start when a button is pushed. After the button is pushed, the display will print out another message saying that the arduino is collecting data and the Arduino will save the 6 values (x,y,z acceleration and gyration) from the accelerometer/gyroscope sensor to the SD card. The data collection will stop after the button is clicked again and the display will print out another message saying that it has stopped collecting data. Then, this process can start again if the button is clicked once again. Thanks in advance


texts:
I have a MAX5724 8 channel 10 bit DAC's connected to a due, i believe i have it wired up correctly, however when  i try to write a value to it doesn't seem to output anything. Either i misunderstood the datasheet in the wiring or im writing incorrectly to it. Since i have the LDAC connected to GND i think i can just use the CODEn command on page 21 of the datasheet.

A link to the datasheet:
http://datasheets.maximintegrated.com/en/ds/MAX5723-MAX5725.pdf

Here the code i use to write:

#include <SPI.h>

#define CS 52

void setup()
{

  Serial.begin(115200);
  SPI.begin(CS);
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(CS, 1);
  SPI.setClockDivider(CS, 3); // 28MHz
  pinMode(CS, OUTPUT);
}

void loop()
{
  digitalWrite(CS, HIGH);
  digitalWrite(CS, LOW);

 byte msg1 = 0b11000010;
 byte msg2 = 0b11111111;
 byte msg3 = 0b11111111;

 SPI.transfer(CS,msg1,SPI_CONTINUE);
 SPI.transfer(CS,msg2,SPI_CONTINUE);
 SPI.transfer(CS,msg3,SPI_LAST);
 delay(4000);

}

wiring:
1 = 5V,
2 - 9 = OUTPUT,
10 = 5V,
11 = 5V,
12 = MOSI (middle pins),
13 = MISO (middle pins),
14 = SCK (middle pins),
15 = PIN 52,
16 = OUTPUT,
17 = 5V,
18 = GND,
19 = GND,
20 = GND,


texts: Object can't get the right value of its property

texts:
I'm doing a program for a robot and I got stuck at a weird problem:
I have classes defined for my robot's internals, for example for a StepMotor. I also defined a class for a Controller, which is going to control the speed of each StepMotor.

Here's a fragment of my code:

    #include <SPI.h>
    #include <Tone.h>
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    /SILNIKI KROKOWE:
    class StepMotor: public Device
    {
        public:
            int motorPin;
            int dirPin;
            int sleepPin;
            int ForwardState;
            volatile double Speed;
            volatile int ControlValue;  //the value sent to the motor
            int MaxControlValue = 4000; //maximum ControlValue
            String Name;

            void Init ( void )
            {
                //init
            }

            void SetSpeed ( int speed )
            {
              toneObject.play(speed);
            }

            void SetMode(bool IsOn)
            {
              if (IsOn)
                digitalWrite(sleepPin, HIGH);
              else
                digitalWrite(sleepPin, LOW);
            }

            void SetDirection ( Dir direction )
            {
    //code for setting direction
            }

        private:
          Tone toneObject;
    };

    StepMotor motor_right;
    StepMotor motor_left;

    class Controller
    {
      public:
        ControllerType controllerType;
        double Kp;
        double Ki;
        double Kd;
        double Tp; //czas próbkowania
        volatile double e;
        volatile double e_old;
        volatile double P_result;
        volatile double I_result;
        volatile double D_result;
        StepMotor Motor;

        int Calculate ()
        {
          int Result;
     //Serial.print(Motor.Speed); HERE's THE PROBLEM
    /********************************
    /********************************
    /*******************************
          e = MoveOrder::speed - Motor.Speed;  //Motor.Speed is always 0.00, although it's not true

             //the rest is not important
        }

        void Reset()
        {
          //reset procedure
        }

    };

    Controller controller_right;
    Controller controller_left;

    setup()
    {
       controller_right.Motor = motor_right;
       controller_left.Motor = motor_left;
    }

    ISR(TIMER5_COMPA_vect)
    {
        motor_right.ControlValue = controller_right.Calculate();
        motor_left.ControlValue = controller_left.Calculate();
        motor_right.SetSpeed(motor_right.ControlValue);
        motor_left.SetSpeed(motor_left.ControlValue);

    }

I have cut the less important parts. The rest works properly, because my robot can drive when I use SetSpeed(somevalue); The only problem is that place where I need to read current speed of my motor.
In the Controller class, there's Calculate() method. In that method I want to calculate e = MoveOrder::speed - Motor.Speed; Unfortunately it can't be calculated properly, because Motor.Speed ALWAYS is 0.00 (when I display it with Serial.print(Motor.Speed) I see 0.00 all the time). It's very strange, because when I display speed of each motor (Serial.print(right_motor.Speed) or Serial.print(left_motor.Speed)) the value is correct (when the wheels are spinning, value is not 0.00).

The speed calculations are in a different function, which I didn't present here, because it would be too long - I'm sure it works, because, as I said, I can get speed values properly.

As you can see in setup(), I set each contorller's Motor porperty to the correct object.
I also used volatile keyword for the properties that are used in the interrupt.

What is wrong with my code?

If the code I provided isn't enough, here's the full version:
https://1drv.ms/t/s!Atl-jM_xUkz1hc1f-qYYotj-pJIgUw

I'm not sure if anyone would want to dive into it, because it's not so short.


texts:
Hey so I got a Arduino Uno today with a Red LED light. Everything worked fine until I disconnected it and then came back replugged it to see that the LED light dosent light up.

I have connected the longer LED lead to Digital Pin 13 and the shorter one to GND.

Heres my script:

  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

I hope y'all can help me!


texts:
Can someone please explain to me, like I'm 5, why this circuit does not work?

Every resistance calculator I use says that there is not enough voltage to calculate a resistance. If I understand correctly, wouldn't the LEDs light but just at a lower brightness?

Using R = V/I, The source voltage is 5v, the LED voltage is 6 divided by the current of 20mA equals -50ohms. All of the charge is used up by the time it reaches the arduino right?


texts:
I'm having a slight problem that I'm unable to work out. I am using an arduino Uno to print an incremental, but predefined wheel circumference. This is all working beautifully except it gives a negative reading during execution, and then runs into the positive etc. Without being exact, the output is something like the following:

1.85, 3.71, 5.56, 7.41, 9.27, 11.15....

When this multiple reaches 32.00 or greater, it then counts negatively back down to zero, then positively up to 32.00 again.

I can't quite work out why this would be, so hoping that one of you guys would be able to shed some light. The code is as follows:

#include <Arduino.h>

int InterruptPin = 2;
int circ = 1854; //mtrs
int km = 0;

void calculate(){
    km = km + circ;
    //float temp = km / 1000;
    float temp = (float)km / (float)1000;
    Serial.println(temp);
}

void setup(){
    pinMode(InterruptPin, INPUT);
    attachInterrupt(digitalPinToInterrupt(2), calculate, RISING);
    Serial.begin(9600);
}

void loop(){

}


texts: Is setup and loop provided for convenience?

texts:
Arduino sketches usually feature a setup and loop function. Are these functions only provided for convenience or do they actually have special purposes? (e.g.: are some operations disallowed or allowed in setup and loop)

Are these two pieces of code equivalent:

Classic

void setup() {
    pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
    digitalWrite(LED_BUILTIN, HIGH);
    delay(1000);
    digitalWrite(LED_BUILTIN, LOW);
    delay(1000);
}

Without loop

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

    while(true) {
        digitalWrite(LED_BUILTIN, HIGH);
        delay(1000);
        digitalWrite(LED_BUILTIN, LOW);
        delay(1000);
    }
}

void loop() {
}

Is it possible to write code without either setup or loop, providing, for example, a main method or other entry point?


texts: What bytes do I send to the MAX7221 to light an LED (in an led Matrix)?

texts:
Datasheets

LED Matrix (p2): https://www.circuitspecialists.com/products/pdf/M105057CHR1.pdf
MAX7221: https://www.sparkfun.com/datasheets/Components/General/COM-09622-MAX7219-MAX7221.pdf

Convention

(Row, Col) Designates an LED at a particular row and column, following the convention set by the datasheet
{Anode, Cathode} Designates a anode/cathode pair to light an LED in the array
Assume that I've connected:
SEG_DP to pin 13
SEG_A to 3
SEG_B to 11
SEG_C to 10
SEG_D to 6
DIG_0 to 9
DIG_1 to 14
...
DIG_6 to 2

Question:
Suppose I'm interested in lighting (1,1). By the convention, I would have to source current to pin 13 and sink current from pin 9. What two bytes should I send to the MAX7221 to achieve this?

My Attempt:
I think it should be 0x01 and 0x80 (0000|0001|1000|0000) with MSB (D15 as it is referred to in the datasheet for MAX7221) on the far left. Code I tried using is below as an image. I checked the signals with a logic analyzer and verified that the SPI protocol was followed (I forgot to take a screenshot but I will provide one when I get a chance). The LED array did not behave as I had anticipated. All LEDs in the matrix were lit!


texts: find out the pin numbers for the Arduino IDE for a certain board - the esp 32

texts:
I followed the tutorial I found here https://techtutorialsx.com/2019/03/29/esp32-arduino-controlling-a-dc-motor/
On the very interesting topic controlling a DC motor with the esp32 and Arduino I have some questions:

The first one: Where in the world did the guy find out the pin numbers for the Arduino IDE for this board? I have no idea how to find them!?

  Taking in consideration that the digital IO pins of the ESP32 can only
  source a maximum current of 40 mA [1], we cannot directly use them to
  control a DC motor.

  Instead, we are going to use a ULN2803A integrated circuit to actually
  provide the current to the motor, while the ESP32 will simply control
  if the motor is running or stopped.

  The connection diagram to control a DC motor from the ESP32 using an
  ULN2803A can be seen below at figure 1. for controlling a DC motor
  with the ESP32, using a ULN2803A integrated circuit

  The controlling of the DC motor with the ESP32 and a ULN2803A IC. In
  short, the ULN2803A will act as a switch, which will turn on / off the
  connection of the motor to GND, depending on the state of the input
  pin labeled as In 1. So, when the GPIO of the ESP32 is at a digital
  high value (VCC), the ULN2803A will connect the motor to GND, and thus
  the motor will be on. When the GPIO is at a digital low value (GND),
  then the motor will be disconnected from GND, and thus it will be off.
  Furthermore, the ULN2803A can be controlled by 3.3 V inputs and
  provide higher voltages, allowing us to control a 5 V DC motor with
  the ESP32.

  The code

  The code for this tutorial will be very simple, since we basically
  only need to control the status (high or low) of a digital pin of the
  ESP32.

  So, we will start by declaring as a global variable the number of the
  pin that will be connected to the DC motor.

  In my case I’ll be using GPIO 13. Note that for the Beetle ESP32
  board, which is the one I’m using, this maps to the pin labeled as D7.

int motorPin = 13;

  After that, we need to initialize the pin as output, in the Arduino
  setup function. To do that, we simply need to call the pinMode
  function.

  This function receives as first argument the number of the pin and as
  second argument a constant indicating the operating mode. So, we will
  pass the as first argument the value of the pin stored in our
  previously declared global variable and as second argument the
  constant OUTPUT.

void setup() {

  pinMode(motorPin, OUTPUT);

}

  We will write the rest of our code in the Arduino main loop. We will
  first turn on the motor, wait some seconds, turn it off, wait some
  more seconds and then repeat.

  So, to turn the motor on, we simply need to set the value of the ESP32
  digital pin to high, which will make the motor run at full speed. We
  can set the digital level of a pin with a call to the digitalWrite
  function.

  This function receives as first argument the number of the pin and as
  second argument a constant indicating the digital level to which the
  pin should be set.


texts: Blew my Arduino. Did I wire this correctly?

texts:
Hi,

I am currently doing a project and it seems that I may have blown my Arduino Nano (or maybe not). The power LED of the Nano was still on and I believe the L pin blinks once every time I press the reset button.

I wanted to use 4AA alkaline batteries to power my project. The servo is a continuous servo rated for 4-6V and 15-200mA from Parallax. Given that the Nano runs optimally when powered at 7-12V, I decided to buy a step-up converter (adjustable output voltage). It looks like this although I bought it elsewhere:

https://www.ebay.com.au/i/283603471149?chn=ps&norover=1&mkevt=1&mkrid=705-139619-5960-0&mkcid=2&itemid=283603471149&targetid=752505019384&device=c&mktype=pla&googleloc=9071392&poi=&campaignid=1979582348&mkgroupid=72745766764&rlsatarget=pla-752505019384&abcId=1139426&merchantid=7364522&gclid=Cj0KCQjwt5zsBRD8ARIsAJfI4Bh8cSOKugFrugHz-gA-s8nXclnO7H8iQ-WX46FRdhDLchwbl6UyWLgaAr4oEALw_wcB

When I tried to test it with the servo running, my Nano stopped working after several seconds later. Did I wire them up wrongly? I also measured the output of the step-up converter when it was running with a voltmeter between the two terminals of the step-up's output. Would it be possible to short it that way?

Appreciate any help I can get. Thanks


texts: Correct Capacitors to use with L7805 Voltage Regulator

texts:
I am making my own arduino.  I am in the process of hooking up power to the Atmega328.

In both these articles they use the L7805 voltage regulator with two 10uF capacitors.

https://www.arduino.cc/en/Main/Standalone

http://www.instructables.com/id/How-to-Build-an-Arduino-Uno-on-a-BreadBoard/?ALLSTEPS

I am looking at the datasheet for the regulator at http://pdf.datasheetcatalog.com/datasheet_pdf/sgs-thomson-microelectronics/L7805CD2T_to_L7885CV.pdf

The data sheet provides a number of figures for how to correctly hook up the L7805 in different situations (pages 4, 16-23).  I think Figure 13 represents our situation (Fixed Output Regulator).  In the figure they use 0.33uF and 0.1uF
capacitors.  Could someone explain why the examples use 10uF and the data sheet specifies 0.33uF and 0.1uF?


texts:
How should I index HardwareSerial ports into a single array?.

This compiles, but do not work.

HardwareSerial Serials[]={Serial,Serial1,Serial2,Serial3};

void setup(){
    for (int i=0;i<=3;i++){
        Serials[i].begin(38400);
        while (!Serials[i]);
    }
}

char s;
void loop(){
    for (int i=0;i<=3;i++){
        if (Serials[i].available()){
            s=Serials[i].read();
            Serials[i].write(s);
        }
    }
}


texts:
i have one input and buzzeer output and reset pushbutton if the input is high the buzzer will be on and i want to turn off the buzzer by the pushbutton even if the input still high
any suggestions to do this
in my code the buzzer is not working at all
int in1 =     2; //input
int in26 =   8;// for buzzer reset
int BUZZER_PIN = 52   ; // output for buzzer out 25
int buttonState1 =  0;  //state for input1
int buttonState26 =  0; //for buzzer reset
bool buzzer_is_on;  // state variable
void setup() {
  pinMode(in1 , INPUT);
  pinMode(in26 , INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  digitalWrite(BUZZER_PIN, LOW); // buzzer LOW

}

void loop() {

  buttonState1 = digitalRead(in1);
  buttonState26 = digitalRead(in26);

  bool input_rises = (buttonState1 == HIGH);
  bool reset_pressed = (buttonState26 == HIGH);

  if (buzzer_is_on) {
    if (reset_pressed) {
      digitalWrite(BUZZER_PIN, LOW);
      buzzer_is_on = false;
    }

  }
  else {  // buzzer is off
    if (input_rises) {
      digitalWrite(BUZZER_PIN, HIGH);
      buzzer_is_on = true;
    }
  }
}


texts: arduino and esp-1 stop workign after 1 day running

texts:
i'm trying to create a system that arduino and esp-1 send an GET request each 2 secs to a server and depend on server reply turns a LED on or off . system works good for 6-7 hours but stops after one day . actually i  checked server logs after one day and i realized no request is sending to serve .
my hardware :
Arduino Uno
ESP-1
LED or Relay

and my arduino codes : ( in know my host is not working now . i turned it off )

#include <ArduinoJson.h>
#include <WiFiEsp.h>
#include <WiFiEspClient.h>
#include <SoftwareSerial.h>

SoftwareSerial Serial1(10,11);

char ssid[] = "AZaz";            // your network SSID (name)
char pass[] = "Az8833394";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
int Relay = 13;

char server[] = "azimi.ir";
unsigned long lastConnectionTime = 0;         // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 1000L; // delay between updates, in milliseconds
WiFiEspClient client;

void setup() {
  // put your setup code here, to run once:

  pinMode(Relay, OUTPUT);
  Serial.begin(115200);
  Serial1.begin(9600);
  WiFi.init(&Serial1);
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println(F("WiFi shield not present"));
    // don't continue
    while (true);
  }

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

  Serial.println(F("You're connected to the network"));
//  printWifiStatus();
}

void loop() {
  while (client.available()) {
  char c = client.read();
  char endOfHeaders[] = "\r\n\r\n";
  if (!client.find(endOfHeaders)) {
    Serial.println(F("Invalid response"));
    return;
  }
  const size_t capacity = JSON_OBJECT_SIZE(3) + JSON_ARRAY_SIZE(2) + 80;
  DynamicJsonDocument doc(capacity);
  DeserializationError error = deserializeJson(doc, client);
  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.c_str());
    return;
  }
      int count = doc["counts"];
      if(count == 1){
        int relay = doc["message"];
        int cmd = doc["val"];
        digitalWrite(relay , cmd);
      }

  }
  if (millis() - lastConnectionTime > postingInterval) {
    httpRequest();

  }
}

void httpRequest()
{

  Serial.println();

  // close any connection before send a new request
  // this will free the socket on the WiFi shield
  client.stop();

  // if there's a successful connection
  if (client.connect(server, 80)) {
    client.println(F("GET /check/ HTTP/1.1"));
    client.println(F("Host: azimi.ir"));
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection
    Serial.println(F("Connection failed"));
  }
}

now i have some questions :

1- why system stops working after more hours ? what is the problem ? my codes or my hardware ?

2- if problem is my hardware , what kind of wifi module or arduino you think will work ?

3- i want this project to make someone else's home . it will be a long term project so i want my system works for one or two years at least . is arduino suitable for this kind of projects ?! if its not , what hardware is ?


texts: What is the advantage of higher priced arduinos to cheaper ones?

texts:
I just got an Arduino Mega ADK (which seems to be functional, based on my limited testing and knowledge) at a yard sale for under $5. I don't have any Arduino experience, but I'm into DIYing, so who not try it.
I noticed that this specific board has a noticeably higher price than the other models. That would be, comparing brandname models to others brandname models, OR offbrand to offbrand.
My question is, why would someone prefer the higher priced models over the more simple/cheaper ones? My guess would be power consumption, I/O, capabilities, or processing speed. But I think I heard that the processing speed of the slower boards is already enough to run most projects, or am I wrong?


texts: Does analogueRead() change the way a number is represented etc?

texts:
Explanatory Comment: The ADC conversion result is a 10 bit number and is placed in two 8 bit registers: ADCH & ADCL. AnalogueRead() reads the output of the ADC. This, I believe is an unsigned number. But, generally taken as only a positive number.

I'm interested in what changes, if any, take place to the number (in it's representation, interpretation, or construction or whatever) when analogueRead() reads the number and presumably makes something of it, or sends it or stores it somewhere.


texts: Arduino ProMini green led flashing and unable to reset

texts:
so I'm using a promini running on solar power. For some reason, after sometime it gets stuck with the green led flashing and only by cutting power can I reset the promini. Even the reset button doesnt work. Exactly like in this post "Watchdog timer stuck in restart loop? (green led flashing)". However, the strange thing is that I am not even using a watchdog timer. So what could be the cause of it? Could it be due to the lack of power from my solar panel?

Here is my code

#include <SPI.h>
#include <RF24.h>

int green = 8;
int red = 6;

// ce,csn pins
RF24 radio(9,10);

// init data buffer to hold a sensor type byte and one uint16_t sensor data
unsigned char data[3] = {
  0};
unsigned long count=0;

void(* resetFunc) (void) = 0;//declare reset function at address 0
void setup(void)
{
  pinMode(4, OUTPUT);
  digitalWrite(4,HIGH);
  pinMode(5, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(red, OUTPUT);
  pinMode(3, OUTPUT);

  Serial.begin(57600);
  Serial.println("**************V1 Send Sensor Data***********");
  radio.begin();
  radio.setPALevel(RF24_PA_MAX);
  radio.setChannel(0x4c);

  // open pipe for writing
  radio.openWritingPipe(0xF0F0F0F0E1LL);

  radio.enableDynamicPayloads();
  radio.setAutoAck(false);
    radio.setDataRate(RF24_1MBPS);
  radio.powerUp();
  Serial.println("...Sending");

}

void loop(void)
{
  digitalWrite(5,HIGH);
  delay(50);
  uint16_t sensorValue = analogRead(0);
  digitalWrite(5,LOW);

  Serial.println(sensorValue);
  if (sensorValue > 600){
    digitalWrite(red,LOW );
    digitalWrite(green,HIGH);
  }
  if (sensorValue >= 0 && sensorValue <= 300){
    digitalWrite(red,HIGH);
    digitalWrite(green,LOW);
  }

  //assign identification to the node.
  // In use = A & B;
  data[0] = 'B';
  //do the bit shift to put uint16 into uint8 array
  data[1] = sensorValue >> 8;
  data[2] = sensorValue;
  Serial.print(count);
  Serial.print("   |   Identity: ");
  Serial.print(data[0]);
  Serial.print("   |   ");
  Serial.print(" data[1]: ");
  Serial.print(data[1]);
  Serial.print("  |  data[2]: ");
  Serial.print(data[2]);
  digitalWrite(3,HIGH);
  // print and increment the counter
  radio.startWrite(data, sizeof(uint16_t)+1);
  Serial.print("  | Temperature sent:  ");
  Serial.println(sensorValue);
  digitalWrite(3,LOW);
  // pause 5 seconds
  delay(5000);
  resetFunc();  //call reset
}

Thank you so much!


texts: Converting `millis()` to decimal seconds?

texts:
I would like to get my Arduino to print milliseconds as decimals of seconds.  For example, instead of printing 10456, printing 10.456

I have tried to set a float value or millis, and dividing by 1000 but that gives me a whole number "0" to "1" which is not ideal

The code I use is:

float ourtime = (millis() / 1000);
dataFile.print (ourtime);

What would be the easiest, and least taxing (for the processor) way of getting a script to return milliseconds as seconds while taxing the unit as little as possible ?


texts:
I recently received two types of Pic32 microcontrollers from Microchip, specifically the PIC32MX270F256B and the PIC32MX230F256B. I would like to use an Arduino Uno to setup the bootloader and to do all the programming. I found a tool to upload to the board here, but as it is from a 2012 forum here, I cannot figure out what it is exactly used for. It seems to be able to upload hex files, but in which format and to what is unclear to me. I also found Arduino bootloaders for a similar group of microcontroller here, however I cannot tell exactly which version I need, if any, or how to upload it.

Any help on how to use these tools or others would be greatly appreciated as my only experience with Arduino before this is with a simple to program to Arduino Uno.


texts: Program Arduino via UART from ESP8266 SPIFFS

texts:
I have built a custom board that has an ATmega328p connected to an ESP8266 module via UART. I am currently programming the ATmega328p using a USBtiny programmer via an SPI header. The ESP8266 module is programmed via an FTDI cable connected the the UART.

Firmware for both are created in Arduino IDE.

I have set up a webserver on the ESP that allows for files to be uploaded to the SPIFFS via FTP. I would like to be able to upload a hex file for the ATmega and then have the ESP program the ATmega via the UART connection. A GPIO on the ESP controls a transistor that can pull the reset pin on the ATmega to ground.

I know I need a bootloader on the ATmega (e.g. optiboot), but I don't know what I need to make the ESP do to trigger the bootloader and flash the ATmega. I'm thinking I need something like:

void initialiseAtmegaFlash () {
  // Trigger the bootloader to accept incoming hex over UART
}

void flashHexToAtmega (File atmegaHex) {
  for (uint32_t i = 0; i < atmegaHex.size(); ++i) {
    // Handle timing of sending byte by byte over serial... or chunk by chunk?
  }
}


texts: Using TMRpcm object, why is the SD Card failing to be found by arduino?

texts:
I am using this micro-sd card reader, and my wiring configuration is as follows (double and triple checked):

3.3v goes to 3.3v on the Arduino UNO
GND goes to Ground on Arduino UNO
D0 goes to pin 12 on Arduino UNO
D1 goes to pin 11 on Arduino UNO
CLK goes to pin 13 on Arduino UNO
D3 goes to pin 4 on Arduino UNO

When I run the 'basic' example from the TMRpcm library, everything compiles and uploads properly with no warnings. Looking at the Serial Monitor, I get "SD Fail", which, according to the comments, means that the SD card failed to initialize. The card is present, and works in my computer. Do I have something wired wrong, or is there another issue?

EDIT

I have tried using a different pin for D3, and changed the code as needed. Still no luck.


texts:
I am trying to have my Arduino wait in a low power idle state given by the LowPower library made by rocketscream on an Uno. However, when I try to have it wait for 8 seconds, it seems to not pause at all. Does anyone know how to make it so it waits the full 8 seconds before running the next line of code?
Here is the code:
#include "LowPower.h"

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

void loop() {
   delay(100);
   Serial.println("above");
   delay(100);

   LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_OFF, TIMER0_ON, SPI_OFF, USART0_OFF, TWI_OFF);

   delay(100);
   Serial.println("below");
}

I would expect this to print "above", then wait 8 seconds, then print "below",  then do it again. But what happens is it runs right through the LowPower.idle without doing anything and the output looks like:

1:12:14.547 -> above
21:12:14.746 -> below
21:12:14.845 -> above
21:12:15.044 -> below
21:12:15.144 -> above
21:12:15.376 -> below

...and so on.
If anyone has any ideas on how to make idle wait, that would be great.
Thanks!


texts:
I'm new to using the esp32 as a microcontroller. I'm currently working on a so-to-say remote control. Since I want to use the esp32 with an external battery I need to put it in deep-sleep after I pressed some buttons to preserve battery.
All that works fine I've connected a small touchpad to put the esp32 into deep sleep mode using the esp_deep_sleep_start() function . The controller itself goes to sleep and can be woken up using the following 2 lines:
  touchAttachInterrupt(T0, wakeCallback, TOUCH_THRESHOLD);
  esp_sleep_enable_touchpad_wakeup();

In order to communicate with my Raspberry Pi 'Base Station' I decided to use BLE.
My server is configured the following way (where bleServer, bleCharacteristic and bleService are global variables):
  BLEDevice::init("esp-32-remote");
  bleServer = BLEDevice::createServer();
  bleServer->setCallbacks(new ServerCallbacks());

  bleService = bleServer->createService(SERVICE_UUID);
  bleCharacteristic = bleService->createCharacteristic(
                        CHARACTERISTIC_UUID,
                        BLECharacteristic::PROPERTY_READ |
                        BLECharacteristic::PROPERTY_WRITE
                      );

  bleCharacteristic->addDescriptor(new BLE2902());
  bleService->start();

  BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
  pAdvertising->addServiceUUID(SERVICE_UUID);
  pAdvertising->setScanResponse(true);
  pAdvertising->setMinPreferred(0x06);
  pAdvertising->setMinPreferred(0x12);
  BLEDevice::startAdvertising();

Upon regular restart using the buttons everything works fine. I can connect to the device using python and the bluepy library.
If I now wake the controller I can't do anything anymore. The setup() function gets called and there are no errors, nor does the controller crash due to any code errors (seemingly).
Then the loop function gets called once, and thats it. I can't connect to the device anymore until I press the hardware reset button.
The questions that arise are:

might there be some error in the way I shutdown the bluetooth module?
Does the loop function work after being woken up from deep sleep?

Maybe one of you has an idea regarding my issue. If there are more information that I need to provide, don't hesitate to tell me, I'm new to the whole mcu topic and I don't know whats best to provide here.


texts:
void loop()
    {
    if ( Serial.available() > 0 )
      {
    static char input[inputLength];

    static uint16_t i;

    char c = Serial.read();

    if ( c != '\n')
      input[i++] = c;

    else
    {
      input[i] = '\0';
      i = 0;

      uint16_t array[80];
      uint16_t j = 0;

      if ( !strncmp(input, "SEND", 4) )
      {
        char* p = input + 4;

        while ( (p = strchr(p, ' ')) != NULL )
          array[j++] = strtol(p, &p, 16);

        ir_start(array);
        Serial.println("WURKS");
      }
    }
  }
}

Hello I can't seem to figure out what this code is doing. I know the main goal but I can't figure out the proccess. If someone could please make the code dumber for me I would appreciate it :). Full code is here since its hard to copy code: https://anonfiles.com/z6ldWff0pf/no_lib_ino


texts:
Is it possible to use only arduino to do voice recognition? or maybe with esp32 no internet.

I found speech recognition chip but that's not what i want
I got esp32 esp8266 and arduino board.
I would like to know if somebody could do it


texts:
I recently purchased a 1.2 8x8 yellow matrix from Adafruit, along with a HT16K33 backpack for it. I joined the matrix and the backpack, connected everything to the arduino, followed the instructions on the site and got it to work. During animation certain rows would not light up and upon later examination I realized that I had to solder up the pins to the backpack because some pins would not completely make contact with the backpack. After soldering the matrix to the backpack, I fired up arduino and uploaded the matrix8x8 sketch that comes with the library to test the matrix and nothing happens.

I don't have a multimeter yet, but tried to check whether electricity is reaching the backpack which turns out to be true. (used a led and connected it to both + and -, and data and clock pins on the backpack.) in both cases the led lights up.

How can I check the health of the backpack and/or matrix?


texts: What is the execution context of the function registered via the Wire.onReceive() method?

texts:
I'm basically wondering if it's OK to Serial.write() or print in the function I register to be called when I2C data is received.  I can't seem to find the execution context or any warnings.

http://arduino.cc/en/Reference/WireOnReceive