texts: Can't use base class and derived class functions

texts:
I have made two libraries and one test program.I have made my custom uart library.first i have included all functions for printing in single uart library file.but then i have made print library for printing functions only.my files are listed below.i have not posted my code directly so it can be read separately.

uart.h

uart.cpp

print.h

print.cpp

  Test.cpp

#include <avr/io.h>
#include "uart.h"

int main(){
    uart.start(9600);
    uart.print("Test");
}

and i get this error..

  Error

src/print.cpp
src/print.cpp: In member function 'void PrintClass::print(unsigned char)':
src/print.cpp:4:12: error: 'write' was not declared in this scope
write(data);
          ^
src/print.cpp: In member function 'void PrintClass::print(char*)':
src/print.cpp:13:22: error: 'write' was not declared in this scope
write(string[index]);
                   ^
.build/uno/Makefile:47: recipe for target '.build/uno/src/print.o' failed make: *** [.build/uno/src/print.o] Error 1
Make failed with code 2

i have referred default arduino libraries like hardwareSerial and LiquidCrystal and i made my library like that but i cant get rid of that.
Please Help me.


texts: How to stabilize magnetic levitation system?

texts:
I followed everything from this project but still, the magnet is not levitating - https://www.hackster.io/jsirgado/magnet-levitation-with-arduino-eeeee4

The best I can do is to make the magnet jump up and down fast but it never levitates. Have tried changing PID setting from the project as aggressive and mild but still didn't achieve the final result.

I need advice from an expert to tell me what I am doing wrong here. All components are in good condition and 5v electromagnet is strong enough.

So what am I missing here? will implementing fast PWM mode be helpful?


texts: Can you pass the entries of a strut array to a int array? if so how?

texts:
typedef struct {
  uint8_t  pitch;
}LearnNote;

#define  MAX_NOTE  500

LearnNote  Noteseq[MAX_NOTE];

int learnindex=0;
void loop() {
 MIDI.read();
}

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


texts: Esp8266-01 AT commands returns random chars and/or "ERROR"

texts:
I'm trying to make my esp8266 work with my arduino.

But when I send AT commands I get some weird symbols and some functions return "ERROR"

Here's the code I'm using.

#include "SoftwareSerial.h"

SoftwareSerial esp8266(6, 7); // RX, TX

void setup()
{
  Serial.begin(9600); // serial port used for debugging
  esp8266.begin(115200);  // your ESP's baud rate might be different
}

void loop()
{
  if(esp8266.available())  // check if the ESP is sending a message
  {
    while(esp8266.available())
    {
      char c = esp8266.read();  // read the next character.

      Serial.write(c);  // writes data to the serial monitor
    }
  }

  if(Serial.available())
  {
    delay(10);  // wait to let all the input command in the serial buffer

    // read the input command in a string
    String cmd = "";
    while(Serial.available())
    {
      cmd += (char)Serial.read();
    }
    // send to the esp8266
    esp8266.println(cmd);
  }
}

Here's the Serial Monitor:

AT

OK
AT+RST

OK

 ets Jan  8 2013,rst catse:2, boot lode:(3,7)

loab 0x40100000& len 1396, qoom 16
tail 4C�,kk�������e
load 0x3fge8000, len 776, room 4 tak0  t0�v�
�!jH+��
����(j5�!
,�2%1�

j
�sl��o�
Ai,Thinker Technology Co. Ltd.

invalid
AT+CWMODE?

+CWMODE:1

OK

AT+GMR

AT version;0.25.0.0(Juo  5 2015 17:27:16)
SDK version:1.0
ryJ 0

AT+CWLAP

+CWLAP:(4,"�P��R�*bj��b���*��2��*����Ҋ�b�Jj
��*A�B�br������Յź�aj��b����2j
":6�*AՉ����J
"�́������

The commands where, AT, AT+RST, AT+CWMODE?, AT+GMR, AT+CWLAP

Why am I getting this weird symbols and etc? I haven't upgraded the firmware, should I?  There other commands I tried return "ERROR" or even "ERROQ"

I don't have a USB to TTL or any other board. I connected my board in the arduino with this schematic:

Cap = 10uF
VolReg = LM1117 3.3v


texts: Significant drop in speed between Arduino IDE and Visual Studio?

texts:
So, I'm not sure what is causing this, but maybe I'm overlooking something simple. I have a simple program designed to read the analog input at 640 Hz, it looks like this:

int Ch0 = 0;
int count = 0;
unsigned long startTime;
unsigned long currentTime;
bool startedReading = false;

void setup() {
  //set up pin(s)
   pinMode(Ch0, INPUT);

  //begin serial at 115200bps
  Serial.begin(115200);
}

...

//if the current time exceeds the start time by one second, set the start time equal to current time, print the count, set count equal to zero
if (currentTime - startTime >= 1000) {
  startTime = currentTime;
  Serial.println("time");
  count = 0;
}

//read input, delay some microseconds as a means of controlling sampling rate, bring count up by one
//should read somewhere along the lines of 640-ish Hz
analogRead(Ch0);
delayMicroseconds(1230);
Serial.println(count);
count++;

And this all works fine and dandy in the Arduino IDE, I pull up the Serial Monitor, and it prints every number 1-640 and then says time, with good consistency. Yet, when I open up a Visual Studio program and call the command:

EDIT: Added entire data received event method

private: System::Void serialPort1_DataReceived(System::Object^  sender, System::IO::Ports::SerialDataReceivedEventArgs^  e) {
    if (!this->reading) return;
    else
    {
         try
         {
            //get incoming port and read
            SerialPort^ sp = (SerialPort^)sender;
            String^ sInData = sp->ReadLine();
            //parse read data
            double inData = double::Parse(sInData);

            //write data to debugger for testing
            Debug::WriteLine(inData);

            //start populating the "in" array
            AppendIn(inData);
          }
          catch (Exception^ e)
          {
            Debug::WriteLine(e->Message);
          }
    }
}

Aside from the obvious error that occurs when I try to parse the string "time" to indicate when 1 second has elapsed, everything works fine. Except for the fact that the numbers feed into the debugger very slowly. As in, it'll take roughly 4-5 seconds to read through all 640 reads of the count integer and then it throws the time at me. Thus, this leads me to conclude that Arduino is indeed calculating that 1 second has elapsed and then sending that over, but the output is essentially the same, the only difference being that the message takes exactly 1 second to read on the Arduino IDE and over 4 seconds to read in real time in Visual Studio.

Maybe it has something to do with the way I'm reading the data in VS? I have it set up to constantly monitor the stream by calling that read method every as an event when data is received over the serial. No data at all is being lost, it's just very slow...and only in VS. Thanks in advance for any help you can give, but I'm at a bit of a loss.


texts:
What does the MQ-2 sensor detect?

I know it detects concentrations of flammable gas. But does it detect smoke from fires too?
What about smoke from cigarettes, and other things?


texts: ESP32-Cam No Response and Unable to Program - Timed out waiting for packet header

texts:
I recently purchased an ESP32-CAM but have had no luck in programming the board or getting any response whatsoever. I first tried to program it using the an FTDI programmer and the Arduino IDE (following the steps from this tutorial: https://randomnerdtutorials.com/esp32-cam-video-streaming-face-recognition-arduino-ide/).

I used this exact wiring diagram:  but got the Timed out waiting for packet header error message. This was with the jumper on the FTDI on the 3.3V section.

Other things I've tried:
-Moving jumper to 5V, powering ESP from 5V pin
-Powering ESP from external 5V source (Arduino pin)
-Powering ESP from external 3.3V source
-Switching computers (Linux and Windows)
-Programming board directly from Arduino (bypassing FTDI)
-Various combinations of pressing/holding reset button during flash process

The other thing is that there is no LEDs that turn on when the board is powered. I couldn't find a concrete reference online that said an LED turns on when the device is on, but I assume the one LED would at least flash or something. Also monitoring the serial output with putty during boot did not yield any output. I'm all out of ideas and I am just starting to suspect that the board is completely dead. Any ideas would be appreciated, thank you.


texts: Code compilation errors for 101 - no errors with Uno

texts:
I asked this question before a few days ago about undefined references errors to custom library functions. By accident I found that the code compiled fine when the board target was set to an Uno, not the Intel Curie 101 that I was indending to use (and what is was set to when the errors appear) Can anyone explain why you would get undefined reference errors that are board specific?

Disclaimer - I haven't got access to the hardware I need to test at the moment so I don't know for certain that the code works on an Uno.

Edit:
I have tested the compilation for a few board targets as below

Uno - no errors
Mega / Mega 2560 - no errors
Leonardo - no errors
Due - no errors
101 - undefined reference as detailed in linked question

Additionally, moving the libaries into the sketch folder rather then having them in the Arduino libaries folder stops compilation errors. Is there a difference in how the 101 links to included files?


texts: Using a phone battery as a power source possible?

texts:
Use
I am assuming that this is possible for any phone model's battery. I am making this vague on purpose (this isn't for a specific project). The goal is to have the most compact and long-lasting battery possible for my arduino projects.

Note
I don't care about the cost. This would be for personal use (not selling this or using it for school), so I don't care about patenting or copyright issues.

Question
I want to know if this even makes sense for a portable arduino power source option. I want to benefit from newer phones' long battery life, as well as their compact size.

Also:
Are there better alternatives to this using different batteries? (I have looked at Nick Gammon's posts over setting sleep cycles to extend battery life (http://www.gammon.com.au/power); If utilizing his methods on different batteries are better than using a phone battery please let me know...)

If Possible...
Does it make sense for something like a:

LED suit (lasting 12 hours)
Portable gaming system (lasting 8 hours) - similar to: (https://www.adafruit.com/products/2510)
I Know this is for Raspberry Pi
BlueTooth Speaker (lasting 6 hours)

etc...


texts:
I'm having a problem. I want to clear the screen on the connected console. And after the clear, I want to rerun my code. But I can't seem to figure out how to do it. Below is some part of the code:

#include <motorStyring.h>
#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h>
#define PORT 6666
motorStyring mt;
int cm;

  YunServer server(PORT);
  const int pingPin = 9;
  int led = 13;
    void setup() {

    Serial.begin(115200);
    Bridge.begin();
    server.noListenOnLocalhost();
    server.begin();
 }
    void loop() {
    long duration, inches, cm;
    pinMode(pingPin,OUTPUT);
    digitalWrite(pingPin,LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin,LOW);
    pinMode(pingPin, INPUT);
    duration = pulseIn(pingPin,HIGH);
    cm = microsecondsToCentimeters(duration);
    h();
   }
    void h()
   {
    YunClient client = server.accept();
     if (client.connected()) {
      String question = "What would you like to drink?\nyou have 4    choises:\n1)Juice\n2)Vodca\n3)Soda\n4)Mix\n";
client.write((uint8_t*)&question[0], question.length());
String response;
while (client.connected()) {
  if (client.available()) {
    char cmd = client.read();
    if (cmd == '\n') {
      break;
    } else {
      response += String(cmd);
    }
  }
}
if (response == "juice") {
  juice();

} else if (response == "vodka") {
  vodka();

} else if (response == "soda") {
  soda();

} else if (response == "mix") {
  mix();

} else {

  String error = "you didn't select anything that corrospond to an option. \n try agin";
  client.write((uint8_t*)&error[0], error.length());
 }
   String awnser = "Here is your " + response;
   client.write((uint8_t*)&awnser[0], awnser.length());
 }
 delay(1000);
}

...

Is there a way to clear the screen on the console, so that all of the text from the previous code is not disturbing the user?


texts: Break a while loop with a push button (AccelStepper.h)

texts:
Disclaimer: This is my first Arduino project.

Background: I am building a "rapunzel tower" lantern for my daughter: the witch pays a visit to Rapunzel meanwhile my daughter can read a book (or still play a bit) before going to sleep.

Goal:If a button is pushed --> a stepper motor turns on and my daughter's lantern switches on (via a relay) --> the stepper motor spins to the left (+/- 5 minutes) to bring the witch to the tower--> a led in the tower room switches on and off (+/- 1 minute) --> the stepper motor spins to the right (+/- 5 minutes) to bring the witch down and the lantern switches off (and my daughter needs my sleep).

Issue If my daughter want to sleep before the witch gets down, she must be able to turn off the lantern while the witch is still on the move (up or down). However, I am unable to do so. That is, I am unable to break the while function when the button is pushed to turn off the latern.

Code
Right now, I use the following piece of code below (compiled from different sources).

I know that I use the delay function instead of the millis function, but that is for my next step. The same goes for the time the motor spins (which I still need to tweak).

Any help is welcome. Thanks.

/* Example sketch to control a 28BYJ-48 stepper motor with ULN2003 driver board, AccelStepper and Arduino UNO: continuous rotation. More info: https://www.makerguides.com */
// Include the AccelStepper library:
#include <AccelStepper.h>
// Motor pin definitions:
#define motorPin1  3    // IN1 on the ULN2003 driver
#define motorPin2  4    // IN2 on the ULN2003 driver
#define motorPin3  5    // IN3 on the ULN2003 driver
#define motorPin4  6    // IN4 on the ULN2003 driver
// Define the AccelStepper interface type; 4 wire motor in half step mode:
#define MotorInterfaceType 8
// Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper library with 28BYJ-48 stepper motor:
AccelStepper stepper = AccelStepper(MotorInterfaceType, motorPin1, motorPin3, motorPin2, motorPin4);

// Code to trigger the light and motor
const int buttonPin = 1;   // the number of the pushbutton pin
const int ledPin =  7;     // the number of the LED pin

int relayPin = 2;          // Connected to relay
int buttonState = 0;       // variable for reading the pushbutton status

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin,INPUT_PULLUP);
  pinMode(ledPin, OUTPUT);
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  // Set the maximum steps per second:
  stepper.setMaxSpeed(1000);
}
void loop() {
  buttonState = digitalRead(buttonPin);
  Serial.println(buttonState);

  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, LOW);
    digitalWrite(relayPin, LOW);
  } else {
    digitalWrite(relayPin, HIGH);
    // Let the witch go up.
      // Set the current position to 0:
      stepper.setCurrentPosition(0);
      // Run the motor forward at 500 steps/second until the motor reaches 4096 steps (1 revolution):
      while (stepper.currentPosition() != 8096) {
          stepper.setSpeed(500);
          stepper.runSpeed();
      }

    // Let the witch the light turn on and off in Rapunzel's room
      digitalWrite(ledPin, HIGH);
      delay(1000);
      digitalWrite(ledPin, LOW);

    // Let the witch let climb down.
      // Reset the position to 0:
      stepper.setCurrentPosition(0);
      // Run the motor backwards at 1000 steps/second until the motor reaches -4096 steps (1 revolution):
      while (stepper.currentPosition() != -8096) {
        stepper.setSpeed(-1000);
        stepper.runSpeed();
      }
  }
  delay(5);
}


