texts: why this unexpected behaviour shows when i use the following code to send the data from the ultrasonic distance sensor to firebase

texts:
I am using nodeMCU esp8266 wifi module to send the data received by the ultrasonic distance sensor to the firebase.
here is my code:

#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <FirebaseArduino.h>

//Firebase settings
#define FIREBASE_HOST "dis3333333333333333aseio.com"
#define FIREBASE_AUTH "Lb21333333333333333333v6HzPatg1HA"

//Wi-Fi settings
#define WIFI_SSID "hello"
#define WIFI_PASSWORD "123456789"

//Define trigger and echo digital pins
const int trigPin = 5;
const int echoPin = 4;

// The amount of time the ultrassonic wave will be travelling for
long duration = 0;
// Define the distance variable
double distance = 0;
double cm=0;
double statusTemp=0;
int temp=0;
unsigned long time_now=0 ;
unsigned long time_prev=0 ;
String stringOne="consump/day";
String stringTwo;

void setup()
{

    Serial.begin(9600);
    // Connect to Wi-Fi
    Serial.print("Wi-Fi...");
    WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
    Serial.print("Connecting...");
    while (WiFi.status() != WL_CONNECTED)
    {
        Serial.print(".");
        delay(500);
    }
    Serial.println();
    Serial.print("Connected to: ");
    Serial.println(WiFi.localIP());

    Firebase.begin(FIREBASE_HOST, FIREBASE_AUTH);

    // Ultrasonic sensor, set echo as Input and trigger as Output

}

void loop()
{

    getDistance();
    time_now = millis();

    Serial.print("Distance: ");
    Serial.println(distance);

    delay(500);
}

void getDistance()
{
    pinMode(trigPin, OUTPUT);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(2);
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10);
    digitalWrite(trigPin, LOW);
    pinMode(echoPin, INPUT);
    Serial.print("Time: ");
    Serial.println(time_now);
    if(statusTemp==0){
      time_prev=time_now;
      statusTemp=1;
      Serial.println("Hello");
    }
    if(statusTemp==1)
    {
      if((time_now - time_prev)> 10000){
        statusTemp=0;
        stringTwo=stringOne+temp;
        Serial.print(stringTwo);
        Firebase.setFloat(stringTwo, distance);
        temp++;
        Serial.print(temp);
      }
        duration = pulseIn(echoPin, HIGH);

        distance = duration * 0.034 / 2;
        Firebase.setFloat("distance", distance);
        if (Firebase.failed()) {
        Serial.print("setting /number failed:");
        Serial.println(Firebase.error());
        return;
    }
 }
}
long microsecondsToCentimeters(long microseconds) {
   return microseconds / 29 / 2;
}

It works totally fine but after some time the below thing appears

Is the following thing happening due to my code or something else is causing this.


texts:
I don’t have a sketch for this project, just doing some thinking before I pullout the keyboard (this is my phone).  I was interested in writing a program that uses a predetermined time limit, for instance having a definition like...

#define RUNTIME 30000

So the game runs for 30 seconds.
By doing this it would be a simple matter of changing the 30000 to 60000 and uploading to the Arduino.

After thinking about that a while, I would prefer to be able to adjust the time using a selector switch.
So my question is....  if I use a 1p4t (on-on-on-on) rotary selector switch,  assign each position to a pin and run 5v to the common. Each pin would defined as RUNTIME and a different time limit, 30000, 60000, 90000, 120000, three pins would be LOW and one HIGH depending on position.
Then using IF and ELSE statements in the loop setup would I be able to switch the times?  I know once the Arduino is powered up the selector switch would need to be at the correct location and if you choose to change the “RUNTIME” a reset would need to be pressed.

Thank you for any assistance or ideas.


texts:
How would you send a struct from an i2c slave when requested by an i2c master?
Slave Struct Respdonder Sketch (Seeeduino Xiao)
#include <Wire.h>

struct TransmitData
{
  int a;
  int b;
  int c;
  int d;
  float e;
  float f;
  float g;
  float h;
};

TransmitData data;

void setup()
{
  Serial.begin(9600);
  Wire.begin(2);
  Wire.onRequest(requestEvent);

  data.a = 1;
  data.b = 2;
  data.c = 3;
  data.d = 4;
  data.e = 5.1;
  data.f = 6.1;
  data.g = 7.1;
  data.h = 8.1;
}

void loop()
{
  delay(100);
}

void requestEvent()
{
  Serial.print("sending ("); Serial.print(sizeof data); Serial.println(" bytes)");
  Wire.write((byte *)&data, sizeof data);
}

Master Struct Requester/Reciever Sketch (Arduino MEGA)
#include <Wire.h>

struct TransmitData
{
  int32_t a;
  int32_t b;
  int32_t c;
  int32_t d;
  float e;
  float f;
  float g;
  float h;
};

TransmitData data;

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

void loop() {
  Serial.print("requesting ("); Serial.print(sizeof data); Serial.print(" bytes)... ");
  if (Wire.requestFrom(2, sizeof data)) {
    Wire.readBytes((byte*) &data, sizeof data);
    Serial.println("done");

    Serial.println(data.a);
    Serial.println(data.b);
    Serial.println(data.c);
    Serial.println(data.d);
    Serial.println(data.e);
    Serial.println(data.f);
    Serial.println(data.g);
    Serial.println(data.h);
  }
  else {
    Serial.println("could not connect");
  }
  delay(500);
}

The serial output on the slave device is:
sending (32 bytes)

The serial output on the master device is:
requesting (24 bytes)... done
1
0
2
0
0.00
0.00
5.10
6.10


texts: 5 switches, 5 leds, 5 tones, in an Array

texts:
The idea is when a switch is pushed, the corresponding tone will be played as well as lighting up the corresponding LED. I have the circuit set up to where each array matches another, for example Switch one will play tone 1 and light LED 1. When the switch is released the LED turns off and the tone no longer plays.

However I have to use an Array for the sketch instead of declaring each individual switch, led, and tone.  My issue is when I compile the code, I get the error message "i" is not declared.  Not sure where my error is within the for loop in the setup portion of the sketch.

I tried following the example from the Exploring Arduino web page but it did not help.

#define NOTE_C   262 //HZ
#define NOTE_D   294 //HZ
#define NOTE_E   330 //HZ
#define NOTE_G   392 //HZ
#define NOTE_A   440 //HZ

const int SPEAKER = 9;   //speaker on pin 10
int LED[5] = {13, 12, 11, 10, 8};   //led pins
int ledcount = 5;
int buttonState;
int buttonState1;
int buttonState2;
int buttonState3;
int buttonState4;

//Button Array
int Buttons[5]= {3, 4, 5, 6, 7};
int ButtonCount = 5;
const int numButtons = sizeof(Buttons) / sizeof (Buttons[0]);

//Tone Note Array
int Notes[5] = {NOTE_C, NOTE_D, NOTE_E, NOTE_G, NOTE_A};

void setup()
{
  for (int i = 0; i < sizeof (Buttons) / sizeof(Buttons[0]); i++){
  pinMode(Buttons[], INPUT);
}
  for (int i = 0; i < sizeof (LED) / sizeof (LED[0]); i++);{
  pinMode(LED[], OUTPUT);
}
  for (int i = 0; i < numButtons; i++){
  pinMode(Buttons[i], INPUT);
  debouncer[i].attach(Buttons[i]);
  debouncer[i].interval(100);
}
  buttonState = digitalRead(Buttons[0]);
  buttonState1 = digitalRead(Buttons[1]);
  buttonState2 = digitalRead(Buttons[2]);
  buttonState3 = digitalRead(Buttons[3]);
  buttonState4 = digitalRead(Buttons[4]);
}

void loop()
{

  if (buttonState == HIGH)
  { tone(SPEAKER, Notes[0]);
  digitalWrite(LED[0], HIGH);
  }
  else if (buttonState1 == HIGH)
  {tone(SPEAKER, Notes[1]);
  digitalWrite(LED[1], HIGH);
 }
  else if (buttonState2 == HIGH)
  {tone(SPEAKER, Notes[2]);
  digitalWrite(LED[2], HIGH);
 }
  else if (buttonState3 == HIGH)
  {tone(SPEAKER, Notes[3]);
  digitalWrite(LED[3], HIGH);
 }
  else if (buttonState4 == HIGH)
  {tone(SPEAKER, Notes[4]);
   digitalWrite(LED[4], HIGH);
 }

  else
 {
  digitalWrite(LED[5], LOW);
  noTone(SPEAKER);
 }
}


texts: Arduino unstable analog reading when using power supply

texts:
As soon as I unplug my Arduino from USB and only use the VIN pin with my 9 V power supply, the analog readings from my Arduino start to get unstable, which means the value fluctuates much more than with USB connected. When I reconnect USB again, the readings are stable again.

I'm trying to build a load scale using a load cell, an INA125P and the Arduino, using this setup here: Instrument Amplifier Calibration.

Therefore I need stable readings. For example, I wrote some code to convert the analogRead() value to grams. While USB and VIN (9 V) connected, I get a stable reading of about 8.3 to 8.7 grams when I put a weight of 8.5 grams on the scale. As soon as I unplug USB, the LCD shows values from 7.8 grams up to 9 grams.

Unfortunately, I don't have any other power supply which I could use to test. I've already tried to use a 9 V battery with the same results. Do I maybe need some additional de-coupling capacitors?


texts: Using arduino uno and an adafruit shield to control 3 dc motors and a linear stepper motor

texts:
Hello I am currently doing a project at my university which requires me to order and program 4 motors using an arduino. I will be using an arduino uno and an adafruit motor shield. 2 of the dc motors will have an encoder for better motor control. While connecting the linear and one of the dc motors shouldn't be difficult, I am wondering how can I connect the two motors with encoders.
I was thinking to connect 1 dc motor and the stepper onto one shield and the encoder motors onto another since the shields can stack. Is this option possible or should I use some other method? I am fairly new to arduino and only had a little bit of experience with coding so any help and suggestions are welcome.


texts: What are the basics in writing a program in Arduino?

texts: I am an undergrad in ICE. I was searching for ideas to do mini projects on and found this Arduino boards and programs. So actually what are the basics to develop our own gadgets? Any guidelines...?


texts:
I need a small display with ~ 5 digits.
The display needs to show number of visits to my site in real-time.

(Every time someone visits it needs to increase by one).

I thought to create an app, that fetches server stats every 10 seconds, and checks new number of visitors.

Do you think it is better to do with Arduino or Raspberry Pi?

Do you know of a digits monitor that can be connected to it?


texts: Can the Arduino 101 extension by MIT App inventor be used in sending data through Bluetooth by an Arduino Uno/Mega?


texts: How to install your own library with Arduino IDE 1.8.5?

texts:
I'm struggling a bit with Arduino language + its IDE not being 100% real C++. I wrote my own I2C library for a sensor but can't get the IDE's compiler to recognise it. I'm using Ubuntu 18.04.

I get no such file or directory for all of these things I've tried:

Include the .h file by absolute and relative path in the .ino code
Put .cpp +  .h files in ~/Arduino/libraries
Put .cpp +  .h files in ~/sketchbook/libraries
Put .cpp +  .h files in ~/sketchbook/libraries/mylibrary
Put .cpp +  .h files in ~/sketchbook/libraries/mylibrary and try to "install" the library in the IDE (Sketch -> Include library -> Manage libraries; it's not listed)

I'm following the official guide here. Any ideas on how to get the compiler to recognise my library?


texts: Trying to power multiple servos at once using a Arduino Mega

texts:
Recently I have been trying to do a project for my end of year project, it involved making a humanoid arm.

I am still a newbie at these things, I usually have my friend do the wiring, but since he is away for the moment can anyone help me with it?

I am currently using 6X MG996R Servos for each finger and 1 for the wrist. I am also using a Arduino Mega with a Adafruit 16-Channel 12-bit PWM/Servo Shield - I2C interface.

I have already searched through the web for the best way to power it but I only found people trying to power it with a 5v adaptor, my problem is I'm trying to make the hand mobile so I need to use a battery. I have tried 2x UltraFire 18650 3000mAh 3.7V rechargeable battery in series (still doesn't work only 1 servo moved), also using a 9v battery (Only moved 2 servos).

