texts: My stepper motor connected to a driver and an Arduino is not working

texts:
I'm using a 28BYJ-48 stepper motor with a ULN2003 driver board. I'm trying to control the motor using an Arduino MEGA. I initially connected the pins on the driver: IN1,2,3,4 to pins of the Arduino: 8,9,10,11 respectively; as was given in a youtube video I referred to(https://www.youtube.com/watch?v=HdqCtAJxhrs). The power for the motor was given from the 5V and GND ports in the Arduino. What happens is that it rotates 180 degrees,and then stops and then goes at random angles and stops. This was the code:

#include <Stepper.h>

Stepper stepper1(64,8,9,10,11);
int a=1;

void setup() {
  stepper1.setSpeed(50);
}

void loop() {
  while(a<10){
    stepper1.step(2048);
    delay(1000);
    a++;
  }
}


texts:
Since today, my Arduino Uno (using Arduino IDE version 1.8.13) lost the capacity to store a sketch upon physical disconnection (does not include button reset).
This means, the sketch works properly but when I unplug it and plug it back again, the Arduino will act as if I uploaded a blank sketch by blinking 3 times fast repeatedly.
To check this, I tried several examples like "Blink" on Windows 10 and Ubuntu and repeats the error.
I feel there is something wrong with the bootloader or something like that, but I'm finding hard to understand some concepts.
Does anyone recognizes what is happening on the Arduino? What can I do to address the problem?
Summary:

Uploads fine.
Works fine.
Resets fine.
Hard-resets INCORRECTLY (can't plug and unplug and expect the program will still work).
Keeps working good until loss of power.


texts: Buzzer - Does the voltage change with the frequency?

texts:
So I have this project where the component "buzzer" is implementet. I was wondering if the voltage is changing along the change of frequency given to the buzzer?

Note that the project just says "buzzer" - not any more details.

Project: http://www.instructables.com/id/Arduino-Distance-Detector-with-a-Buzzer-and-LEDs/?ALLSTEPS


texts: I am trying to find a small voice recorder that I can use with my Arduino Micro, and I found this. It is exactly what I am looking for, but it is now a retired product. I googled ISD1932, but many other sites are out of stock or not selling it anymore. Is there something of this size that does the same things, and why is it retired?


texts: How can I move an arduino library into my project repo and use it from there?

texts:
I've got this project that that is using the LiquidCrystal.h library. My import looks like this...

#import <LiquidCrystal.h>

I've tried making a 'libraries' folder in my repo, and copying the LiquidCrystal directory from arduino's global libraries folder to my_project/libraries and changing my import to...

#import "libraries/LiquidCrystal/LiquidCrystal.h"

and it explodes on me. I know the path is right, because it gives me a different error if I change the import path to be wrong... but even when it's right, I get this traceback...

Arduino: 1.8.1 (Mac OS X), TD: 1.36, Board: "Arduino/Genuino Uno"

/var/folders/sz/cdsmvqws6rq9839mhd802prm0000gp/T//cc4gIISN.ltrans0.ltrans.o: In function `__static_initialization_and_destruction_0':
/Users/chris/art/greenhouse/greenhouse/greenhouse.ino:36: undefined reference to `LiquidCrystal::LiquidCrystal(unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char)'
etc....

What's the deal? Aren't I supposed to be able to import libraries with an absolute path to the library? This is literally the same file.

What is the difference between #import <foo.h> and #import "my_libraries/myfoo.h" ?


texts:
I am using an ESP8266 board and I had it plugged in to my computer via usb. I reached accross the board to press the reset button, and it felt like my finger got stung. The best I can figure, I touched the VIN and Gnd pins with my finger, and, I didn't think this at first, the reset pin. Whenever I try to open a serial port all that shows, and at a different baud rate then I specified, is this error message

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

 load 0x4010f000, len 1384, room 16
 tail 8
 chksum 0x2d
 csum 0x2d
 v951aeffa
 ~ld

Everything I find online says that this means that the reset pin is causing problems. Although this is the first time a 7 showed up, it used to be a 6. Also, the computer doesn't seem to have a problem uploading the sketches, but they don't seem to run.

I have tried re-flashing the firmware, but just now when I was typing this out, I thought to upload Blink, just to say I could, and it worked, but it isn't sending anything to the computer of serial, at all. I own two of these boards, but the problem happened across both making me think that something happened to my computer.

Any help is appreciated.

Edit: I am running Win 10, using Vscode to upload sketches, and arudino IDE v1.8.7 to monitor serial. I have many Serial.print() lines, and Serial.begin(115200)


texts:
It all started when I was working on my Arduino project, which involves an Arduino Nano, an HC05 module and a bunch of sensors (DHT 11, soil moisture and LDR) with Blynk App. Everything worked as it should (compiled properly) but there was no transfer of data (HC05 was paired).

At that time before pairing, the HC05 was blinking rapidly and after pairing it was blinking twice rapidly every 5 seconds. Note I connected everything as the example said... (You know HC05s TX RX to HW Serial Pins vice-versa).

So later I tried again with everything stripped out (took out all sensors and just the barebones sketch) and added the button widget in the app to control the Nano's onboard LED). Again everything worked as it should but there was no connection between the HW and the Blynk APP (it was not switching on the LED).

Then I tried with an another Bluetooth app and it didn't work as it should. Then I got to know something's wrong with the board itself. So I tried to boot it into AT command mode with this Guide. But it wasn't accepting any commands (NO replies).

So what do I do?

NOTE: I didn't get any relevant question so sorry for that. And do you need anything else?

Edit: It worked. I dont really know how. I think there was maybe a problem with the voltage divider but not sure. Thanks for your time and answers.


texts: Forwarding serial output from a Nano to Uno that's used as the ISP

texts:
I'm trying to program a Nano by using an Uno as the ISP. So far, I've followed along with the example project for getting the Uno running as the ISP on https://www.arduino.cc/en/Tutorial/ArduinoISP.

After a bit of tinkering, it works, but the serial monitor won't work correctly. I'm uploading a super simple program that delays for 500 ms and prints to the log.

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

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

I've wired the TX pin on the Nano to the RX pin on the uno. The monitor updates every 500 ms as expected after doing so, but displays ��� instead of the word test. When I tried wiring TX -> TX, the serial monitor does not update. Does anyone have any insight what's missing here?


texts: İs there any way different way than GND's Arduino

texts:
İ'm making  a project on my arduino uno when i figured out i had no more GND left to finish the circuit. İs there any other way to optimize, use pins as input maybe. İ tried whit other websites, however, they weren't much of a use. Can you show an example also.
Thank you sooo much in advance,
Dario


texts: Integrating an analog signal using Arduino Mega 2560

texts:
The sample code is this:

Sample code for Edgar Bonet

I have questions. I need to integrate the analog sine wave of 60 Hz, this signal described in the next picture, adding an offset near 2.5 V, because I can damage the Arduino board with the negative signal cycle. Internally on the Arduino board, I remove this offset, multiplying by 2, and subtracting 1.

V1=analogRead(A0)*2/1023.0-1.0;

The sampling period must be at least fs=300 Hz, T=1/fs and V1 is the signal I need integrate.

What modifications can I make to Edgar Bonet's code?


texts: Which sources of randomness are available?

texts:
I need a souce of randomness to generate a seed to pass to randomSeed. Where can I get this randomness from?

Well, I hear I can read random noise from an unconnected pin.

But I need to connect 9 LEDs and 9 buttons to the board. There seem to be enough pins for this purpose: digital pins 2-13 + analog pins 0-5 makes a total of 18 pins. But does this leave any free pin for a source of randomness?

There are digital pins 0 and 1 left free but I'm reading these should be left free if the board's USB socket is connected and I'm planning to power the whole device by connecting it to a computer through USB. Does this mean I'm supposed to just left pins 0 and 1 unconnected or is it also forbidden to read noise from them?

Or are there any other available sources of randomness? Can I use any other pins for this purpose?

I remember when I was showing this project to the instructor I specifically asked if I have enough pins, noting that I need a source of randomness in addition to 9 LEDs and 9 buttons. He said there are enough pins. Only sadly I forgot to ask how can I read random noise then...

What are my options to somehow obtain a random seed?


texts:
I am trying to set up a PJON SoftwareBitBang network with a bunch of DigiSparks. My setup works well with any other Arduino devices except the DigiSparks. Based on some internet searching I came to the conclusion that it's because DigiSpark doesn't have a built in oscillator.

I bough a bunch of 16Mhz Crystal Oscillators hoping the internet will help me set them up but I couldn't find any resources on how to do that

Does anyone know any resources on how to use an external oscillator on DigiSpark?
Alternatively, can anyone think of any other reason why SoftwareBitBank goesn't work with Digisparks?

Thanks,
Andi


texts: Ardunio Mega/ATmega2560: Using Port F or K for both analog inputs and digital outputs

texts:
On an ATmega2560, can ports have some pins used for analog inputs but others as digtial i/o? Specifically, I only need to use 3-5 analog inputs but have many digital inputs. I would like to use the remaining 3-5 pins as digital outputs if possible.
Additionally, does it make a difference if the port in question is Port F vs. Port K? For Port F, the datasheet seems to imply that all 8 of the pins are analog only if the ADC is enabled:

Port F serves as analog inputs to the A/D Converter.
Port F also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used.

For Port K, however, the datasheets port description does not have the distinction:

Port K serves as analog inputs to the A/D Converter.
Port K is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).

It seems that this is definitely possible for the Arduino Uno/ATmega328P ADC port (except for the ADC6/7 pins for 32-pin form factors), but I can't seem to find anything confirming for the Arduino Mega/ATmega2560 or distinguishing between whether this is done on Port F or Port K


texts: Suggest some highly sensitive temperature sensor

texts:
Currently I am using DHT11 in my project, but its not very sensitive, it is quite slow in detecting temperature changes.

What sensor could I use that will be more sensitive?


texts:
I want to make a stepper motor increase and decrease speed working with a HCSR04 sensor. The idea is that if the sensors detects an object the stepper motor is going to decrease, and stop as close as possile to the object.

I have made some code, and it is sorta working..

My current code looks like this:

if (distance > 30)
{
  digitalWrite(13,HIGH); // Output high
  delayMicroseconds(500); // Wait
  digitalWrite(13,LOW); // Output low
  delayMicroseconds(500); // Wait
}

if (distance > 20 && distance < 30)
{
  digitalWrite(13,HIGH); // Output high
  delayMicroseconds(2000); // Wait
  digitalWrite(13,LOW); // Output low
  delayMicroseconds(2000); // Wait
}

if (distance > 10 && distance < 20)
{
  digitalWrite(13,HIGH); // Output high
  delayMicroseconds(10000); // Wait
  digitalWrite(13,LOW); // Output low
  delayMicroseconds(10000); // Wait
}

if (distance > 1 && distance < 10)
{
  //digitalWrite(13,HIGH); // Output high
  //delayMicroseconds(1000); // Wait
  digitalWrite(13,LOW); // Output low
}

But I thought it could be easier, So I made a function:

void velocity()
{
 digitalWrite(13,HIGH); // Output high
 delayMicroseconds(500); // Wait
 digitalWrite(13,LOW); // Output low
 delayMicroseconds(500); // Wait
}

Now my question is: Can I manipulate the delayMicroseconds to change if the distance changes? Is there a formula to do so?

Entire code:

int trigPin = 11;
int echoPin = 10;

void setup()
{
pinMode(trigPin, OUTPUT); //Sensor
pinMode(echoPin, INPUT); //Sensor
pinMode(6,OUTPUT); // Enable
pinMode(13,OUTPUT); // Step
pinMode(12,OUTPUT); // Dir
digitalWrite(6,LOW); // Set Enable low
digitalWrite(5,LOW); // Set Step low
Serial.begin(9600);
}

void loop()
{
//rotateleft();
//Serial.println("ik draai nu exact een rotatie linksom");
//delay(1000);
//rotateright();
//Serial.println("ik draai nu exact een rotatie rechtsom");
//delay(1000);
//velocity();

 //sensor
 long duration, distance;
 digitalWrite(trigPin, LOW);
 delayMicroseconds(2);
 digitalWrite(trigPin, HIGH);
 delayMicroseconds(5);
 digitalWrite(trigPin, LOW);
 duration = pulseIn(echoPin, HIGH);
 distance = (duration/2) / 29.1;
 Serial.print ("cm ");
 Serial.print (distance);

//eigen creatie

if (distance > 30)
{
  digitalWrite(13,HIGH); // Output high
  delayMicroseconds(500); // Wait
  digitalWrite(13,LOW); // Output low
  delayMicroseconds(500); // Wait
}

if (distance > 20 && distance < 30)
{
  digitalWrite(13,HIGH); // Output high
  delayMicroseconds(2000); // Wait
  digitalWrite(13,LOW); // Output low
  delayMicroseconds(2000); // Wait
}

if (distance > 10 && distance < 20)
{
  digitalWrite(13,HIGH); // Output high
  delayMicroseconds(10000); // Wait
  digitalWrite(13,LOW); // Output low
  delayMicroseconds(10000); // Wait
}

if (distance > 1 && distance < 10)
{
  //digitalWrite(13,HIGH); // Output high
  //delayMicroseconds(1000); // Wait
  digitalWrite(13,LOW); // Output low
}

//Own functions
}

void velocity()
{
 digitalWrite(13,HIGH); // Output high
 delayMicroseconds(500); // Wait
 digitalWrite(13,LOW); // Output low
 delayMicroseconds(500); // Wait
}

void rotateleft()
{
 digitalWrite(12,HIGH); // Set Dir high
 for(int x = 0; x < 200; x++) // Loop 200 times
  {
    digitalWrite(13,HIGH); // Output high
    delayMicroseconds(1000); // Wait
    digitalWrite(13,LOW); // Output low
    delayMicroseconds(1000); // Wait
   }
  }
  void rotateright()
  {
   digitalWrite(12,LOW); // Set Dir high
   for(int x = 0; x < 200; x++) // Loop 200 times
   {
     digitalWrite(13,HIGH); // Output high
     delayMicroseconds(1000); // Wait
     digitalWrite(13,LOW); // Output low
     delayMicroseconds(1000); // Wait
   }
 }


texts: VS2019CE/VisualMicro project won't compile without specific reference

texts:
I have a small project to test a Sparkfun MPU9250 breakout board.  'Class_MPU9250BasicAHRS_t3.h', 'MPU9250BasicAHRS_t3.h' and 'Class_MPU9250BasicAHRS_t3.cpp' are all in the local project folder. Compile fails with an 'undefined reference' error at any reference to the Class_MPU9250BasicAHRS myIMU object  unless I add 'Class_MPU9250BasicAHRS_t3.cpp' to the project as a 'Source File' in the Solution Explorer window.

Why is this?  I thought the compiler was smart enough to look for a .cpp file with the same name as an #include'd header file.

TIA,

Code attached:

/*
    Name:       Teensy_MPU9250_Test.ino
    Created:    9/15/2019 11:46:10 AM
    Author:     FRANKWIN10\Frank
*/

/*  All this program does is display heading values from a Sparkfun MPU9250
    breakout board at the default (0x68) I2C address
*/

#include "Class_MPU9250BasicAHRS_t3.h" //extracted all #defines from MPU9250BasicAHRS_t3.ino
#include <i2c_t3.h>
#include <elapsedMillis.h>

elapsedMillis sinceLastPrint;
Class_MPU9250BasicAHRS myIMU;

int pulsePin = LED_BUILTIN;//04/10/18 added per-step pulse pin parameter
bool bFirstTime = true;
const long MSEC_PER_PRINT = 100;

void setup()
{
    Serial.begin(115200);
    delay(3000); //delay required to wait for Serial object creation
    //Wire.begin();

    pinMode(LED_BUILTIN, OUTPUT);
    Wire.begin(I2C_MASTER, 0x00, I2C_PINS_18_19, I2C_PULLUP_EXT, 400000);
    Wire.setDefaultTimeout(200000); // 200ms

    //IMU init & test
    Serial.println("Starting program...");
    Serial.println("Initializing 9250 IMU...");
    myIMU.init9250IMU();
    Serial.println("Done...");
}

void loop()
{
    float hdg_deg = myIMU.GetIMUHeadingDeg();
    if (bFirstTime)
    {
        bFirstTime = false;
        Serial.printf("Msec\tHdg\n");
    }

    if (sinceLastPrint > MSEC_PER_PRINT)
    {
        Serial.printf("%lu\t%4.2f\n", millis(), hdg_deg);
        sinceLastPrint -= MSEC_PER_PRINT;
    }
}


texts: Issue with Serial PINs (RX/TX) on Arduino

texts:
I have an issue with an Arduino Nano.

I want to communicate with it through the Serial-Port. Meaning I want to send and receive Serial commands. With USB and the "Serial Monitor" this works nice.
Now I have connected the COM-Port of the PC with Adruinos Digital Pins 0 and 1 (RX and TX) and a GND PIN. (3 Cables total).

Here is a minimal example of my Code:

void setup() {
  Serial.begin(9600,SERIAL_8N1);
  Serial.println("Start");
}

void loop() {
  Serial.println("Hello World");

  delay( 1000 );
}

The Serial Monitor says:

Start
Hello World
Hello World
Hello World
Hello World
...

Putty however says:

▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒::
                                                     ▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*▒▒    ▒R▒▒▒t▒*▒▒▒R▒▒▒t▒*

Putty is connected with
- BaudRate: 9600
- Data Bits:
- Stop Bits: 1
- Parity: None
- Flow Control: None

What is wrong here?

Update:
The PC has a 9-pin D socket (Image)
This is connected to a RS232 to RJ45 connector (image)
From the RJ45-Cable I used the Brown, Blue, and White/Green Cable to connect with the Arduino


texts: I am getting blocks on my lcd screen 16*2

texts:
When I have tried interfacing my 16*2 LCD with Arduino I am getting only the black coloured boxes on my screen. What might be the problem?

Is there any solution to that? Do I need to connect any additional physical device to avoid that situation?

product is here lcd display 16*2


texts:
I m getting serial does not name a type error, expected declaration before '}' token line 69

const int trigPin = 9;
const int echoPin = 10;
const int buzzer = 11;
const int ledPin = 13;

// defines variables
long duration;
int distance;
int safetyDistance;

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

void loop() {
// Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);

// Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

// Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);

// Calculating the distance
  distance = duration * 0.034 / 2;

  safetyDistance = distance;
  if (safetyDistance <= 5) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);

    tone(buzzer, 1000);
    delay(100);
    noTone(buzzer);
    delay(100);
  }

  else {
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
  }
  if (safetyDistance > 5 && safetyDistance <= 10) {
    digitalWrite(buzzer, HIGH);
    digitalWrite(ledPin, HIGH);

    tone(buzzer, 3000);
    delay(3000);
    noTone(buzzer);
    delay(3000);
  } else {
    digitalWrite(buzzer, LOW);
    digitalWrite(ledPin, LOW);
  }
  }
  Serial.print("Distance: ");
  Serial.println(distance);

}


texts:
I am trying to send 2 variables with wire.h. I tried with  this code:

MASTER RECEIVER:

#include <Wire.h> // include la libreria
#include <LiquidCrystal_I2C.h>
#include "RTClib.h"

LiquidCrystal_I2C lcd(0x3E, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
RTC_DS1307 RTC; // orologio

static int anno;
static int giorno;
static int mese;
static int ora;
static int secondo;
static int oldSecondo;
static int minuto;
static int oldMinuto;
static int annoGrezzo;
char t[10] = {};
char v[10] = {};

void setup() {
  Wire.begin(); // join i2c bus with address #4
  lcd.begin(16, 2);
  Serial.begin(9600); // start serial for output
  //-----------orologio-----------
  RTC.begin();
  // Check to see if the RTC is keeping time. If it is, load the time from your computer.
  if (! RTC.isrunning()) {
    Serial.println("RTC is NOT running!");
    // This will reflect the time that your sketch was compiled
    RTC.adjust(DateTime(__DATE__, __TIME__));
  }
  //-----------fine orologio-----------
}

void loop() {
  //------------------------------------------------------------
  //   si stampano i dati ricevuti e ricomposti
  //------------------------------------------------------------
  Wire.requestFrom(8, 6);
  int i = 0;
  while (Wire.available()) {
    Serial.println(i);
    t[i] = Wire.read();
    // every character that arrives it put in order in the empty array "t"
    i = i + 1;
  }
  Serial.println(t);
  DateTime now = RTC.now();
  annoGrezzo = now.year();
  anno = (annoGrezzo % 100);
  mese = now.month();
  giorno = now.day();
  ora = now.hour();
  minuto = now.minute();
  lcd.setCursor(0, 0);
  lcd.print(t);
  lcd.setCursor(5,0);
  lcd.print(v);
  lcd.setCursor(0, 1);
  lcd.print(giorno);
  lcd.print(" ");
  lcd.print(mese);
  lcd.print(" ");
  lcd.print(anno);
  lcd.print("  ");
  lcd.print(ora);
  lcd.print(":");
  lcd.print(minuto);
  delay (1000);
  lcd.clear();
}

SLAVE SENDER

#include <Wire.h> // si include la libreria
//---------------------------------------------------------
char t[10];
char v[10];

void setup() {
  Wire.begin(8);
  // join i2c bus (address optional for master)
  Wire.onRequest(requestEvent);
}

void loop() {
  int mioInt = random(30000);
  int mioInt2 = 1234;
  dtostrf(mioInt, 3, 2, t);
  //convers the float or integer to a string. (floatVar, minStringWidthIncDecimalPoint, numVarsAfterDecimal, empty array);
  dtostrf(mioInt2, 3, 2, v);
  //------------------------------------------------------
  delay (500);
}

void requestEvent() {
  Wire.write(t);
  Wire.write(v);
}

I'm unable to receive v in my master receiver. Thanks for your help.


texts: How to adapt this code using a DF Mini Player and interrupts for the ATTiny85?

texts:
So I programmed my Arduino Mega 2560 to play certain sound effects from a DF Mini Player that I have. I  took the base code that I modified from online so some fo the names might seem odd. Currently, when uploaded to the Arudino, it works as it should, "buttonPause" and "play()" only play one of the audio files WHILE I am pressing a button. "buttonNext"/"play1()" and "buttonPrevious"/"play2()" activate a sound when a button is tapped (not held down). To allow the sound effect to play in full only while I'm, holding down "buttonPause," I had to use a delay as well as interrupt to stop the playback as soon as I released the button. However, I know aside from changing pin numbers, there are some other alterations I have to make for the interrupt to adapt it to work with the ATTiny85. Any idea how I can get started on making those changes? I have been confused by the sources I have found online.

Full code for using the DF Mini Player with the Arduino Mega

///              MP3 PLAYER PROJECT
/// http://educ8s.tv/arduino-mp3-player/
//////////////////////////////////////////
#include "SoftwareSerial.h"
SoftwareSerial mySerial(10, 11);
# define Start_Byte 0x7E
# define Version_Byte 0xFF
# define Command_Length 0x06
# define End_Byte 0xEF
# define Acknowledge 0x00 //Returns info with command 0x41 [0x01: info, 0x00: no info]
# define ACTIVATED LOW

int buttonNext = 2;
int buttonPause = 3;
int buttonPrevious = 4;
boolean isPlaying = false;
const byte interruptPin = 3;
volatile byte state = LOW;
int buttonState = 0;
int buttonState1= 0;
int buttonState2= 0;
int ledPin = 9;

void setup () {
pinMode(buttonPause, INPUT);
digitalWrite(buttonPause,HIGH);
pinMode(buttonNext, INPUT);
digitalWrite(buttonNext,HIGH);
pinMode(buttonPrevious, INPUT);
digitalWrite(buttonPrevious,HIGH);
mySerial.begin (9600);
attachInterrupt(digitalPinToInterrupt(interruptPin), pause, CHANGE);
pinMode(ledPin, OUTPUT);

}
void loop () {

buttonState = digitalRead(buttonPause);
buttonState1 = digitalRead(buttonNext);
buttonState2 = digitalRead(buttonPrevious);

if (buttonState == LOW)
  {
      play();
      setColor(255, 0, 222); // red
      digitalWrite(ledPin, HIGH);
      delay(1500);

  }

if (buttonState1 == HIGH)
  {

  }

if (buttonState == HIGH)
  {

  }

  if (buttonState1 == LOW)
  {
      play1();

      delay(100);

  }

if (buttonState2 == HIGH)
  {

  }

    if (buttonState2 == LOW)
  {
      play2();

  }

}

void pause()
{
  execute_CMD(0x16,0,0);

      digitalWrite(ledPin, LOW);
}
void play()
{
  execute_CMD(0x03,0,1);
}
void play1()
{
  execute_CMD(0x03,0,2);
}
void play2()
{

  execute_CMD(0x03,0,3);
}

void execute_CMD(byte CMD, byte Par1, byte Par2)
// Excecute the command and parameters
{
// Calculate the checksum (2 bytes)
word checksum = -(Version_Byte + Command_Length + CMD + Acknowledge + Par1 + Par2);
// Build the command line
byte Command_line[10] = { Start_Byte, Version_Byte, Command_Length, CMD, Acknowledge,
Par1, Par2, highByte(checksum), lowByte(checksum), End_Byte};
//Send the command line to the module
for (byte k=0; k<10; k++)
{
mySerial.write( Command_line[k]);
}
}

Board Layout

The amount and placements of the resistors seemed to reduce the amount of noise as much as possible.


texts:
I have read before that you can't use delay() inside I2C receiveEvent because it is an ISR.
What I want to do is as follows: I have a servo connected to my Arduino Uno and I want to control that using an I2C signal. Since I want to decrease the speed of the servo, I was previously using a loop with delay inside, which doesn't work when the function is called by I2C.
This is the code that I used before to control the servo:
void setServo(bool status) {
    if (status) {
        for (int pos = 0; pos <= 180; pos += 5) {
            servo.write(pos);
            delay(50);
            Serial.println(pos);
        }
    } else {
        for (int pos = 180; pos >= 0; pos -= 5) {
            wasteFlapServo.write(pos);
            delay(50);
            Serial.println(pos);
        }
    }
    servoStatus = status;
}

How could I still control the speed of the servo even if I use I2C? Thanks for your help.
Kind regards,
Moritz


texts: How do I adjust the scale/calibration of a photoresistor?

texts:
This photoresistor has a min/max of 0-1023.

I'm trying to scale the brightness of a cathode RGB LED based on the sensor's value, but based on my current lighting, the min/max readings I generally am getting are 100-700.

So how can I scale the sensor reading so that 100 = no light on the LED and 700 = max brightness?


texts:
I am using Arduino Uno R3 and a SIM800L (voltage regulator built in). My initial setup included a 10kΩ resistor soldered between the lower end of the RX and GND pins on the SIM800L, and a 4.6kΩ resistor soldered on the jumper connecting SIM800L's RX and Arduino's declared TX (pin 7). SIM800L has its own power supply (5v-2A). This is a setup I have used previously on two different SIM800L modules, and everything worked fine without any (visible) problems.

Baud rate is set to 9600 in Arduino IDE, PC port (via Device manager), and the module, through the sketch.

After loading the sketch (first one) shown on this site, the SIM800L connects to the GSM network (I can tell by the delay between blinks), but the module does not respond to AT commands send via serial monitor.

The sketch

#include <SoftwareSerial.h>

//SIM800 TX is connected to Arduino D8
#define SIM800_TX_PIN 8

//SIM800 RX is connected to Arduino D7
#define SIM800_RX_PIN 7

//Create software serial object to communicate with SIM800
SoftwareSerial serialSIM800(SIM800_TX_PIN,SIM800_RX_PIN);

void setup() {
  //Begin serial comunication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);
  while(!Serial);

  //Being serial communication witj Arduino and SIM800
  serialSIM800.begin(9600);
  delay(1000);
}

void loop() {
  //Read SIM800 output (if available) and print it in Arduino IDE Serial Monitor
  if(serialSIM800.available()){
    Serial.write(serialSIM800.read());
  }
  //Read Arduino IDE Serial Monitor inputs (if available) and send them to SIM800
  if(Serial.available()){
    serialSIM800.write(Serial.read());
  }
}

Things tried

Thinking that the resistors might be causing this, I removed all of them, and made a clean connection with Arduino. And the problem persisted.

I tried resetting the module, by passing the ATW command into a sketch:

serialSIM800.write("ATW\r\n");

and that also gave no results. Further testing with:

if(!serialSIM800.available()) {
    Serial.println("Not working");
}

indicated where the problem might be.

I have also tried changing the baud rate to 48000, 57600, and 115200, but that did not solve my problem.

The question

Am I right in assuming that a reset to factory settings could solve my problem? If so, how can I reset the module, without the AT commands? If resetting would do me no good, what else could I try?


texts: Button debounce using millis() in this example

texts:
I have been trying to find a way to use millis() instead of delay(), in order to press 2 buttons to turn on and off a blue led.

EDITED:

const int right_button = 8, left_button = 9, yellow_led = 7, blue_led = 6, green_led = 5, red_led = 4;
int previous_left_button_status = LOW, previous_right_button_status = LOW, blue_status = LOW, green_status = LOW;
unsigned long time_setup = millis();
const int delay_task = 250;

void setup()
{
  pinMode(right_button, INPUT_PULLUP);
  pinMode(left_button, INPUT_PULLUP);
  pinMode(blue_led, OUTPUT);
  pinMode(green_led, OUTPUT);
  pinMode(red_led, OUTPUT);
  pinMode(yellow_led, OUTPUT);
  Display.clear();
}

void loop()
{
  int right_button_status = digitalRead(right_button);
  int left_button_status = digitalRead(left_button);
  unsigned long time_passes = millis();
  if (time_passes - time_setup >= delay_task)
  {
    time_setup = time_passes;
    if (right_button_status == previous_right_button_status)
    {
      green_status = !green_status;
      digitalWrite(green_led, green_status);
    }
  }
}


texts:
I want to monitor an input and then send the information in an encrypted way that can't be easily unlocked even if a malicious actor gets access to the device itself. I'm new to using the Teensy although I have done a few simple things with Arduino microcontrollers. I was hoping to find out if anyone has implemented RSA or other asymmetrical encryption on a Teensy or to figure out if it has enough processing power to make it feasible. I would also accept using other Arduinos (I have an MKR1000 as well), for this but I assume because the Teensy has much better performance it's more likely to be able to do computationally expensive encryption.
This won't need to decrypt anything, it will only be sending data encrypted using the public key of the receiving user.


texts: AT42QT1070 TOUCH SENSOR SENSITIVITY INCREASE

texts: i AM USING AT2QT1070 TOUCH SENSOR IN STANDALONE MODE. HOW CAN I INCREASE THE SENSTIVITY OF THE CAPACITIVE TOUCH PNS. i NEED RANGE BEYOND 7MM?


texts: Use Arduino as transmitter and receiver UART

texts:
I know UART and serial communication model and data frame. But I want to ask about something else, when I searched in internet just found examples of one Arduino as (receiver) and another Arduino as (transmitter).
So my question is how can I implement two Arduino and both of arduinos can communicate each other when after transferring data from one to another
(example A->B). If the interpretation of the received data has to be forwarded to the first sender again(B->A).


texts:
I am working on air quality measuring project. it should be able to record gps and air quality data into a SD card and then when wifi is available it should send it to a server. Please help me decide the required hardware for this.
Can i use ESP8266 module to send this data


texts: How to shake hands (Atheros-ATmega comms)

texts: How does one assert, from the Linux user land (root-er land?) on the Atheros AR9331, the 32u4's arduino-pin 7 for communication handshake?


texts: Regarding running multiple functions using millis

texts:
I have been writing code for measuring when the digital signal comes and goes (ON and OFF respectively). I have done the part calculating a single system's downtime (difference in timings between ON and OFF from the system), but when I'm not able to scale up to multiple systems when I try to copy the same code which worked above. So it would be helpful if anyone could provide some insight into how it can be done plus explaining with the code would help.

My code:

unsigned long a=0, b=0, difference;
void setup()
{
  Serial.begin(9600);
  pinMode(2, INPUT);
  Serial.print("start");
  Serial.print(",");
  Serial.print("stop");
  Serial.print(",");
  Serial.print("minutes");
  Serial.print(",");
  Serial.println("seconds");
}

void loop()
{
 //delay(1000);
 int A = digitalRead(2);
 if(A == LOW)
 {
  b = millis();
 }
 if(A == HIGH)
  {
     a = millis();
     display_output();
   }
 delay(3000);
}
void display_output()
{
 int minutes, seconds, sec;
 difference = a - b;
 seconds = int(difference/1000);
 if(seconds >= 60)
 {
  //sec = seconds;
  seconds = seconds%60;
  minutes = minutes+1;
 }
 //minutes = int(seconds/60);
 Serial.print((a/1000)+1);
 Serial.print(",");
 Serial.print((b/1000)+1);
 Serial.print(",");
// Serial.print(difference);
 //Serial.print(",");
 Serial.print(minutes);
 Serial.print(",");
 Serial.println(seconds);
 //Serial.println(",");
}


texts: Measuring Lithium ion cell voltage used to power Arduino via a boost module

texts: Can I measure lithium ion cell voltage with Arduino ADC which is used to power the same Arduino through a boost module (XL6009)? The output voltage of boost module is 9 volts.


texts: Anyone using ModBus RTU on Galileo gen 2?

texts:
I'm trying to communicate with some industrial hardware, on ModBusRTU, from my Intel Galileo Gen2 board. I use this board to convert UART to RS485 http://linksprite.com/wiki/index.php5?title=RS485_Shield_V2.1_for_Arduino and I can talk serially between Arduino (with SoftwareSerial on pin 2/3) and Galileo (with Serial1 on pin 0/1). So I know the RS485's link is working.

With Arduino Uno I can talk with my devices using ModBusRTU, thanks to this library https://github.com/4-20ma/ModbusMaster

On galileo gen2 I received this warning WARNING: library ModbusMaster claims to run on [avr, sam] architecture(s) and may be incompatible with your current board which runs on [i586] architecture(s). because of the different architecture.

Now I'm trying to use the examples of cooking hack's tutorial about modbus and rs485 for Arduino, Raspberry and Galileo but I can't make it works for me. I received tons of compiling errors like these:

C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp: In member function 'uint8_t ModbusMaster485::ModbusMasterTransaction(uint8_t)': C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:701:50: error: '_crc16_update' was not declared in this scope
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:814:52: error: '_crc16_update' was not declared in this scope
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp: At global scope:
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:881:14: error: prototype for 'unsigned int ModbusMaster485::makeWord(unsigned int)' does not match any in class 'ModbusMaster485'
In file included from C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:25:0: C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:302:11: error: candidates are: uint16_t ModbusMaster485::makeWord(uint8_t, uint8_t)
C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:301:14: error: uint16_t ModbusMaster485::makeWord(uint16_t) C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:887:14: error: prototype for 'unsigned int ModbusMaster485::makeWord(uint8_t, uint8_t)' does not match any in class 'ModbusMaster485'
In file included from C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.cpp:25:0: C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:302:11: error: candidates are: uint16_t ModbusMaster485::makeWord(uint8_t, uint8_t) C:\Intel\arduino-1.6.4\libraries\ModBusMaster485\ModbusMaster485.h:301:14: error: uint16_t ModbusMaster485::makeWord(uint16_t) Error compiling.

Did someone has got ModBus working on Galileo Gen2?


texts: D1 Mini + TFT & I2C Connector Shield not going into deepSleep

texts:
I'm trying to write a sketch to use a Wemos D1 mini connected to several shields including a LOLIN TFT & I2C Connector Shield (v1.1.0). This powers a small ePaper display (LOLIN 2.13" diagonal ePaper/eInk display) with a TFT e-Paper Cable.

The problem I'm running into is that I can't get the board to either boot properly or get out of deepSleep due to the pin assignment of the TFT display.

I have placed the following code before the void setup() as described in the manufacturer's GitHub example for the board:

/*D1 Mini*/
#define EPD_CS D0
#define EPD_DC D8
#define EPD_RST -1  // can set to -1 and share with microcontroller Reset!
#define EPD_BUSY -1 // can set to -1 to not use a pin (will wait a fixed delay)

By doing this, however, it results in the board entering a boot loop when I try to connect D0 --> RST

If I leave the D0 --> RST disconnected, the board will successfully run the sketch and enter into deepSleep but will not be able to Wake Up after a predetermined amount of time (10seconds).
I see the Builtin LED flash after 10seconds and there is some activity on the serial monitor so I suspect that the board is trying to wake up however it is unable to with the D0 disconnected to the reset pin.

If I try to connect the D0 --> RST after the board has gone to deepSleep and before the timer ends, it continues to sleep until the 10 seconds is completed, then starts its boot loop again with the Built-In LED flashing constantly.

Has anyone else had success in this?  I suspect I'm missing something very simple but cannot find much info on this shield anywhere.


texts: My two ultrasonic sensors are reading inaccurately

texts:
I am having trouble getting two of my ultra sonic sensors to read accurate results in cm. I am using a HC-SR04 currently.

I get random numbers at different distances with an object in front (smooth cover book)

Test 1:
Real distance: 10 cm
Sensor 1: 0.00cm
Sensor 2: 82.42

Test 2:
Real distance: 10cm
Sensor 1: 92.11cm
Sensor 2: 95.03

Against the wall with no book:

Test 1:
Real distance: 10 cm
Sensor 1:0.00cm
Sensor 2: 13.20

Test 2:
Real distance: 10 cm
Sensor 1:24.37cm
Sensor 2:26.75

The numbers constantly fluctuate. I am trying to get accurate results.

I am not sure if the sensors are broken or if my code is incorrect.I appreciate any help.

Here is my set up: [

#define trigPin1 13
#define echoPin1 12
#define trigPin2 11
#define echoPin2 10

float duration, distance, duration1, distance1, duration2, distance2;

void setup() {
  Serial.begin (9600);
  pinMode (trigPin1, OUTPUT);
  pinMode (echoPin1, INPUT);
  pinMode (trigPin2, OUTPUT);
  pinMode (echoPin2, INPUT);

}

void loop() {

  FindRange(trigPin1, echoPin1);
  duration1 = duration;
  distance1 = distance;
  FindRange(trigPin2, echoPin2);
  duration2 = duration;
  distance2 = distance;
  Serial.print(distance1);
  Serial.print(" cm  ");
  Serial.print(distance2);
  Serial.println(" cm");
  delay(100);

}

void FindRange(int trigPin, int echoPin) {

  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) * 0.0345;
  delay(100);

}


texts:
I'm having Arduino Due board and Logitech F710 Wireless Gamepad. I have connected the receiver dongle to native port of Due board via OTG cable.

As the native usb host library supports only keyboard and mouse,
pease help me with correct library for connecting my gamepad with Due board without usb_host_shield as I have budget constraint and space constraint.

Thanks in advance


texts:
Yesterday evening everything worked well. Today morning I am trying to upload sketch to the Arduino (nano china, CH340) and get the following:

Writing |

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

############avrdude: stk500_cmd(): programmer is out of sync

avrdude: stk500_recv(): programmer is not responding

Check wiring, settings, cable, another PC. The same result.
Took another Arduino from the same supply. Works.

What could damage my Arduino nano? Static voltage? This is the first time in 3 years of insensitive playing with Arduino. I was told that Arduino nano is quite tolerant to static voltage.

What can I do with this damaged Arduino? Is it possible to restore it?
The boards is still recognizable by PC and blinks with leds when it is connected.


texts: Where do I get the wider arduino pro micro from?

texts:
I have a bunch of boards already fabricated for a game controller that uses the arduino pro micro. I ran out of the arduinos and ordered more. But the new ones are 0.6" wide from pin to pin, and my boards are 0.8". I got narrower pro micros. Now that I'm looking for it online they all seem to be the narrower ones. Same pinout, but they have a smaller version of the MEGA32U4. It also had a USB mini connector instead of USB micro, but for my purposes that doesn't really matter.

Does anyone know where I can get the older 0.8" width version?


texts: Writing to partially reserved registers of sensors

texts:
I'm trying to change the range of a gyroscope I'm using and there is the following guideline:

it is recommended to mask out
(logical and with zero) reserved bits of registers which are partially marked as reserved.

I tried reading about bit masking with the bitwise operators and I feel I understand it for trying to read only certain bits, but not for writing.
For example, how would I write to the following register, masking out the 2 bits which are reserved?


texts: Weirdest behaviour with arduino and bootloaders for GPS

texts:
I have an EM408 GPS and an Arduino Duemilanove with an ATMega328. I have the following code to talk to the GPS and get raw data:

#include <SoftwareSerial.h>
SoftwareSerial GPS = SoftwareSerial(2,3);  //rx,tx
void setup()
{
  GPS.begin(4800);
  Serial.begin(9600);
}

void loop()
{
  //Serial.print(GPS.read(), BYTE);
  Serial.write(byte(GPS.read()));  //as of Arduino 1.0
}

That worked fine a while ago. I retried it recently and it didn't work for some reason. We tried this on an Uno board with nothing. Then, we opened an old version of Arduino (022). When we tried the above code in Duemilanove in Arduino 1 with the previous Uno bootloader selected from the IDE it run fine.
Then we uploaded with the default Duemilanove bootloader and it threw junk data

ÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïÿïïïïïïïïïïïïÿïïïÿïïïÿïïïÿïïïïïïïÿïïïïïïïïïïïÿïïïÿïïïÿïïïÿïïïïïïÿïïïÿïïïïïïÿïïïïïïÿïïïÿäáàýáàæäääýääçäæåúææææäæôäææøâæäçäæúææäúääçäàâãäáàýáàæàæäææææúæææúææææææ÷äàâãäáøáááøåæäæäåöåäæúææäæäæåäæäôææäùäæäææääæäåþäæäææääæäåùäååæçåúâãäáàáùáæåùåæäåæåúæäåæåååææäúæääæäåôææåûæääæäæþææäåæääæäåú

Then we couldn't upload the Uno bootloader to it to experiment

So why my code, on my Duemilanove, using the Duemilanove bootloader isn't working and I get all this junk data, instead of NMEA codes?


texts: Problem in reading data from encoder with arduino

texts:
Hello guys I am trying to count the number of the steps of a stepper motor with an encoder (Avago heds).

I found an Arduino sketch to count that steps and display them on the console and I found online the scheme to connect that encoder to Arduino.

The problem is that the encoder returns as output only 0, even if I rotate manually the motor. I also tried to measure the voltage of the encoder with a voltmeter but the voltage does not change even if I rotate the motor.

That is the Arduino Sketch

Here some picture's of Arduino-encoder connections

P.S. The motor works because I tried it before

Thank you for help


texts: Unexpected value change of 2nd Potentiometer

texts:
I'm trying to connect 2 potentiometer (10k) and pass their value to Hairless Midi software (For Serial to Midi Bridge) the first pot is working fine but the second pot's value keep on changing and when i move around the knob of pot1 the value of pot 2 also changes.

I have tried reading the value twice but no luck....

My code:

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

void loop()
{
  analogRead(0);
   val = analogRead(0)/8;   // Divide by 8 to get range of 0-127 for midi
   if (val > lastVal+1 or val < lastVal+1 )
   {
   MIDImessage(176,1,val);}
   lastVal = val;

  analogRead(2);
   val2 = analogRead(2)/8;   // Divide by 8 to get range of 0-127 for midi
   if (val2 > lastVal2 + 1 or val2 < lastVal2 + 1 )
   {
   MIDImessage(176,2,val2);}         // 176 = CC command, 2 = Which Control, val = value read from Potentionmeter 2
   lastVal2 = val2;

   //val3 = analogRead(2)/8;   // Divide by 8 to get range of 0-127 for midi
   //if (val3 != lastVal3)
   //{
   //MIDImessage(176,3,val3);}         // 176 = CC command, 3 = Which Control, val = value read from Potentionmeter 3
   //lastVal3 = val3;

delay(100);
}

void MIDImessage(byte command, byte data1, byte data2) //pass values out through standard Midi Command
{
   Serial.write(command);
   Serial.write(data1);
   Serial.write(data2);
}


texts:
I would like ask for help. Can you give me an advice how to create (contacts) nubers who can turn on led.

#include <GSM.h>
#define PINNUMBER ""
GSM gsmAccess;
GSMVoiceCall vcs;
char numtel[20];

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

Serial.begin(9600);
while (!Serial) {
;
}

Serial.println("Receive Voice Call");

boolean notConnected = true;

while (notConnected)
{
if (gsmAccess.begin(PINNUMBER) == GSM_READY)
  notConnected = false;
else
{
  Serial.println("Not connected");
  delay(1000);
}
}

vcs.hangCall();

Serial.println("Waiting for a call");
}

void loop()
{

switch (vcs.getvoiceCallStatus())
{
case IDLE_CALL:

  break;

case RECEIVINGCALL:

  Serial.println("RECEIVING CALL");

  vcs.retrieveCallingNumber(numtel, 20);

  digitalWrite(13, HIGH);

  vcs.answerCall();
  vcs.hangCall();
  digitalWrite(13, LOW);

  break;

  }
  delay(1000);
  }


texts: MAX72XX with 8 digit 7 segment display library

texts:
A while ago, I found a library for the MAX72XX that had functions for writing text to the display, but unfortunately cannot find such library now.

Which would be the best library to use for a text and number display? I'm using LedControl but it is very awkward to use.


texts:
Can anyone recommend an Arduino-based asynchronous scheduling library for controlling a small mobile robot?

I'm writing the control code for a small 2-wheeled Arduino-Uno based robot. It has a few bumper sensors, IR sensors, and ultrasonic sensors. I've written an initial pass from scratch, using loop() to read sensors and set motor values appropriately and then wait for the motor to have effect, but I'm finding this cluggy. Some of the sensors, like the ultrasonic range finders, require a small delay to operate, and the motors require a delay to have an effect. Blocking loop() is the simplest way to achieve this, but it wastes cycles, and can be difficult to time each action properly without throwing off other behaviors. Writing an asynchronous scheduler would be more efficient, but a lot more complicated, and I expect I would be reinventing the wheel.

I found this list, of existing scheduling libraries, but I'm not sure which, if any, would be appropriate.


texts: Arduino Due: Interrupt-based ADC hangs processing

texts:
I am trying to build an oscilloscope using an Arduino Due and an LCD. I have the LCD running perfectly and started working on using the ADC peripheral to sample signals. Here's what I have so far:

#define SAMPLE_BUFFER_SIZE 800
volatile int sample_buffer[SAMPLE_BUFFER_SIZE];
volatile bool sample_buffer_full = 0;
volatile int sample_buffer_idx = 0;

void adcm_init() {
    pmc_enable_periph_clk(ID_ADC); // To use peripheral, we must enable clock distributon to it
    adc_init(ADC, SystemCoreClock, ADC_FREQ_MAX, ADC_STARTUP_FAST); // initialize, set maximum posibble speed
    adc_disable_interrupt(ADC, 0xFFFFFFFF);
    adc_set_resolution(ADC, ADC_12_BITS);
    adc_configure_power_save(ADC, 0, 0); // Disable sleep
    adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1); // Set timings - standard values
    adc_set_bias_current(ADC, 1); // Bias current - maximum performance over current consumption
    adc_stop_sequencer(ADC); // not using it
    adc_disable_tag(ADC); // it has to do with sequencer, not using it
    adc_disable_ts(ADC); // deisable temperature sensor
    adc_disable_channel_differential_input(ADC, ADC_CHANNEL_7);
    adc_configure_trigger(ADC, ADC_TRIG_SW, 1); // triggering from software, freerunning mode
    adc_disable_all_channel(ADC);
    adc_enable_channel(ADC, ADC_CHANNEL_7); // just one channel enabled
    adc_enable_interrupt(ADC, ADC_IER_DRDY);            // Data Ready Interrupt Enable
    NVIC_EnableIRQ(ADC_IRQn);
    adc_start(ADC);
}

void ADC_Handler(void)  {
    if (!sample_buffer_full) {

        if ((adc_get_status(ADC) & ADC_ISR_DRDY) == ADC_ISR_DRDY) {

            sample_buffer[sample_buffer_idx] = adc_get_latest_value(ADC);
            sample_buffer_idx++;

            if (sample_buffer_idx == SAMPLE_BUFFER_SIZE) {
                sample_buffer_full = 1;
                sample_buffer_idx = 0;
            }
        }
    }
}

void setup()
{
    adcm_init();
    Serial.begin(115200);
}

void loop() {
    Serial.print("Loop\n");
    if (sample_buffer_full) {
        for (int i = 0; i < SAMPLE_BUFFER_SIZE; i++) {
            Serial.print(sample_buffer[i]);
            Serial.print(" ");
        }
        Serial.print("\n");
        sample_buffer_full = 0;
    }
}

This was copied and slightly modified from somewhere on the internet (can't remember where, though). I have also studied the docs and this code seems to make perfect sense and it should work.

The idea is for the sampling to be interrupt-based. However, if I set the ADC to freerunning mode and enable interrupts, it just gives up and stops working.

What I mean by that is: on my serial monitor, after pressing reset, all I see are 2 lines saying "Loop" and it just stops there. Normally it should print "Loop" indefinitely, and also print ADC values from time to time.

If I disable interrupts, "Loop" is printed indefinitely, but of course no values are shown. If I disable free-running mode, "Loop" is printed and no values are shown unless the buffer size is 1, in which case the same value is printed over and over (as expected, in that case the interrupt runs only once, right at the beginning).

The CPU clock freq. is 84Mhz, I'm going for the fastest I can get out of the ADC, so a sample is taken (and an interrupt is fired) every 1Mhz. That means 84 clock cycles per interrupt. Don't know for sure if that is enough for the rest of the program to work, but my gut tells me that's not a problem. Besides, I tried with a lower ADC clock value and it still didn't work.

Any ideas? I'm really at a loss here...


texts: programming STM32 with arduino IDE issues

texts:
I'm currently trying to program an STM32 with arduino, but along the way, i encountered some issues with pin modes. To be more specific, programming certain pins to certain modes. Some pins have consistent digital outputs like PC13, while others have wonky outputs like PA11 and PA12, despite being able to be used as digital outputs.

here is what i get from PA12

here is what i get from PA11

i've read the pinout diagrams, and im not too sure if both mentioned pins can be used digitally according to this pinout diagram :

can anyone help me explain what is going on, how do i program an STM32 with Arduino IDE exactly (stm32duino programming procedures, rule of thumb, etc), and can an stm32duino be used to do complex programs like an arduino like for example driving a motor with PWM in a balancing robot or do we have to use C or C++ using atollic TrueSTUDIO and all of those software?


texts: Help understanding circuit for button example

texts:
I´m working on the button example
.Basically, i don't quite get the use of this connection.

Also, the breadboard i'm using is not quite the ones i see on most tutorials.

is there any 'mapping' i could make between them?

I really appreciate any help you can provide.


texts: Problems with I2C connection on ESP8266 - 12F, which pins should I use?

texts:
Previously I had pined the temp/hum sensor HDC1080 with an Arduino using this sketch and everything worked fine. Now I want to run it over an ESP-12F, I uploaded it but it has issues at the time of establishing I2C connection. Basically, I'm not sure if at the end of setup() the I2C connection has actually begun, because I get this at the serial monitor:

As far as I see, the code skips everything related to Wire library. I blame it on the SDA/SCL pins, but actually none of the pins are working for me. I found that default I2C GPIO's are 2 and 14, I tried with them and got no result; later I tried with 12/16, as the commented Wire.begin line says, but it was the same. I even read some possible solutions in this post but I not even have the mentioned libraries.

Could you give me any suggestion, please? This is the sketch I'm using:

#include <Wire.h>

#define HDC 0x40 //B1000000 MSB
#define cociente 65536 //2^16

uint16_t humrawvalue;  //Raw data value, MS byte = valmsb, LS byte = vallsb
uint16_t temrawvalue;  //Raw data value, MS byte = valmsb, LS byte = vallsb
uint8_t humvalmsb, humvallsb;  //Raw 8-bit byte of humidity
uint8_t temvalmsb, temvallsb;  //Raw 8-bit byte of temperature
int incomingByte = 0; //Action input
float humidity, temperature;

void setup() {
  delay(100);
  Serial.begin(9600);
  delay(100);
  Serial.println("Hello");
  //Wire.begin(12,16);
  Wire.begin();
  Wire.setClockStretchLimit(1500);
}

void loop() {
  if (Serial.available() > 0) {    //User presses 1 to start sensor reading
    // read the incoming byte:
    incomingByte = Serial.read();
    yield();
    // say what you got:
    Serial.print("I received: ");
    Serial.println(incomingByte, DEC);
  }

  Serial.println("---g-");  //Just guideline

  if (incomingByte == 49){
    Serial.println("IIIII");  //Just guideline
    Wire.beginTransmission(HDC);
    Wire.write(0x00);
    Wire.endTransmission(true);
    delay(200);

    Wire.requestFrom(HDC,4,true); //It asks for 4 bytes, 2 bytes per register
    if(Wire.available()){
      Serial.println("     ");
      Serial.println("Measuring: ");
      temvalmsb = Wire.read();
      temvallsb = Wire.read();
      humvalmsb = Wire.read();
      humvallsb = Wire.read();

      Serial.println("====TEMPERATURE====");
      Serial.print("MSB: "); Serial.println(temvalmsb, BIN);
      Serial.print("LSB: "); Serial.println(temvallsb, BIN);
      temrawvalue = temvalmsb <<8| temvallsb; //Locates each byte in its proper place
      Serial.print("Temp: "); Serial.println(temrawvalue, BIN);
      temperature = ((float)temrawvalue/(float)cociente)*165.0-40.0;
      Serial.print("Temperatura [C]: "); Serial.println(temperature);

      Serial.println("====HUMIDITY====");
      Serial.print("MSB: "); Serial.println(humvalmsb, BIN);
      Serial.print("LSB: "); Serial.println(humvallsb, BIN);
      humrawvalue = humvalmsb <<8| humvallsb;
      Serial.print("Hum: "); Serial.println(humrawvalue, BIN);
      humidity = ((float)humrawvalue/(float)cociente)*100.0;
      Serial.print("Humidity [%]: "); Serial.println(humidity);

      Serial.println("     ");
      delay(3000);
    }
  }
  Serial.println("++++"); //Just guideline
  delay(3000);
}

Regards!


texts: How do I communicate with the Uno using R through RStudio?

texts: I am working on a real time application which is recording sensor data continuously. I need to process the data in realtime using R. Is there a way to connect and communicate with the uno board through RStudio via serial port?


texts:
Have a problem: new house but it gets super-windy and the doggy doors' magnets are too weak and blow open. Can't use bigger magnets because the doggies are too small.
So I thought I'd reinforce the pet-doors with a latch.
Next problem: the dogs are too dumb to learn wait for the doors to open. So the release mechanism must be rapid.
My plan was:
Arduino - uno or beetle/leonardo
motion sensor or ultrasonic sensors x2 (one inside and one outside) -> arduino -> relay ->wall power supply -> electromagnet release (normally on)

only the electromagnet gets super hot, so may not be best. Do servos or solenoids open fast? as in < 1s

Anyone have any suggestions on a  better way?? THanks so much!


texts: Two pots controlling 2 servos -- odd behavior

texts:
I'm trying to control 2 servos with 2 pots. I thought I could just amend the tutorial code by adding in the extra pot on a1 and extra servo on d8 (am using a Nano).

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
Servo myservo_2;

int potpin = 0;  // analog pin used to connect the potentiometer
int potpin_2 = 1;
int val;    // variable to read the value from the analog pin
int val_2;

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

void loop() {
  val = analogRead(potpin);            // reads the value of the potentiometer (value between 0 and 1023)
  val_2 = analogRead(potpin_2);
  val = map(val, 0, 1023, 0, 180);     // scale it to use it with the servo (value between 0 and 180)
  val_2 = map(val_2, 0, 1023, 0, 180);
  myservo.write(val);                  // sets the servo position according to the scaled value
  myservo_2.write(val_2);
  delay(15);                           // waits for the servo to get there
}

...but the servos only respond to one of the pots (on a0) & both move to the same position regardless of what value is on a1.

Am I missing something really obvious? Why is the value on a1 ignored & why is the value mapped from a0 sent to both d8 & d9?

I have swapped out the pot on a1 just in case it was faulty but I get the same behavior.

EDIT: Added schematic

EDIT: I swapped out the Nano for another Nano but that failed to upload the sketch. So I put the original back in & now evrything is working fine!

Darn'd if I can get my head around it, possibly a bad connection with the bread board?

Anyway all working now thanks for your suggestions.


texts:
I am sending a HTTP Request to my WiFi module http://192.168.4.1/STA/ID=HelloWorld/Pass=Testin123

How can I parse above string in Arduino. First I need to check for STA, if it exists, continue to scan the string. Put Value of ID, in this case HelloWorld should be store in String data type SSID and Value of Pass, in this case Testin123 should be store in String data type Pass.

How can achieve above using ARDUINO code! Please help.


texts: How can I communicate from Arduino to MATLAB

texts:
I want to use sensors on an Arduino to control values in a MATLAB program. What are my options for communicating?

I've used Processing to receive data sent via the serial cable, and that strategy has worked pretty well. Is there something similar I can do using MATLAB? I'm somewhat new to MATLAB, so gentle guidance would be great.

I'm not really looking for something like the ArduinoIO package -- I want to have separate computation executing on the Arduino and occasionally informing my MATLAB program (which will occasionally poll the serial line, I suppose).


texts: How do I repeat else if (cmd == '3') until I press another cmd?

texts:
This code is for automatically opening and closing a window using a motor with senors such as dust, humidity, temperature, and rain sensor with bluetooth module through phone. With this code if I press 1,2 it would close or open the window and 3 would let the window open or close regarding the measures that the  sensor reads. Right now pressing 3  would only simulate this once and then turn off untill I press it again
So I would want this part
 else if (cmd == '3')
to repeat itself until I press another cmd button so the window keeps opening and closing.

//////////////////////////////////////////////////////////////////////////
#include <SoftwareSerial.h>
#include <Stepper.h>
#include <DHT.h>
#define DHTPIN A1
#define DHTTYPE DHT11
#define D_IN 3
#define A_IN A0

int Txpin = 7;
int Rxpin = 8;
int stepsmotor = 1024;
const int stepsPerRevolution = 64;
SoftwareSerial BTSerial(Txpin, Rxpin);
DHT dht(DHTPIN, DHTTYPE);
int measurePin = 0;          // measurePin을 0으로 설정합니다.
int ledPower = 2; // ledPower를 2로 설정합니다.
int samplingTime = 280;    // samplingTime을 280으로 설정합니다.
int deltaTime = 40;           // deltaTime을 40으로 설정합니다.
int sleepTime = 9680;       // sleepTime을 9690으로 설정합니다.
float voMeasured = 0;      // voMeasured를 0으로 설정합니다.
float calcVoltage = 0;       // calcVoltage를 0으로 설정합니다.
float dustDensity = 0;       // dustDensity를 0으로 설정합니다.

Stepper myStepper(stepsPerRevolution, 8, 10, 9, 11);

void setup()
{
  Serial.begin(9600);
  BTSerial.begin(9600);
  myStepper.setSpeed(550);
  pinMode(ledPower,OUTPUT);
  pinMode(D_IN, INPUT);
}

void loop()
{
 if (BTSerial.available())
  {
    char cmd = (char)BTSerial.read();
    if(cmd == '1'){
      for(int i=0; i<(32*3-6); i++){
    myStepper.step(stepsPerRevolution);
      }}
    else if (cmd == '2')
      for(int i=0; i<(32*3-6); i++){
    myStepper.step(-stepsPerRevolution);
   }
    else if (cmd == '3'){
     int dIn = digitalRead(D_IN);
  double aIn = analogRead(A_IN);
    int h = dht.readHumidity();
    int t = dht.readTemperature();
digitalWrite(ledPower,LOW);
  delayMicroseconds(samplingTime);

  voMeasured = analogRead(measurePin);
  delayMicroseconds(deltaTime);
  digitalWrite(ledPower,HIGH);
  delayMicroseconds(sleepTime);

  calcVoltage = voMeasured * (5.0 / 1024.0);

  dustDensity = (0.17 * calcVoltage - 0.1) * 1000;

    Serial.print(dustDensity);
    Serial.println(" ug/m3");
  Serial.print("Digital Input = "); Serial.println(dIn);
  Serial.print("Analog Input  = "); Serial.println(aIn);
  Serial.println();
    Serial.print("humidity:");
    Serial.println(h);
    Serial.print("temperature:");
    Serial.println(t);
    delay(1000);

    if (t >= 25 or h >= 70 or dustDensity >= 100 or aIn <= 50)
     for(int i=0; i<(32*3-6); i++){
    myStepper.step(stepsPerRevolution);
    }
    else
     for(int i=0; i<(32*3-6); i++){
    myStepper.step(-stepsPerRevolution);
    }

  delay(3000);
    }
    else if (cmd == '4'){

    }
      }
    }


texts:
I am working with an Arduino due and currently using the Arduino liquid crystal library to display data on an LCD screen (mc42004A6wk-bnmlw) which uses the Hitachi HD44780 controller. The LCD has been update to v2 and is now using the Sitronix ST7066U controller.

From what I have read the two controllers are compatible and the liquid crystal library should work for both. I am using the same software and hardware setup as before but the screen will not display anything.

The software I use is quite complex so I moved to a simple hello world program (below) to test and I still have the same issues. Any advice would be greatly appreciated.

#include <LiquidCrystal.h>
#include <Arduino.h>

LiquidCrystal lcd(30, 31, 32, 33, 46, 47);

void setup()
{

  pinMode(36,OUTPUT);

  digitalWrite(36, LOW);

  delay(5000);

  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);

  lcd.clear();

  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop()
{

  delay(5000);
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}


texts: How to scale a bitmap (uint8_t array) in Arduino?

texts:
So I have a project where I send text to an Arduino, which is then printed out as a QR code on a thermal printer that can take a bitmap image with a given width and height.

Is there a way I can "scale up" the "image," making it so one pixel is scaled up to 4 or 8 pixels?

Additionally, would it be possible to add a "quiet zone" of sorts on the left side of the image, as I am not able to offset/justify it to the middle.

QR Code lib: https://github.com/ricmoo/QRCode

Thermal printer lib: https://github.com/adafruit/Adafruit-Thermal-Printer-Library


texts:
When i restart my raspberry pi 4 and check for mosquitto status it brings to me active: failed it seems to be it works for just the first time when i setup it all i need is to communicate esp32 with raspberry pi 4 throgh mqtt mosquitto but it fails
I hope you will help me


texts: How to interface DS1801 digital resistor with Arduino DUE SPI interface? What clock rate so use?

texts:
I am trying to program a digital resistor and set it's wiper resistance. The general circuit looks a little like this where "pot" represents the Maxim DS1801 digital resistor and DUE is, of-course the 3.3v Arduino DUE.

POT       DUE
CLk ----> SCK
D    ----> MOSI
RST ----> CS (ChipSelect) (PIN10)

Now so far, I have sucessfully been able to interface with the DS1801, but I am having issues determining how to properly set the wiper resistance values. The DS1801 datasheet says the it accepts a 16bit input and from application example online it looks like the values range from 0 to 64. Here is my code:

// include the SPI library:
#include <SPI.h>

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;
int mute = 64;
int loud = 63;
int soft = 0;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  // initialize SPI:
  SPI.setBitOrder(LSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);
  SPI.begin();
  delay(10);
   digitalPotWrite(mute, mute);
}

void loop() {

  // Raise the volume from off to loud
for(int i = 0; i <= 63; i++){
  digitalPotWrite(i, i);
  delay(5);
    }
  }

void digitalPotWrite(int left, int right) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin, HIGH);
  //  send in the address and value via SPI:
  SPI.transfer(left);
  SPI.transfer(right);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin, LOW);
}

I THINK my issue lies with setting the clock rate for the DS1801. The data sheet say the chip runs at 10MHz which is why I wrote

SPI.setClockDivider(slaveSelectPin,SPI_CLOCK_DIV8);

to divide the 84MHz default speed down to 10MHz.

Anyone have suggestions on why my code is not working??? At the moment, I have LED's connected to chip with series resistors to limit current below 2mA. The resistors just blink randomly with the code posted above.


texts:
I happened to short-circuit my Arduino by mistake. It was powered by USB on my Windows 7. The OS was so smart to pop-up warning about USB power surge and shut it down immediately. Arduino survived.

I fixed the circuit and connected it back. Arduino was powered again, but it was not recognized as COM port anymore. There was no unknown device in Device manager. I tried different USB connector on the same computer and it was found and it worked. But the other USB was out.

I restarted the computer and connected the Arduino back to the broken connector. The drivers were automatically reinstalled (I don't know why) and it worked again.

Is it possible to re-enable Arduino on the same USB connector without restart? I'd like to understand what happened on the computer side.


texts: I want to make a sketch that is as small as possible, for test purposes. The problem is, when i compile the BareMinimum sketch (with an empty setup and loop), i get 466 bytes for the Uno and a whopping 4,242 for the Leonardo. Is there any way to write your own code that has no extra functions (namely Timer0 for millis() and delay()). I would also like to be able to disable the keyboard/mouse functions for the Leonardo.


texts: Most efficient way to store number in EEPROM?

texts:
I would like to store temperature readings in eeprom, the value from -55.00 to 125.99. What is the most space efficient way to store these numbers with two significant digits along with epoch timestamp?

Thanks


texts:
I have a simple sketch that prints out "Hello World" to the serial, but I'm getting a bunch of gibberish instead.

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

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

Why isn't it printing "Hello World" like the code says?


texts:
Just to illustrate my work here, I found a tutorial on how to code an accelerometer, I wanted to understand how does it work, literally get how it works, and not simply using the code without understanding it.

In the beginning of the program,there's a char variable declared as :

char values[10];

then later on the code, there was couple lines of getting the information stored in this variable, I'll give this as as example :

x = ((int)values[1]<<8)|(int)values[0];

we want X to receive values[0] and values[1] , that's what that line does up there.

My question is : can someone explain to me how does that line work, and why can't we simply write it as x = ((int)values[1])|(int)values[0]; ?


texts: Using an external pull-up resistor vs INPUT_PULLUP

texts:
When would one would prefer to use an external pull-up resistor vs the internal:

pinMode(fanPin, INPUT_PULLUP);

Dredging through the forums and this site, the commonly recommended value for a pull-up resistor is seems to fall at 10K.

However, the ATmega32U4 datasheet's Table 29-1 says that RPU or "I/O Pin Pull-up Resistor" is between 20K and 50K ohms.

This question asks about internal vs external pull-ups for a simple button, but I'm asking in the general case.

What types of projects would fare better with internal pull-ups, and what type of projects would be better off with external pull-ups?

What are the considerations for preferring one over the other?

At the present, my project is hooking up an AM2302 / DHT22 temperature sensor.


texts: How do I detect the Computer's operating system?

texts:
I'm working on an emoji keyboard and it requires different input depending on the OS it's connected to. I've written the relevant methods using Arudion's default Keyboard library and can manually set which one is used. I'm wondering if there is a method or library for Arduino (currently using a Adafruit Feather 32u4 Bluefruit LE) that allows me to detect the OS.

If not, I'll set up a switch, but that'll cost me pins.


texts:
Arduino newbie here, so this question might sound too simple. I am trying to run a parallax continuous rotation servo using Arduino Uno. From the reference, I learned that the servo needs to be "attached" to one of digital pins with PWM capability, and the servo's speed can be controlled by write(0~180, 90=stop).

But I am having a hard time understanding the role of the PWM digital pin. If the servo's speed and direction of rotation is determined by write(), what is the role of attach(pin#)?

Thanks in advance!


texts:
I have a new atmega328p IC that I wanted to program. To do so I placed it into the socket of an arduino uno. I accidentally placed it the wrong way around (180° rotated), and powered it via USB and tried to upload the blink sketch, which obviously did not succeed. After I noticed it I turned it around and placed it into the socket the right way. I tried again uploading the blink sketch again without success.

Have I fried the atmega328p by placing it in the socket the wrong way?
Is there something else you need to do to new atmeag328p before you can program them the usual way?

Update: It seems that just rotating the IC did not damage it in the state where there was no bootloader programmed. And and the bootloader needed to be programmed first before the IC could be used.


texts:
I am using Arduino ATmega 2560.
When i am using "AT+CGNSINF" command to get GPS value, sometimes it showing incorrect speed.
The correct speed should be (50-60)km/h but sometimes it showing (200-300)km/h.
How can I fix the problem or avoid/ignore the unexpected speed.
here is my code

void get_GPS()
{
    sendATCommand("AT+CGNSINF","OK", 1000);

    // condition for valid response
    while (strstr(AT_Buffer, "+CGNSINF: 1,1") != NULL)
    {
        delay(3000);
        strtok(AT_Buffer, ",");
        strtok(NULL, ",");
        strtok(NULL, ",");
        strtok(NULL, ",");
        strtok(NULL, ",");
        strtok(NULL, ",");
        Serial.println("\n");
        Serial.println(strtok(NULL, ","));

        //sendATCommand("AT+CGNSINF", "OK", 1000);
    }
}
uint8_t sendATCommand(char* ATcommand, const char *expectedResponse, unsigned long timeout)
{
    uint8_t x = 0, answer = 0;

    memset(AT_Buffer, '\0', AT_BufferLength);    // Initialice the string
    delay(100);
    while (Serial1.available() > 0) Serial1.read();    // Clean the input buffer
    if (ATcommand[0] != '\0')
    {
        Serial1.println(ATcommand);    // Send the AT command
    }

    unsigned long previous = millis();

    // this loop waits for the answer
    do {

        if (Serial1.available() != 0) {    // if there are data in the UART input buffer, reads it and checks for the asnwer
            AT_Buffer[x] = Serial1.read();
            //Serial.print(AT_Buffer[x]);
            x++;
            if (strstr(AT_Buffer, expectedResponse) != NULL)    // check if the desired answer (OK) is in the response of the module
            {
                answer = 1;
                break;
            }

        }
    } while ((millis() - previous < timeout));    // Waits for the asnwer with time out

    return answer;
}


texts: Sense checking Arduino Uno barebones schematic

texts: I have had some difficulties finding a barebones Arduino board and have had the following made. I just wanted to see if anyone could spot any issues? I think it has everything. I'm really trying to get it as minimalistic as possible, but at the same time able to use a power source like a 12v/24 battery. Any help would be greatly appreciated. Many thanks


texts: Running many devices on 5V pin. How to provide external power

texts:
I'm using my Arduino DUE 5V pin to power a lot of sensors and I'm worried about the drop in current.

I'm powering the board using the USB port. Is this the correct way or is there a different way of powering the board to make sure the current drop is limited as much as possible?

Thanks in advance.


texts: what is good practice around initializing variables

texts:
Should vars be initialed when declared or in setup fuction?
Safe to assume compiler will initialze?
Boolean x;      --- init to true/false here?
Void setup()
.
.            --- or init here?
.
Void loop()
If (x)       --- x is unknown state if not initialized.


texts: rfm69 on M0 Express... init() doesn't work

texts:
I have already connected succesfully the rfm69 on my Feather M0 Express... but I cannot do it again.
The connections are (in the order of the rfm69):

Vin -> 3V
Gnd -> Gnd
En  -> (nothing)
G0  -> 9
SCK -> SCK
MISO -> MI
MOSI -> MO
CS  -> 10
RST -> 6

The code of the setup is
#include <SPI.h>
#include <RH_RF69.h>

#define RFM69_CS      10
#define RFM69_INT     9
#define RFM69_RST     6
#define LED           13

// Singleton instance of the radio driver
RH_RF69 rf69(RFM69_CS, RFM69_INT);

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

  Serial.println("Feather RFM69 RX Test!");
  Serial.println();

  // manual reset
  digitalWrite(RFM69_RST, HIGH);
  delay(10);
  digitalWrite(RFM69_RST, LOW);
  delay(10);

  if (!rf69.init())
    //***********************************
    Serial.println("init failed");
  else
    Serial.println("init ok");

  // Defaults after init are 434.0MHz, modulation GFSK_Rb250Fd250, +13dbM (for low power module)
  // No encryption
  if (!rf69.setFrequency(434.0))
    Serial.println("setFrequency failed");
  else
    Serial.println("setFrequency ok");

  // If you are using a high power RF69 eg RFM69HW, you *must* set a Tx power with the
  // ishighpowermodule flag set like this:
  //rf69.setTxPower(14, true);

  // The encryption key has to be the same as the one in the client
  uint8_t key[] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
                    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08};
  rf69.setEncryptionKey(key);

#if 0
  // For compat with RFM69 Struct_send
  rf69.setModemConfig(RH_RF69::GFSK_Rb250Fd250);
  rf69.setPreambleLength(3);
  uint8_t syncwords[] = { 0x2d, 0x64 };
  rf69.setSyncWords(syncwords, sizeof(syncwords));
  rf69.setEncryptionKey((uint8_t*)"thisIsEncryptKey");
#endif
  Serial.println("Fin du Setup");
}

But during the execution, the program stops at //**************************
I do not understand.
Can somebody help me?
Thanks a lot and merry Xmas


texts:
I'm using the ModbusMaster.h library on a project, with arduino-uno and a TTL/RS-485 converter, and the function has to identify the slave that it is communicating. The slaves goes from 1 to 16. After I've begun the connection,

ModbusMaster node(1);
node.begin(9600);

I have to send a message, and if this massage returns an error, I have to change the slave number, until I got an valid answer. But I didn't find any functions to close this connection, or to delete it, I even have tried,

delete &node;

but it didn't work. I'm trying to close this connection so I could begin another one with another node, because I didn't find a function to change the slave number.


texts: Trying to control two WS2811 strip lights with one controller off of 12V power source

texts:
I'm attempting to build a set of UTV LED lighted whips.
I have 2 5 meter strips of WS2811 RGB strip lights from BTF Lighting ran through a Bluetooth controller that has 12V power coming from the battery on my UTV. The controller is a SP110E from BTF Lighting. I have both strips hooked together via a harness I built to hook them both to the controller so that the two strips will run in sync with each other.
I hooked everything up and at first everything was working properly. After a couple minutes the lights were still lit, but wouldn’t respond to the controller.   And after another handful of minutes neither strip would light up.
The strips have 60 LEDs per meter. I’m wondering if:

I have enough current to properly run the lights.

If I’ve over loaded the controller.

I’m not real savvy when it comes to this type of stuff.  I’ve researched elsewhere to try to figure it out on my own, but I believe I’m in deeper than I can solve on my own. If anyone has any idea’s or advice I’d greatly appreciate it.


texts: Arduino connecting relay has no power output

texts:
I'm a newbie trying to control something through a relay. I've tried two relays with two different setups.

Setup 1

External 12V dc input to the relay (SRD-12VDC-SL-C) and signal pin from arduino to the IN pin, GND of ext. power supply to the GND of the Arduino, NO and COM to the load object (i.e. an LED).

Setup 2

Similar to setup 1, but using SRD-05VDC-SL-C, 5V from Arduino (Vin from Arduino also tested).

Test program

Modified version of the 'blink' example.

Symptom

The load object has been verified to be working before the testing.
Both setup can be verify the input is working, the power led and switch led of the two relay module are lighted as expected, and I can hear the click sound while switching.
No output can be obtained, both from the load object and using a multimeter.

Update

Sorry, I'm supposed to upload a Fritzing schematic, but I can't find a proper relay as I'm using.

The DC+ (red) of the relay is connected to the external ATX 12V.
The DC- (black) of the relay is connected to the external ATX ground.
The IN (blue) of the relay is connected to the Arduino pin 8.
The external ATX ground (white) is connected to the Arduino ground.
The NO (red) of the relay is connected to the load object Vcc.
The COM (black) of the relay is connected to the load object ground.

Sketch

A simple modified version of Blink example is used for testing.

const int relaySignalPin = 8;

void setup() {
  // put your setup code here, to run once:
  pinMode(relaySignalPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(relaySignalPin, HIGH);
  delay(1000);
  digitalWrite(relaySignalPin, LOW);
  delay(1000);
}

Question

I have no idea on why there's no voltage can be obtain between NO and COM while the switch is on, what's wrong with my setup?


texts: How is LED powered when PIN 2 is disconnected?

texts:
Using the Arduino tutorial "Button", I have noticed that if I totally disconnect Pin2 from the circuit, the LED comes on dimly.

I am trying to understand HOW this happens.  Is it simply due to being a floating ground?


texts: Sending MIDI messages using PING ultrasonic sensor

texts:
I am working on a project that uses a potentiometer and an ultrasonic sensor to create MIDI signals. This is my first time working with an arduino. I took a class in C++, but am teaching myself some C in order to program the arduino. So far I have been looking at code that has been written, I've been trying to understand it and mess with it so that my arduino works. The first code creates notes, but I have no control over what notes play or when they play. The first code:

#include <SoftwareSerial.h>

int val;
int AnalogValue = 0;
byte note = 0;
SoftwareSerial midiSerial(2, 3);

void setup ()
{

  pinMode(Pingpin, OUTPUT);
  Serial.begin(9600);
  midiSerial.begin(31250);
}

void loop()
{
  val = 0;
  digitalWrite(Pingpin, LOW);
  delayMicroseconds(2);
  digitalWrite(Pingpin, HIGH);
  delayMicroseconds(5);
  digitalWrite(Pingpin, LOW);

  AnalogValue = analogRead(0);
  note = AnalogValue/8;

  pinMode(Pingpin, INPUT);
  val = digitalRead(Pingpin);
  while(val == LOW)
  {
    noteOn(val, note, 0x40);
  }
  while(val == HIGH)
  {
     noteOn(val, note, 0x40);

  }

}
void noteOn(byte cmd, byte data1, byte  data2)
{
    midiSerial.write(cmd);
   midiSerial.write(data1);
   midiSerial.write(data2);
}

The second code makes more sense to me, but I get no notes to play. I am lost, and can't seem to get the second code to work. Second code:

#include <SoftwareSerial.h>

int val;
int timecount;
int AnalogValue;
int ultrasoundValue;
const int Pingpin = 8;

byte note = 0;

SoftwareSerial midiSerial(2, 3);

void setup ()
{

  pinMode(Pingpin, OUTPUT);
  Serial.begin(9600);
  midiSerial.begin(31250);
}
void loop()
{
  AnalogValue = analogRead(0);
  note = AnalogValue/8;
  Serial.print(note,HEX);
  Serial.print("\t");

  timecount = 0;
  val = 0;
  digitalWrite(Pingpin, LOW);
  delayMicroseconds(2);
  digitalWrite(Pingpin, HIGH);
  delayMicroseconds(5);
  digitalWrite(Pingpin, LOW);

  pinMode(Pingpin, INPUT);
  val = digitalRead(Pingpin);
  while(val == LOW)
  {
   val = digitalRead(Pingpin);
  }

  while(val == HIGH)
  {
   val = digitalRead(Pingpin);
   timecount++;
  }

   ultrasoundValue = timecount;
   ultrasoundValue = ultrasoundValue - 14;
   ultrasoundValue = ultrasoundValue / 5;

  Serial.print(ultrasoundValue);

if(ultrasoundValue > 127)
 {

 }

else
  {

   noteOn(ultrasoundValue, note, 0x40);

  }

}
void noteOn(byte cmd, byte data1, byte  data2)
{
   midiSerial.write(cmd);
   midiSerial.write(data1);
   midiSerial.write(data2);
}


texts: samd21 linking, change the base addresse from the default

texts:
I'm working on creating a safe firmware upgrade for my adafruit feather m0.
I understand from my CTO that wrote the previous upgrade that for either samd21 or all arm m0 (not sure which) the compiler compiles non relative addresses, meaning bx 0x3000 will jump to address 0x3000 and not 0x3000 bytes from my location.
My goal is to split the flash into 4 banks:

bootloader (2k)
user data
firmware #1
firmware #2
which firmware will be booted is up to a flag in the flash do decide.
i understand from my predecessor this is an issue since firmware#2 when loaded to ram might not run.
I disagree and do believe simple changes in the .ld script should accomplish the task.

My only question to  you guys is changing the .ld script .text address is enough ? i know the bootloader jumps to an address that was defined in the  .ld script if it's not 0xFFFFFF (if the flash was written to).
do i ned to change the .ld script to include two .text sections ? do i need to also define how they reside in the RAM as well ?
any examples ? hint ?

Thanks.


texts:
I am using a NodeMCU from Amica. I tried interfacing the HC-05 module to the NodeMCU.

The following code works fine without any errors

#include<SoftwareSerial.h>
SoftwareSerial btport(D2, D3);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(38400);
  btport.begin(38400);
}

void loop() {
  if(Serial.available()){
    btport.write(Serial.read());
  }
  if(btport.available()){
    Serial.write(btport.read());
  }
}

But when I change the code to the following the serial monitor displays garbage values.

#include<SoftwareSerial.h>
SoftwareSerial btport(D2, D3);

int count = 0;
char data[200];
char c;
int flag = 0;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(74880);
  btport.begin(38400);
}

void clearData(){
  int i = 0;
  while(i < 200){
    data[i] = '\0';
    //yield();
  }
  count = 0;
}

void loop() {
  clearData();
  btport.write("AT+INQ\r\n");
  delay(200);
  if(btport.available()){
    while(btport.available()){
      c = btport.read();
      data[count++] = c;
      data[count] = '\0';
    }
  }
  Serial.println(data);
}

The output of the above code is

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1392, room 16
tail 0
chksum 0xd0
csum 0xd0
v3d128e5c
~ld

Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffe00 end: 3fffffc0 offset: 01b0
3fffffb0:  feefeffe feefeffe 3ffe84e4 40101289
<<<stack<<<
¢„*«P*V¡¡ET©«´¥T«ª«*¥u´U+UZªªUT¢üªTQT¥UQ©©jPªV©µuª¥…¢üZT¥(EŠª«ªQTEªj*QTE«ªUUªŠø/¥Å
Soft WDT reset

>>>stack>>>

ctx: cont
sp: 3ffffe00 end: 3fffffc0 offset: 01b0
3fffffb0:  feefeffe feefeffe 3ffe84e4 40101289
<<<stack<<<
¢„*«P*V¡¡ET©«´¥T«ª«*¥u´U+UZªªUT¢üªTQT¥UQ©©jPªV©µuª¥…¢üZT¥(EŠª«ªQTEªj*QTE«ªUUªŠø/¥Å

What should I do to solve this issue?


texts:
I'm trying to wrap my head around a public art project that I've recently received funding for, and I'm hoping that someone here can help me with a bit of guidance.

The concept I'm working on is a kind of 'digital campfire' that builds and falls in intensity as people approach and depart.

The way I imagine it working is with a 15x15x15 RGB LED cube that plays fire-like animations of varying intensities in response to the presence of nearby people - detected by a 360 degree array of thermal sensors (probably something like Omron D6T sensors, rather than IR movement sensors).

Full disclosure: I'm an Arduino noob. I've tinkered with LEDs and soldering, but even the thought of building a non-responsive 4x4x4 LED cube hurts my brain. That said, I have a couple of months up my sleeve, a bit of cash, and a willingness to forge new neural pathways to get this done.

My main questions at this point are:

Can an Arduino even handle the processing power required to run a thermal activated 15x15x15 LED cube, even with multiplexing?
I'm considering 15-cubed because I want the object to have a fairly large physical presence, and have a relatively high definition. Is there any game-changing reason I should seriously consider something smaller? I anticipate being able to connect to a 240v power outlet (I'm in Australia), but running off battery would be ideal.
How difficult would it be to build a 360 degree thermal sensor array consisting of, say, 8 separate thermal sensors? The programming is clearly beyond me, and I expect to out-source this...

Any help or suggestions would be hugely appreciated. And don't be gentle – if my expectations need to be 're-aligned' to something closer to reality, I'd rather that happen sooner than later.

Cheers,

Adam


texts: Debugger with Breakpoint and Variable read/set capability

texts:
Is there any free/open or commercial/paid Arduino IDE Sketch Debugger (not Atmel chip factory standard tool set) with Breakpoint and Variable read/set capability?

I read about VM on web. Is there any similar product?


texts: Bluetooth a pushbutton from one arduino to another to turn on a LED

texts:
For a major project at school i need to get a bluetooth module to be able to communicate between two  HC-05 modules as a master and slave. They need to be able to press a pushbutton on the slave and it lights up a LED on the master.
I have been able to get the two hc-05's to connect to each other but i cant find a code and wiring that will work for what i need to do.
any help will be appreciated. Thanks


texts: I am trying to connect an LCD panel (RioRand (TM) IIC/I2C/TWI Serial 2004 20x4 LCD Module Shield For Arduino UNO MEGA R30) to a Lilypad Arduino.  How can I get them to talk to each other?   I cannot figure out how to connect them.


texts: Options for turning on/off an output at a specific time?

texts:
I am building a night light that will turn on when it detects motion using a Passive Infrared (PIR) sensor. I only want the light to turn on overnight, between specific hours that I specify. Outside of this time the Arduino will sleep.

For my Arduino to check the time, there are a couple of options:

1. Real-time clock

Description: A small add-on board powered by a cell battery (lifetime usually a couple of years). The user sets the time manually after the battery is inserted. Communicates with the microcontroller via SPI, I2C, etc. Upon request from the microcontroller (using a supplied real-time clock library function), the real-time clock sends back the current time (in a specified format).

Advantages

Completely offline

Disadvantages

The clock time can drift (due to electronic component manufacturing tolerances, temperature cycles and oscillator ageing).

To account for daylight saving, a "daylight saving" switch could be used that is manually set by the user.

2. WiFi link to an Internet time server

Description: A WiFi add-on board that allows access to the Internet. A time server could be requested for a specific time.

Advantages

Daylight saving is taken into account automatically
Clock would not need resyncing periodically

Disadvantages

Dependent on connection to the Internet
Dependent on availability of time server

Questions

Before I invest hours of time into making something work, are there any other options?
How much could a real-time clock be expected to drift after a year? (I'd be happy with +/- 15 minutes).
Are there any pitfalls with trying to obtain the time from an Internet time server?

I guess a third option is a combination: an Internet time-syncing Real-Time Clock that conducts synchronisation every week or so!

Note: I am planning on using my Arduino Pro Mini, but I wouldn't be against investing in other hardware.


texts:
I am fearly new to Arduino and FastLED. I found a nice Sketch which fits almost perfectly to my needs.

Just one Problem:

I dont want the Sketch to effect ALL LEDs in one color.
I want some LEDs in Red (ex. LEDs 0-4) Some in green and others in blue.

They could all have the same effect and timing, but it would be really neat if I could make them out of sync a little bit.

But having the possibility to make different LEDs different colored would be great. Here is the "Pulse" or "Breath" Sketch I want to use.

    #include <FastLED.h>

    #define NUM_LEDS 37
    #define DATA_PIN 11
    #define CLK_PIN 13

    CRGB leds[NUM_LEDS];

    int fadeAmount = 5;  // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
    int brightness = 0;

    void setup()
    {
      FastLED.addLeds<APA102, DATA_PIN, CLK_PIN, BGR>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
      FastLED.setBrightness(50);
    }

    void loop()
    {
       for(int i = 0; i < NUM_LEDS; i++ )
       {
       leds[i].setRGB(0,255,250);  // Set Color HERE!!!
       leds[i].fadeLightBy(brightness);
      }
      FastLED.show();
      brightness = brightness + fadeAmount;
      // reverse the direction of the fading at the ends of the fade:
      if(brightness == 0 || brightness == 255)
      {
        fadeAmount = -fadeAmount ;
      }
      delay(80);  // This delay sets speed of the fade. I usually do from 5-75 but you can always go higher.
    }


texts:
So I came across a library that lets you turn your TeensyLC/3.X into an xinput device. I only have a 2.0 on hand. I spend the past few hours messing around with the LC example to see if I could hack it over to work on a 2.0 board. Admittedly, it will take much more time analyzing everything before I can make a more educated attempt. I saw another project that is able to use the 2.0 as xinput devices but the firmware is only available in its hex form.

So I'm wondering what would be the best way to go here... all of the xinput code is in the /core/teensy3 directory. It has many spidering dependencies which will take a lot of time to go through and try and port(would that even work?). Is there a super "lite" version of the core that lets you fill out device descriptors/handshake/etc? If there is, the xinput just becomes a task of emulating the xinput packets.

Anyway, as this is my first usb input project, any suggestions would be greatly appreciated. Again, I already have the 2.0 and I know its possible so just getting a LC/3.X I'd like to avoid. I'm more just looking for direction on the best way to get started.


texts: Integer goes garbage after iteration. struct pointer manipulation messed up other variables in memory

texts:
I'm writing a library for Charlieplexed LED display (trying to write a common one actually). The library is working quite fine. In my arduino sketch, I'm using an integer to keep track of the LED, currently on. The integer value increases with time and the LED(s) glow one by one. The problem is, after couple of iterations, this integer value just goes out of chart (in Serial monitor, it has garbage values).

MatrixCharlieplex mch(Pins, 5, MXCHARLIE_CA); // instance of Class
int i = 0, j = 0;
boolean busy = false;
unsigned long time;
void setup() {
  //Serial.begin(9600);
  time=millis();
}
void loop() {
  if(millis() - time > 100){ // runs every 100 ms interval // corrected from (millis() > (time + 100))
    time=millis();
    blink();
  }
}
void blink(){
  if(!busy){
    busy = true;
    //Serial.print("i:\t");
    //Serial.println(i);
    //Serial.print("Node:\t");
    //Serial.println(i+1);
    mch.TurnOn(i+1);
    increase();
    busy = false;
  }
}
void increase(){
  i = (++i % 20); // resets after every 20 intervals
}

Output:

i:  16
Node:   17
i:  17
Node:   18
i:  18
Node:   19
i:  19
Node:   20
i:16 <-- Stopped working here. it should be "i:    0" & "Node:    1"
    16
Node:   17
    17
Node:   18
    18
Node:   19
    19
Node:   20
16
    16
Node:   17
    17
Node:   18
    18
Node:   19
    19
Node:   20

The sketch can also be found here

Update:
There were no hardware-fault. The problem lies in the struct variable declaration as pointers.updated the question & posted answer. The files in the github links have also been updated.


texts: producing sine wave variable in amplitude and frequency

texts:
How to produce a sine wave with variable frequency and variable amplitude?
I found a library to produce variable frequency called sinwave but not produce variable amplitude (I want -2V to 2V amplitude)


texts: Does a pulldown resistor use less battery power than a pullup resistor?

texts:
I am designing a circuit connected to a simple open-close sensor, like a switch. For ease of construction, the circuit with the sensor switch closes to ground, and uses a 1 MΩ pullup resistor to Vcc to signal HIGH when the switch is open.

I realize that power is flowing the entire time the switch is open, which may (or may not) drain the battery. Would it be more efficient to use a pulldown resistor to ground, and have the switch open to Vcc?

Tangentially, should there be a resistor on the connection to Vcc as well? Either to reduce current (save battery power) or prevent damage to the ATmega328?

Thank you!


texts:
I have this simple code who send a signal to a android phone when I press a button:

const int botonPinD = 8;
const int relayPin =  12;
int retardo = 100;
int finBoton=1000;

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

  pinMode(botonPinA, INPUT);
  pinMode(botonPinB, INPUT);
  pinMode(botonPinC, INPUT);
  pinMode(botonPinD, INPUT);
}
void loop(){
    botonD = digitalRead(botonPinD);
    if (botonD == HIGH){
   // for simplicity remove botonA, botonB and botonC code, but it's the same with a few digitalWrite
        digitalWrite(relayPin, HIGH);
        delay(retardo);
        digitalWrite(relayPin, LOW);
        delay(retardo);
        digitalWrite(relayPin, HIGH);
        delay(retardo);
        digitalWrite(relayPin, LOW);
        delay(retardo);
        digitalWrite(relayPin, HIGH);
        delay(retardo);
        digitalWrite(relayPin, LOW);
        delay(retardo);
        digitalWrite(relayPin, HIGH);
        delay(retardo);
        digitalWrite(relayPin, LOW);
        delay(retardo);
        delay(finBoton);
      }
      else{
        digitalWrite(relayPin, LOW);
      }
}

But if I press the button fast (maybe a half a second between clicks) I only receive once the signal.

I'm not very sure about what's happened here (I'm an Arduino newbie). The first signal, has it locked the channel? Can signals be queued? Can I control the way that they are queued?


texts:
So I am new to the board and looking for a source to answer an Arduino servo project's rough power up.  The project uses a pair of servos operating together to swing a small door.  I have been working with intro level sketches over the last few weeks. I have powered and re-powered my Arduino Uno several times with different codes and each time the unit is powered the two servo motors move to their last position at what appears to be full speed resulting in a rather jerky and jumpy power up.

What can you suggest in the code that would force the servo motors to gently move toward their new code starting position?  Like a 'warm up cycle'.


texts: Seven-Segment Display doesn't work on two lights

texts:
This is my code:

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

void loop() {
    digitalWrite(2, HIGH);
}

This is my circuit:

Problem:

Light A and B doesn't work when I plug the red cable to 4 and 5.
All the other lights works just fine.