texts: Having trouble figuring out CTC on Timer 1 with ATTiny85

texts:
I'm using Timer1 on the Attiny85 clocked at 1MHz to toggle an LED every 1 second. However, I'm having some issues regarding prescaler and OSC value selection.

I'm using this formula, which I found in the datasheet for the Attiny.

fOCnx = fclk/(2*N*(1+OCRnx))

N = Prescaler
I'm taking fOCnx = 0.5Hz as I want a square wave
So based on the above formula, I tried the following cases

N = 2048, OCR1C = 243
N = 4096, OCR1C = 122
N = 8192, OCR1C = 61
N = 16384, OCR1C = 30

The LED toggles after an interval of 1s for cases 3 and 4. However, for cases 1 and, it seems to toggle after 2 seconds. Can anyone tell me why this is happening? Eventually, I want to use this to time data acquisition from a sensor I have so I need to be accurate.

Here's my code

#include <SoftwareSerial.h>

int ledPin = 1;
int state = 0;

SoftwareSerial ser(3, 4);
void setup() {
  // put your setup code here, to run once:
  TCCR1 |= 0x8F;
  OCR1C = 30;
  TIMSK = (1 << OCIE1A);
  pinMode(ledPin, OUTPUT);
  ser.begin(9600);
}

ISR(TIMER1_COMPA_vect)
{
  state = !state;
  digitalWrite(ledPin, state);
  ser.println(state);
}

void loop() {
  // put your main code here, to run repeatedly:
}


texts: How to execute operation once till a condition then restart it from start

texts:
I am making a project using IR sensor,servomotor and Push button.
I am not able write code for the logic as stated:
it will execute the operation when it reads the digital value of IR high and rotates the servomotor till a threshold and then rotates the servo reverse  on using push button.It will perform no actions till the push button is used altough IR sensor is reading value.Then it will again perform the same action after push button is used.


texts: Trying to measure distance using an ultrasound sensor

texts:
I am relatively New to Arduino and need your help. Actually i made a code and the problem is that the ultrasound sensor doesn't work at all. It isn't displaying the distance between the object and and the sensor. Can you help me please!
Here is my code:

note: the code has some motor cotrol commands

int enableBridgePin = 10;
int forwardPin = 11;
int backWardPin = 9;
int tickPin = 2;
const int trig = 5;
const int echo = 6;

int dt;
int distance;

float rotationSpeed[50];

void setup() {
  pinMode(enableBridgePin, OUTPUT);
  pinMode(forwardPin, OUTPUT);
  pinMode(backWardPin, OUTPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(9600);

  digitalWrite(forwardPin, LOW);
  digitalWrite(backWardPin, LOW);

  interrupts();
  digitalWrite(enableBridgePin, HIGH);
}

void loop() {
  analogWrite(enableBridgePin,255);

  digitalWrite(forwardPin, HIGH);
  digitalWrite(backWardPin, LOW);

  distancefonction(dt, distance);
  if(distance>5){
   detachInterrupt(digitalPinToInterrupt(tickPin));
   digitalWrite(forwardPin, LOW);
   }

}

int distancefonction(int dt, int distance)
{
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  dt = pulseIn(echo, HIGH);
  distance = 0.034/2*dt;
  Serial.println(distance );}


texts: Calculating the Distance between a Special Object and Center

texts:
I just want to detect a small object specified in the system and show the distance between it and the object. If I need to explain briefly; I want to detect a small object that I put on the foot of a bird when it approaches 10-15 meters to its cage and measure the distance between them. I plan to have a device that scans around, like a radar. When there is a special object approaching this tool 15 meters, I need to detect it and measure the distance between them. (for example, 12 meters now, and 9 meters after 3 seconds). I thought that if i use a very small (electromagnetic or infrared ray, etc.) signal emitted by the small object attached to the bird's foot, the continuously operating radar can detect this particular signal. Also, it should measure the distance between radar center and the signal. It's like a bluetooth device. But also, it should measure the distance between radar center and the signal.
But I could not find a sensor to do this. (I tried to explain briefly in the photo)

Do you think which product should i use or what should i do for this?
Thank you


texts: How can i split an incoming data in arduino?

texts:
So  for my arduino project I need to split this line of servos data

180 0 0 0 90 90 0

Which would be parsed as:

servo position1 servo positin2 servo positin3 ...servo position 6

in to separate servo values, but i am new at arduino and c typе languges so a little bit help will be very good. So my question is how can I split these values up?


texts: Arduino IDE Unable to detect ZumoMotor.H ( PIXY PET )

texts:
recently i trying to make the pixy pet work for my project. (https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/playing-with-your-pet).

I used the given code for the arduino IDE, but i keep on getting this error Arduino: 1.5.7 (Windows 7), Board: "Arduino Leonardo"

sketch_sep17a.ino:27:24: fatal error: ZumoMotors.h: No such file or directory compilation terminated.

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

The Code, im using, was given by the official maker of the Pixy Pet. Please have a look. ( https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/the-code)

Thank You.


texts: Trying to understand compilation error message

texts:
C:\Users\Field\Documents\Arduino\Adafruit_TCS34725-master\examples\tcs34725autorange\tcs34725autorange.ino:2:31: fatal error: Adafruit_TCS34725.h: No such file or directory

 #include "Adafruit_TCS34725.h"

                               ^

compilation terminated.

exit status 1
Error compiling.


texts:
I am trying to get a simple button (GPIO shortcircuit) to work. I have chosen Pin D0 as input and Pin D7 as output. It works fine in an Arduino sketch but I can't get it to run in pure C. What am I doing wrong? I bet I got the bits all wrong...

My code:

DDRD = 0b11111110; // set all port D pins to Output besides pin 0, which is set to input
PORTD = 0b11111111; // set all D pins to WRITE / PULL-UP
int a = PIND & 1; // a is 0 or 1, depending on whether pins D0 and D7 are physically connected

It doesn't work though, a is never zero, whether the pins are connected or not.

Here is my complete code sample, where the on board LED depends on my pins connection state:

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
 DDRB |= _BV(DDB5);
 DDRD = 0b11111110;
 PORTD = 0b11111111;

     while(1) {
        int a =  PIND & 1;
        if(a != 0)
             PORTB |= _BV(PORTB5); // blink on
         else
             PORTB &= ~_BV(PORTB5); // blink off
         _delay_ms(1000);
    }
}


texts: What does “LSB per degree per second” mean?

texts:
I'm currently working with a digital output gyroscope. Its sensitivity is given as 120 least-significant bit per degree per second.

While every single component of that unit is easy to understand I don't quite get what it means altogether.

Can you explain it to me?


texts:
I am brand new to Arduino and am having a difficult time understanding the "lay of the land". I'm looking for the beefiest, fastest, most compute-centric Arduino available to the market that will run embox.

As I understand it, there is really only the Uno and the Mega, both of which are 32-bit. However I also believe that 64-bit variations/designs exist and was wondering if anyone has actually implemented Arduino Uno/Mega as a 64-bit MCU. I also see there is the Arduino Due, but not sure how that fairs (beefiness-wise) with Uno/Mega.

So to summarize: What is the beefiest Arduino one can find, is it 32- or 64-bit, and will it run an embedded RTOS like embox?


texts: Reading multiple DI pins in parallel as one byte/word

texts:
I need to capture a single parallel 'snapshot' from a 10-bit shaft encoder. I understand that I can read individual bits and shift them into position, but any given input pin might change while reading the bits sequentially, which would give an bogus value. In fact, given the asynchronous nature of the device this is guaranteed to happen on occasion.

I've read hints that it might be possible to combine pins into a 'port' for this purpose but I can't find any examples. Is this ability available only on certain processors? Or is there some way to latch the input pins while scanning them into a pair of bytes, to avoid them changing while I read?

If not I suppose I could use external latches but I'm hoping to avoid additional hardware.

It did occur to me that I could sync readings using an ISR triggered by a change in the LSB, but alas, this encoder outputs Gray code. :(


texts: Why is Serial.Write that slower when writing x+1 characters than when it is writing x characters?

texts:
Using Serial.Write() in a time sensitive application. I realize that the number of characters being written not only had an impact on the time spent writing in the buffer, but actually had a bigger impact than expected.

Consider the following sketch, which measures the time it takes to write NB_CHARS characters, using Serial.Write(). I sampled 1000 times in order to get a more reliable measure.

#define NB_CHARS 100

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

  uint8_t chars[NB_CHARS];
  for (int i=0; i<NB_CHARS; i++)
  {
    chars[i] = 66;
  }

  unsigned long time1, time2;
  unsigned long totalTime = 0;

  delay(100);

  for (int i=0; i<1000; i++)
  {
    time1 = micros();
    Serial.write(chars, NB_CHARS);
    time2 = micros();
    totalTime += time2 - time1;

    delay(10);
    Serial.println("");
    delay(10);
  }

  float meanTime = (float)totalTime / 1000.0f;
  Serial.print("meanTime = ");
  Serial.println(meanTime);
}