So i have been wondering if I could utilise the Adafruit 16-Channel 12-bit PWM/Servo Shield - I2C interface..


texts:
I have a very basic script that is supposed to display something to the serial monitor but no matter what I try the serial monitor won't display anything...I;ve watched about 5 tutorials now and each one has failed to display anything. Any ideas what I'm doing wrong?

Here is my code:

char rx_byte;

void setup() {
  Serial.begin(115200);
  pinMode(13, OUTPUT);
  digitalWrite(13, LOW);
}

void loop() {
  if(Serial.available() > 0){
    rx_byte = Serial.read();
    Serial.print("You typed: ");
    Serial.println(rx_byte);
    digitalWrite(13, HIGH);
    delay(1000);
    digitalWrite(13, LOW);
  }
}


texts:
I'm working with this http://knolleary.net/arduino-client-for-mqtt/. I'm using Arduino Uno + Ethernet shield + Tinkerkit Shield. But, if i have only Arduino Uno + Ethernet Shield, i can connect my arduino with MQTT and make publish/subscribe, but, when i put the tinkerkit shield, i lost the connection and i cannot connect any more. Any idea? Tinkerkit sensor shield is incompatible with mqtt?

Thanks.


texts: I want to run an arduino board at a slower - but more accurate - clock speed. What (if anything) needs to be changed in the arduino code/libraries in order to achieve this? Normally the boards I use run at 16MHz, but I wish to derive a 10MHz clock from a GPS timing module and run the ATMEL processor off the 10MHz timing clock.


texts: Can't program Arduino via Bluetooth (HC-06) with a Mac

texts:
I bought a HC-06 Module for my Arduino Uno the other day, yesterday it arrived and I'm having trouble using it with the Arduino IDE.