void loop()
{

}

Here are some results for different NB_CHARS values:

NB_CHARS: Time (microseconds)
1: 12
2: 18
3: 24
[...]
99: 2912
100: 2997
101: 3082
[...]
199: 11412
200: 11497
201: 11582

It seems that at first, each new character adds around 6 microseconds of delay, but afterward it becomes 85 microseconds. I tested every values from 1 to 100 to find where it changes and it seems to be right after 70:

It seems weird to me.

A quick Google search gets me to this 2013 post by Tom Carpenter. I am not sure how true this is or if it is still relevant.

  Part of the trouble is that the Hardware Serial library is so
  incredibly inefficient (I don't think they could have made it less
  efficient if they tried!). After each byte is sent, there is an
  interrupt called which spends a lifetime loading the next byte into
  the buffer to send. The write function also wastes lots of time doing
  calculations as to where to put a character in a ring buffer.

  [...]

Why is there such a "long" delay for each character and is there a way to make it faster?

What happens after 70 characters that slows it down even further?


texts: Can I remove soldered atmega328P from arduino board, using hot air gun, without damaging it?

texts: I need to remove atmega328P from arduino board and the best tool what comes up to my mind is a hot air gun. What is the maximum temperature that atmega328P can withstand?


texts:
I  have connected a circuit to analog pin 0 in the Arduino.I have this code ,which I understand partially(online resources).The problem is that it prints nothing neither on Tera Term nor on Cool Term .Where am I mistaking ?(I am new to AVR programming).Here is the code:

  #include<stdio.h>
 void InitADC()
 {
 ADMUX=(1<<REFS0);// For Aref=AVcc;
 ADCSRA=(1<<ADEN)|(7<<ADPS0);
  }

 uint16_t ReadADC(uint8_t ch)
 {

    //Select ADC Channel ch must be 0-7
     ch=ch&0b00000111;
     ADMUX|=ch;

     //Start Single conversion

     ADCSRA|=(1<<ADSC);

      //Wait for conversion to complete
      while(!(ADCSRA & (1<<ADIF)));

      //Clear ADIF by writing one to it
      ADCSRA|=(1<<ADIF);

     return(ADC);
}

int main()

  {

uint16_t adc_value;

InitADC();

while(1)

{

  adc_value = ReadADC(0);
  printf("%d",adc_value);

  }

   return 0;

  }


texts: Why does Adafruit guide for motors use transistors on ground rather than modulating the power source

texts:
I'm going through the Adafruit Motors guide for Arduino, found here, and I'm struggling to understand how each of these parts play in. From what I understood, pulse width modulation is basically a way to send varying levels of power through a digital output source. Additionally, it seems that the guide is using a transistor with the PWM signal as the gate, so it can allow the percentage given by the PWM signal to control how much flow is given to the motor. However, what I'm confused here is that both the power and ground are interfacing with this transistor/diode setup.
This is more specifically what I mean, on the bottom seems really simple: the PWM signal comes on the yellow wire, fed through the resistor so that it doesn't fry the transistor into the gate.
After this though, there's a ground signal being passed into the source leg of the transistor, and the sink leg is connected to both a diode for power AND the ground of the motor? I might be misunderstanding how a diode works but this doesn't seem to make sense as to why the ground signal is being modulated.

My initial thought for this would be a system where only the power of the motor is varied by the PWM signal, sorta like in this way (apologies for the terrible drawing style, I haven't gotten used to some of the Arduino sketching software online):

I've not gotten to try this yet, but I assume it wouldn't work or would destroy components somehow since this does seem to be a simpler solution, and it's not being used. I was sorta trying to figure out 1) why my solution would be bad and 2) how the official solution works, as they haven't really given any actual schematic (not that I would understand it, haha) Any help would be appreciated! Thanks!


texts: How to connect this motor driver board to Arduino to drive bidirectional motor?

texts:
I am familiar with using PWM on Arduino and have done so with simple 3-pin interfaces: e.g. PWM, DIR (direction) and GND pins. Choose a direction with DIR, set speed with PWM in software (0 - 255), simple stuff.

But this board I'm buying seems different:

http://www.ebay.com/itm/DC-43A-Double-BTS7960B-Stepper-Motor-Driver-H-Bridge-PWM-for-Arduino-Smart-Car-/141485439094

There seems to be 6 control pins:

R_IS, R_EN, RPWM, L_IS, L_EN, LPWM

But from what I understand this board would only be used for controlling one motor bidirectionally, so why is there a distinction between left and right?

So how would I go about using this motor driver board in a similar way to my PWM, DIR, GND boards that I've used before to control the motor direction and speed?

Thanks!


texts:
I am trying to read data from an XV-11 sensor using the description of the format found here https://xv11hacking.wikispaces.com/LIDAR+Sensor.  This is the code I am currently using to communicate with the computer by USB and the sensor with software serial on an arduino uno.

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  mySerial.begin(115200);
}

int count = 0;

void loop()
{
    if(mySerial.available())
    {
      byte in = mySerial.read();
      Serial.println(in, HEX);
    }
}

However, the data I am receiving on the computer is inconsistent with what I expect.  For example, I am expecting a 0xFA byte every 22 bytes, however this only sometimes happens.  Many times extra or fewer bytes appear in the middle of the data.  I am using the 5 volt arduino serial communication, however I have heard that it is still compatible with 3.3 V sensor communication, so I doubt it is the problem.  I don't thinkthe sensor is broken, as it is new from a working unit.


texts: Is it permissible to connect 3.3V powered devices to the 5V I2C bus?

texts:
I have several devices on the I2C bus:

RTC DS3231SN
TMP100 temperature sensor
EEPROM 24LC256

All devices are powered by 3.3V. The voltage on the I2C bus is 5V.

Question:
Is the voltage difference on the bus and device power normal?


texts:
I am looking for a way to listen for received text messages on multiple numbers. When I came across the Arduino and its shields, I thought to myself this might be the perfect way to do just that.

One of the modules / shields I found on the internet by watching a youtube video is the TC 35 GSM.

I have been reading multiple questions here regarding the "stacking" of shields, and the usual reply is "check what pins / if they are using the same pins". Though these questions were not GSM module specific, and did not include stacking the same shields.

So I am very curious if this is possible. Let's say I want to listen to 10 SIM cards at once for received messages, will this be possible by stacking the modules on one Arduino?

Thanks!


texts: How to connect a phone's camera to an Arduino?

texts: I would like to ask how to connect my phone's camera to an Arduino, just like it is done in this this video. Is anyone familiar with this application they are using?


texts: Stepper wait for X seconds in a loop with millis (not delay)

texts:
In the code below I would like the stepper to bounce back and forward between two limit switches and while it is doing this it should turn and than wait for e.g. 1 second.

I thought I could achieve this with the if ((unsigned long)(currentMillis - previousMillis) >= interval) part, but it doesn't work.It won't turn. Any help would be great. Thank you.

// defines pins numbers
const int stepPin = 5;
const int dirPin = 4;
const int enPin = 12;
const int homeSwitchPin = 9;
const int homeSwitchPin2 = 11;

unsigned long interval=1000; // the time we need to wait
unsigned long previousMillis=0; // millis() returns an unsigned long.

void setup() {

   Serial.begin(9600);

  // Sets the two pins as Outputs
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(homeSwitchPin , INPUT);
  pinMode(homeSwitchPin2 , INPUT);
  pinMode(enPin,OUTPUT);
  digitalWrite(enPin,LOW);

  // Set Dir to Home switch
  digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction

}
void loop() {

    int homeSw = digitalRead( homeSwitchPin);
    int homeSw2 = digitalRead( homeSwitchPin2);

    if( homeSw == HIGH && (digitalRead(dirPin) == LOW) ){
        unsigned long currentMillis = millis();

        if ((unsigned long)(currentMillis - previousMillis) >= interval) {
        motorStep(1);
        previousMillis = millis();
        }
    }
    else if( homeSw == LOW && (digitalRead(dirPin) == LOW) ){
          digitalWrite(dirPin,HIGH);
          delay(2000);
    }

    if( homeSw2 == HIGH && (digitalRead(dirPin) == HIGH)){

        motorStep(1);
        // motorStep(32000);
        //digitalWrite(dirPin,LOW);

        //delay(2000);
    }
    else if( homeSw2 == LOW && (digitalRead(dirPin) == HIGH) ){
          digitalWrite(dirPin,LOW);
          delay(2000);
    }

}
void motorStep( int MAX){

   for(int x = 0; x < MAX; x++) {
        digitalWrite(stepPin,HIGH);
        delayMicroseconds(100);
        digitalWrite(stepPin,LOW);
        delayMicroseconds(100);
      }
}


texts: Why these specific voltage divider resisters needed for Arduino Uno RX TX pins?

texts:
I have an Arduino Uno attached to a Parallax Boe-Bot shield, and plugged into the shield breadboard, the Parallax WX ESP8266 Wi-Fi SIP.

When I attach the DO/DI pins of the ESP8266 board to the RX/TX pins of the Uno, it does not work without a very narrow range of resisters in a voltage divider configuration. I'm trying to learn more about electronics and I would like to know, why these specific values in this specific case?

The DI/DO pins of the SIP are documented as "SIP - output high (set by Vin voltage, either 3.3 or 5.0 V), low 0 V. Input high >Vin/2, input low

When I attach the Parallax shield 5V to the SIP Vin, and the DO to a 220 resister to RX, and also DO to a 1K resister to ground, and DI to 220 to TX and also DI to 1K to ground, serial communications works fine.

If I use the shield 3.3V to SIP Vin, it does not work.

If instead of 220 / 1K, I use 470 / 2K, or 4.7K / 10K, for example, it doesn't work.

If I only set up the voltage divider on the RX pin, it doesn't work.

However, if instead, with either 5V or 3.3V to the SIP Vin, and no resisters, I can run the Uno TX direct to the SIP DI, and the SIP DO to a digital pin, and run that digital pin with SoftwareSerial, for example.

I can run both DI and DO directly with SoftwareSerial, and either 5V or 3.3V to supply Vin.