I set it up, connecting 5V, GND and RX/TX crossed. After a bit of searching, it shows up on the bluetooth settings on the macbook. When I click "connect", it fails, after I click "Options", then set the Pin to 1234 it says "Connected". The LED on the HC-06 is still blinking (which is OK I guess, since I'm not yet communicating).

I have a Sketch running on the Uno that prints out some text. When I open the serial monitor (after connecting like above) it works, displaying the values I expect. However, after closing the serial monitor the HC-06 changes to "not connected" on the mac.

Also, if I try to upload code via the Arduino IDE it states: avrdude: ser_open(): can't open device "/dev/tty.HC-06-DevB": Resource busy
ioctl("TIOCMGET"): Inappropriate ioctl for device or throws a processing.app.SerialException: Fehler beim Öffnen des seriellen Ports "/dev/tty.HC-06-DevB". (German for "Error while opening Serial Port "/dev...." ").

Do I have to configure the HC-06 or the Arduino IDE in any way to make this work, and, if so, how can I do that?

Edit:
I've also connected TX and RX uncrossed, though that alone doesn't solve the problem.

Thanks in advance for your Support!


texts: Controlling LED from Aux Switch on RC Controller thru Arduino Uno

texts:
I am trying to control an LED to go on and off using the Aux Switch (SwA) of an RC controller (FS-iA6B). I have gotten the serial read to work but am stuck trying to implement basic Arduino LED code and the RC code. I can see it on Serial Monitor and Plotter using the code below (this is not the full tank code). This is for an RC Tank that I built. The Tank moves great and the Servos for the Gun Turret are finally working. But I can't seem to get the LED to turn on and off. I am new to coding so I was wondering if anyone had any suggestions. Thank you.
PWM READ CODE
    int ch1,ch2,ch3,ch4,ch5;
    const int in1 = A0, in2 = A1, in3 = A2, in4 = A3, in5 = A4;

    void setup() {
      Serial.begin(9600);
      pinMode(in1, INPUT);
      pinMode(in2, INPUT);
      pinMode(in3, INPUT);
      pinMode(in4, INPUT);
      pinMode(in5, INPUT);
    }

    void loop() {
      ch1 = pulseIn(in1, HIGH, 35000);
      ch2 = pulseIn(in2, HIGH, 35000);
      ch3 = pulseIn(in3, HIGH, 35000);
      ch4 = pulseIn(in4, HIGH, 35000);
      ch5 = pulseIn(in5, HIGH, 35000);

      Serial.print("1: ");
      Serial.print(ch1);
      Serial.print(", 2: ");
      Serial.print(ch2);
      Serial.print(", 3: ");
      Serial.print(ch3);
      Serial.print(", 4: ");
      Serial.print(ch4);
      Serial.print(", 5: ");
      Serial.println(ch5);
    }


texts:
I am using HC-05 Bluetooth module to control two servos. I use Bluetooth terminal in my android phone to control them.

Problem is that myServo1 is moving like I want but I can't control myServo2. Code is reading the variable a but it can't read variable b.

#include <SoftwareSerial.h>
#include <Servo.h>
Servo myServo1;
Servo myServo2;
int servo;
SoftwareSerial BT(2, 3);
void setup()
{
myServo1.attach(11);
myServo2.attach(10);
servo = 90;

Serial.begin(9600);
BT.begin(9600);
}
char a;
char b;
void loop()
{
 if (BT.available())
{
a=(BT.read());
b = (BT.read());
if (a=='1')
{
  myServo1.write(180);
  delay(50);

}
if (a=='2')
{
  myServo1.write(-180);
  delay(50);

 }
  if (b=='3')
{
  myServo2.write(90);
  delay(50);

}
  if (b=='4')
{
  myServo2.write(-90);
  delay(50);

}
}
}

Where is the problem?


texts: Student Project Inquiry(Building a Self Balancing robot)

texts:
I am currently building a self balancing robot using an L298N motors driver,and MPU6050 using an arduino microcontroller.

I managed to control my motors movements with no issues. After I extracted the data from my MPU6050 which was easy by using MPU6050 library I faced a problem: When linking the motors movement according to MPU6050 readings, the sensor freezes and stops showing its data on the serial monitor after giving couple of readings, the motors keep moving. I even have capacitors soldered into my motors to filter the noise. I am definitely sure my sensor works perfectly because it was tested before implemented into the motors drivers circuit and code.

If anyone can give me any hints why does the MPU sensor stop giving readings please.

Thanks.


texts: Read BLE Characteristic Value in Arduino Uno

texts:
I am trying to build a Smart Led project using Arduino Uno, RGB Led, HM-10 BLE module, and Android device.

I am able to connect HM-10 with my android device and read and write characteristic values using Android BlueDroid stack.

But for this project to work I need to check changes in characteristic value in Arduino and process color value and produce output to light up LED.

I thought I could possibly use AT commands (like AT+Name? AT+POWE? AT+CHAR?) parse their result , but I couldn't find any AT command to read characteristic value. If anyone know such working AT commands for HM-10, please answer?

Also, I looked into CurieBLE library from Intel for Arduino. I think the library is to work on an Arduino board which has BLE hardware as a built-in feature. If that's not the case, please help me how can I communicate Arduino and HM-10 using CurieBLE or any other available library?


texts: Using Capacitive Sensing Library with a 74HC4067 multiplexer

texts:
I'm trying to use the Capacitive Sensing Library by Paul Badger in conjunction with one or more 74HC4067 multiplexers to achieve a lot of capacitive touch inputs. I came across this youtube video where the poster seems to have accomplished what I'm trying but I can't seem to replicate this.

Here is the setup I'm using with an arduino nano, some 1MΩ resistors and a CD74HC4067 breakout :

Here is my Arduino code :

#include <CapacitiveSensor.h>

#define muxS0Pin 7
#define muxS1Pin 6
#define muxS2Pin 5
#define muxS3Pin 4
#define muxSignalPin 3
#define muxEnPin 8
#define capSenseSendPin 2
#define sampleRate 5

int touch[4] = {};

CapacitiveSensor capSense = CapacitiveSensor( capSenseSendPin, muxSignalPin );

void setup() {
    digitalWrite( muxEnPin, LOW );
    Serial.begin( 115200 );
}

void loop(){
    byte touchIndex = 0;
    for ( byte channel = 0; channel < 4; ++channel ) {
        digitalWrite( muxS0Pin, ( channel & 1 ) >> 0 );
        digitalWrite( muxS1Pin, ( channel & 2 ) >> 1 );
        digitalWrite( muxS2Pin, ( channel & 4 ) >> 2 );
        digitalWrite( muxS3Pin, ( channel & 8 ) >> 3 );
        touch[touchIndex] = capSense.capacitiveSensor( sampleRate );
        ++touchIndex;
    }
    for ( byte i = 0; i < 10; ++i ) {
        Serial.print( touch[i] );
        Serial.print("\t");
    }
    Serial.println();
}

This example attempts only four capacitive touch pads but eventually I plan to use all 16 and then another multiplexer, but right now I'm stuck on getting anything, I seem to be getting some readings on touching the last pad but it's not what I expect to see, and it affects all the reading.

I've successfully got a version of this running without a multiplexer just on ten IO pins and it worked great. I also got the multiplexer running fine in a separate example with 16 push buttons.

Could the problem be due to pad charge times or the send-recieve capsense signals getting stopped in the multiplexer?

Any and all help would be appreciated.


texts: serial communication between several arduinos to pc

texts:
Is possible the communication between several Arduinos to one serial port in the PC ?

If I have ARD_A, ARD_B,... ARD_Z running with some code like this

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

void loop()
{
    while (Serial.available() > 0)
    {
       String stringID = Serial.read()
       int nFound = stringID.indexOf("@ARD_01");
                    // ---> Id is unique for each arduino
       if ( nFound > 0 )
          Serial.print("this is @ARD_01 responding sending some data");
     }
}

And in the pc there is an exe sending a string:

"@ARD_01 I want your data"
   process the data
"@ARD_02 I want your data"
   process the data
"@ARD_03 I want your data"
   process the data


texts:
(I have a Sparkfun RedBoard, but this question seems to apply to R3 Unos and Uno-compatible boards.) As I was building the first circuit in my SIK guidebook (add a resistor, LED, hook it up and make it blink from code), I noticed a blue LED on the board itself did everything that the circuit's LED did - blinking according to the programming.

Why is this LED here? What use cases is it for?

What kind of circuits will I have to adjust to account for this LED?

Is pin 13 traditionally a debug or a troubleshooting pin? Where did this convention come from?


texts: Noise when running Arduino close to analogue audio circuit

texts:
TL;DR: My Arduino is injecting a lot of noise into an analogue audio circuit, even when not physically connected.

I'm experimenting with using an Arduino as a low-frequency oscillator in audio circuits (modular synths, guitar effects etc).  I'm using an Arduino Uno powered with a USB + mains plug.

As a test I set up a simple circuit -- I don't believe the circuit matters much in this case but I'm including it here anyway:

simulate this circuit – Schematic created using CircuitLab

The Arduino is set up with one PWM pin supplying 0-5v, varying in a triangle wave (i.e. ramping slowly up, then slowly down again). This is connected to the JFET, which acts as a variable resistor. I have tested the analogue part of the circuit manually and it works as expected.

With the Arduino connected, however, the circuit produces a very loud "squishing" noise that swamps the audio signal passing through it, not unlike someone tuning an old short-wave radio. The noise "squishes" in time to the oscillation of the voltage.  It's not unlike the sound in this video associated with the PC power supply: https://youtu.be/lXPJvSU8MwI?t=10m52s.

This happens even if I physically disconnect the PWM pin from the circuit -- the closer its wire is to the circuit, the louder the noise, but it's clearly audible even when they're separated by are a foot or more of air.

Things I've tried:

Tying the Arduino ground to the analogue circuit ground, and also keeping them separate.
Adding power filtering caps to both circuits.
Putting the Arduino in an aluminium box, grounded to either its own ground or the analogue circuit's, or both.
Powering the Arduino from my laptop instead of plugged directly into the mains.

The analogue circuit is on breadboard right now so some noise is expected, but this is far outside anything I've experienced before even with very badly-behaved circuits.

I'm FAR from knowledgeable about Arduino so my hope is that I'm doing something stupid and easily fixed. I would happily accept an answer that proposes an entirely different way to achieve the desired result.


texts: Problems with inputting into serial monitor

texts:
I am currently working on a project where i take a frequency, and i want the code to take that value and use a formula to work out its mmh2O level. I use the Serial Monitor to input the values, but i have a problem. When writing the values e.g. "44.62352548","44.49151522". The value that is sent is wrong and displayed wrong.

I know the code i have written does not support this many signigicant figures from a float. And i have tried a few things to try and solve it but i cannot crack it.
I have tried using dtostrf() command, but i have never used this before and dont understand. Somebody from the arduino Forums had helped me out but it didnt seem to work.
I have also tried formatting aswell, and that did not seem to work.
If anyone has any help and advice it would be much appreciated.
float level;
float myValue;

String msg1 = "Enter Frequency (type 0 to exit): ";
String msg2 = "Your Frequency is: ";

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

void loop()
{
  Serial.print(msg1);

  while (Serial.available() == 0);
  {

  }
  myValue = Serial.parseFloat();
  if (myValue == 0.0)
  {
    Serial.end();
  }
  else
  {
    freqConversion();
  }
}

 void freqConversion()
{
  level = (myValue-44.712)/-0.0285493333;
  Serial.println(myValue);
  Serial.print(msg2);
  Serial.println(level);
}


texts: How to combine strings and text together?

texts:
I'm trying to combine two strings (strings/int) together with text in below code:

int foo = String((char*)payload).indexOf(' ');
int message1;
int message2;

message1 = String((char*)payload).substring(0, foo).toInt();
Serial.print(message1); // Returns 1

message2 = String((char*)payload).substring(foo + 1, length).toInt();
Serial.print(message2); // Returns 0

client.publish(msg, String(message1 + " " + message2).c_str(), true);
// published value: 1 0

Instead of publishing "1 0" its publishing some weird values, what am i missing?


texts: Using 8-bit instead of 16-bit in Adafruit library

texts:
I tried to modify the Adafruit_GFX and Adafruit_ST7735 libraries to make the color variable( as shown in code below) to use 8-bit instead of 16-bit for displaying 8-bit color on LCD screen.

void Adafruit_ST7735::pushColor(uint16_t color) {
 #if defined (SPI_HAS_TRANSACTION)
   SPI.beginTransaction(mySPISettings);
 #endif
  *rsport |=  rspinmask;
  *csport &= ~cspinmask;

   spiwrite(color >> 8);
   spiwrite(color);

   *csport |= cspinmask;
 #if defined (SPI_HAS_TRANSACTION)
   SPI.endTransaction();
 #endif
}

I changed it to the below

void Adafruit_ST7735::pushColor(uint8_t color) {
  #if defined (SPI_HAS_TRANSACTION)
   SPI.beginTransaction(mySPISettings);
  #endif
   *rsport |=  rspinmask;
   *csport &= ~cspinmask;

   //spiwrite(color);
   spiwrite(color);

   *csport |= cspinmask;
#if defined (SPI_HAS_TRANSACTION)
  SPI.endTransaction();
#endif
}

I have made similar changes in other portions of the code. This time nothing was displayed in the LCD(it was blank). However, when the spiwrite(color) is written twice i.e. the comment is removed, the code works fine.
Why is there a need to write 'spiwrite' function twice even in case of 8-bit color?

The original Adafruit library files are also attached.
drive.google.com/open?id=0B3x_NfKXnhtHR0VBcTNZbk5WT0E


texts:
I have Two Arduinos, One with the help of sensors it will dynamically updates in to my server database. Other Arduino, reads the stored contents from the server database and sends sms to phones.

Now, I have a text file in my server which updates dynamically for every 5 min - 10 min. I am trying to read that text file contents.

I want my server to be always connected, So It must be in setup() function.
I want update only to my text file which dynamically changes, so it must be loop() function.

How to implement this ? Any Suggestion ?


texts: How can I know how far a button is pressed?

texts:
I want to make a system that can count coins. The problem that I know have is that I need a way to detect the size of the coin.

The idea that I have is a beam that becomes smaller if you a inject a coin. The size of the beam depends than on the size coin. See it as a button that you can press a little bit or very deep.

But how can I know far the button (beam) is pressed?


texts: I keep getting an exit status 1 expected primary-expression before ')' token for my code

texts:
I am trying to compile my sketch for a servo motor in order to make it move back in forth (like a pulse) I used two for loops to make this happen but when I determine the scope before the loop I get this error not matter what i change for the variable ctr before the loop commences. Here is my code so that you can see where I most likely messed up.
edit: I added the fixes so far that was suggested in the comments now I am having a new issue with line 85 i get an error that says

exit status 1
expected ';' before ':' token

here is the code in question with all the edits suggested so far

 #include <ESP8266WiFi.h>
#include <Servo.h>

const char* ssid = "RETProject";
const char* password = "mporfiri";

WiFiServer server(80);

int ledPin = 13; // GPIO13
Servo servoLeft;
Servo servoRight;
//int ctr = ();
 int ctr = 0;

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

  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

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

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.print("Use this URL to connect: ");
  Serial.print("http://");
  Serial.print(WiFi.localIP());
  Serial.println("/");

  //servoLeft.attach(2);
  //servoRight.attach(4);

}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }

  // Read the first line of the request
  String request = client.readStringUntil('\r');
  Serial.println(request);
  client.flush();

  // Match the request

  int value = LOW;
  while (value = LOW);
  if (request.indexOf("/LED=ON") != -1)  {
    digitalWrite(LED_BUILTIN, HIGH);
    value = HIGH;
    servoLeft.attach(2);
    servoRight.attach(4);

    for (ctr = 0:pulse:1) {
      servoRight.write(ctr);
      servoLeft.write(ctr);
    }

    for (ctr = 1:-pulse:0) {
      servoRight.write(ctr)
      servoLeft.write(ctr);
    }

  if (request.indexOf("/LED=STOP") != -1)  {
    digitalWrite(LED_BUILTIN, LOW);
    value = LOW;
    servoLeft.detach();
    servoRight.detach();
    delay(1000);

  }

// Set ledPin according to the request
//digitalWrite(ledPin, value);

  // Return the response
  client.println("HTTP/1.1 200 OK");
  client.println("Content-Type: text/html");
  client.println(""); //  do not forget this one
  client.println("<!DOCTYPE HTML>");
  client.println("");

  client.print("Robot is now: ");

  if(value == HIGH) {
    client.print("Moving Forward");
  } else if(value == LOW) {
    client.print("Moving Backward");
  } else {
    client.print("Stopped");
  }
  client.println("

");
  client.println("<button>Move Forward </button>");
  client.println("<button>Move Backward </button>
");
  client.println("<button>STOP </button>
");
  client.println("");

  delay(1);
  Serial.println("Client disonnected");
  Serial.println("");

}


texts: How to use a 4-pin ultrasonic sensor as a 3-pin ping sensor?

texts:
const int pingPin = A0;

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);
  inches = microsecondsToInches(duration);
  cm = microsecondsToCentimeters(duration);
  Serial.print(inches);
  Serial.print("in, ");
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
}

How to change this code for a 4-pin ultrasonic sensor?


texts: Arduino UNO with LMT86LP temperature sensor

texts:
I am trying to use the Arduino Uno with the LMT86LP temperature sensor, but I am getting strange output voltages from the sensor.

I have the pins (from left to right, flat side facing forward) as VDD, OUT, and GND. VDD is connected to 5V, GND to GND, and Vout to A0 (analog pin 0). The readings from the Arduino are consistently around 360 mV but should be somewhere around 1800 mV as I measured the output of the sensor using a multimeter and got a constant 1.8 V.

Right now the code is very simple. I am just doing analogRead() and printing to the Serial Monitor.


texts: Real-time Pub/Sub thru MQTT between JoyStick and OnBoard Drive units [both ESP8266] - Connection issues

texts:
I looked around for solutions to my issue by searching on the forum and elsewhere and haven't seen similar issues - (https://arduino.stackexchange.com/search?page=2&tab=Relevance&q=MQTT%20ESP8266)

I am describing below what I am trying to achieve: (I am relatively new)

I would like to pass streaming joystick data from a "Remote Control" through MQTT to a "OnBoard" unit to drive my robot. Both the "Remote Control" and "OnBoard" units are NodeMCUs ESP8266.

I am able to separately send data from my Joystick to the MQTT broker and also separately read streaming data from the MQTT broker on any MQTT client. However, the moment I connect the "Remote Control" and the "OnBoard" Units to run their respective code, I keep receiving a Lost Connection to MQTT server error. I also observe this happens right after my Joystick ESP8266 connects.

I suspect this is related to one of the following -

0>> I am doing something fundamentally wrong [Syntax, usage of libraries, logic?]
connection parameters to the MQTT client [keep alive?, QoS?, delay?] b) there
is something to with sequence of Sub & Pub?
the version of ESP MQTT libraries i am using??
this is not the best way to stream data to
control devices? WebSockets?

I am copying my code for both units below:

RemoteControl Unit: [Joystick input is given through Serial]

#include <PubSubClient.h>
#include <EspMQTTClient.h>

void onConnectionEstablished();

EspMQTTClient client(
  "mywifi",           // Wifi ssid
  "somepwd!",           // Wifi password
  "iot.eclipse.org",  // MQTT broker ip
  1883,             // MQTT broker port
  "usr",            // MQTT username
  "mqttpass",       // MQTT password
  "test1",          // Client name
  onConnectionEstablished, // Connection established callback
  true,             // Enable web updater
  true              // Enable debug messages
);

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

void onConnectionEstablished()
{
  Serial.println("Remote Connection Established");
}

void loop()
{
  if (Serial.available() > 0) {
    Serial.println("Inside Serial");
    char bfr[101];
    memset(bfr,0,101);
    Serial.readBytesUntil('\n',bfr,100);
    client.publish("DriveChannel", bfr);
  }
  client.loop();
}

OnBoard Unit:

#include <PubSubClient.h>
#include <EspMQTTClient.h>

void onConnectionEstablished();

EspMQTTClient client(
  "mywifi",           // Wifi ssid
  "somepwd!",         // Wifi password
  "iot.eclipse.org",  // MQTT broker ip
  1883,             // MQTT broker port
  "usr",            // MQTT username
  "mqttpass",       // MQTT password
  "test1",          // Client name
  onConnectionEstablished, // Connection established callback
  true,             // Enable web updater
  true              // Enable debug messages
);

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

void onConnectionEstablished()
{
  client.subscribe("DriveChannel", [] (const String &payload)
  {
    Serial.print("In Connection payload---> ");
    Serial.println(payload);
  });
}

void loop()
{
  delay(3000);
  client.loop();
}


texts: Handling double (8 byte) in Arduino mega 2560?

texts:
I am receiving 8 bytes from serial.

I want to convert and save in double variable.

This is how i tried.

union u_data
    {
        byte b[4];
        double fval;
    } u;

double BytesToDouble (byte b8,byte b7,byte b6,byte b5,byte b4,byte b3,byte b2,byte b1)
{
    u.b[0] = b1;
    u.b[1] = b2;
    u.b[2] = b3;
    u.b[3] = b4;
    u.b[4] = b5;
    u.b[5] = b6;
    u.b[6] = b7;
    u.b[7] = b8;
 return u.fval;
}

But i am getting 0.00. Because here double size is 4 bytes.

Is there is any other way to do this?

Thanks


texts: Arduino IDE doesn't release COM port after programming

texts:
I have an arduino mega 2560 and I'm trying to program it using Arduino IDE 1.8.1. The problem is that I also need to keep open another program that will communicate with the Arduino using the COM port. I usually have to make very small changes to the code with the IDE and then check the results in the program.

However, when the IDE has finished uploading the program it will not release the COM port, and the program I'm using will give me an error message saying "access denied". This is a problem because I want to keep both programs open at the same time.

In fact I could just: make my correction to the code, close the IDE when it has finished, open the program I need, check whether the correction I made was right, otherwise close it again and open the IDE again, but that would take an insane amount of time and it would be quite annoying.

Is there a way to force the Arduino IDE to release the COM port so that other programs could communicate with the Aduino?


texts: If a Timer is used, disabling some PWM pins, can I still use those pins for Digital write?

texts: It's my understanding that when a Timer is used on an Arduino (in my case the Arduino Mega), it can disable analog write on some PWM pins, which pins depends on the Timer being used. For instance on the Mega, pins 44,45,46 are controlled by Timer 5.  If I enable Timer 5, does that mean that I can't use these pins for anything else? Or does it only mean I can't use those pins for AnalogWrite, and that I can still use those pins for DigitalWrite.


texts: How do I get the Itead 3G shield to work?

texts:
I've tried a pretty standard code but the Serial Monitor yields zero response.

Using a standard Arduino Uno (tried a second one as well, just to be sure) and am now trying the second shield with this code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX

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

}

void loop() // run over and over
{
  if (mySerial.available())
    Serial.write(mySerial.read());
  if (Serial.available())
    mySerial.write(Serial.read());
}

There is nothing coming back whatsoever in the serial monitor (yep, I checked the baud rate and tried several others).

Any ideas?

What should I be seeing if anything?


texts: GSM serial get event or read the whole input?

texts:
I am using an Arduino Uno with GSM shield, trying to read some SMS. Here is my code.

#include <SoftwareSerial.h>
SoftwareSerial SIM900(7, 8);

char incoming_char=0;

void setup()
{
  Serial.begin(19200); // for serial monitor
  SIM900.begin(19200); // for GSM shield
  SIM900power();  // turn on shield
  delay(20000);  // give time to log on to network.

  SIM900.print("AT+CMGF=1\r");  // set SMS mode to text
  delay(100);
  SIM900.print("AT+CNMI=2,2,0,0,0\r");

  delay(100);
}

void loop()
{
  // Now we simply display any text that the GSM shield sends out on the serial monitor
  if(SIM900.available() >0)
  {
    incoming_char=SIM900.read(); //Get the character from the cellular serial port.
    Serial.print(incoming_char); //Print the incoming character to the terminal.
  }
}

My issue is: am testing sending this sms to the shield

  A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

but somehow am not getting all the info, why?


texts: How to convert voltage to current from ACS712-20A?

texts:
I've been used the ACS712-20A to measure the current flow. Actually I used LIFA program (LabVIEW interface for Arduino).

I used this equation:

current = ((analog read)-2.5 )/ 0.1

But I am still not sure with the result.

Any suggestion?


texts: How to eliminate drift with the magnetometer in the MPU9250

texts:
I have a sketch running that uses a complementary filter for my X and Y values.

However, the Z value has no complementary filter (as you can tell by the slight drift when stationary) because I was told that a magnetometer is required to eliminate this drift.
Thus I purchased the MPU9250.

How would a magnetometer be able to eliminate drift it only measures magnetic fields?

How would I be able to help reduce the drift?


texts: Arduino GSM module + SMS string sending garbage value

texts:
I want to check the water level and have an SMS sent via a GSM module. Reed switches are connected to four Arduino analog inputs.

I am unable to add a string and tank level (TKLVL) in program.
The program is sending some garbage value via SMS. But TKLVL variable prints the right value.

What is wrong with my code?

    #include <SoftwareSerial.h>
    SoftwareSerial SIM900(10, 11);
    String textMessage;
    #define LED1 2
    #define IRLED 3
    //#define rf433DATA 4
    //D4 IS CONNECTED TO RF433MHZ RECEIVER CHANGE ACC TO LIBRARY
    #define PIRpower 5
    int receiver = 6;
    #define VALVE1 7
    #define GSMRESET 8
    #define pumpONdetect 9
    #define VALVE2 12
    //#define TANK_SENSPOWER 13 //
    #define TANK_SENS4 A0  //full tank wigh buzzer
    #define TANK_SENS3 A1
    #define TANK_SENS2 A2
    #define TANK_SENS1 A3  //low tank
    int TKLVL= 0;
    int LEVEL;

    void setup()
    { pinMode(LED1, OUTPUT);
      pinMode(IRLED, OUTPUT);
      pinMode(PIRpower, OUTPUT);
      //CHECK RECEIVER PIN
      pinMode(GSMRESET, OUTPUT);
      pinMode(VALVE2, OUTPUT);
      // pinMode(TANK_SENSPOWER, OUTPUT); //DRIVE THIS PIN LOW TO ON TANK POWER(PNP TRANSISTOR)
      pinMode(TANK_SENS4, INPUT); //FULL TANK WITH BEEP BUZZER
      pinMode(TANK_SENS3, INPUT);
      pinMode(TANK_SENS2, INPUT);
      pinMode(TANK_SENS1, INPUT); //LOW TANK WATER
      // digitalWrite(TANK_SENSPOWER, HIGH); //turns OFF tanksenspower OFFvia PNP transistor..
      Serial.begin(9600);
      SIM900.begin(9600);
      Serial.print("SIM900 ready...");
      SIM900.println("AT+CMGD=1,4\r");
      delay(1000);
      // AT command to set SIM900 to SMS mode
      SIM900.println("AT+CMGF=1\r");
      delay(400);
      // Set module to send SMS data to serial out upon receipt
      SIM900.println("AT+CNMI=2,2,0,0,0\r");
      delay(400);
      digitalWrite(VALVE1, LOW);

    }

    void loop()
    {
      if (SIM900.available() > 0) {
        textMessage = SIM900.readString();
        Serial.print(textMessage);
        delay(10);
      }
      if (textMessage.indexOf("Von") >= 0)
      {
        G_valve1On();
        Serial.println("on loop");
        textMessage = "";
      }
      if (textMessage.indexOf("Voff") >= 0)
      {
        G_valve1Off();
        Serial.println("off loop");
        textMessage = "";
      }

      if (textMessage.indexOf("Tanklvl") >= 0)
      {
        Tanklvl_calc();
         Serial.print("TKLVL is=");
         Serial.println(TKLVL);
        //  TKLVL=LEVEL;
        // Serial.print("level is=");
        //Serial.println(LEVEL);
        String msg ="TANK IS " + TKLVL;
        Serial.println(msg);
        sendSMS(msg);
        textMessage = "";
      }

    }
    //SEND SMS function
    void sendSMS(String lvlmsg)
    {
      SIM900.print("AT+CMGF=1\r");
      delay(1000);
      SIM900.println("AT+CMGS=\"+9182375*****\"\r");
      delay(100);
      SIM900.println(lvlmsg);
      delay(100);
      SIM900.println((char)26);
      delay(1000);
      SIM900.println();
      delay(5000);
    }

    void G_valve1On()
    {
      digitalWrite(VALVE1, HIGH);
      Serial.println("...turning valve1 on...");
    }
    void G_valve1Off()
    {
      digitalWrite(VALVE1, LOW);
      Serial.println("...turningvalve1 off...");
    }

    int Tanklvl_calc()
    {
      if (digitalRead(TANK_SENS4) == HIGH)
      {
        TKLVL = 100;
        Serial.println("TANK LEVEL 100%");
      }
      else if (digitalRead(TANK_SENS3) == HIGH)
      {
        TKLVL = 75;
        Serial.println("TANL LEVEL 75%");
      }
      else if (digitalRead(TANK_SENS2) == HIGH)
      {
        TKLVL = 50;
        Serial.println("TANK LEVEL 50%");
      }
      else if (digitalRead(TANK_SENS1) == HIGH)
      {
        TKLVL = 25;
        Serial.println("TANK LEVEL 25%");
      }
      else
      {
        TKLVL = 0;
        Serial.println("TANK LEVEL IS LESS THAN 25%");
      }
      return(TKLVL);
    }


texts: How to recover from DHCP Renewal and Rebind failures?

texts: I'm using an Ethernet shield with the built-in Ethernet library. I obtain an IP address using DHCP, and call Ethernet.maintain() periodically to ensure that the DHCP lease is renewed as required. So far I've never seen this fail, but maintain() can return error codes for renew fail and rebind fail and I assume that I should be handling them. What conditions would cause these errors to occur, and what's the best practise for recovering from them? Is it enough to call Ethernet.maintain() repeatedly until it returns cleanly, should I call Ethernet.begin() to reinitialise the Ethernet shield, or would it be best to reset both the Arduino and Ethernet shield using the watchdog timer?


texts: Arduino + 4051 -> noise on certain 4051 pins

texts:
I am trying to use two 4051 ICs with an Arduino Micro right now. The idea was to have an 16-sensor demo station (8 sensors per 4051) wherein each 4051 pin selection is controlled by a potentiometer as input. I am new to using MUX's, so I mocked the following up as a quick demo based on this help document via Arduino (it's basically the same), which only uses one 4051 and does not use a potentiometer as selector input. So, I should be able to set the variable which to whatever number (0 - 7) to change the sensor selection that shows up at A2 on the Arduino.

Setting which to 0 is fine, but when I have more than two sensors plugged into 4051 and set the selector pin to any other number than 0 there is a strong likelihood that the output that shows up in the Serial Monitor is both unresponsive to the selected sensor change and appears to be simply noise (random numbers around 200 or so). I have been trying to isolate where this noise is coming from and am totally stumped. Has anyone had this issue and, if so, any suggestions on how to further diagnose what is happening? I am currently powering everything off of the Arduino 5V, which I am under the impression should be okay, though I have tried this with external power supplies (12V at 2A, for example) and gotten the same results (so I am fairly certain power is not the issue here).

Measuring voltage on pins 2, 3, and 4, I am seeing 1mV on pin 2, 1mV on pin 3, and 0.9mV on pin 4 following the initial spike during upload. When comparing against the Arduino 4051 doc I linked to above, I see that in that file pins 2, 3, and 4 show a Voltage of 2.5V following the initial spike during upload. Any idea what I am doing incorrectly?

/*
Sensor Station via MUX

 * code example for useing a 4051 * analog multiplexer / demultiplexer
 * by david c. and tomek n.* for k3 / malmï¿½ hï¿½gskola
 *
 * edited by Ross R.
 */

int r0 = 0;      //value of select pin at the 4051 (s0)
int r1 = 0;      //value of select pin at the 4051 (s1)
int r2 = 0;      //value of select pin at the 4051 (s2)
int which = 0;   //which y pin we are selecting
int val;

void setup() {
  pinMode(A2, INPUT);       // mux1 input
  pinMode(2, OUTPUT);    // s0
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
}

void loop () {

  which = (0);

  // select the bit
  r0 = bitRead(which, 0);
  r1 = bitRead(which, 1);
  r2 = bitRead(which, 2);    // use this with arduino 0013 (and newer     versions)

  digitalWrite(2, r0);
  digitalWrite(3, r1);
  digitalWrite(4, r2);

  //Either read or write the multiplexed pin here
  // refactor, this should be digitalWrite with millis or something
  val = analogRead(A2);     // MUX ouputs here

  Serial.print("sensor number ");
  Serial.print(which);
  Serial.print('\t');
  Serial.print("val is ");
  Serial.println(val);

  delay(2);
}