It's only when I want to connect DO/DI direct to use the Uno's UART (because I don't want serial-driving interrupts to interfere with servo pulses) that I have to carefully select these resisters (through trial and error) and be sure to power with the 5V. Some combinations get communication with errors, but just these specific values (out of the resisters I happen to have on hand) work.

I understand that it is something to do with 3.3V vs TTL serial, but I would like the details. (I will be picking up a logic level converter to try in place of the voltage divider.)

EDIT:

By "not working" -- in all but two cases, with fresh batteries, the SIP seems to get data from the Uno TX, and the DO lamp on the SIP flashes, but Serial.read() sees nothing on the Uno regardless of configured rates. In one of the two cases (I can't recall which) unintelligible, incomplete data is read on the RX pin, and in the last, good case -- where both pins have voltage dividers and the SIP is powered by the 5V line of the Arduino shield (for the Boe-bot) -- with those specific resister values -- the data from the SIP DO is received on the Serial, from pin RX.


texts:
I need to send 6 bytes value from Arduino UNO to the actuator using serial port in order to make it extends. I have added a button to send the data. For example, 0 20 1 1 0 0. The communication settings are 9600 baud rate, 8 data bits, no parity and 1 stop bit. I have used MAX 232 to build a TTL to RS232 circuit. The actuator does not move. Are there any problems on my program? I am new to create USART code. I think I have some problems on transmit function. I am using the build in USART with c code. Here is my code:

#define BAUD_PRESCALER 0x67
int buttonPin1 = 4;
int buttonState1 = 0;

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

unsigned char data1 = 0x00; // 0
unsigned char data2 = 0x14; // 20
unsigned char data3 = 0x01; // 1
unsigned char data4 = 0x01; // 1
unsigned char data5 = 0x00; // 0
unsigned char data6 = 0x00; // 0

void USART_Init(void) {
    /*Set baud rate */
    UBRR0 = BAUD_PRESCALER;
    UCSR0A = 0x00;
    /*Enable receiver and transmitter */
    UCSR0B = 0x08;
    /* Set frame format: 8data, 1stop bit */
    UCSR0C = 0x06;
}

void USART_Transmit( unsigned char data ) {
    /* Wait for empty transmit buffer */
    while ( !( UCSR0A & (1<<UDRE0)) )
    {
        ;
    }
    /* Put data into buffer, sends the data */
    UDR0 = data;
}

void loop() {
    // put your main code here, to run repeatedly:
    buttonState1 = digitalRead(buttonPin1);
    if (buttonState1 == LOW)
    {
        USART_Init();
        USART_Transmit(data1);
        USART_Transmit(data2);
        USART_Transmit(data3);
        USART_Transmit(data4);
        USART_Transmit(data5);
        USART_Transmit(data6);
    }
}


texts: Reading multiple pins via registers on the Arduino Due

texts:
I would like to read multiple pins at once in Arduino Due via registers just like PINB, PINC, PIND of the arduino uno. I know that the pins will be scattered to multiple registers, but i deduce it would still be faster this way since there for sure there will be multiple pins on a single register rather than call digitalRead 40 times.

Arduino shared the documentation for what digital/analog pins corressponds to the what ports to the actual sam chip, i just need that snippet of code that reads via registers.

So if any can give me the equivalents to these, It would be greatly appreciated:

DDRx - The Port C Data Direction Register - read/write
PORTx - The Port C Data Register - read/write
PINx - The Port C Input Pins Register - read only


texts:
This (maybe stupid) question is bothering me for a long time...

If the pin 0 has to be connected to the ground for uploading a sketch into ESP8266, and after the uploading the chip automatically starts the uploaded sketch (without waiting for reboot with pin 0 to be disconnected), then won't it destroy the chip if I do digitalWrite(0, HIGH) in my sketch? Correct me if I'm wrong, but it should short 3.3V directly to the ground through this pin... Is this problem secured somehow? Or maybe this pin can be safely used for reading only?

Edit:

I have seen it connected to ground directly on every schematic about ESP8266, but maybe I should just use a pull-down resistor? Or maybe the chip already has a resistor before this pin to solve this problem?


texts: Sparkfun Spectrum Analyzer: Problems with frequency bands

texts:
I bought around 2 years ago the Spectrum Analyzer Shield from Sparkfun, but I never had the time to do something with it. Recently I found the time to start a project to build a graphical equalizer. For that I use the Spectrum Analyzer Shield to split the left and right audio channel into 7 different bands. After I finished to build my first LED-Matrix panel and tested it out with the Spectrum Analyzer Shield I thought that everything works as it should. I made than the second LED-Matrix panel and tested everything again. Well, the result was odd. I noticed that the order of the bands inside of my arrays are switching around between every restart of my Arduino. Here are two example outputs. I played a 64 Hertz tone and expected to see an increase for the right and left channel for the first band.

Band0 R:70 ,L: 76 | Band1 R:92 ,L: 81 | Band2 R:548 ,L: 83 | Band3 R:108 ,L: 575 | Band4 R:76 ,L: 108 | Band5 R:64 ,L: 82 | Band6 R:63 ,L: 83 |
Band0 R:67 ,L: 78 | Band1 R:87 ,L: 83 | Band2 R:552 ,L: 82 | Band3 R:108 ,L: 575 | Band4 R:80 ,L: 109 | Band5 R:68 ,L: 83 | Band6 R:63 ,L: 78 |
Band0 R:77 ,L: 75 | Band1 R:88 ,L: 78 | Band2 R:546 ,L: 83 | Band3 R:105 ,L: 575 | Band4 R:79 ,L: 109 | Band5 R:61 ,L: 79 | Band6 R:59 ,L: 77 |
Band0 R:73 ,L: 74 | Band1 R:92 ,L: 85 | Band2 R:546 ,L: 84 | Band3 R:113 ,L: 572 | Band4 R:78 ,L: 105 | Band5 R:58 ,L: 74 | Band6 R:65 ,L: 78 |
Band0 R:71 ,L: 77 | Band1 R:92 ,L: 82 | Band2 R:550 ,L: 84 | Band3 R:107 ,L: 573 | Band4 R:76 ,L: 107 | Band5 R:59 ,L: 76 | Band6 R:59 ,L: 79 |

After restart of the arduino (pressed 5 sec the reset button)

Band0 R:71 ,L: 576 | Band1 R:86 ,L: 106 | Band2 R:545 ,L: 87 | Band3 R:107 ,L: 82 | Band4 R:76 ,L: 78 | Band5 R:55 ,L: 80 | Band6 R:61 ,L: 79 |
Band0 R:71 ,L: 575 | Band1 R:83 ,L: 105 | Band2 R:549 ,L: 80 | Band3 R:109 ,L: 87 | Band4 R:75 ,L: 79 | Band5 R:55 ,L: 84 | Band6 R:64 ,L: 78 |
Band0 R:69 ,L: 575 | Band1 R:88 ,L: 103 | Band2 R:546 ,L: 79 | Band3 R:109 ,L: 82 | Band4 R:73 ,L: 79 | Band5 R:63 ,L: 78 | Band6 R:62 ,L: 84 |
Band0 R:70 ,L: 575 | Band1 R:87 ,L: 103 | Band2 R:547 ,L: 84 | Band3 R:106 ,L: 82 | Band4 R:76 ,L: 78 | Band5 R:61 ,L: 80 | Band6 R:61 ,L: 90 |
Band0 R:71 ,L: 574 | Band1 R:83 ,L: 106 | Band2 R:550 ,L: 79 | Band3 R:109 ,L: 84 | Band4 R:77 ,L: 77 | Band5 R:57 ,L: 85 | Band6 R:60 ,L: 81 |
Band0 R:64 ,L: 576 | Band1 R:92 ,L: 109 | Band2 R:549 ,L: 80 | Band3 R:105 ,L: 80 | Band4 R:75 ,L: 72 | Band5 R:56 ,L: 76 | Band6 R:60 ,L: 80 |

I experienced the same issue with the source code from Sparkfun: https://github.com/sparkfun/Spectrum_Shield/blob/HW_1.6_FW_1.1/Firmware/SparkFun_Spectrum_Demo/SparkFun_Spectrum_Demo.ino

I modified this code only slightly to log everything.

void Read_Frequencies(){
  //Read frequencies for each band
  for (freq_amp = 0; freq_amp<7; freq_amp++)
  {
    Frequencies_One[freq_amp] = analogRead(DC_One);
    Frequencies_Two[freq_amp] = analogRead(DC_Two);
    digitalWrite(STROBE, HIGH);
    digitalWrite(STROBE, LOW);

    Serial.print("Band");
    Serial.print(freq_amp);
    Serial.print(" R:");
    Serial.print(Frequencies_One[freq_amp]);
    Serial.print(" ,L: ");
    Serial.print(Frequencies_Two[freq_amp]);
    Serial.print(" | ");
  }
  Serial.println("");
}

Hopefully I'm doing something fundamental wrong, if not that would mean I have to buy a new Shield :/


texts: Boolean function call with character pointer input - dont understand how to get updated pointer value

texts:
Thank you for everyone's help in trying to find a solution. This library I'm working with was prewritten and is one of the most buggy hardware libraries I've had the misfortune to use. I have now solved to problem by reusing the response parsing code from the library and rewriting my own sequence to return the number using a completely different approach. Many Thanks again!

I am currently attempting to understand how this function works and am struggling. I want to be able to access the 'number' variable in my main function but currently when I do that I get nothing (as in "") when I try to printout the variable with:

Serial.println(incomingNumber);

I am currently preassigning the number as:

char incomingNumber[14];

at the top of my project file.
With a class initial setup of:

DFRobot_SIM808 sim808(&Serial);

I'm then later calling the function like this:

if(sim808.isCallActive(incomingNumber)){Serial.println(incomingNumber);}

This seems like I'm currently making a fundamental error in understanding data types but I'm a bit lost so any help would be really appreciated.

I havent included my entire project here because its currently quite long and spread across both the main and some library files but if anyone needs more info please ask and I'll upload the extras.

The function from the library I'm working with is included below:

bool DFRobot_SIM808::isCallActive(char *number)
{
char gprsBuffer[46];  //46 is enough to see +CPAS: and CLCC:
char *p, *s;
int i = 0;

sim808_send_cmd("AT+CPAS\r\n");
/*Result code:
    0: ready
    2: unknown
    3: ringing
    4: call in progress

  AT+CPAS   --> 7 + 2 = 9 chars
            --> 2 char
  +CPAS: 3  --> 8 + 2 = 10 chars
            --> 2 char
  OK        --> 2 + 2 = 4 chars

  AT+CPAS

  +CPAS: 0

  OK
*/

sim808_clean_buffer(gprsBuffer,29);
sim808_read_buffer(gprsBuffer,27);
//HACERR cuando haga lo de esperar a OK no me har閾哸 falta esto
//We are going to flush serial data until OK is recieved
sim808_wait_for_resp("OK\r\n", CMD);
//Serial.print("Buffer isCallActive 1: ");Serial.println(gprsBuffer);
if(NULL != ( s = strstr(gprsBuffer,"+CPAS:"))) {
  s = s + 7;
  if (*s != '0') {
     //There is something "running" (but number 2 that is unknow)
     if (*s != '2') {
       //3 or 4, let's go to check for the number
       sim808_send_cmd("AT+CLCC\r\n");
       /*
       AT+CLCC --> 9

       +CLCC: 1,1,4,0,0,"656783741",161,""

       OK

       Without ringing:
       AT+CLCC
       OK
       */

       sim808_clean_buffer(gprsBuffer,46);
       sim808_read_buffer(gprsBuffer,45);
        //Serial.print("Buffer isCallActive 2: ");Serial.println(gprsBuffer);
       if(NULL != ( s = strstr(gprsBuffer,"+CLCC:"))) {
         //There is at least one CALL ACTIVE, get number
         s = strstr((char *)(s),"\"");
         s = s + 1;  //We are in the first phone number character
         p = strstr((char *)(s),"\""); //p is last character """
         if (NULL != s) {
            i = 0;
            while (s < p) {
                number[i++] = *(s++);
            }
            number[i] = '\0';
         }
         //I need to read more buffer
         //We are going to flush serial data until OK is recieved
         return sim808_wait_for_resp("OK\r\n", CMD);
       }
     }
  }
}
return false;
}


texts: Inaccurate and non-precise voltage reading from Arduino Analog pin

texts:
float get_volt() {
  rawVolt = analogRead(voltageSensor);
  vOUT = (rawVolt * 4.6) / 1024.0;
  vIN = vOUT / (R2/(R1+R2));
  //if(vIN>12.0){vIN=12;}
  //if(vIN<11.12){vIN=11.12;}
  //return (vIN - 10.18) * (100 - 0) / (12.0 - 10.18) + 0;
  return vIN;
}

I am using a voltage sensor module which has a voltage divider with R1=30K Ohms and R2=7.5K Ohms and can measure up to 0-25V by using 10-bit Analog pin of arduino. the battery voltage comes as 11.4 volts when measured with a multimeter but I am getting an inaccurate reading from arduino ranging from 10.8 to 11.4. the Arduino voltage reference is stable at 4.6 V. Please help me to fix this, you can see the voltage reading in the image
PS: the battery and arduino are connected to the same ground.

edit1: adding 0.1uf capacitor helped to improve from this

to this!

the data is taken for over a period of 1 hr at every 5 seconds, its a 12V 4000 mAh battery


texts: What am I missing? Send data from Matlab to Arduino to Micro SD

texts:
First off. This is not in any way a class assignment. This is my own personal work and research. I just want to get that out of the way.

I am learning how to use Matlab with various Arduino projects. I am a seasoned Matlab user but I am fairly new to the entire Arduino space.

I am trying to send some numerical data from Matlab (via a GUI) to my Arduino Uno and have the Arduino write it to my micro SC card. This is a temporary step to my larger project. However, there is no need to go into those specifics as they are outside of the scope of my issues.

I am fairly confident that the Matlab code works and the Arduino code is slightly modified from another project I did where I wrote and read random numbers from my micro SD card.

However, as I run the Matlab code, the Arduino blinks as if it is receiving the data but after I check the micro SD card it remains blank.

I am confident that my Arduino is wired correctly to my micro SD card adapter since this remains the same from my prior project.

Therefore, I am sure I am missing something trivial to get it to work.

I have researched several websites on the subject and their method and mine seem to align very well.

I am fairly certain the problem is in the conditional statement:

if (Serial.available() > 0) {

As you will see.

The Matlab code is below:

arduinoCom = serial('COM3', 'BaudRate', 115200);
sendData = 5;
fopen(arduinoCom);
fprintf(arduinoCom,'%i',sendData); %this will send 5 to the arduino
fclose(arduinoCom);
delete(arduinoCom);

The Arduino code is as follows:

#include <SD.h> // load SD library

int chipSelect = 4;  // Chip select pin for the MicroSD Card Adapter
int incomingByte = 0; // for incoming serial data.
File SDF; // Serial data received is saved here.

void setup() {
     Serial.begin(115200); // start serial connection to print out debug messages and data
     pinMode(chipSelect, OUTPUT); // chip select pin must be set to OUTPUT mode
     if (!SD.begin(chipSelect)) { // Initialize SD card
        Serial.println("Could not initialize SD card."); // if return value is false, something went wrong.
     }
     while (!Serial) {
     }
}

void loop() {
        // Open file, Write data, Close file only when you receive data
        if (Serial.available() > 0) {
           incomingByte = Serial.read();
           SDF = SD.open("SerialDataFile.txt", FILE_WRITE); // open "SerialDataFile.txt" to write data
           SDF.println(incomingByte, DEC); // write ASCII-encoded decimal number to file
           SDF.close(); // close file
           }
}

The expected result would be a file "SerialDataFile.txt" stored on my micro SD card with the value 5.

Thank you for your help!


texts:
I have been trying to convert numbers in lines of a txt file into usable integers. I have a file filled with numbers, and I have narrowed the problem down to the fact that the file isn't successfully being turned into an array.

So I just broke it down into trying to print the numbers one by one on a serial monitor (there are 500 lines in the text file, each containing characters that look like numbers)

Here is the code:

#include <SD.h>
#include <SPI.h>

const int chipSelect = 4;
char array[500];
int n = 0;

void setup()
{
  Serial.begin(9600);
  Serial.print("Initializing SD Card....");
  if(!SD.begin(chipSelect))
  {
    Serial.println("Card failed, or not Present");
    return;
  }
  Serial.println("Card Initialized");
  File dataFile = SD.open("list.txt");
  if(dataFile)
  {
    Serial.println(dataFile);
    while(dataFile.available())
    {
     array[500] = dataFile.read();
    }

    dataFile.close();
    Serial.println("list.txt");
  }
  else
  {
    Serial.println("File does not exist");
  }
  n = 0;
  while (n < 500) {
    Serial.println(array[n]);
    n = n + 1;
  }
}

void loop()
{

}

It returns:

Initializing SD Card....Card Initialized
list.txt

and then 500 lines of blank text. I don't think I'm doing the array conversion right.

EDIT; One more thing I forgot, I can't really use a big text file, unless theres a way to only store one line in dynamic memory at a time. Is it possible to only check a single line of a text file?


texts:
Iam trying to set up the arduino uno with the wifi module ESP8266. I use this schematic setup:

I have followed this tutorial: Tutorial ESP8266

Thereby I removed the Mega328P Chip like it says above, I can communicate trough my terminal in the arduino IDE with the ESP-module but when I want to upload an simple test file like this:

#include <SoftwareSerial.h>

SoftwareSerial ESP8266(0, 1); // RX = 8 en TX = 9

boolean FAIL_8266 = false;

void setup() {
  // put your setup code here, to run once:
   do {
    ESP8266.begin(115200); // start communicatie met esp8266

    //Wait Serial Monitor to start
    while (!Serial);

    ESP8266.print("AT\r\n");

    delay(500);

    if (ESP8266.find("OK")){
        ESP8266.print("ready");
    }

   } while (FAIL_8266);
}

void loop() {
  // put your main code here, to run repeatedly:

}

Than it keeps throwing me this error: avrdude: stk500_getsync() attempt x of x: not in sync: resp=0x20 is it because I removed the Mega328P Chip?

Thereby I've tried the test code from the tutorial here is an link to the code: LINK.

There it keeps saying that Serial2 was not declared in scope

I'll hope someone can help me out on this one and run an simple test script to communicate with the ESP8266 WIFI Module


texts: remove weird chars from char array ESP32

texts:
When I'm converting a string to a char array there are always some weird chars at the end.
I have to do it manualy because the convertTochar function crashes my ESP.

  String sssid = module.getCssid(); //String is stored in the eeporm
  char cssid[sssid.length()];
  Serial.println(sssid.length()); //prints correct length of 6
  //convert do ssid
  for( int i = 0; i<sizeof(cssid);i++){
    cssid[i] = sssid[i];
  }
  Serial.println(cssid); //prints myssid⸮?⸮2⸮?
enter code here

If I'm printing the value directly fromm eeprom there are no wired characters.
Also the max eeprom size for the string is 10 bytes...

Why are these characters at the end of string?


texts: Can I hook up two micros to one GPS module?

texts:
I've worked with a few different GPS modules. Most of them seem to just pump out data and not really interact with the micro controller.

I have a quadcopter (Cheerson CX 20 Big Sky) It has a gps break out board that looks similar to the one I've worked with before. Is it likely that I connect another micro controller to this board? I want to add a cellular module to my quad.

I know that the answer may be "it depends" but before I start testing and researching I just want to know if it's even likely to work.

If the gps is just barfing out coordinates and not interacting with the main board I think it could work. I could just tap in and "listen" -- is this even a possibility?


texts: Trying to Serial.write RAW code properly

texts:
I have a SIM800L Module connected to my arduino Nano. I want to open a TCP connection from the sim800l module to my own server and send a text string. The connection is working however I am not able to send text, because there is an issue with the arduino write() function I think... Below is the code I am trying to execute. Right after the message is sent, I need to send the stop value 0x1A (byte 26) to tell the sim800l module that the message end is reached and to send out the message.
My problem is, that it is not working in the arduino IDE and I don't know why.

My arduino code:

#include <SoftwareSerial.h>

#define SIM800_TX_PIN 8
#define SIM800_RX_PIN 7

SoftwareSerial serialSIM800(SIM800_TX_PIN, SIM800_RX_PIN);

void setup() {

serialSIM800.println("AT");
delay(500);

serialSIM800.println("AT+CIPSTART=\"TCP\",\"IP-ADRESS-HERE\",\"9999\""); //connection works
delay(500);

serialSIM800.println("AT+CIPSEND");
delay(500);

serialSIM800.print("TEXT MESSAGE HERE");
delay(500);

serialSIM800.write(26);
delay(500);

serialSIM800.println("AT+CIPCLOSE");
delay(500);
}

void loop() {
  //Empty
}

On my server I am running this python script that opens a socket:

import socket
import sys

HOST = ''   # all available interfaces
PORT = 9999 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

#Bind socket to local host and port
try:
  s.bind((HOST, PORT))
except socket.error as msg:
  print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
  sys.exit()

print 'Socket bind complete'

#Start listening on socket
s.listen(10)
print 'Socket now listening'

#now keep talking with the client
while 1:
  #wait to accept a connection - blocking call
  conn, addr = s.accept()
  print 'Connected with ' + addr[0] + ':' + str(addr[1])
  data = conn.recv(1024)
  print len(data)
  print data
s.close()

Once I execute this, I see the connection is working because "Connected with IP:PORT" is printed on my console. However right after that "len(data)" is printed (0) and "data" is an empty string. I even upped the delay from 500 to 5000, still same result.

However, if I leave the arduino IDE and send the message using the program "HTerm", it is working! In HTerm I typed in the text message and hit enter. After that I switched from ascii to hex mode (there is a checkbox) and I just typed 1A and sent it. That way it worked. Anybody can help me? Why is it not working @arduino?


texts:
I need two Arduino units with the HC-06 Bluetooth board to communicate with each other and one of these Arduino units also connected to my Android phone. Is this possible to do with just two HC-06 modules, or even three? Or is there a better solution for this?

To reiterate what is going on here:
I have two Arduinos that are running off battery. Arduino 1 is sending data every 0.5 seconds to the Arduino 2. Arduino 2 collects this, adds its own bit of data to it, and then sends this new data packet to my Android phone which will only be connected to Arduino 2.

I haven't completely decided upon what kind of Arduino board to get, but it needs to be fairly small, but I am planning on the Adafruit Pro-Trinket 5v.

Hopefully you get the basic scenario, let me know if you need more clarification and what you think could be done here.

Thanks a lot!


texts:
First post here. So I have an issue, which I have identified, but I'm not quite sure how to fix it.
I'd really appreciate some input and suggestions.
I realize that my "pwmDelta" is the problem, but I am not sure what to do to fix it.

I am trying to write a program that will increment the value of the pin 3 a set amount of time, in a somewhat linear fashion, starting at my low point, and finishing at my high point.

The issue is that my equation is incorrect and I can't output a partial bit value. Huge oversight on my part. If you read the data from the serial monitor with the code written as I have it, you'll see that it isn't coming even close to reaching my max value.

I need suggestions on how I can have the program figure out the delta in a way that I can send an integer value to the PWM output pin, yet still keep a somewhat linear increase over time. Would this even be possible?

int motor1 = 3;         //pin for PWM output to motor
float t = 0;            //Variable to keep Track of time
int tLim = 30;          //Time Limit for Ramp
float lowLim = 21;      //Low Limit, in Duty Cycle %
float highLim = 65;     //High Limit, in Duty Cycle %
float motorPWM = 53.55; //Starting Value of PWM, in Bits
float pwmDelta = ((255/100)*(highLim-lowLim))/(tLim); //Delta equation, to calculate how much to change PWM value each time it is incremented
float motorDelta;       //Variable to write value to Motor Output

void setup() {
  pinMode(motor1, OUTPUT);
  analogWrite(motor1, 53.55); //run motor at initial value for 20 seconds before beginnning ramp
  delay(20000);
  Serial.begin(9600);
}

void loop() {
  motorDelta = motorPWM + pwmDelta; //incrementing output value based on Delta Equation
  motorPWM = motorDelta; //Setting new incremented value equal to old value, so incrementing can continue

  if (t <= tLim) {  //Check if time is <= time limit
    analogWrite(motor1, (motorDelta)); //write incremented value to output pin
    delay(1000);  //wait 1 second, increment t, to keep track of time
    t++;
  }
  else {
    analogWrite(motor1, motorPWM = 165.75); //set pin to high value for 60 seconds, then set to 0
    delay(60000);
    analogWrite(motor1, motorPWM = 0);
  }
  Serial.print(motorDelta);
  Serial.println();
  Serial.print(t);
  Serial.println();
}


texts: Multiplex 7 segment during delay (external IC?)

texts:
I am using some sensors with the arduino which take a second to receive the data from them. My guess is that there is a delay used somewhere in the library. During this time the multiplexed displays stop working as the rapidly changing grounds are temporarily paused and only one of the displays has the digit lit up. I could change the sensor I'm using (DHT11) to something I could AnalogRead, however I'm curious if there is an external IC for this which drives multiplexed displays with some sort of serial communication or I2C between the arduino and it. I could use a separate arduino(or ATTiny) and write some code for it to do this, but is there a class of chips which already do this? Something where you could pass bytes of the digits and the multiplex delay and it continues to multiplex until the next data is received.

I don't mind if in this time the digits are left in their last states similar to how it would operate if they were directly driven rather than multiplexed. If anyone has insight that would be great!


texts: Is it possible to use the galileo's ethernet port through arduino IDE? Or should I buy an arduino ethernet shield? Will I be able to use galileo as a server to which arduino board can send data to?


texts: How to enable auto reset in Arduino Leonardo?

texts:
I am  trying to program an ATMega32u4 microcontroller through arduino IDE. I have added external oscillator(16Mhz) and capacitors and few other connections according to the Schematic. I had put a sparkfun bootloader onto it(caterina) using Avr Pocket Programmer. A usb 2.0 is connected to the microcontroller. Arduino IDE recognizes microcontroller as Arduino Leonardo with the help of this usb. Bootloader file.

I was able to upload codes into the microcontroller but the issue is, I have to put the reset pin to ground momentarily each time when the IDE goes to uploading stage.
If i do not reset it, the COM Port for leonardo disappears but it never comes back until I reset it manually and therefore the uploading bar just gets stuck. I have also added the circuit connected to the Reset Pin according to the schematic but even if i remove all of it and just connect a switch, no difference can be observed. No power on reset is working.

Since one can upload codes without having to manually reset each time in Arduino Leonardo, I was wondering what could be the issue here.

Is there a way to auto reset this? Or perhaps fix the auto reset issue in this case?


texts:
I want to use a my existing WiFI USB Dongle with Arduino Uno. I know that there is no USB port in Arduino Uno as such so I opened the USB Dongle and Soldered it so that I can plug the wire to Arduino. Below is the picture of Dongle -

Now the problem is, I am not able to find any way to use this with Arduino. I can see there are some standard WiFi modules like WiFi Shield and ESP Module available which are mostly used. But is it necessary to use those modules only ? Can we use this USB module and if yes then how ?

The details information about this WiFI dongle is available at below path -
https://www.amazon.in/gp/product/B0088TKTY2/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1


texts: Help - Atmega328p, converting a PWM servo code from pin9 to pin6

texts:
I found a working code that uses pin9 (PB1) on my Arduino for controlling a Servo, but in my project, an ultrasonic sensor is already using that pin/timer. I want to convert the code to use pin6 (PD6), changed the registers according to the atmega's datasheet, but it doesn't work. Need help :/

The code should allow me to turn a servo using a potentiometer.

#define F_CPU 16000000 //16MHz
#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include <stdlib.h>

#define PWM_PRESCALLER 64
#define ICR_MAX (long double)F_CPU/PWM_PRESCALLER/50
#define OCR_MIN (float)ICR_MAX/37.5 // /8.75
#define OCR_MAX (float)ICR_MAX/8.7 // 37.5

volatile unsigned long adc_val=0;
volatile unsigned long counter=0;
unsigned long curr_adc=0;

ISR (ADC_vect)
{
adc_val += ADC;
counter++;
}

int main(void)
{
    DDRD |= (1<<DDD6);
    ICR1 = ICR_MAX;
    OCR0A = OCR_MIN;
    TCCR0A = (1 << COM1A1) | (1<<WGM00) | (1<<WGM01);
    TCCR0B = (1<<WGM02) | (1<<CS01) | (1<<CS00);
    ADMUX = (1 << REFS0);
    ADCSRA = (1 << ADEN)|(1 << ADATE)|(1 << ADIE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0);

    sei();
    ADCSRA |= (1<<ADSC);

    while(1)
    {
        if(counter >= 1000)
        {
            cli();
            unsigned long round_val = round(adc_val / counter);
            adc_val=0;
            counter=0;
            if(abs(round_val - curr_adc) > 1)
            {
                curr_adc = round_val;
            }
            long double ocr = OCR_MIN + ((long double)curr_adc * (OCR_MAX - OCR_MIN)/1024);

            OCR0A = (int)round(ocr);
            sei();
        }
    }
}


texts: How to convert the 0-5V to a 4-20mA current loop?

texts:
I'm pretty clueless about electronics so everything has to be explained in simple terms to me.

I have an Arduino with a program which provides a value via the Analog output, so that is anything from 0-5V.

On the other side I have a PLC (programmable logic controller) with an IO card which allows to connect to a (4-20mA) current loop.

How do I convert from lets say 1-5V to the 4-20mA in a somewhat cheap and safe way (I don't want to destroy the PLC [and possibly the Arduino])?

Of course the Arduino and the PLC have separate power sources.


texts: Stepper motor only rotates once in a loop?

texts:
I am quite new to this , I am trying to program two motors , aStepper and bStepper.
I want the program to rotate aStepper then rotate the bStepper and when that is done rotate aStepper again , and then repeat.
The first iteration works fine.However, it only does the loop once and the bStepper doesn't rotate again.

Am I doing something wrong with the loop?

(aStepper is the UNIPOLAR 28BYJ-48 connected to its driver , and bStepper is a Nema 17 connected to A4988)

#include <AccelStepper.h>
#include <Stepper.h>

#define StepsPerRotation 2038

#define dirPin 2
#define stepPin 3
#define motorInterfaceType 1

AccelStepper bStepper = AccelStepper(motorInterfaceType, stepPin, dirPin);
Stepper aStepper(StepsPerRotation, 8, 10, 9, 11);

void setup() {

  bStepper.setMaxSpeed(200);
  bStepper.setAcceleration(30);
}

 void loop() {

   aStepper.setSpeed(20);
   aStepper.step(1016);

   bStepper.moveTo(-6000);
   bStepper.runToPosition();

   aStepper.setSpeed(20);
   aStepper.step(-1016);
}

Thank you in advance


texts: Source power with 2 V and LED with forward voltage of 2 V

texts:
I have a source power with 2 V and 100mA. I have an LED that has a forward voltage of 2 V and a max current of 20mA.

Should I use a resistor to reduce the current? I see many formulas in the internet saying the the resistor value should be:

(Source Voltage - LED forwared voltage)/LED max current

This formula always worked fine for me, but now that I have a 2 V source power this formula tells me that the resistor should be 0 ohm. Of course this would damage my LED cause the 100mA provided by my source power is way above the 20mA current limit of the lED.


texts:
I am running the program for GY80 10 DOF , and runs fine . Date is printed on the serial monitor
How ever I have failed to use this program for my WalkerBot
(walker bot is a Robotic suit that I want to build for 4 years old my grand son He can not walk due to C P )
Unless the PID is not introduced in the program it will not be good for Balancing of the walker Both the program is as under , and my further questions are in comments
I need help Please
I tried to use the Code Control to insert the codes But it did not work , I may be excused for that Please

the codes

  #include <Wire.h>
  #include <GY80.h>

     GY80 sensor = GY80(); //create GY80 instance

  void setup()
  {
    // initialize serial communication at 115200 bits per second:
    Serial.begin(115200);
    sensor.begin();       //initialize sensors
  }

     // How to envelop this program with PID
     // where the gyro output is supposed to maintain the vertical position of the //bot , and the accelerometer will be doing countermeasure of tilts
// unless they both are on a feedback with PID this bot will not balance
//as the servomotors if do not respond in runtime the bot will fall
void loop()
{
    GY80_scaled val = sensor.read_scaled();       //get values from all sensors
    // print out values

    Serial.print("Mag:");                         //magnetometer values
    Serial.print(val.m_x,2);
    Serial.print(',');
    Serial.print(val.m_y,2);
// tried to get some output from here for using in PID but failed
if(val.m_y,2 >2 ||val.m_y,2<0){Serial.print("Output has been managed");}
but there was no output
    Serial.print(',');
    Serial.print(val.m_z,2);
    Serial.print(' ');
    Serial.print("Acc:");                         //accelerometer values
    Serial.print(val.a_x,3);
    Serial.print(',');
    Serial.print(val.a_y,3);
    Serial.print(',');
    Serial.print(val.a_z,3);
    Serial.print(' ');
    Serial.print("Gyro:");                        //gyroscope values
    Serial.print(val.g_x,1);
    Serial.print(',');
    Serial.print(val.g_y,1);
    Serial.print(',');
    Serial.print(val.g_z,1);
    Serial.print(' ');
    Serial.print("P:");                           //pressure values
    Serial.print(val.p,5);
    Serial.print(' ');
    Serial.print("T:");                           //temperature values
    Serial.println(val.t,1);

    delay(250);        // delay in between reads for stability
}


texts: Why is there a limitation in using Serial.println on ESP8266?

texts:
I'm trying to upload this code on ESP8266, and when I do, it just resets continuously.  This also happens when you have memory bugs, but obviously, this code has no memory bugs!  Here is the code:

#include "Arduino.h"

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

void loop()
{

}

void foo(){
    for(unsigned int i = 1; i <= 10000; i++){
        Serial.println("FOOBAR");
    }
}

Also, in the serial monitor, I get this (per reset):

Soft WDT reset

ctx: cont
sp: 3ffef130 end: 3ffef390 offset: 01b0

>>>stack>>>
3ffef2e0:  feefeffe feefeffe feefeffe 00002580
3ffef2f0:  0000001c 00000001 3ffe85b1 402023d4
3ffef300:  feefeffe 00000005 3ffe842d 3ffee364
3ffef310:  3fffdad0 00000006 3ffee340 40201fd1
3ffef320:  3ffe85b0 00000000 3ffee340 40201fd1
3ffef330:  3ffe8428 00000000 3ffee340 40201fec
3ffef340:  00000001 feefeffe 3ffee340 40202010
3ffef350:  feefeffe 00000000 00002580 40201c00
3ffef360:  3fffdad0 00000000 3ffee35c 40201c2e
3ffef370:  feefeffe feefeffe feefeffe 402021c8
3ffef380:  feefeffe feefeffe 3ffee370 40100718
<<<stack<<<
Õ®(ŽL‰Ì==   I5

So, why is this happening?


texts: Connecting E-paper display (GD) to Arduino?

texts:
I'm still learning how to use Arduino and electrical components, but I will try my best to understand any answers!

So I just bought an e-paper display off a website, not from the manufacturer itself (http://www.good-display.com/products_detail/productId=305.html). The product is a 1.54 inch E-paper display 200x200 partial update GDEP015OC1.

I was a bit puzzled by how to connect the display to the Arduino Uno. Turns out that to connect the display to a board, it needs a breakout board (is this the correct term?). I could buy it online from the manufacturer, however, it will take me at least a month and the shipping cost is too high.

I was wondering if it is possible for me to make my own breakout board? Is there any 'general' breakout board for an e-paper display, or does it have any special from the manufacturer? If it is possible, how difficult would it be for a beginner who has almost no knowledge on circuit building/electrical components?

The aim is just to display an image onto the e-ink display.

Thanks!

edit: I bought the mentioned display because of the size. I was afraid of not knowing how to connect the mention display (which is where I am now), so I bought this e-ink display also: https://www.smart-prototyping.com/E-ink-E-paper-Display-module-3.3V-2.04-inch-177x72.html I was thinking to take the 60mmx30mm display off the board and try connecting the 30mmx30mm display to the 'breakout board' if I am unable to build my own board. Both seemed to have the same pin number (need to confirm later).


texts: Arduino shuts off and doesn't turn on after couple hours

texts:
I use a mega 2560, pir sensor and a SG90 9g Servo motor in my project. Basically while the pir outputs high, the Servo Motor rotates from 0 to 180 degrees.

Here is how everything is wired up:

PIR sensor:

Data: pin 24

Vcc: 5 volt

Gnd: Ground

Servo:

PWM pin: pin 11

Vcc: 5 volt

Ground: ground

The arduino mega has two 5 volt and ground pins, one next to the analog pins and other at tho bottom bar of pin, where pins 22 and up are. I connected the Servo to the first 5v and gnd and the pir to the second.

My power source is my nexus 5 charger(5v 1.8 or 2 A).

My code:

Servo myservo;

    void setup() {
      myservo.attach(11);
     pinMode(24, INPUT);
    }

    void loop() {
     if(digitalRead(24) == HIGH){
       myservo.write(0);
       delay(500);
       myservo.write(180);
       delay(500);
     }
    }

All of this works fine for the first ~10 hours. After that the arduino just shuts down. The power led of the arduino isn't lit up. Disconnecting the adapter and reconnecting it or pressing the reset button of the arduino doesn't work.  I Have to wait for a couple of minutes with the adapter disconnected and reconnect it. After that it works fine for the next ~10 hours.

Seems like a hardware issue, but I'm not sure what exactly fails and why.


texts: sleep mode and watchdog at the same time

texts:
suppose a project with Arduino that we should save battery power, so we use sleep mode and also avoiding the Arduino of hanging and use watchdog timer. But the problem is here that when the Arduino goes to sleep the watchdog timer never(or cant be) reset again because of sleep and it will overflow over and over and reset the Arduino over and over.
so what do you suggest to solve this problem, I mean running sleep mode and watchdog timer at the same time in a code?


texts: Seeeduino V3.0 (Atmega 328P) and Rotary Angle Sensor Mystery Message

texts:
I am attempting to do a simple example with the Rotary Angle Sensor.

Here is my development environment:

Visual Studio 2013 Premium
Arduino Debug Tool

Board setup (Simple as can be single analog input):

Code:

const int ROTARYSENSOR = A0;

void setup()
{
    Serial.println("Setup Start...");
    Serial.begin(9600); //Set the serial communication frequency at 9600 bits per second

    pinMode(ROTARYSENSOR, INPUT);

    Serial.println("Setup End!");
}

void loop()
{
    Serial.println("Loop Start...");

    int value = analogRead(ROTARYSENSOR);
    Serial.println(value); //display on serial monitor
    delay(1000); //wait 1000ms before printing next value

    Serial.println("Loop End!");
}

Issue:

I have a single solution with multiple projects as my sensor playground. All other projects I have so far work flawlessly no issues.  Although with this project (RotaryAngleSensor) I am getting a strange message.

I am not seeing any of the Serial.println() messages. What is printed to the screen after a good 30 seconds is S?

Does anyone know what could be returning this S? to the standard output?


texts: I have a bunch of libraries but all of them are came as .ino files. I need to turn them into .h files

texts: I recently bought an arduino starter pack online, did some poking around, and learned that I have to install the libraries to get them to work for my projects. The issue is, they all came as .ino files instead of the .h that I need. I tried just changing the .ino to a .h file, but it just messed it up. Is there any way to turn the .ino into a .h, or maybe just a way to install the libraries as .ino Please bear in mind that I am using an Uno with Mac-OS. Thanks!


texts: Arduino code does not function when relays are powered

texts: I have a mega arduino, which is supposed to to power 4 relays using 4 touch sensors TTP 223, the relays are 5V coil and 220V. the arduino is powered by a 5 V adapter "mobile phone charger" and it powers the relay module, the problem when the relays are not connected to the 220 V the arduino and code work well; the Arduino triggers the relays, when the 220V circuit is connected and the relays are supposed to operate solenoids the relays start to work differently and sometimes shuts off, some times just blink,the relay module has 8 only 4 are used, 1, 2, 3 and 8 all are NO wired. the module is powered from the 5V  port of arduino, (https://i.stack.imgur.com/o 30IA.jpg) the charger's output is 5V 2A. jd-vcc is jumped with vcc


texts: WS2812B LEDs start flickering after some time

texts:
I've built a WordClock with a NodeMcu and some ws2812b LEDs some time ago and it worked really well for like half a year but now the LEDs are starting to flicker when the WordClock runs longer than some days.
Video of the problem
I've got a 25w meanwell power supply, has this something to do with undervoltage? The strip is connected on both side to the PSU and I've measured stable 5V on the strip back when I installed them.
Any recommendations?


texts: How to connect to LCD and communicate via serial usb simultaneously? (UNO)

texts:
Pretty simple home automation project I am working on. I'm trying to hook my arduino which has a 16x2 LCD, DHT22 temp/humidity sensor to my Pi via usb. I want to be able to maintain the values on the LCD and send the values to the Pi via serial usb.

I am in Arduino IDE currently and can see the serial values in the monitor...however the LCD is all scrambled. Can someone take a look at my code and tell me what I am doing wrong?

#include <LiquidCrystal.h>
#include "DHT.h"

#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal lcd(1, 2, 4, 5, 6, 7);

void setup() {

  lcd.begin(16, 2);
  dht.begin();
  Serial.begin(9600);
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  float f = dht.readTemperature(true);

  if (isnan(h) || isnan(t) || isnan(f)) {
    lcd.print("Failed to read from DHT sensor!");
    return;
  }

  lcd.setCursor(0,0);
  lcd.print("Temp = ");
  lcd.print(f);
  lcd.setCursor(0,1);
  lcd.print("Humidity = ");
  lcd.print(h);
  lcd.clear();

  Serial.println(f);
  Serial.println(h);
}


texts: i2c of Atmega 328 on arduino uno not working

texts:
I am using Arduino uno board with Atmega 328 for i2c.
The ic is not showing any clock signal on its SCL line on oscilloscope, The same code when used with different new atmega 328, and same code. It is showing a good clock signal on oscilloscope.

The ic whose i2c is not working can be still programmed and can be used for other purposes like serial communication , adc etc.

So, is there any way by which i can confirm and surely say that i2c of my atmega 328 is fried up. And what can be the possible methods by which it can be fried up.


texts: How do I directly access a memory mapped register of AVR with C

texts:
Assume I want to write the following without using DDRD or PORTD:

#include <avr/io.h>
#include <util/delay.h>

int main(void) {
    DDRD = 0xFF;
    PORTD = 0xFF;
}

I found this link which includes a list of mapped registers to memory addresses:
https://github.com/DarkSector/AVR/blob/master/asm/include/m328Pdef.inc

So I replaced one of the keywords with a pointer:

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
    DDRD = 0xFF;
    unsigned char *portd = 0x0b;
    *portd = 0xFF;
}

But it's not working (my LED isn't turning on with the second code). Why is that?


texts:
I need your help. I have purchased and mounted an arduino pro micro handbrake from AliExpress on my playseat which plays just fine on my computer. My ps4 though does not register it at all. It doesn't even show up in the connected devices. I have zero knowledge on what code it uses or how I can access it.
Is there a way I can make it work on my ps4? Maybe an external mod I can purchase? Or maybe could I connect it to my pc and tweak the code so it can recognize it? Thank you


texts:
If I connect a 12V / 12V+ battery to the arduino (uno) analog, will it be damaged ? What if I connect 230-240V to it ? Don't worry I haven't tried it yet. :D

Thanks in advance.


texts: dns lookup only works with DHCP and not with static setup (EtherCard library)

texts:
When I use DHCP with ether.dhcpSetup() the DNS lookup for NTP ether.dnsLookup("0.pool.ntp.org") works fine, but when I use a static setup (because my Android app needs to know the IP address) with ether.staticSetup(myip); then this returns false and I don't get an IP address from the NTP pool. How come?

I have an Arduino Nano ATmega328 with a ENC28j60 ethernet shield, and therefore use the EtherCard libray.

Full MWE:

#include <EtherCard.h>      // https://github.com/jcw/ethercard
#include <Time.h>           // http://www.arduino.cc/playground/Code/Time

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
static byte myip[] = {192, 168, 2, 106};
const char poolNTP[] PROGMEM = "0.pool.ntp.org"; //pool to get time server from
uint8_t ntpMyPort = 123; //port for the time server, no idea why needed

byte Ethernet::buffer[700];

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

 //do not forget to add the extra '10' argument because of this ethernet shield
  if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) {
    Serial.println(F("Failed to access Ethernet controller"));
  }

  //static setup
  ether.staticSetup(myip);
  ether.printIp("Address: http://", ether.myip);

 //this works
//  if (!ether.dhcpSetup())
//    Serial.println(F("DHCP failed"));

  //Find ip address of a time server from the pool
  if (!ether.dnsLookup(poolNTP)) {
    Serial.println("DNS failed"); //with static setup this line is executed, not so with DHCP
  }
  ether.printIp("Lookup IP   : ", ether.hisip);
}

void loop () {}


texts:
What should one expect when the following program runs on Arduino Uno?

void setup()
{
    Serial.begin(9600);
    DDRD |= 0b11;
}

void loop()
{
    PORTD |= 0b11;
    delay(100);
    Serial.print("ABCD");
    PORTD &= ~0b11;
    delay(100);
    Serial.print("DEFG\n");
}

When Serial.begin() is used, the pins PD0, PD1 might be configured as UART pins. After that if DDR is used, are the pins configured as GPIO, or are they still UART Rx, Tx pins?


texts: Controlling DC motor with Pololu shield Arduino

texts:
I'm trying to power 2 DC motors with my Pololu DRV8835. I'm using the code found in this library. It works as expected BUT ONLY if the whole thing is powered via USB. When I try to power it through the shield with an external battery, the motors only beep. So the program AND the wiring have been tested.

PS.: I've also measured the voltage across the shield (M1A-M1B, M2A-M2B) and they only get like .01 V when powered via external battery. Also I'm using and Arduino Due.


texts:
Sorry if this question been posted but I couldn't find the one that matches my issue. I couldn't pass my struct values from the main file to a class. Any ideas? I got this:

error: no matching function for call to 'ODriveArduino::SetParam(R_motor_params&)'

Main.cpp:

#include ODriveArduino.h
ODriveArduino odrive(Serial1);

struct L_motor_params{
 int axis=1;
 float vel_Gain= 2.5f/10000.0f ;
 float pos_Gain= 40.0f;
 float vel_Int_Gain= 0.0f/10000.0f;
};
struct R_motor_params{
 int axis=0;
 float vel_Gain= 2.75f/10000.0f ;
 float pos_Gain= 40.0f;
 float vel_Int_Gain= 0.0f/10000.0f;
};

void setup() {
  struct R_motor_params M;
  odrive.SetParam(M);
}

ODriveArduino.h:

class ODriveArduino {

private:

    struct motor_Params{
      int axis;
      float vel_Gain;
      float pos_Gain;
      float vel_Int_Gain;
    };

public:
    ODriveArduino(Stream& serial);

    // Commands
    void SetParam(struct motor_Params M);

 }

ODriveArduino.cpp:

#include "ODriveArduino.h"
template<class T> inline Print& operator <<(Print &obj,     T arg) { obj.print(arg);    return obj; }
template<>        inline Print& operator <<(Print &obj, float arg) { obj.print(arg, 4); return obj; }

ODriveArduino::ODriveArduino(Stream& serial)
    : serial_(serial) {}

void ODriveArduino::SetParam(struct motor_Params M){
  Serial1 << "w axis" << M.axis << ".motor.config.pos_gain " << M.pos_Gain << '\n';
  Serial1 << "w axis" << M.axis << ".motor.config.vel_gain " << M.vel_Gain << '\n';
  Serial1 << "w axis" << M.axis << ".motor.config.vel_integrator_gain " << M.vel_Int_Gain << '\n';
}


texts:
I want to know if it is possible to send an SMS from a SIM900 using Arduinos to another SIM900.

Problem: When the gsm is connected to the network, it does not send an sms; my airtime balance remains the same.

Here is the code I used:

#include <SoftwareSerial.h>
SoftwareSerial SIM900 (9,10);

void setup()
{
   serial.begin(9600);
   SIM900.begin(9600);
   delay(5000);
}

void loop()
{
   sendSMS();

   while(SIM900.available()!=0)
     {
        Serial.println(SIM900.read());
     }
}

void sendSMS()
{
    SIM900.println("AT+CMGF=1\r");
    delay(100);
    SIM900.println("AT+CMGS=\"+27769384488"\r");
    delay(100);
    SIM900.println("Hello");
    delay(100);
    SIM900.println((char)26);
    delay(100);
    SIM900.println();
    delay(5000);

}


texts:
I am building an electronic gadget eventually to sell.

I think the Atmega IC is used in the arduino and could this be programmed as easily as the arduino?

I'm wondering if I can use the chip and buy just what I need for my circuit, which would be cheaper as there would be no licensing obligations to the Arduino company

Cheers
Eamonn


texts: Make Arduino Nano 33 IOT talk to another Arduino via Bluetooth

texts: I have an Arduino Nano 33 IOT and I want it to talk to another Arduino that has an HC-05 Bluetooth module. Is this possible? I cannot find anything on the internet that talks about doing this.


texts:
I'm trying the following code on an Uno. I'm pulling the high side of a pull down 10K resistor to 5V, but it can only be woken once. Just once. Does anyone know why this might be the case?

It works fine if I use LOW for attachInterrupt along with a pull-up resistor though. Just not with RISING and a pull-down.

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

int pin2 = 2;

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

  /* Setup the pin direction. */
  pinMode(pin2, INPUT);

  Serial.println("Initialisation complete.");

}

void pin2Interrupt(void)
{
  /* This will bring us back from sleep. */

  /* We detach the interrupt to stop it from
   * continuously firing while the interrupt pin
   * is high.
   */
  detachInterrupt(digitalPinToInterrupt(pin2));
}

void enterSleep(void)
{

  sleep_enable();

  /* Setup pin2 as an interrupt and attach handler. */
  attachInterrupt(digitalPinToInterrupt(pin2), pin2Interrupt, RISING);
  delay(100);

  set_sleep_mode(SLEEP_MODE_PWR_DOWN);

  sleep_mode();

  /* The program will continue from here. */

  /* First thing to do is disable sleep. */
  sleep_disable();
}

int seconds=0;
void loop()
{
  delay(1000);
  seconds++;

  Serial.print("Awake for ");
  Serial.print(seconds, DEC);
  Serial.println(" second");

  if(seconds >= 3)
  {
    Serial.println("Entering sleep");
    delay(200);
    seconds = 0;
    enterSleep();
  }
}


texts: Pair of nRF24L01s ping/pong example sketch works, but using my own code fails after first successful transmit

texts:
I have a pair of nRF24L01s connected to a pair of Arduino Unos and I'm using the RF24 library from here: RF24 library. When I run the pingpair example sketch, the radios transmit and receive back and forth just fine. So I tried to program my own very simple example but I'm running into a problem where the first message transmits successfully (and is received successfully), however, subsequent messages fail to send. The call to radio.write() returns false.

I'm using the following code on the 'sender':

RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
uint8_t payload[1];

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPayloadSize(1);
  radio.openWritingPipe(pipes[0]);
}

void loop() {
  payload[0] = 1;
  bool ok = radio.write(payload, 1);
  Serial.println("Status: " + (String) ok);
  delay(200);
}

And the following on the 'receiver':

RF24 radio(9,10);
const uint64_t pipes[2] = { 0xF0F0F0F0E1LL, 0xF0F0F0F0D2LL };
uint8_t payload[1];

void setup() {
  Serial.begin(9600);
  radio.begin();
  radio.setRetries(15, 15);
  radio.setPayloadSize(1);
  radio.openReadingPipe(1, pipes[0]);
  radio.startListening();
  Serial.println("Listening: " );
}

void loop() {
  if (radio.available()) {
    bool done = false;
    while (!done) {
      done = radio.read(payload, 1);
      Serial.println("Got payload: " + (String) payload[0]);
    }
  }
}

I'm guessing the problem has to be with my code because the example sketches work, but I can't figure out what the problem is. Again to summarize, when I reset the Arduino, the first call to radio.write() returns true and the message is transmitted. After that, subsequent calls to radio.write() return false.

Also note that I did try adding a 10uF capacitor across +3.3V and Ground but it did not help.

Thanks for any help.


texts: How does Arduino determine whether the given condition provided to it is true or false?

texts:
I want to understand how does the microcontroller determine that the conditions provided to it in the input are true or false. eg:

if (someVariable > 50)
{
  // do something here
}

Then how does Arduino determine if the value that I put in `somevariable' is larger than 50 (as apposed to less than or equal to 50)?


texts:
I have a buzzer and an IR led emitter so I have to use the tone function to sound the buzzer and to modulate the output of the LED.
I have connected the led pin 5 of the arduino, the buzzer pin A0.

int tones[] = {261, 277, 294, 280, 230};
const int pinBuzzer = A0;
const int cr_pin = 5;

void setup(){
  Serial.begin(1200);
  tone(cr_pin, 38000);  /* For modulation at 38kHz */
  pinMode(pinBuzzer, OUTPUT);
}

void soundBuzzer() {
  for (int i = 0; i < sizeof tones; i ++) {
    tone(pinBuzzer, tones[i]);
  }
    noTone(pinBuzzer);
}

void irLED() {
  Serial.println("Hello");
}

This is my code but I can not make the led and the buzzer work at the same time, apparently the buzzer is affected by the tone line (cr_pin, 38000); / * For modulation at 38kHz * /.

I tried to remove (cr_pin, 38000); / * For modulation at 38kHz * /. of the setup and leave code in the following way.

int tones[] = {261, 277, 294, 280, 230};
const int pinBuzzer = A0;
const int cr_pin = 5;

void setup(){
  Serial.begin(1200);
  pinMode(pinBuzzer, OUTPUT);
}

void soundBuzzer() {
  for (int i = 0; i < sizeof tones; i ++) {
    tone(pinBuzzer, tones[i]);
  }
    noTone(pinBuzzer);
}

void irLED() {
tone(cr_pin, 38000);  /* For modulation at 38kHz */
      Serial.println("Hello");
noTone(cr_pin);
    }

In the first code the LED works but not the buzzer and in the second code the buzzer now works but not the LED.


texts: Voltmeter using Arduino mega 2560 giving unexpected result after some time

texts:
I have been trying to construct a smart energy meter that can observe readings of 220v household. For now i am working on voltmeter. I have been following the circuit I attached. Transformer step down 220V to 6V. Zener diode is of 5V.
The output from the circuit( 5v max) is fed to arduino Mega 2560 A0 pin.
* I am powering arduino using a USB cable *
Arduino takes this voltage as input from pin A0 in form of analog values between 0 to 1023. 0 being 0 volt and 1023 being 5v.So any random analog value corresponds to X=(5/1023)*Y where Y is obtained analog value. X is then multiplied by a value obtained by hit and try method (165 in my case) to reach the exact reading of voltage in line observed via multimeter.
Now the problem is that, everything works fine when i calibrate it, but after some time when i switch circuit on the value is inaccurate by margin, and i have to calibrate it again and again every time I turn circuit on after some time.If i switch circuit on soon after switching it off, it gives almost accurate value. I guess this issue is due to the capacitor, but i don't know anything about it or how to solve it I have constructed the same circuit more than 5 times, soldering it 3 times and 2 times on bread board and i am sure there is no problem with my implementation, verified it many times.
this is my code:

float V; // Voltage samples
float V0;

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

void loop() {
  for(int i=0; i<=20000; i++){
    V = V + analogRead(A0);
  }
  V = V / 20000;
  V = round(V);

  float V0 = V * (5.0 / 1023.0);
  I0 = I0 * 165; // has to be callibrated again and again each time circuit is switched on after a while

  Serial.print("Voltage = ");
  Serial.print(V0);
  Serial.println(" -------------- ");
  delay(1500);
}

this is the link i am following
http://engineerexperiences.com/3-phase-smart-energy-meter-using-arduino.html

Any help would be appreciated, Thanks!


texts:
I am a newbie in Arduino and serial communication. I am working on a project that use Arduino to send data bits to an actuator using RS232 communication protocol. In order to control the actuator, an instruction consists of 6 bytes must be sent with 9600 baud, no hand shaking, 8N1 format.

Here are the instructions:
Byte 1 - Device, Byte 2 - Command, Byte 3 - Data(LSB), Byte 4 - Data, Byte 5 - Data, Byte 6 - Data(MSB)

For example to send 1, 20, 1, 1, 0, 0 (Move the actuator to absolute position of 257 microsteps)

This is my draft code. How can I send start and stop bit? I am confused on sending start and stop bit. The Serial.write() is sending binary data as a byte. Does it mean that I write Serial.write(20), the compiler will send the data in 00010100 binary format? I am quite frustrated with serial communication.


texts:
include SPI.h
include Ethernet.h
include Modbus.h
include ModbusIP.h

//Modbus Registers Offsets (0-9999)
const int SENSOR_IREG = 100;
//Used Pins
const int sensorPin = A0;

//ModbusIP object
ModbusIP mb;

long ts;

// Set Port to 502
EthernetServer server = EthernetServer(502);

void setup() {
  //Assign the modbus device ID.
  regBank.setId(1);

    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    byte ip[] = { 192, 168, 1, 177 };

    mb.config(mac, ip);

    // Add SENSOR_IREG register - Use addIreg() for analog Inputs
    mb.addIreg(SENSOR_IREG);

    ts = millis();

}

void loop() {

   //Call once inside loop() - all magic here
   mb.task();

   if (millis() > ts + 2000) {
       ts = millis();

       mb.Ireg(SENSOR_IREG, analogRead(sensorPin));
   }
}

I am trying to read data from the first analog pin through ModbusTCP using SimplyModbusTCP but I keep getting errors when I poll my Arduino. I am using an Arduino UNO with a Ethernet Shield W5100 and Modbus Library. I am request data from Ip address 192.168.1.177 Port:502 Slave:1 and Function Code:03. The error I get is "Error 66 occurred at TCP Read in SMT8.0.vi. LabVIEW: The network connection was closed by the peer."


texts: Blink doesn't work on pin D3,D4 and D0 but works on D7

texts:
I am facing a strange issue. I am trying to blink an external LED using Wemos D1 mini V2 board. But it is not working. My sketch is as below.

int LED = D3;
void setup()
{
  pinMode(LED, OUTPUT);
}
void loop() {
  digitalWrite(LED, LOW);   // LED off
  delay(1000);              // Wait 1 second
  digitalWrite(LED, HIGH);  // LED on
  delay(1000);              // Wait 1 second
}

The same problem happens on D0, D3, and D4 pins. I am getting 0 volts constantly on pin D0 and 3.3v constantly on pins D3 and D4.

However, The same sketch works for the D7 pin.

Does anyone know how to fix this?


texts: How to enable maximum Dead Code Removal?

texts:
I am running out of code and data memory space on ATMega328P.

Code size is big as I used several libraries, but, I only use a few functions of those library.

Apparently, the default IDE is only doing a partial job in dead code removal (remove unreferenced code and data).

Some experiments shows:

A normal program that uses several Arduino libraries is 22 kilo bytes in code size.
Rename setup to o_setup.
Rename loop to o_loop

Add

void setup(){};

void loop(){};

Code size is 8 kilo bytes while the program is 'empty' effectively.
Start a new program.

Add

void setup(){};

void loop(){};

Code size is 0.5 kilo bytes

Apparently, the IDE (linker called by IDE) is doing a 'partial' dead code removal job, as reducing code from 22kB to 8kB (case 1 and 2), instead of 0.5kB (case 3).

How can I enable maximum dead code removal function (reclaim code space occupied by unused library functions)?