texts:
I am doing a project with bluetooth and an LED. I wrote a code which supposed to turn on an LED after it receives a byte of value 1 after 5 seconds, unless it receive another byte of value 1 (which make it need to wait another 5 seconds) so that if it receive the byte periodically, the LED doesnt turn on, and only turn on if byte value sending is stopped/bluetooth disconnected. I wrote this code and it doesn't seem to work. It doesn't even turn on the LED after 5 seconds. Can you help me spot the mistake here?

unsigned long timebetween=5000;
unsigned long lastreceivedtime;
int value;
bool timerReady = false;

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

void loop() {
  unsigned long currentMillis = millis();
  if( Serial.available() >0){
    value = Serial.read();
  }
  if ( value ==1 ){
    lastreceivedtime = currentMillis;
    timerReady = true;
  }

  if(timerReady) {
    if((unsigned long)(currentMillis - lastreceivedtime) >= timebetween){
      digitalWrite(11, HIGH);
      delay(90);
    }
  }
}


texts: Initialize a class (HX711) within a class with constructor and parameters

texts:
I am far from being an Arduino specialist, so please bear with me if some of my code below is far from correct.

I am writing a sketch in which I need to use 3 instances of the HX711 library, as I am using 3 different weight sensors.

In order to try to clean up the code, I want to put basically all the code using HX711 in my own class.

Here is what my ScaleMeasure.h looks like:

// ScaleMeasure.h
#ifndef _SCALEMEASURE_h
#define _SCALEMEASURE_h

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

#include <CmdMessenger.h>
#include "HX711.h"

class ScaleMeasure
{
 public:
    ScaleMeasure(int Dout, int Clk, float CalibF, int ScaleID);
    void Setup();
    float Measure();

private:
    int _dout_pin;
    int _clk_pin;
    float _calibration_factor;
    byte _scaleID;
    HX711 _scale = HX711(_dout_pin, _clk_pin);
};

and .cpp

#include "ScaleMeasure.h"

ScaleMeasure::ScaleMeasure(int Dout, int Clk, float CalibF, int ScaleID)
{
    _clk_pin = Clk;
    _dout_pin = Dout;
    _calibration_factor = CalibF;
    _scaleID = ScaleID;
}

void ScaleMeasure::Setup()
{
    _scale.power_up();
    _scale.set_scale();
    _scale.set_scale(_calibration_factor);
    _scale.tare();
    _scale.read();
}

float ScaleMeasure::Measure()
{
    return _scale.get_units(5);
}

but there is obviously something wrong, as a call to the constructor lock the rest of the program. I believe that my instantiation, of HX711 in ScaleMeasure.h  HX711 _scale = HX711(_dout_pin, _clk_pin); is not correct, or not in the right place. The code compile fine, though.

Thanks for your help.


texts: I want to have an Arduino based game you can play on a nokia 5110 screen. The problem is you cant make a medium sized game on an Arduino because the flash size is only 32k. I sit possible to have multiple Arduino's connected to each other, communicating to make it possible to have a bigger game. If it is possible how does it work?


texts:
Why do we need level logic converter to have 5V or 3.3V?

Because in Arduino Uno/Mega (don't know about other boards), they already provide 5V and 3.3V for us to use.


texts: Arduino - RF 433 Mhz transmitting string and but receiving ASCII values of those characters

texts: When I am using RF 433 MHz module with ARDUINO MEGA then it is transmitting any text or anything in ASCII values. Now how to decode those ASCII values to alphabets? If I use ASCII conversion programme then what if I send a number and that conversion program converts that number also to text or related ASCII character? please suggest any way.


texts:
I have to port a Project written for an Arduino Micro to an MKRZERO.

It communicates via UART with an IC and should also provide a clock signal.

The former code I have used is this:

#define OUTPUTPIN 8
#define CLOCKOUTPIN 5
#define CONTRLEDPIN 13

void Setup() {
pinMode(OUTPUTPIN, OUTPUT);
// Needed for initialization
digitalWrite(OUTPUTPIN, HIGH);
// set clock PIN
pinMode(CLOCKOUTPIN, OUTPUT);
// sets PIN for internal LED
pinMode(CONTRLEDPIN, OUTPUT);

TCCR3A = (1 << COM3A0);
TCCR3B = ((1 << WGM32) | (1 << CS30));
TIMSK3 = 0;
OCR3A = 7;
}

As the MKRZERO uses a different IC the registers are not the same. I've waded through the data sheet document but cannot find something similar.

Does somebody have any experience with the MKRZERO and can help me with this?


texts:
I have mini project which is Emergency Traffic Light for Ambulance, police etc.
What I am try to do is when emergency traffic light go through first sensor 1 (in this code I just using button, “SA”), traffic light will be pause and the traffic light for ambulance will be green.
After ambulance go through second sensor (SB), traffic light will be reset and the flow become normal (red → orange → green).

My problem is I don’t know how to make interrupt for this code.
I hope anyone can help me.

#define SA 2 //sensor 1
#define SB 3 //sensor 2
#define IND 6 //indicator
/////////////////////////////////////
#define AH 13   // A
#define AK 12
#define AM 11
/////////////////////////////////////////
#define CH 10    //C B
#define CK 9
#define CM 8
#define yellowBlinkTime 500 // 0.5 seconds for yellow light blink

///////////////////////////////////c
#define BH A0   // B
#define BK A1
#define BM A2
///////////////////////////////////////////////

boolean TA = true; // west = true, east = false
int flowTime = 10000; // amount of time to let traffic flow
int changeDelay = 2000; // amount of time between color changes

void setup()
{
pinMode(SA, INPUT); //sensor 1
pinMode(SB, INPUT); //sensor 2
pinMode(IND, OUTPUT);   //indicator

pinMode(AH, OUTPUT);   // A
pinMode(AK, OUTPUT);
pinMode(AM, OUTPUT);
///
pinMode(CH, OUTPUT);   //C
pinMode(CK, OUTPUT);
pinMode(CM, OUTPUT);
///////
pinMode(BH, OUTPUT);   // B
pinMode(BK, OUTPUT);
pinMode(BM, OUTPUT);

// set initial state for lights -
//jalan A
digitalWrite(AM, LOW);
digitalWrite(AK, LOW);
digitalWrite(AH, HIGH);

//jalan C
digitalWrite(CM, HIGH);
digitalWrite(CK, LOW);
digitalWrite(CH, LOW);

///// JAlAN B
digitalWrite(BM, HIGH);
digitalWrite(BK, LOW);
digitalWrite(BH, LOW);

}//-------setup end

void loop()
{
  if(digitalRead(SA) == HIGH )
  {
  blink();
  //flow();
  //break;
  }

  else{

  flow(); // p void flow normal
} // end else
} // end void loop

void flow() // flow normal tf
{
//flow1
digitalWrite(AK, LOW);
digitalWrite(AM, LOW);
digitalWrite(CK, LOW);
digitalWrite(AH, HIGH);
digitalWrite(CM, HIGH);

digitalWrite(BH, LOW);
digitalWrite(BK, LOW);
digitalWrite(BM, HIGH);

delay(changeDelay);

//flow2
digitalWrite(AH, LOW);
digitalWrite(AM, LOW);
digitalWrite(AK, HIGH);

digitalWrite(CM, HIGH);

digitalWrite(BM, HIGH);
delay(changeDelay);

//flow3
digitalWrite(AK, LOW);
digitalWrite(CM, LOW);
digitalWrite(AM, HIGH);
digitalWrite(CH, HIGH);
digitalWrite(BM, HIGH);
delay(changeDelay);

//flow4
digitalWrite(AK, LOW);
digitalWrite(AH, LOW);
digitalWrite(CM, LOW);
digitalWrite(CH, LOW);
digitalWrite(AM, HIGH);
digitalWrite(CK, HIGH);
digitalWrite(BM, HIGH);
delay(changeDelay);

//flow 5
digitalWrite(AK, LOW);
digitalWrite(AH, LOW);
digitalWrite(AM, HIGH);
digitalWrite(BH, HIGH);
digitalWrite(BM, LOW);
digitalWrite(CK, LOW);
digitalWrite(CH, LOW);
digitalWrite(CM, HIGH);
delay(changeDelay);

//flow 6
digitalWrite(AK, LOW);
digitalWrite(AH, LOW);
digitalWrite(AM, HIGH);

digitalWrite(BK, HIGH);
digitalWrite(BH, LOW);

digitalWrite(CM, HIGH);
digitalWrite(CK, LOW);
digitalWrite(CH, LOW);

delay(changeDelay);

}//-------flow end

void blink()
{
[enter link description here][2]
    digitalWrite(AH, LOW);
    digitalWrite(AM, LOW);

    digitalWrite(BH, LOW);
    digitalWrite(BM, LOW);

    digitalWrite(CH, LOW);
    digitalWrite(CM, LOW);

    digitalWrite(AK, LOW);
    digitalWrite(CK, LOW);
    digitalWrite(BK, LOW);
    delay(yellowBlinkTime);

    ////////////////////////////////////////////////// BLINK BLINK
    digitalWrite(AK, HIGH);
    digitalWrite(CK, HIGH);
    digitalWrite(BK, HIGH);
    delay(yellowBlinkTime);

}  ///////////////// end void blink


texts: Why does my code treat my sound sensor as if it's always HIGH

texts:
I have a sound sensor that was working perfectly fine as I was using it as a clap sensor to turn lights on and off. However, I tried to change the code to make it work a little smoother and for whatever reason it stopped working. I then tried to write a very simple script to allow it to turn on and off using just one clap but now it treats the sound sensor as if it's always inputting HIGH. Any ideas why this might be happening?

note: I've turned up the sensitivity and can see that the sound sensor isn't always HIGH. Even when it's too high to hear me clap it still turns the LED on and off as if the if statement below was always true.

int SENSOR = 2;
int LED = 13;

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

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

  if(digitalRead(SENSOR) == HIGH){
    digitalWrite(LED, (digitalRead(LED) == HIGH ? LOW : HIGH));
    delay(100);
  }
}

This is the sound sensor module I am using: Robojax Sound Detection Microphone Module


texts:
When I use JSSC and call serialPort.readLine(event.getEventValue()) from public void serialEvent(SerialPortEvent event) I've got fragments, not all string. What I must do to get all string from begin to "\r\n"? What I must do to get all string from my start marker (like "[start]") to my stop marker (like "[stop]")? What to modify in this code:

private static class PortReader implements SerialPortEventListener {
    public void serialEvent(SerialPortEvent event) {
        if(event.isRXCHAR() && event.getEventValue() > 0){
            try {
                String data = serialPort.readString(event.getEventValue());
                serialPort.writeByte((byte) 1);
            }
            catch (SerialPortException ex) {
                System.out.println(ex);
            }
        }
    }
}


texts: about required memory size in ATmega32 to execute a certain program

texts:
If I want to add two numbers and print the output on LCD

char answer[8];
float a=5.1,b=3.2,c;
c=a+b;
 dtostrf(c,8,3,answer);//convert float to ASCII to print it on LCD
for(i=0;i<8;i++) Lcd8_Write_Char(answer[i]);

What is the required memory space to execute this program?


texts:
At first, I sorry if I make some English faults but I'm French.

So, I'm making a connection between a client and an Arduino Uno. I receive all data that I need but when I send a response to my client some characteres are lost.
I receive this format : GET /?b=7&p=100$ (for exemple)
And my Arduino sends this to my client : GET /?b=7&p=1d

This is the function where I get all data from my client :

void read_data(int *state, int *progress_program){
  // Check if there is a client
  EthernetClient client = server.available();
  if (client) {
    url = "";
    index = 0;
    Serial.println("\nnew client");
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.println(c);
       if(c != '$') { // if end of char
          url[index] = c;
          index++;
        } else {
          url[index] = '\0';
          int i;
         Serial.print("\n");
          for(i=0;i<index;i++)
            Serial.print(url[i]);
          if(interpret(state, progress_program)){
            action();
            delay(100);
          }
          answer(client);
          break;
        }
      }
    }
    url[0] = '\0';
    // give the web browser time to receive the data
    client.stop();
    delay(100);
    Serial.println("\nclient disconnected");
  }
}

And the response sent to the client :

void answer(EthernetClient client){
  Serial.print("\nResponse"); // debug
  delay(100);
  client.print(url);
  Serial.print("Response Sent");
  delay(100);
}

With client.write(url) there is the same problem.

Have you got a solution?
thanks


texts: After update via ICSP can't use usb for Serial Reading and Usb for programming board

texts: after update software on my arduino Nano board via ICSP i can't use USB for serial monitor and update software, why?


texts: Communication arduino MODBUS fails on high number of registers

texts:
When I try to run the following program it runs ok:

#include <modbus.h>
#include <modbusDevice.h>
#include <modbusRegBank.h>
#include <modbusSlave.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
modbusDevice regBank;
modbusSlave slave;

void setup()
{
  lcd.begin(40, 2);
  regBank.setId(10);
  int numSet=0;
  for (int i=0; i <= 300; i++){
    if (numSet <= 8) {
      regBank.add(i);
    }
    if (numSet == 16) {
      numSet = 0;
    }
    numSet++;
  }
  slave._device = &regBank;
  slave.setBaud(9600);
}

void loop() {
  int numSet=0;
  for (int i=0; i <= 300; i++){
    if (numSet <= 8) {
        if (regBank.get(i) >= 1) {
          lcd.setCursor(2, 0);
          lcd.print("test");
        }
    }
    if (numSet == 16) {
      numSet = 0;
    }
    numSet++;
  }
  slave.run();
}

But whenever I add more code, or raise the number of the loops, it starts failing to communicate over MODBUS.

Is it that some part of the Arduino can't handle the amount of work? It's confusing because it not only fails when adding more regBank.add() or regBank.get() actions, but also when adding more program code (for example add 40 lines of code to write to the LCD display).


texts:
Does anyone know of any Pelco D libraries available for Arduino?

I already have a PTZ joystick controlling 3 PTZ cameras, but I would like to add an Arduino 'intelligent' controller capable of sending automated sequences of Pelco D commands according to various PIR triggers etc.


texts: LEDs lighting up when off due to servo motor being on

texts:
Within my arduino project I have began to run out of GND ports on my arduino so I am having to resort to using 1 GND port for lots of electric components. I have 2 LEDs that are each connected to a digital pin and then go down to ground and for the servo it has a 5V pin connected into the breadboard and then has a pin that connects the 5V from the breadboard into the servo. In addition to these, the servo also has a GND pin and a PWN pin. (for all of this I am using an arduino mega and a breadboard that looks like this for the LEDs and the servos).

I don't think this breadboard is efficient for doing this. How I have wired it is like this (sorry if it is not the best attempt, I tried my best):
[![enter image description here][2]][2]
when the digital pins that are controlling the LEDs have been turned off the LEDs seem to still be on (which is what should no be happening). When the digital pins are turned off the LEDs themselves should turn off.
Here is my attempt of the schematic:

simulate this circuit – Schematic created using CircuitLab


texts: Arduino UNO/Nano communication with SP1ML-868 module

texts:
Good evening, I'm trying to establish serial communication between an Arduino UNO/Nano (ATMega328P) and a SP1ML-868 RF radio module (http://www.st.com/en/wireless-connectivity/sp1ml.html). I can talk to the radio with an FTDI breakout board, connected directly to my PC, but I can't do it with the Arduino.

As the radio is 3.3V and the Arduino is 5V, I tried to use the logic level converter from Sparkfun in the RX/TX lines, but that didn't work as well.

Any idea as to what I might be doing wrong? Thanks!

EDIT
I was able to talk to the radio by uploading a blank sketch to my Arduino and using only the RX/TX pins and the FTDI chip on the board. When I configure the Serial port (i.e. Serial.begin), this no longer works, which leads me to believe the problem is in the ATmega USART configuration. For some weird reason, this only works when the Arduino RX is connected to the module RX, and TX with TX.

As requested, below is the simple serial echo code I'm using, and an image with the wiring. This assumes the normal RX->TX and vice-versa connection. The module is powered through wires underneath its breakout board (3.3v).

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

void loop(){
  while(Serial.available() > 0){
    Serial.print((char)Serial.read());
  }
}


texts: Do I need to use a resistor if I am using a potentiometer to control an LED's brightness?

texts:
I am currently tinkering with an arduino, and am using a potentiometer to change the brightness of an LED.

I understand that usually, a resistor is added to the circuit to limit the current flowing through the circuit in order to prevent the LED from burning out.

However, as I am currently using a potentiometer to adjust the LED's brightness, AND as a potentiometer is basically a variable resistor, would I still need a resistor to prevent the LED from burning out? Currently, I do not see a difference between using a 220 ohm resistor and not using it, as the LED seems unaffected.

My code:

const int pot=A0;
const int led=11;
int potValue;

void setup(){
  Serial.begin(9600);
  pinMode(pot,INPUT);
  pinMode(led,OUTPUT);
  analogWrite(led,100);
}

void loop(){
  potValue = analogRead(pot);
  potValue=map(potValue,0,1023,0,255);
  analogWrite(led,potValue);
  Serial.println(potValue);
}

PS: My LED is hooked up to the arduino's PWM pin, and connected to ground on a breadboard.


texts: Cannot pair HM10 BLE 4.0 module from Android phone

texts:
I am currently learning Arduino Bluetooth connectivity with a HM-10S module.
I did some sample tutorial code and it works only with LightBlue app.
However, when I use the default Bluetooth pairing function from the android phone(samsung S10 plus), it seems failed to pair or connect.
So here is the cases I tried:
Android App(LightBlue and also Arduino Bluetooth Controller) :
Success connection without entering password.
Windows 10 PC:
Success pairing only by entering password: "123456", but no com port added
Android phone(S10 plus) Default pairing method from setting
Entered "123456" as password to pair, then no response.
So, what puzzles me is:

I can connect with some apps and do my work, without pairing using Android's setting utility; Is that implies establishing a connection for further action does not necessary to firstly getting things paired?

There are no com port installed after I paired the bt module, so it probably mean the module does not provide my desired feature. If that's the case, which BT module is recommended?

Great thanks if somebody could give me some ideas.


texts: Powering two stepper motors with A4988 drivers

texts:
New to this site and wanted advice and sanity checking on my project design. I know there are similar questions to this but I couldn’t find one that was closely similar to mine.

I’m creating a device the uses two NEMA 17 stepper motors (https://www.omc-stepperonline.com/nema-17-stepper-motor-bipolar-l48mm-w-gear-raio-1001-planetary-gearbox-17hs19-1684s-pg100.html) with chunky 100:1 gearboxes in addition to using 1/16 microstepping. The end result of this is to achieve a stepper motor that turns very slowly (minutes per revolution).

Each motor is rated at 2.8V and 1.68A per phase (3.36A total since two phase) and I’m using an A4988 driver for each of them (https://www.amazon.co.uk/gp/product/B07FKXXJ41/ref=ppx_yo_dt_b_asin_title_o00_s00?ie=UTF8&psc=1) (note that these are Chinese versions where RCS = 0.1Ω). Since the A4988 drivers are limited to 1A without additional cooling, I’ve used the onboard potentiometer to reduce Vref to just below 0.9V to prevent overheating (using the equation Vref = 8 x Imax x RCS from Pololu).

This should mean that consequentially the torque output from each motor is reduced by a factor of 1/(3.36) = 0.3 (as torque α current) since each motor is only being supplied with 1A (which is not an issue due to the large gearing ratio giving a suitable output torque). I think 1/16th microstepping might also reduce the torque slightly, but I couldn’t find any conclusive sources that didn’t contradict each other on this.

This gives a power requirement of 2.8 x 1 = 2.8W per motor, hence 5.6W in total. So, I plan to use a power source that provides at least 3A (surplus on the 2A required by the drivers) and rated at a voltage of 12V-24V to run the stepper motors. I’m also aware that I need to make sure I power the drivers in parallel from this source, and not in series to reduce strain / overheating.

I’ve included two power sources I was thinking of using:

1: 24V, 4A, 96W Desktop Switching Power Supply (https://www.amazon.co.uk/DTK-Charger-90-240V-Switching-Transformers/dp/B07K85GJ54/ref=sr_1_1_sspa?crid=362Z7XFFLAYLL&keywords=24v+3a+dc+power+supply&qid=1565084176&s=electronics&sprefix=24V+3A+dC%2Celectronics%2C124&sr=1-1-spons&psc=1&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUFHM1hUTjRTOUhYVDcmZW5jcnlwdGVkSWQ9QTA5NzA5MzQzM09IT05IR1JITEpQJmVuY3J5cHRlZEFkSWQ9QTA0NjgyMTUyQjY0UEYzRFI5OVBFJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==)

2: 24V, 15A, 360W PSU Transformer Adaptor (https://www.amazon.co.uk/NEWSTYLE-Universal-Regulated-Switching-Transformer/dp/B0758BNMLH/ref=sr_1_3?keywords=PSU+24V&qid=1565084433&s=electronics&sr=1-3)

Overall question is: would either of these power supplies be suitable, I think the second might be a bit overkill but i'm not sure.

Here’s the circuit diagram for reference:

Apologies for the long post, just needed to get all the information out of my head. I’m curious to see if I’ve made any errors in my calculations / assumptions, so any help is greatly appreciated.


texts: Uploading to standalone atmega using UNO as ISP

texts:
I am following this procedure to upload a sketch to a standalone atmega328p, without using a bootloader, with an Arduino UNO as ISP.
It is my understanding that I first have to "burn the bootloader" just to set the fuses, and then I can upload my sketch. The first time I upload a sketch, everything works fine.
However, when I try to re-upload a sketch, an error occurs:
The only way to re-upload a sketch, is to first re-burn the bootloader.
I have seen in forums that uploading a sketch from ICSP overwrites the bootloader (thus saving space). Does this also have to do with the fact that I cannot re-upload a sketch? If that is the case, can you explain why this occurs? I would expect that, since programming from ICSP does not require a bootloader, I could easily upload sketches without bothering about bootloaders.


texts: How to perform a data transfer to an external server

texts:
So I'm doing a project that involves getting sensor data from several sensors, and then sending them to an external server when a tragic occurs. But I've been having trouble figuring out how to send this data, and I am welcome to advice (I'm still relatively new to Arduino coding).

I'm using an Arduino mega, with a sim900 GSM shield and an SD card. The sensors are just analog reads and a GPS.

I've looked into FTP, a Xively account and http requests to a web server but couldn't figure it out.


texts: Native USB port on custom ATSAM3x8e board not recognised in windows

texts:
I have been designing my own PCB using the atsam3x8e chip, the same as the Arduino due which I used to prototype with. So far I've managed to get my boards up and running by programming them via the serial TX & RX pins using a USB to serial converter, but I can't seem to get the "Native" USB port to work in windows.
When the boards are plugged in, they show up in the windows device manager as "Unknown USB Device (Device Descriptor Request Failed)" but do not show up in BOSSA or Atmel Studio 7.0. My understanding was that when the chip is reset and erased, it should just show up as a "BOSSA programming port" the same as the Arduino DUE does when it is put through the same procedure.
I'm not sure whether this is an issue with the hardware design of the board or not. I have used a USB C connector instead of a Micro USB so have not connected the UOTGID pin and instead added two pulldown resistors to the CC pins on the new connector.
If anyone has any suggestions on this please let me know.


texts:
I want to create a class to better use strings in flash. At its core is the following

template<size_t N>
struct progstr
{
    constexpr progstr(const char (&str)[N])
        : progstr(str, make_index_sequence<N> {}) {}

    template<size_t... Is>
    constexpr progstr(const char (&str)[N], index_sequence<Is...>)
        : _str{str[Is]...} {}

    constexpr operator const char*() const {
        return _str;
    }

    const char _str[N] PROGMEM;
};

Where make_index_sequence and index_sequence are the same as those from <utility>.

The problem arises when I try to emulate PSTR

template<size_t N>
constexpr const char* pstr(const char (&str)[N])
{
    return progstr<N>{str};  // huh?
}

It even compiles. However

The returned pointer is "dangling", but it is pointing into flash memory. Will this work?
A constexpr function may be called with an array with runtime values, and that cannot possibly create the string in flash can it?


texts: HTTP post request in JSON Format using SIM900 module

texts:
I tried to send HTTP post requests to a server in JSON Format using a SIM900 module. But the code is not posting the data. While posting the data I'm getting the error response while initializing the server using the command:

{("AT+HTTPPARA=\"URL\",\"http://test.server/insert-path")}

I don't know what the error is and how to fix it. Please help me to fix this.

#include<SoftwareSerial.h>

SoftwareSerial client(2,3);

String testReading="{  \"testID\" : 1,  \"testLevel\" : 1, }";

void setup() {
  Serial.begin(9600);
  client.begin(9600);
  delay(1000);
  if(client.available()) {
    Serial.print("Connected");
  } else {
    Serial.print("Not Connected");
  }
  checkSignal();
  connectGPRS();
  postData();
  delay(1000);
}

void loop() {
  if(client.available()) {
    checkSignal();
    connectGPRS();
    postData();
    delay(1000);
  }
}

void connectGPRS() {
  client.println("AT+CGATT?");
  delay(1000);
  ShowSerialData();
  client.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);
  ShowSerialData();
  client.println("AT+SAPBR=3,1,\"APN\",\"www\"");
  //Using Indian Standard Vodafone Sim and so APN is www
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=1,1");
  delay(1000);
  ShowSerialData();

  client.println("AT+SAPBR=2,1");
  delay(1000);
  ShowSerialData();
}

void checkSignal() {
  client.println("AT+CSQ");
  delay(1000);
  ShowSerialData();
}

void ShowSerialData() {
  while(client.available()!=0)
    Serial.write(client.read());
}

void postData() {
  client.println("AT+HTTPINIT");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"URL\",\"http://test.server/insert-path");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPPARA=\"CONTENT\",\"application/json");
  delay(1000);
  ShowSerialData();

  client.println("AT+HTTPDATA=99,10000");
  delay(1000);
  ShowSerialData;

  client.println(testReading);
  delay(1000);
  ShowSerialData;

  client.println("AT+HTTPACTION=1");
  delay(10000);
  while(!client.available());
  ShowSerialData();
}


texts: How to connect the INT pin of a MPU 6050?

texts:
I am using an Arduino Leonardo together with a GY-521 breakout board (like this one, schematic) for an MPU 6050.

I am currently trying to get the DMP Version of the examples from Mr Rowberg to work.

For all my tests, I use these connections:

GY-521 ->  Leonardo
VCC -> 5V (3.3V has the same behaviour)
SDA -> SDA
SCL -> SCL
GND -> GND

The "raw" sketch works fine, I can read out the sensor data. For the DMP version I think I need to connect the INT pin to pin 3 on the leonardo, to allow the MPU6050 to trigger an interrupt.

But as soon as I connect INT to anything (pins 0 through 3), the sketches do not find the MPU6050 any more. (They report ""MPU6050 connection failed").

Is my wiring off, or is my chip defective, and even more important, how could I figure that out on my own in the future? =)

Edit:
The example source code says

/* =========================================================================
   NOTE: In addition to connection 3.3v, GND, SDA, and SCL, this sketch
   depends on the MPU-6050's INT pin being connected to the Arduino's
   external interrupt #0 pin. On the Arduino Uno and Mega 2560, this is
   digital I/O pin 2.
 * ========================================================================= */

The example does nothing (that I can see) to configure this pin.

Edit again:

I've borrowed an oscilloscope. SDA and SCL sit on 3.3V during normal communication, and I can see packets being exchanged. As soon as I connect the INT pin to any input pin on my Leonardo, both SDA and SCL go to ground. This means nothing to me, but maybe to someone else.


texts: Arduino Pong game Circuit Board Troubleshoot

texts:
I am following a tutorial online to make a pong game. I have managed to make quiet a lot work apart from my paddles in the game keep on shaking. The buttons do work fine, up and down on both ends.

Tutorial Link

I am sure, there is something with the power being supplied and not reaching to all points in the breadboard.

I am attaching a picture of my circuit board. Any advice?

Thank you,
W


texts:
How to create a USB CDC device. (I'm using stm32f103c8 black pill board) and I want to read the data through USB in my raspberry pi as a serial port.

I am using a black pill to read RFID-rf522 to read a tag (SPI) and send it to raspberry pi through a USB (using DM and DP pins).

Quick responses are welcomed.


texts:
In my current project I have to communicate with 10 different devices with PLC.

PLC is the master. When input comes from PLC to a device, the Arduino controller through RS485, I want to check the input and perform an action accordingly and once completed need to send acknowledgement back to PLC.

Communication protocol is MODBUS can some one suggest something on it.

I am completely new to Arduino and PLC.

If there is any sample program which I can check, it will be more helpful

Thanks


texts: TX light not flashing, screen.print works sometimes.. UNO

texts:
I've got 2 Analog accelerometers and a Gyro/Acc/Mag connected to my arduino and it's been working and reading fine until a few hours ago.
I've got the arduino sending data over the serial connection and Unity reading the values and interpreting.

#include <Wire.h>
#include <LSM303.h>
#include <L3G.h>

LSM303 compass;
L3G gyro;

void setup() {
  Serial.begin(9600);
  Wire.begin();
  compass.init();
  compass.enableDefault();
  gyro.init();
  gyro.enableDefault();
}

void loop() {

  /* Accelerometers: */

  int sensorValueA = analogRead(A0);
  int sensorValueB = analogRead(A1);
  //Serial.flush();
  Serial.print(sensorValueA);
  Serial.print(",");
  Serial.println(sensorValueB);
  delay(10);

  /* Accelerometer + Magnometer: */

  compass.read();
  //Serial.flush();
  Serial.print(compass.a.x);
  Serial.print(",");
  Serial.print(compass.a.y);
  Serial.print(",");
  Serial.print(compass.a.z);
  Serial.print(",");
  Serial.print(compass.m.x);
  Serial.print(",");
  Serial.print(compass.m.y);
  Serial.print(",");
  Serial.println(compass.m.z);
  delay(10);

  /* Gyro: */

  gyro.read();
  //Serial.flush();
  Serial.print((int)gyro.g.x);
  Serial.print(",");
  Serial.print((int)gyro.g.y);
  Serial.print(",");
  Serial.println((int)gyro.g.z);
  delay(10);

}

If I have it unplugged for several minutes then replug it, the print will work for a min or two then just stop completely. I've checked wires several times and it hasn't moved since it was working this morning.

As I said, which I think is probably of importance, the TX light is off when not printing.

Acc1: GND - GND | VCC - 3.3v | Y - A2

Acc2: GND - GND | VCC - 3.3v | Y - A3

Gyro: VIN - 5v | GND - GND | SAO - A4 | SCL - A5

Thanks


texts:
I have a LED Matrix just like this one

but couldn't find the data sheet for it (1855AS)
I asked around in my country and one guy told me to try attaching one side to 5v and the other to GND. Some LEDs worked fine and others didn't light up at all. In the end one if not more got burned.

So I'm here asking if anyone can tell me a way to figure out how it works.
I would appreciate the help!


texts: How to program your Arduino Due while its connected to a display?

texts:
Im trying to program my Arduino Due and it seems that I have to disconnect the display from it every time. Is there a work around for this?

Im using a 7" TFT with a CTE TFT LCD/SD Shield with a arduino due board.


texts: Can I connect to a DALI network as a master node using an Arduino?

texts:
I have googled a lot, and mostly every website you can link me I have already explored, some are outdated and don't work, others aren't clear in their documentation, and use equipment too expensive to run the risk of buying it and it not working.

https://github.com/edinburghhacklab/dali

https://github.com/sde1000/python-dali

https://github.com/krzychb/DimSwitch/blob/master/extras/pictures/PHILIPS-HF-REGULATOR-TOUCH-a-DALI%2018-58w-T8-%201-a-2-LAMPS.pdf

http://microcontrollershop.com/product_info.php?products_id=5384

Moreover, like any free protocol, you have to pay to access the DALI standard.

What can I do to control a network of connected DALI dimmable ballasts?


texts: Arduino port grayed out for Fake Board with CH340

texts:
I have downloaded and used Arduino IDE v1.8.4 from official site (needs no install) for windows10, and connected my random board with a ch340, but it's LED is only blinking and I can't select the port (ie. it's grayed).

I did test all USB ports and restarted my laptop but that didn't work!

I tried to install 1.6.9 IDE that I had before, but again the port option is unselectable!

This is my board:
http://uupload.ir/files/xgv_uno.jpg


texts: How can I hack my intercom system to buzz people in remotely?

texts:
How would you go about activating this button remotely?

This board is from the intercom in my apartment. The button when pressed unlocks the building door. I've just ordered the MKR IoT bundle (https://store.arduino.cc/arduino-iot-mkr1000-bundle). My plan is to learn the basics and figure out how to activate this button remotely.


texts: Relay module and internal pull-up resistors

texts:
I'm currently assembling a prototype of the lightning infrastructure (based on several MEGAs interconnected via RS485, as described in this other post)

The prototype consists of three MEGAs, a couple of wall-push-button and the two relay modules here below:

250V 2A 8 Channel OMRON SSR G3MB-202P Solid State Relay Module For Arduino
5V 4 CH OMRON SSR G3MB-202P Solid Relay Module with Resistive Fuse For Arduino

Obviously I've:

connected one endpoint of each push-buttons to Arduino INPUT-PIN; the other endpoint to ground;
connected the relay-module control-pins to Arduino OUTPUT-PIN (and ensuring a properly connected ground).
connected lamps to relay-modules power connectors.

My question relates to "pull-up resistor": I've read in lots of places that when involving push-buttons, "pull-up resistors" are needed in order to prevent shorts between ground and input-pin. As such, there are lots of tutorial/videos on the web, showing a nice resistor added in the push-button circuit.

Further investigating, I've also learnt from the official documentation that "...There are 20K pullup resistors built into the Atmega chip that can be accessed from software....", by setting the pinMode() as INPUT_PULLUP or setting it to INPUT and the forcing a digitalWrite(<PIN>,HIGH).

So, I ended:

directly connecting the two relay-modules to MEGAs INPUT-PINs and...
...activating the internal pull-up, with digitalWrite(<INPUT_PIN>,HIGH);

Nothing more.

This is the second evening I'm "testing" my Arduino-luggage-prototype and... lamps are turning on/off like a charm, without any noticeable problem.

The question is: am I doing something nasty toward my MEGAs? Is the approach depicted above, a commonly-safe (as for the Arduino's health) approach?

P.S.: should you wonder about how the prototype looks like, here is a photo (actually, taken right after the first power-up ;-)


texts: I need help setting up my Arduino Uno with the port

texts:
I'm using a Windows computer, and if I recall correctly I installed the IDE using the installer, so I probably don't need to manually install the drivers. However, I can't figure out how to set up the serial port with the Arduino. For me under Tools, there's no "Serial Port" option but instead "Serial Monitor" and "Serial Plotter."

When I tried to upload my file, it failed. When I clicked Serial Plotter, it gave this error message:

Arduino: 1.8.4 (Windows 8.1), Board: "Arduino/Genuino Uno"

Sketch uses 940 bytes (2%) of program storage space. Maximum is 32256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2039 bytes for
local variables. Maximum is 2048 bytes.
avrdude: ser_open(): can't open device "\\.\COM1":
The system cannot find the file specified.

Problem uploading to board.
See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.
Board at COM1 is not available

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

How am I supposed to resolve this?


texts:
I am trying to make a menu for a monitoring/control system.  I am not sure how to make this without interrupting my current code which needs to be monitoring my system at all times to shut off if it reads overload. It is mostly swtich () and case x: stuff. I have looked into attachInteruupt and rotary encoder examples, but none have really helped me figure out how to display a multiple layer menu where I can select to see the system readings as well as edit outputs.

There are a lot of posts here on rotary encoders with LCDs, but I can't seem to find a good skeleton menu code that works well and uses current libraries.  My biggest problem right now is making the menu layers without interrupting my monitoring code running in the background.


texts: Setting a pointer to NULL in Arduino library - error: ‘NULL’ was not declared in this scope

texts:
I am writing my own library for using with my Arduino. In my code, if I set a pointer I have declared to NULL, such as

int *ptr=NULL;

I get the error

error: ‘NULL’ was not declared in this scope

I need to initialize it to NULL as I am using pointers to implement a list.

If I use NULL directly in the program in the IDE, I do not get this error. This seems to be happening only when it is a part of the library code.

How do I correct this? Is there any alternative keyword to use? Or do I have to include some library?

Thank you.


texts:
Is there a way to monitor the battery that feeds an esp8266 in a portable project?

I have been meaning to implement that feature into my project so that i can be warned when the battery runs low on juice but i don't know if the esp has some kind of onboard sensor to do that.


texts: Extract binary data from text string. Like Perl pack, not just regexp

texts:
If I have data coming into an Arduino in an ASCII serial format from some external device (or from a PC, or whatever) and I want to extract binary values from that data and log it or put it on a little display or react to it or whatever there are a few ways I can do it. But it seems like there should be a reversed version of sprintf, mashed up with regexp, mashed up with Perls pack/unpack that would make it easy and configurable.

For example, let's say I'm getting hex numbers from a data logger. something like
c,03,1234,5678,9ABC
where c is just a code telling me this line is channel data, there are 3 channels installed, and then there are the 3 sets of data. I can use split or something like that and then extract the values, convert the hex to binary, apply Y=mX+B and display the channel readings. If a channel goes flat, I can sound an alarm, etc... No worries.

But then I have a different data logger plugged in, and this one uses a different format. Like decimal raw ADC counts. It spits out
2342 1313 234236
Now I gotta recode.

But wait, what if I just had a regexp in eeprom and I used that to extract the data? Something like /^c,\X+,(\X+),(\X+),(\X+)$/ for the first logger and /^(\d+) (\d+) (\d+)$/ for the second. That would be really cool because I could pretty much extract data from any serial device for local display. No need to reprogram, just update the regexp. And there is a nice regexp library:
https://github.com/nickgammon/Regexp
although it uses the LUA regexp syntax.

Oh, but that won't work... because although my program in the Arduino gets back 3 values from the regexp, it doesn't know that the first set are hex strings, and the second set are decimal.

Now, if I was doing this in Perl, I'd just apply a pack string to the binary data. But then pack can't reject a bad match, it always returns a result, even if the input wasn't valid.

Doesn't it seem like the regexp should be able to return /binary/ values instead of just the string? It knows those values are hex. And shouldn't pack be able to do matching against the other characters in the string and reject the value if it's not a match?

Seems to me like there is a hole in our standard libraries. Something that does both simple matches, and converts data to binary return values on the fly.

Or is that too much to ask from an engine? Perhaps few people would use it; better to just hardcode for the rare times you need something like this?


texts: Alright, so I just recently got an Arduino Uno and I'm really not sure what to do/where to start with it. So far I've only made a light blink on it, but I was wondering if it is possible to have it do more complicated things like run programs or, say, a keylogger. How would I be able to do this and is this even possible on an Uno?


texts: Arduino Ethernet Shield on Arduino Mega Pin Usage!

texts:
I currently have an Arduino Ethernet Shield which is Mega Compatible. I've found on the Arduino Ethernet Library https://www.arduino.cc/en/Reference/Ethernet that the Shield uses different Pins on the Arduino Uno and Arduino Mega. How is this possible? The Ethernet shield isn't connected to those pins mentioned.

Arduino Uno:
Pin: 13 - SCK
Pin: 12 - MISO
Pin: 11 - MOSI
Pin: 10 - SS for Ethernet Controller

Pin: 4 - SS for SD Card

Arduino Mega:
Pin: 52 - SCK
Pin: 50 - MISO
Pin: 51 - MOSI
Pin: 53 - SS for Ethernet Controller

Pin: 4 - SS for SD Card


texts: 4x4 matrix keypad - Multiple inputs cause extra readings

texts:
I have the following matrix keypad -

I am using this as a sort of controller with my Arduino (Mega2560) but I can't get real multiple inputs to work. I am able to have say two individual keys pressed at a time but after that they overlap with eachother. (Using the Keypad library also).

Here is an illustration of the issue:

If I press the 3 blue buttons and use the getKeys function it thinks that the red one is also pressed. This works when any three or more buttons are pressed that produce a square.


texts:
I'm looking for a way to read a 24 bpp bmp file from a SD cart, and than convert it to text and write it to the serial monitor.

So the output should look something like this:
R255,B255,G255

And that for each pixel


texts: What Arduino boards would be compatible?

texts:
I am considering using an arduino over the raspberry pi for a new project. However, I am not sure what arduino I should buy so that it is compatible with the below add-on.

Are all Arduinos compatible?

TIA.

Edit:

Link to product- https://www.adafruit.com/product/3387

My goal is to use an arduino with the above product to move a 3D model in Unity 3D.


texts:
For a school project I Have to make an IoT solution in the retail. We were thinking of a smart clothing hanger. We want to make the hanger smart enough to recognize what clothing is hanging on it. In order to do so the clothing has to be able to send some sort of ID to the hanger.

first thing we thought of was RFID but the hanger next to an one hanger would pick up the signal from the other hanger so that wouldn’t be an option.

Does anyone have any other ideas on what we could try to let the piece of clothing talk to the hanger?


texts: Problem with power supply ws2812b Arduino 5v vs 12v

texts: I have an Arduino wired to ws2812b with 10 100uF capacitors and 2 1000ohm resistors(picture). When I'm plugging 5v power supply everything is working when I plug 9v battery everything is fine but when I'm plugging 12v power supply in one moment leds stops.(NeoPixel standardtest example. How I can power the ws2812b by 12v


texts: At what frequency/rate does the digitalRead function read an input?

texts:
Consider the following code:

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(ledPin, HIGH);
  }
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

The line buttonState = digitalRead(buttonPin); checks the input voltage.

But how is that checked internally?

I mean at what rate the input is checked?


texts: What would you change to make this circuit safer and more efficient?

texts:
I have a 24v battery bank and need to power a 24v pump for a duck pond.
In my existing setup, I have a submersible pump with, effectively, a 100% duty cycle but this pump is not submersible and while it is thermally protected, I plan to control it using an Arduino.
Here's a drawing of the proposed setup:

"A" is a 24V battery bank that I have, deep cycle batteries in series, charged by some 100W photovoltaic panels.
I'm planning to split at the fuse block "B" with two fuses a 20A one for the pump and then a 5A one for the Arduino "D" and the Relay "E" and to step down the 24V I have a DC-DC converter "C" that will give me 5V 3A for those two.  The Converter has a couple of USB outputs and those two will independently power "D" and "E" - a signal line from the Arduino (in purple).  The relay will be normally open and close to power the pump "F" for perhaps 10 minutes an hour.  The goal is just to pull out ~100 gallons from the bottom of the pond, dump it into a holding tank and let gravity separate some of the solids from the water.
Eventually, I am planning to add a TPL5110 to turn the Arduino on and off as 80-90% of each hour the pump won't be running.  But that's probably going to have to wait until I figure that out.
Can you see anything that is glaringly wrong or things you would add or change to make this work in a more safe and/or efficient manner?


texts:
I am using the Adafruit Fona 808 to make a wearable device. One of the main features is GPS but I cannot seem to find a suitable antenna for wearables. My question is: What is a good GPS antenna for a wearable project and should it be active or passive?
Thanks


texts: combine the two sensors(DHT22 and Apds 9960 rgb gesture) code,, anyone help me? thankyou

texts: i am making the prototype of my project using DHT22 and Apds 9960 RGB gesture with Ardunio, i dont know how to combine two sensor and at a time


texts: Configuring Accelerometer on BNO055 sensor

texts:
I'm using the BNO055 9DOF Adafruit sensor to measure the acceleration/orientation. How can I change the configuration of the accelerometer from 4G (default) to 16G?

What I already know:

The datasheet : https://cdn-shop.adafruit.com/datasheets/BST_BNO055_DS000_12.pdf

From point 3.5.2 from page 27, I need to change xxxxxx01b to xxxxxx11b in the configuration file (that is the library). I use https://github.com/adafruit/Adafruit_BNO055 but I could not find any information on what to change and where in the .h file.

Any ideas?

Thank you


texts:
I am looking for an efficient (and safe) way to use the Arduino to switch a higher voltage device off and on. The first option would be a relay, but they are fairly bulky. I was wondering if I should use an Optoisolator instead ?

Here is a link to the Data sheet for the Optoisolator I am using..

http://www.everlight.com/file/productfile/el817.pdf
I think (if I am reading it correctly) it expects an input voltage of 1V at about 20mA ?

However, I think it may be more involved than I originally thought. Here is a sort of simulation of what I am trying to achieve.
http://tinyurl.com/y9xd7lzb

As you can maybe tell, I am using a voltage divider to reduce the output from the arduino (from 5V to 1V).
My concerns are ..

Is this the best approach ?
Is it efficient ?
are there any problems I should be aware of ? Precautions I need to take ?
Is the voltage divider a good approach to feed the input to the Optoisolator ?

Also, efficiency is an issue as the Arduino (probably a Nano) will be running off batteries.

The target device is a 20V DC motor. I am a novice when it comes to electronics, so I would be grateful of any help or advice you can give.

Many thanks..

Dave.


texts: Writing and reading multiple values through serial

texts:
I am currently busy with a project that requires me to use an Arduino and 3 potentiometers (to change background in RGB format) to write values through the serial port and read and separate them in processing.

What I want to do is to be able to use my Arduino to write multiple values to a processing program. I am quite new to coding and its been a while since I worked with my Arduino. I know how to read and write one value, but not multiple values.

Also is there a way to write 20 values?

Thanks in advance!


texts: Is it possible to recover an Arduino if it does not wake up after putting it to sleep

texts:
I have an ATTiny85 controlling the power to a number of devices. When I first power on it will power the devices via a mosfet. Take the readings it needs to and then puts itself to sleep for 15 minutes then wake up and repeat.

My question is, because I am using the Watchdog timer to put it to sleep, I can't use the reset functionality of the watchdog (ie wdt_Reset). So is there anyway to detect a lock or hang if the ATTiny85 never wakes up for some reason or would I need additional hardware to check for this. If so what kind of circuit would I need.

Thanks