texts: Arduino MySQL Connector Issues with Select only

texts:
first question i am doing so hope this is the right place.

I have an issue with an Arduino Uno and an Arduino ESP8266WiFi Shiald by WangTongze using this tutorial (https://www.instructables.com/id/ESP8266-ESP-12E-UART-Wireless-WIFI-Shield-TTL-Conv/) I have been able to connect to the my Wifi and host a small webserver.

Then with the Examples of the MySql Connector Library I have been able to do a simple Insert to a MySQL Database on a NAS Server. However, I want to be able to select a value from my DB and print it on the screen for some reason the Cursor always returns a null. I have been able to select from my PC using the same user. and created the user francis@% so that the host isn't an issue. Please note that this same code with a few tweaks worked to insert a record to the same table. Is there anything I am missing? Below is the code:

//#include <WiFi.h> // Use this for WiFi instead of Ethernet.h
#include <WiFiEsp.h> //use for ESP8266
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

// Emulate Serial1 on pins 2/3 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif

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

IPAddress server_addr(192,168,x,x); // IP of the MySQL server here
char user[] = "francis";
char password[] = "xxxxxx";

// WiFi card example
char ssid[] = "PintoLoco"; // your network SSID (name)
char pass[] = "xxxxxxxx"; // your network password

//WiFiClient client; // Use this for WiFi instead of EthernetClient
WiFiEspClient client; //Use this for ESP8266
MySQL_Connection conn((Client *)&client);
MySQL_Cursor cur = MySQL_Cursor(&conn);

char query[] = "SELECT Value FROM Peceras.Parameters ";

void setup() {

  Serial.println("Starting....");
  Serial.begin(115200);
  // initialize ESP module
  WiFi.init(&Serial);
  Serial.println("Connecting to WiFi");

  // Begin WiFi section
  int status = WiFi.begin(ssid, pass);
  while(status != WL_CONNECTED){
      status = WiFi.begin(ssid, pass);
    }
  // print out info about the connection:

  Serial.println("Connected to network");
  IPAddress ip = WiFi.localIP();
  Serial.print("My IP address is: ");
  Serial.println(ip);

  // End WiFi section

  Serial.println("Connecting...");
  if (conn.connect(server_addr,3306,user,password)) {
  delay(1000);
  }
  else
  Serial.println("Connection failed.");
}
MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
void loop() {
  row_values *row = NULL;
  long head_count = NULL;
column_names *cols = cur_mem->get_columns();
cur_mem->execute(query);
  // Execute the query
  do {
    row = cur_mem->get_next_row();
    if (row != NULL) {
      for (int f = 0; f < cols->num_fields; f++) {
        head_count = atoi(row->values[f]);
          Serial.print("Ingestelde Temperatuur:  ");
          Serial.println(head_count);
        if (f < cols->num_fields-1) {
          Serial.println(',');

        }
      }
      Serial.println();
    }
  } while (row != NULL);
  // Deleting the cursor also frees up memory used
  delete cur_mem;
  delay(2000);
}


texts: Reading from SPIFFS - What's the best way to deal with a string (or char) array with undefined length?

texts:
I've read that it's best to avoid using String in Arduino so I'm ready to use a char array if it's better.
I'm reading the file names from an SD Card and my goal is to store them in an array and then be able to read that array. What I'm currently doing is:

String lib_arr[100];
int lib_arr_size;

and then

File dir = SD.open("/");
int c = 0;
while (true) {
  File entry = dir.openNextFile();
  if (!entry) {
    // If no more files
    lib_arr_size = c - 1;
    break;
  }
  if(strcmp(entry.name(), "SYSTEM~1") == 0) {
    continue;
  }
  lib_arr[c] = entry.name();
  entry.close();
  c++;
}

and then

for (int i = 0; i < lib_arr_size; i++) {
  if(i == pos) {
    tft.print("> ");
    tft.println(lib_arr[i]);
  } else {
    tft.println(lib_arr[i]);
  }
}

This is not a solution because, for my purposes, the String lib_arr[100] can be 1000 or 10000 or 100000... and I found out that by increasing that value the global variables use skyrockets and Arduino says that it's out of memory. My goal is memory optimization. I don't know how to go about this problem.


texts: Value read is not changing while rotating pot in arduino?

texts:
I am trying to read voltage using analogRead in Arduino Uno from a voltage divider circuit consisting of 1k resistor and 10k pot. The Pot used is bourns 3296. The values obtained only range from 1011 to 1023? Why is the count not reducing further if I rotate the pot?

(this how i have connected the circuit, but the pot is the one that i have mentioned above, i couldn't find that kind in the software, but i have made the connection this way only)

int analogPin = A0;

// variable to store the value read
float val = 0;

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

void loop() {
  Serial.println(val); // read the input pin
  val = analogRead(analogPin); // debug value
}

Since potentiometer itself is a voltage divider, I have tried connecting as per the answer, the ends of the 10k pot to 5V and ground , and the slider pin to the analog pin A0. The new circuit is as shown below, but I am still unable to get the value ranging from 0 to 1023. The values returned only vary in between 1010 to 1023. What is going wrong? How do I get the full range?


texts: I want to print onto serial monitor when it's detected the value change

texts:
This code is measuring distance from object by using the Ultrasonic Sensor and print onto serial monitor.

However, serial monitor constantly output values.
I want to print only one time if detected value not change.
and serial monitor print again only when detected value change.
and The above condition keeps repeating.

How can i change the code?

int distance ;
int trig = 3;
int echo = 2;

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

void loop()
{
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  distance = pulseIn(echo, HIGH) / 58;
  Serial.println(distance);
}


texts: How many interrupt pins can an Uno handle?

texts: I am looking at using a 7 channel RC receiver with the Arduino Uno R3. In the documentation, there are mentions of a maximum of 2 interrupt pins, whereas on certain other blogs I have seen mentions of using upto 20 pins as interrupts, with PinChangeInt library. So, how many interrupts can the Arduino handle natively? And is this different from  how many can be handled with software support such as PinChangeInt?


texts: Warning when verifying sketch with VS code

texts:
I use Visual Studio Code to develop for arduino which uses Arduino Studio installed files and needs the installation to work. This works very well.

Annoying is that when verifying a sketch it takes longer than in the Arduino IDE. I suspect the following warning to cause it:

  [Warning] Output path is not specified. Unable to reuse previously
  compiled files. Verify could be slow. See README.

I would like to get rid of the warning and I searched through all README files in the arduino installation folder and I also searched google but haven't found out what its supposed to mean and how to fix it. No readme file mentions that or I overlooked it.

Is there a documentation on how to fix this anywhere?


texts:
Im using a potentiometer to control the speed of two generic 6-8V DC motors. The potentiometer input is scaled from 0-1023 to 0-255, I then use the analogWrite() function to write this value to the enable pins on my L293D motor controller.

Im sure this should control the speed but it doesn't, I have the code printing the value it sends to the enable pins and this is correct, but no speed increase, the motors either move at one speed or don't move at all. My enable pins are 12 and 13 on my Arduino Uno, previously 5 and 6 but I moved them to see if that was the problem.

Is there a problem with the PWM frequency maybe? I don't understand why it won't go faster and slower after days of troubleshooting.. The inputs are all set correctly, allowing both motors to move in the forward direction..

int Speed = analogRead(speedChange);
int SpeedMap = map(Speed,0,1023,0,255);
analogWrite(enable1, SpeedMap);
analogWrite(enable2, SpeedMap);

Its a long shot but does anyone know enough about PWM control on DC motors to think of any things I may be missing while trying to do this? Ill provide any info ASAP, thanks


texts: Does Serial.read() ever return a character?

texts:
I'm trying to program my Arduino Mega to work with a TSL1401 line scan module and while looking over someone else code I came across this:

void loop()
{
    int b = Serial.read();      //Reads incoming serial data. Returns the first byte of
                                //incoming serial data available (or -1 if no data is available)

    if (b == 's')
    {
        getCamera();
        delay(2000);
    }
}

For the most part I understand what it's doing but I got confused when I saw that he was setting the return value of Serial.read() equal to a variable and then checking to see if that variable was a character. To my understanding Serial.read() returns an integer so why would you compare it to a character?


texts:
I have DHT22 sensor attached to an ESP8266. When running a sketch that read the sensor values, it suffer from frequent hangs (something like each 1 second).

All outputs are stopped (Sound from speaker or even the Serial output) during those hangs.

Here is a small Sketch to reproduce:

#include "DHT.h"
DHT dht(D1,DHT22);
void setup(){
  Serial.begin(115200);
}
void loop(){
  Serial.println(dht.readTemperature(true));
  Serial.println(dht.readHumidity());
  delay(1);
}

P.S. it is not about the small delay(1). Even if I read the sensor values each 1 second, this problem will occur. To make sure, you may run this example:

#include "DHT.h"
DHT dht(D1,DHT22);

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

unsigned long last = 0UL;
void loop(){
  if(millis() - last > 1000){
      Serial.println("#########" + String(dht.readTemperature(true)));
      Serial.println("#########" + String(dht.readHumidity()));
      last = millis();
  }
  Serial.println(String(rand()));
  delay(10);
}

After flashing it, opens serial monitor and you can see clearly the hangs (I put random number printing so your eyes can not cheat you by an cashed old value;) )


texts:
I am trying to use the micro SD card module on the 1.8 inch TFT display as shown in the photo. However, I am not able to make it work. The display module is 5/3.3 volt tolerant. The display works fine but the SD module doesn't. So far I have tried powering it up with 3.3V and 5V, changing the SD cards, connecting the display and SD module at the same time as well as individually, have tried formatting the card and lastly trying out different CS pins for the SD module. None of that has worked.

After examining the pin connections, it seemed to me that may be SD module is missing the connection to VCC so I checked with the DMM and it reads around 3.1V on the CS pin so I suppose it is working. So I am not sure what else I could try before giving up on that. Ideas?
// include the SD library:
#include <SPI.h>
#include <SD.h>

// set up variables using the SD utility library functions:
Sd2Card card;
SdVolume volume;
SdFile root;

// change this to match your SD shield or module;
// Arduino Ethernet shield: pin 4
// Adafruit SD shields and modules: pin 10
// Sparkfun SD shield: pin 8
// MKRZero SD: SDCARD_SS_PIN
const int chipSelect = 8;

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

  Serial.print("\nInitializing SD card...");

  // we'll use the initialization code from the utility libraries
  // since we're just testing if the card is working!
  if (!card.init(SPI_HALF_SPEED, chipSelect)) {
    Serial.println("initialization failed. Things to check:");
    Serial.println("* is a card inserted?");
    Serial.println("* is your wiring correct?");
    Serial.println("* did you change the chipSelect pin to match your shield or module?");
    while (1);
  } else {
    Serial.println("Wiring is correct and a card is present.");
  }

  // print the type of card
  Serial.println();
  Serial.print("Card type:         ");
  switch (card.type()) {
    case SD_CARD_TYPE_SD1:
      Serial.println("SD1");
      break;
    case SD_CARD_TYPE_SD2:
      Serial.println("SD2");
      break;
    case SD_CARD_TYPE_SDHC:
      Serial.println("SDHC");
      break;
    default:
      Serial.println("Unknown");
  }

  // Now we will try to open the 'volume'/'partition' - it should be FAT16 or FAT32
  if (!volume.init(card)) {
    Serial.println("Could not find FAT16/FAT32 partition.\nMake sure you've formatted the card");
    while (1);
  }

  Serial.print("Clusters:          ");
  Serial.println(volume.clusterCount());
  Serial.print("Blocks x Cluster:  ");
  Serial.println(volume.blocksPerCluster());

  Serial.print("Total Blocks:      ");
  Serial.println(volume.blocksPerCluster() * volume.clusterCount());
  Serial.println();

  // print the type and size of the first FAT-type volume
  uint32_t volumesize;
  Serial.print("Volume type is:    FAT");
  Serial.println(volume.fatType(), DEC);

  volumesize = volume.blocksPerCluster();    // clusters are collections of blocks
  volumesize *= volume.clusterCount();       // we'll have a lot of clusters
  volumesize /= 2;                           // SD card blocks are always 512 bytes (2 blocks are 1KB)
  Serial.print("Volume size (Kb):  ");
  Serial.println(volumesize);
  Serial.print("Volume size (Mb):  ");
  volumesize /= 1024;
  Serial.println(volumesize);
  Serial.print("Volume size (Gb):  ");
  Serial.println((float)volumesize / 1024.0);

  Serial.println("\nFiles found on the card (name, date and size in bytes): ");
  root.openRoot(volume);

  // list all files in the card with date and size
  root.ls(LS_R | LS_DATE | LS_SIZE);
}

void loop(void) {
}

Update: I have also added the pictures of the connections


texts: Testing ID and Serial Communication (Update)

texts:
Here is my challenge: I have to create a sketch where I would have a prompt asking the user to enter an ID. If it is successful, it would turn on the green LED and response with "Hello, your name is so-so."  If it failed, it would turn on the red LED and response with "Invalid username! Try again."

The code is here:

//Establish myID as CHAR data type
 char myID = 'tg123';
 //Establish testID to receive data to be tested against myID
 char testID;

 //Establish green and red LEDs to PWM pins
 const int gLED = 10;
 const int rLED = 5;

 void setup()
 {
  //Establishing baud rate at 9600
  Serial.begin(9600);
  pinMode(gLED, OUTPUT);
  pinMode(rLED, OUTPUT);
 }

 void loop()
 {
  //Act when there are data in the buffer
  while (Serial.available())
  {
    testID = Serial.read();
    //If data = myID, turn on green LED and acknowledge
    if (testID == myID)
    {
      digitalWrite(gLED, HIGH);
      digitalWrite(rLED, LOW);
      Serial.println("Hello! Your name is Trevor.");
      delay(5000);
    }
    else
    {
      digitalWrite(rLED, HIGH);
      digitalWrite(gLED, LOW);
      Serial.println("Invalid ID! Try again.");
      delay(2000);
    }
  }
 }

Two problems I have had with this:

The damn thing would print the line "Please enter your ID:" infinitely if it was inside the loop, so I got fed up and moved it to the set up, and
no matter what I enter in the serial monitor, it does not do anything.

Update: After reading Arduino's website, I found I can predefine the char data type by adding char myID = 'tg123';.  It is getting closer to achieving what I want, but it's exhibiting some strange behavior.  When I type in exactly tg123 in the serial monitor, it would report the error message as defined in the sketch before passing.


texts: Use a button on LCD shield to pause the code

texts:
I'm creating a Temperature logging device with thermocouple K and SD card breakout and a RGB LCD Shield Kit w/ 16x2 Character Display (with buttons).

Everything runs ok: temperature displaying on the LCD and logging on txt file on the micro SD card work well

Now I try to configure button on the shield

button UP to reset measurements and timer , it works
button Down to pause measurements, then when pushed again, continue measurements. I don't know how to do that (how to go out the while condition).

 if (buttons) {

if (buttons & BUTTON_UP) {

  lcd.clear();
  lcd.print("RESET ");
  if (SD.exists("datalog.txt")) {

    SD.remove("datalog.txt");
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
  }

  else {

    // open the file. note that only one file can be open at a time,
    // so you have to close this one before opening another.
    File dataFile = SD.open("datalog.txt", FILE_WRITE);
    // if the file is available, write to it:

  }
 StartTime = millis();

  delay(500);

}
if (buttons & BUTTON_DOWN) {
  lcd.clear();
  lcd.print("STOP");
  while (buttons & BUTTON_DOWN){

      ;
  }

}

I already thank you for your help,

Vincent


texts: Board and library updates required caused an error

texts:
I compiled my code several times today,
I would quit and restart randomly through the day.
each time I started I get a error box board and libraries need updates.
I did an AVR board up date, then compiled and now I get this every time.....

avrdude: no programmer has been specified on the command line or the config file
         Specify a programmer using the -c option and try again

Yes I have tried rebooting my Windows 7 64 bit AMD machine.

this is on IDE "Arduino 1.6.8"

Of course I made the mistake of not backing up my IDE folders in the belief that an update would not screw my IDE up.

Nothing will upload, not even any of the examples.
I turned on Show Verbose output during Compilation, and upload
I pasted the full output and it was 4500 char to many for this so I turned of the compilation check and left just the upload check on show verbose errors

I loaded in the example blink,

the file followed by the IDE lower window text.

/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://www.arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald
 */

// the setup function runs once when you press reset or power the board
void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
}

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

END OF FILE
Copy and paste of the lower IDE window  last lines the same as above

Sketch uses 928 bytes (2%) of program storage space. Maximum is 32,256 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 2,039 bytes for local variables. Maximum is 2,048 bytes.
C:\Users\Lee\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino2/bin/avrdude -CC:\Users\Lee\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino2/etc/avrdude.conf -v true -patmega328p -carduino -PCOM10 -b115200 -D -Uflash:w:C:\Users\Lee\AppData\Local\Temp\build9c9ef3bdfe2fccb480bc6e4bac749e41.tmp/Blink.ino.hex:i

avrdude: Version 6.3, compiled on Jun 22 2016 at 16:05:21
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\Lee\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino2/etc/avrdude.conf"

avrdude: no programmer has been specified on the command line or the config file
         Specify a programmer using the -c option and try again

There is that line again   What do I do to fix this?
besides deleting everything and starting all over again?

I do not want to delete and start over


texts: AVRdude does not read the FUSE byte values correctly

texts:
I am exploring the ATmega328p MCU via a standard Arduino UNO, with the help of avr-gcc toolchain and AVRdude (All in the WINAVR package). I have successfully programmed the board a few times with it. However, when I try to read the fuse values via AVRdude, I get 0x0 for lfuse, hfuse and efuse.
I am using the following command (or its variants) to read:
avrdude -c arduino -p ATMEGA328p -P com3 -b 115200 -v -F -U hfuse:r:hi_fuse_val.hex:h
Following is the output I get:
avrdude.exe: safemode: lfuse reads as 0
avrdude.exe: safemode: hfuse reads as 0
avrdude.exe: safemode: efuse reads as 0
avrdude.exe: safemode: lfuse reads as 0
avrdude.exe: safemode: hfuse reads as 0
avrdude.exe: safemode: efuse reads as 0

The file hi_fuse_val.hex also has 0 written to it.What am I doing wrong?


texts:
I have a simple network created using XBee Series 2 devices.

My network is very simple, my end-device with Arduino Uno read a temperature and Lightning, display this value into LCD and send using XBee to a coordinator. It is setting for sleep and wake up using PIN hibernation.

It is setting like End-Device AT mode.

I try to send a Remote AT command with XCTU from coordinator to my end device and it parse this command and response.

What I try to do is parse received packet into my Arduino code and decide what response (for example discharge it).

It is possible to do using only one Serial? The Arduino Uno and XBee are connected with an XBee shield.

I have try using this code but the Arduino don't display the packet received from the Coordinator.

This is my code:

#include <avr/sleep.h>
#define XBEE_sleepPin 7
#include <LiquidCrystal.h>

//Sensor variable
int sensorPin = 0;
int fotoResistenzaPin = A1;
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String data = "";
String name = "Arduino1";

//Time Variable
unsigned long seconds = 1000L;
unsigned long minutes = seconds * 60;
unsigned long hours = minutes * 60;

void setup() {
  pinMode(fotoResistenzaPin, INPUT);
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Status:");
  lcd.setCursor(0, 1);
  lcd.print("Connected");
  Serial.begin(9600);
  delay(2000);
}

void xbeesleep() {
  delay (300);
  pinMode (XBEE_sleepPin, OUTPUT);   // put XBee to sleep
  digitalWrite(XBEE_sleepPin, HIGH); // Setting this pin to LOW turns off the pull up resistor, thus saving precious current
  //delay(10 * minutes);
  delay(5 * seconds);
}

void xbeewake() {
  pinMode(XBEE_sleepPin, OUTPUT);  // Set the "wake-up pin" to output
  digitalWrite(XBEE_sleepPin, LOW); // wake-up XBee
  delay(10 * seconds); //make sure that XBee is ready, time to connect to Xbee Coordinator

}

void loop() {
 //wait message
  if (Serial.available()>0) {

    //see if it is a Xbee packet
    if (Serial.read() == 0x7E) {

      for (int i = 0; i < 15; i++) {
        byte skip = Serial.read();
        Serial.println(skip);

        //check if it is a Remote AT commnad
        if (skip == 0x17) {

            //do something when i find the Remote AT command packet
          lcd.setCursor(0, 0);
          lcd.print("Remote AT command ");
        }
      }
    }
  }

  xbeewake();
  int reading = analogRead(sensorPin);
  int val = analogRead(fotoResistenzaPin);
  float voltage = reading * 5.0;
  voltage /= 1024.0;

  float temperatureC = (voltage - 0.5) * 100 ;
  data = name + ',' + temperatureC + ',' + val;
  if (Serial) {
    Serial.println(data);
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("Temp: ");
    lcd.print(temperatureC);
    lcd.print(" C");
    lcd.setCursor(0, 1);
    lcd.print("Lightning: ");
    lcd.print(val);
  }
  else {
    lcd.setCursor(0, 0);
    lcd.print("Serial Error ");
    lcd.setCursor(0, 1);
    lcd.print("Stop Trasmission");
  }

  xbeesleep();

}


texts:
I am trying the example ros arduino publisher using an ESP32 Dev Module.
When I try to connect using rosserial I get "Uable to sync" error.
I have tried using different baud rates, 115200, 57600 and 9600
None of them worked. I clicked on the serial port monitor of the arduino IDE by mistake and saw this message:
Rebooting...
ets Jul 29 2019 12:21:46

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1100
load:0x40078000,len:9232
load:0x40080400,len:6400
entry 0x400806a8

Not sure what to make out of the above error.
What am I doing wrong?
Thanks in advance.


texts: AMIS30543 | DataSheet Understanding CIRCULAR TRANSLATOR TABLE

texts:
I was reading the data sheet of AMIS-30543 stepper motor and I didn't understand fully what does this Circular Translator Table means, I have a couple of doubts

What does Circular Translator table Stands for.? How to read it .? pg:13
What does the current pairs can be projected approximately on a circle in Ix, Iy plane means.? pg:25

In the data Sheet it is given that Changes on the NXT input will move the motor current one step up/down in the translator table (even when the motor is disabled:  = 0). So the changes happened in the table while the motor was disabled will reflect as soon as the motor become active.? Like if I give say 5 step input while the motor was disabled and when I make the motor enable , will the motor will move by itself to reach that position in the translator table.? pg:25

Link to datasheet


texts: esp_partition_get_sha256() mismatches PHP's hash() function in HTTPUpdate

texts:
Disclaimer: It may be that this question belongs to a PHP forum instead of this one. However, this question is also very ESP32/Arduino related. Please correct me if this is the case.

The scenario:

Implementing self-update routines for my ESP32 project, using HTTPUpdate
Using a server-side PHP script to decide which binary image to serve to the device, or return HTTP 304 return code if no updates available.
Using the sketch's MD5 and SHA-256 hashes provided by the HTTPUpdate library as request headers, server-side, to check binary version.

The problem:

The MD5 hash contained in the request header "x-ESP32-sketch-md5" is the same as the MD5 hash calculated by a simple md5() call using the raw binary for the currently running version.
The SHA256 hash contained in the request header "x-ESP32-sketch-sha256" is not the same as the hash obtained by calling PHP's hash("sha256", $v) (where $v contains the same raw binary).

Example:

MD5 (HTTPUpdate): c93d814989b53a24a0164e561b6a8bf8
MD5 (PHP): c93d814989b53a24a0164e561b6a8bf8 (no difference)
SHA256 (HTTPUpdate): 5634674253E095600CD863A34287FCA742BCFCF9B5BF409870DD65AF0ADEF7A0
SHA256 (PHP): 1ECDDF3215520C79AAD13BBC1D116D9286910490DF316B9B203FCBFC89CBCCC2 (different)

Am I doing something wrong?

Note: The esp_partition_get_sha256() function is called internally by the update() method of the HTTPUpdate library.

PHP Code (for calculating the hashes):

<?php

$v = file_get_contents("fw.bin");

print("MD5: ". md5($v)."\r\n");
print("SHA256: ".hash("sha256", $v)."\r\n");

Arduino code (the relevant part):

// Called once or twice a day
void update_fw()
{
    Serial.println("Checking for updates...");

    t_httpUpdate_return ret = httpUpdate.update(client, "http://my_server/fw/check_fw.php");  // For now it only logs the headers and returns HTTP 304 code

    switch (ret)
    {
      case HTTP_UPDATE_FAILED:
        Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str());
        break;

      case HTTP_UPDATE_NO_UPDATES:
        Serial.println("HTTP_UPDATE_NO_UPDATES");
        break;

      case HTTP_UPDATE_OK:
        Serial.println("HTTP_UPDATE_OK");
        break;
    }
}

PHP code (logs headers and returns HTTP 304 code):

<?php

$headers = getallheaders();

if (!file_exists("log.txt"))
{
    file_put_contents("log.txt", print_r($headers, true));
}

http_response_code(304);            // No updates.

exit;

Thanks in advance.


texts: Can I use the SVG headers on the SainSmart Uno to drive servos?

texts:
I am working with a Sainsmart Uno with SVG header pins.  This header is really convenient for hooking a servo to directly, so I have two servos connected to it on D9 and D10 and a 9v battery supplying power via the power jack.

Everything seems to work fine at first, but eventually (sometimes quickly), the board becomes unresponsive.  If, instead, I wire my servos to use the 5v pin on the Arduino (not from this SVG header), I don't run into this trouble.

Does anyone know if I am running into a limitation of this header Voltage pin?  Has anyone had any success using this mechanism to drive servos?  Certainly, I don't NEED to do it this way, but it sure is convenient.


texts:
I connected an OLED display to SDA and SCL Pins of Arduino UNO. However, I cannot find the adress by using the Arduino I2C Scanner.
All of the wires are connected correctly and the display has power. What else could be the problem?
Edit:


texts: How do I connect an accelerometer (GY-521) to a SparkFun Thing Dev (ESP8266)?

texts:
All of the wiring diagrams I've found for wiring up a GY-521 accelerometer to an Arduino have looked something like this:

I've read in several places that it needs to be connected to A4 and A5. I want to connect one to a SparkFun ThingDev, which unfortunately only has a single analog input:

Is this possible?

I only need it for a very simple application (finding out if a machine is vibrating or not).


texts:
I have a question about using the Arduino and Processing. I want to build a touch sensor using aluminum foil and connect it to an interface built in Processing. However i've come across a problem. I don't know how to send the serial data from the Arduino to Processing. This is the code I'm using to get the sensor value from the aluminum foil:

#include <CapacitiveSensor.h>

CapacitiveSensor   cs_4_2 = CapacitiveSensor(4,2);

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

void loop(){
  long start = millis();
  long total1 =  cs_4_2.capacitiveSensor(30);

  Serial.print(millis() - start);
  Serial.print("\t");

  Serial.print(total1);
  Serial.print("\t");
  Serial.print('\n');

  delay(100);
}

The foil is connected to dig pin 4 with a resistor of 1M in between and to dig pin 2 with a resistor of 1K. Pin 4 is the send pin, pin 2 is the receive pin. It all works just fine, in the serial monitor in the Arduino software I get the value of the time between refreshes and the sensor value. But how do I use this sensor value in a Processing sketch? I thought of maybe using Firmata on the Arduino, but then I wouldn't know how to use the CapacitiveSensor library and get the sensor values. Does anyone know how to get this to work? Help would be greatly appreciated!


texts: Side by side two TFT LCDs 1.8'' with ST7735 driver but one acts differently

texts:
Hardware setup:

Custom PCB with ATMega 2560
Working Batch: TFT LCDs 1.8'' with ST7735 driver (Chinese version)
Bad Batch: TFT LCDs 1.8'' with ST7735 driver (Chinese version)

Library:
From Adafruit, latest version (1.7.0)
I've been using those LCDs for years. But, the LCDs I bought lately are not working as they should be.
They look completely identical from outside. I've bought from several different sellers from China just in case. All of them have the same behavior.
I therefore decided to find a software solution rather than trying out all LCDs in Chinese market.
Whatever variant of ST7735s I have (sellers claim they are just ST7735 nothing else), I need to adapt it to my software accordingly.
In order to keep the trial efforts efficient, I only test on the examples given by Adafruit until I proof it works. I share the outcome of the good and bad LCDs for your comparison below.
Any input greatly appreciated.

EDIT: A library had been sent by a seller. But, It doesn't look like it is 100% corresponding to ST7735. For example, since @Majenko asked, I add the initialization code from the library;
void Lcd_Init(void)
{

//调用一次这些函数，免得编译的时候提示警告
    LCD_CS =1;
    if(LCD_CS==0)
    {
       LCD_WR_REG_DATA(0,0);
       LCD_ShowString(0,0," ");
       LCD_ShowNum(0,0,0,0);
       LCD_Show2Num(0,0,0,0);
       LCD_DrawPoint_big(0,0);
       LCD_DrawRectangle(0,0,0,0);
       Draw_Circle(0,0,0);
     }

    LCD_REST=1;
    delayms(5);
    LCD_REST=0;
    delayms(5);
    LCD_REST=1;
    LCD_CS=1;
    delayms(5);
    LCD_CS =0;  //打开片选使能

        LCD_WR_REG(0x11); //Sleep out
    delayms(120); //Delay 120ms
    //------------------------------------ST7735S Frame Rate-----------------------------------------//
    LCD_WR_REG(0xB1);
    LCD_WR_DATA8(0x05);
    LCD_WR_DATA8(0x3C);
    LCD_WR_DATA8(0x3C);
    LCD_WR_REG(0xB2);
    LCD_WR_DATA8(0x05);
    LCD_WR_DATA8(0x3C);
    LCD_WR_DATA8(0x3C);
    LCD_WR_REG(0xB3);
    LCD_WR_DATA8(0x05);
    LCD_WR_DATA8(0x3C);
    LCD_WR_DATA8(0x3C);
    LCD_WR_DATA8(0x05);
    LCD_WR_DATA8(0x3C);
    LCD_WR_DATA8(0x3C);
    //------------------------------------End ST7735S Frame Rate-----------------------------------------//
    LCD_WR_REG(0xB4); //Dot inversion
    LCD_WR_DATA8(0x03);
    LCD_WR_REG(0xC0);
    LCD_WR_DATA8(0x28);
    LCD_WR_DATA8(0x08);
    LCD_WR_DATA8(0x04);
    LCD_WR_REG(0xC1);
    LCD_WR_DATA8(0XC0);
    LCD_WR_REG(0xC2);
    LCD_WR_DATA8(0x0D);
    LCD_WR_DATA8(0x00);
    LCD_WR_REG(0xC3);
    LCD_WR_DATA8(0x8D);
    LCD_WR_DATA8(0x2A);
    LCD_WR_REG(0xC4);
    LCD_WR_DATA8(0x8D);
    LCD_WR_DATA8(0xEE);
    //---------------------------------End ST7735S Power Sequence-------------------------------------//
    LCD_WR_REG(0xC5); //VCOM
    LCD_WR_DATA8(0x1A);
    LCD_WR_REG(0x36); //MX, MY, RGB mode
    LCD_WR_DATA8(0xC0);
    //------------------------------------ST7735S Gamma Sequence-----------------------------------------//
    LCD_WR_REG(0xE0);
    LCD_WR_DATA8(0x04);
    LCD_WR_DATA8(0x22);
    LCD_WR_DATA8(0x07);
    LCD_WR_DATA8(0x0A);
    LCD_WR_DATA8(0x2E);
    LCD_WR_DATA8(0x30);
    LCD_WR_DATA8(0x25);
    LCD_WR_DATA8(0x2A);
    LCD_WR_DATA8(0x28);
    LCD_WR_DATA8(0x26);
    LCD_WR_DATA8(0x2E);
    LCD_WR_DATA8(0x3A);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x01);
    LCD_WR_DATA8(0x03);
    LCD_WR_DATA8(0x13);
    LCD_WR_REG(0xE1);
    LCD_WR_DATA8(0x04);
    LCD_WR_DATA8(0x16);
    LCD_WR_DATA8(0x06);
    LCD_WR_DATA8(0x0D);
    LCD_WR_DATA8(0x2D);
    LCD_WR_DATA8(0x26);
    LCD_WR_DATA8(0x23);
    LCD_WR_DATA8(0x27);
    LCD_WR_DATA8(0x27);
    LCD_WR_DATA8(0x25);
    LCD_WR_DATA8(0x2D);
    LCD_WR_DATA8(0x3B);
    LCD_WR_DATA8(0x00);
    LCD_WR_DATA8(0x01);
    LCD_WR_DATA8(0x04);
    LCD_WR_DATA8(0x13);
    //------------------------------------End ST7735S Gamma Sequence-----------------------------------------//
    LCD_WR_REG(0x3A); //65k mode
    LCD_WR_DATA8(0x05);
    LCD_WR_REG(0x29); //Display on

}


texts: How can I concatenate multiple byte Arrays into one Array

texts:
I have three byte arrays. I first change their values during runtime and after that I want to combine them into one bigger 4th array.

byte a1[] = { 0x01, 0x00, 0x01 };
byte a2[] = { 0x00, 0x11, 0x01 };
byte a3[] = { 0x11, 0x00, 0x01 };

byte c1[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

I first tried this, but it did not compile.

c1 = a1 + a2 + a3;

I also tried strcat() and I did got a error.


texts:
I am currently working on a project with a HC-06 module. I hooked it up accordingly like so:

Arduino -> HC-06
5V -> VCC
GND -> GND
TX -> RX
RX -> TX

and I ran this code:

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

void loop() {
   Serial.print("test");
   Serial.print("\n");

}

Strangely enough that does not work at all. When I am using neither with or without PC as the power source. When I am using SoftwareSerial like this it works like a charm:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // RX, TX

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

void loop() {

   mySerial.print("test");
   mySerial.print("\n");

}

Can someone please explain why and of course how to fix that?


texts: Master Reader/Slave Sender with Distance Sensor

texts:
I am currently working on a project and want to transmit the information from a distance sensor from one arduino the another, but what i receive in the master board are not the correct measurements.

Slave Code

#include <Wire.h>

const int trig = 12;
const int echo = 13;

int state = 0;
int count = 0;
int contor = 0;
int set_distance = 5;
long duration, Distanceincm;

void setup()
{
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(9600);           // start serial for output
}

void loop()
{
 digitalWrite(trig, HIGH);
  delay(15);
  digitalWrite(trig, LOW);
  duration = pulseIn(echo, HIGH);
  Distanceincm = (duration / 58);
  if (state == 0 && (Distanceincm < set_distance) ) {
    state = 1;
    count++;
    contor++;
    Serial.print("Distance=");
    Serial.println(Distanceincm);
    Serial.print("Count=");
    Serial.println(count);
    Serial.print("ConuntDay=");
    Serial.println(contor);
  }
  if (Distanceincm > set_distance) {
    state = 0;
  }
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {

  Wire.write(Distanceincm);
  Wire.write(count);
  Wire.write(contor);
}

Master Code

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start Serial for output
}

void loop()
{
  Wire.requestFrom(2, 6);    // request 6 bytes from slave device #2
  while(Wire.available())    // slave may send less than requested
  {
    long a = Wire.read();
    Serial.print ("Distance = ");
    Serial.println(a);

    int b = Wire.read();
    Serial.print ("Count = ");
    Serial.println(b);

    int c = Wire.read();
    Serial.print ("CountDay = ");
    Serial.println(c);
  }

  delay(500);
}

What i get on the serial monitor is this :


texts:
Here is the shiftOut function code from wiring_shift.c

void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val)
{
     uint8_t i;

     for (i = 0; i < 8; i++)  {
           if (bitOrder == LSBFIRST)
                 digitalWrite(dataPin, !!(val & (1 << i)));
           else
                 digitalWrite(dataPin, !!(val & (1 << (7 - i))));

           digitalWrite(clockPin, HIGH);
           digitalWrite(clockPin, LOW);
     }
}

Does this mean that least significant bit is on the left and most significant bit is on the right? Or LSBFIRST means that will be the last outputted bit so it will be "first" in outputted sequence?

One more thing

here is a sample code:

shiftOut(dataPin, clockPin, LSBFIRST, B00101001);
shiftOut(dataPin, clockPin, LSBFIRST, B11010011);

Why does this

union
{
     word uniform;
     byte separate[2];
} state;

state.uniform = 54057; // aka 11010011 00101001
shiftOut(dataPin, clockPin, LSBFIRST, state.separate[1]);
shiftOut(dataPin, clockPin, LSBFIRST, state.separate[0]);

have different output but if i swap last two lines it works correctly?


texts: Is there a way to make the RESET pin work in the inverse?

texts:
Is there a way for me to have this work the opposite way?
I have one cable with an alligator clip hooked up to the reset pin and another hooked up to ground.
When I clip them both together, the board resets.
However, I would like for this to work in the opposite way such that they’re already clipped together and when you detach the cables, the board resets.


texts: What is happening when digitalWrite(pinname, LOW) is invoked after pinMode(pinname, INPUT_PULLUP)?

texts:
I read the Arduino official docs on digitalWrite and am confused about what is happening from an electrical perspective when digitalWrite is invoked on INPUT_PULLUP pins.
Say my code says this:
pinMode(4, INPUT_PULLUP);
digitalWrite(4, LOW);

The docs say:

If the pin is configured as an INPUT, digitalWrite() will enable
(HIGH) or disable (LOW) the internal pullup on the input pin. It is
recommended to set the pinMode() to INPUT_PULLUP to enable the
internal pull-up resistor. See the Digital Pins tutorial for more
information.

Does this mean pin 4 is floating or is it at ground?  Are those two lines of code equivalent to pinMode(4, OUTPUT); digitalWrite(LOW);  ?


texts:
Is it safe to run an arduino pro mini 3.3v by 5v?
I mean directly connect 5v to vcc not raw pin.


texts: Simple serial message not consistent (sometimes jumbled up)

texts:
I have the following code, it works (most of the time) - yet it's not 100% reliable and now and then will send through a double message on one line or 2 subsequent alpha characters:
const byte interruptPin0 = CONTROLLINO_IN0;
const byte interruptPin1 = CONTROLLINO_IN1;
int counter1 = 0;
int counter2 = 0;
unsigned long previousMillis = 0;
unsigned long interval = 2000;
int a = 60;
char buffer1[256];
char buffer2[256];

void setup()
{
  pinMode(interruptPin0, INPUT_PULLUP);
  pinMode(interruptPin1, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(interruptPin0), pin1Fired, RISING);
  attachInterrupt(digitalPinToInterrupt(interruptPin1), pin2Fired, RISING);
  Serial.begin(9600);
}

void loop()
{
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    previousMillis = currentMillis;
    sprintf(buffer1,"A%d",counter1);
    Serial.println(buffer1);
    sprintf(buffer2,"D%d",counter2);
    Serial.println(buffer2);
    counter1 = 0;
    counter2 = 0;
  }
}

void pin1Fired()
{
  counter1 = counter1 + 1;
}

void pin2Fired()
{
  counter2 = counter2 + 1;
}

Result:

This later causes a problem when my code on the other end of the serial comms expects [LETTER][NUMBER].
What have I missed here? I'm relatively new to C for Arduino so quite possibly took a bad approach here?
I've tried to avoid sending serial comms from the interrupt, I read that was risky - hence me tracking the interrupt counts separately.
Can also confirm baud rate matches.
EDIT
To confirm MCU resets I have printed in setup - note: no interrupts firing, still the same issue:


texts: How to re-send UDP data packet to a esp8266 board?

texts:
I have several connected esp8266 boards. Lower level client boards connect to middle level esp8266 board and middle level board connects to the top level Esp8266 board (AP).When a client sends UDP data packet to middle level esp8266 which should re-send that data packet to top level AP. The middle level board successfully got the UDP packet from the client, but top level AP does not receive the data packet from the middle esp866 board.

This is my middle level esp8266 code.

StaticJsonDocument<200> doc;
unsigned int locPort1 = 1000;
unsigned int locPort2 = 2000;
WiFiUDP udp1;
WiFiUDP udp2;
char packetBuffer[100];
IPAddress addrs;

void setup() {

  Serial.begin(9600);
  delay(10);
  Serial.println('\n');

  ConnectToAP();
  delay(1000);
  EnableAP();
  delay(1000);

  udp1.begin(locPort1);
  udp2.begin(locPort2);
}

void loop() {

int Icb = 0;
int Scb = 0;
int Acb = 0;

  Icb = udp1.parsePacket();

  if(Icb > 0){
      GetSensorDataPacket();
      Icb = 0;
    }
}

void EnableAP(){

  WiFi.softAPConfig(local_IP, gateway, subnet);
  WiFi.softAP("xxxxx", "123456789101");
  delay(1000);

  Serial.print("Access Point \"");
  Serial.print("xxxxx");
  Serial.println("\" started");
  Serial.print("IP address:\t");
  Serial.println(WiFi.softAPIP());
}

void ConnectToAP(){

  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP(ssid, pwd);

  Serial.print("Connecting to ...........");
  Serial.print(ssid); Serial.println("...");

  int i = 0;
  while (WiFiMulti.run() != WL_CONNECTED) {

   delay(1000);
   Serial.print(++i); Serial.print(' ');
  }

  Serial.println('\n');
  Serial.println("Connection established!");
  Serial.print("IP address:\t");
  Serial.println(WiFi.localIP());
}

void GetSensorDataPacket(){

  Serial.println("GetSensorDataPacket Function");
  udp1.read(packetBuffer,100);
  DeserializationError error = deserializeJson(doc, packetBuffer);

  IPAddress ClientAddrs = udp1.remoteIP();

  double SensorData = doc["SensorData"];
  int ClientID = doc["ID"];

  delay(1000);
  Serial.println();
  Serial.print("Sensor reading = ");
  Serial.println(SensorData);
  Serial.print("Client ID = ");
  Serial.println(ClientID);

  SendDataToNextAP(SensorData,ClientID);
}

void SendDataToNextAP(double Sensor_Data,int Client_ID){

  StaticJsonDocument<500> jsonBuffr;
  Serial.println("I'm in SendDataToNextAP Function");

  udp2.beginPacket(NextAP, locPort1); //gateway
  JsonObject Sob1 = jsonBuffr.to<JsonObject>();
  Sob1["SensorData"] = Sensor_Data;
  Sob1["ID"] = Client_ID;
  serializeJson(jsonBuffr, udp2);

  udp2.println();
  udp2.endPacket();

  delay(1000);
}

This is my top level esp8266 board code.

StaticJsonDocument<200> doc;
unsigned int locPort1 = 1000;
WiFiUDP udp1;
char packetBuffer[100];

void setup() {

  Serial.begin(9600);
  delay(10);
  Serial.println('\n');

  EnableAP();
  udp1.begin(locPort1);
  delay(1000);
}

void loop() {

int Icb = 0;
int Scb = 0;

  Icb = udp1.parsePacket();
  if(Icb > 0){
      GetSensorDataPacket();
    }
}

void EnableAP(){

  WiFi.softAPConfig(local_IP, gateway, subnet);
  WiFi.softAP(ssid,pwd);
  delay(1000);

  Serial.print("Access Point \"");
  Serial.print(ssid);
  Serial.println("\" started");
  Serial.print("IP address:\t");
  Serial.println(WiFi.softAPIP());
}

void GetSensorDataPacket(){

  Serial.println("GetSensorDataPacket Function");
  udp1.read(packetBuffer,100);
  DeserializationError error = deserializeJson(doc, packetBuffer);

  IPAddress ClientAddrs = udp1.remoteIP();

  double SensorData = doc["SensorData"];
  int ClientID = doc["ID"];

  delay(1000);
  Serial.println();
  Serial.print("Sensor reading = ");
  Serial.println(SensorData);
  Serial.print("Client ID = ");
  Serial.println(ClientID);
}

I have a hard time figuring this out, so if anyone can help me, thanks a lot.


texts:
I am trying to read data from RS232 Shield with an Arduino Mega.

This is the schematic pin, TX is 3 and RX is 2.

Wiring:
PC > USB-RS232 cable > Arduino RS232 Shield.
Software to send/receive data:
Hercules Setup Utility

From Arduino, I can transmit data to RS232, the TX led blink and I got the value at PC.
From PC, I send the data, the RX led blink but nothing is showed in Arduino Monitor.

#include <SoftwareSerial.h>

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

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

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

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

I also tried to move RX and TX to Pin 15 and 14 but worked as the same as before.


texts: Esp32(Arduino Core) + Blynk Wifi Connection Problems

texts:
So I am making a football playing robot which consists of 3 servo motors. Currently,i am only checking only a single servo(myservoKicker)which is operated via button in the blynk app and trying to read x and y values from joysticks in blynk. I am using wifi communication. I have seen that wifi.begin never properly starts as the serial.print("Blynk Connected") after it does not run, plus on my blynk app the project constantly connects and disconnects.
Note: The code for steering other servo's is not implemented yet and is just a stub.
Board: DoIt ESP32 Devkit V1 30 GPIO
Blynk: 0.6.1
myservoKicker connected to pin 13

#include <ESP32Servo.h>
#include <SPI.h>
#include <Ethernet.h>
#include <ETH.h>
#include <WiFi.h>
#include <WiFiAP.h>
#include <WiFiClient.h>
#include <WiFiGeneric.h>
#include <WiFiMulti.h>
#include <WiFiScan.h>
#include <WiFiServer.h>
#include <WiFiSTA.h>
#include <WiFiType.h>
#include <WiFiUdp.h>
#include <BlynkSimpleEsp32.h>

Servo myservoKICKER;
Servo myservoLEFTWHEEL;
Servo myservoRIGHTWHEEL;
int pos;

char auth[] = "9Itekdu3vf_B_3YmNxxHu9G3Bs_1IWs9";
char ssid[] = "RO IMRAN RO";
char pass[] = "xxxxxxxxxxx";
char localserver[16]= "192.168.1.1";
BLYNK_WRITE(V1)
{
    int xAxis = param[0].asInt();
    int yAxis = param[1].asInt();

    // Do something with x and y
    Serial.print("X = ");
    Serial.print(xAxis);
    Serial.print("; Y = ");
    Serial.println(yAxis);

}
BLYNK_WRITE(V4){                                        //WHEEL CALIBRATION
    int WheelCalibration=param.asInt();
    if(WheelCalibration == 1)
    {
        myservoLEFTWHEEL.attach(26);
        myservoRIGHTWHEEL.attach(27);
        delay(100);
        myservoLEFTWHEEL.write (90);
        myservoRIGHTWHEEL.write (90);
        delay(30000);

    }
}
BLYNK_WRITE(V5){                                        //KICKER 90 DEGREE CALIBRATION
    int KickerCalibration= param.asInt();
    if(KickerCalibration == 1)
    {
        myservoKICKER.attach(13);
        delay(100);
        myservoKICKER.write (90);
        delay(200);

    }
}

void setup(){
    // Attach servos to pins
    myservoLEFTWHEEL.attach(26);                        //1
    myservoRIGHTWHEEL.attach(27);                       //2
    myservoKICKER.attach(13);                           //3

    // detach servos to avoid jitter on power up
    myservoLEFTWHEEL.detach();
    myservoRIGHTWHEEL.detach();
    myservoKICKER.detach();

    Serial.begin(115200);
    delay(10);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid,pass);
    int wifi_ctr = 0;
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
        Serial.print(".");
    }
    Serial.println("WiFi connected");
    Blynk.begin("9Itekdu3vf_B_3YmNxxHu9G3Bs_1IWs9",ssid,pass);
    Serial.println("Blynk connected");
}

void loop()
{
    Blynk.run();
}


texts:
I'm working on a Arduino-based synthesizer using this tutorial, specifically using a wavetable and 1-bit DAC. I understand that the value for OCR2A register sets the frequency, but how do I calculate the value?

I've seen this list of notes which is great, but I want arbitrary frequencies in Hz...

Here's the code I'm working from:

#include <avr/interrupt.h>

// sinewave parameters
#define FREQ 18
#define PI2 6.283185    // 2*PI saves calculation later
#define AMP 127         // scaling factor for sine wave
#define OFFSET 128      // offset shifts wave to all >0 values

#define LENGTH 256      // length of the wave lookup table
byte wave[LENGTH];      // wavetable

void setup() {

  // populate wavetable
  for (int i = 0; i < LENGTH; i++) {
    float v = (AMP * sin((PI2 / LENGTH) * i));
    wave[i] = int(v + OFFSET);
  }

  // set timer1 for 8-bit fast PWM output
  pinMode(9, OUTPUT);       // make timer’s PWM pin an output
  TCCR1B = (1 << CS10);     // set prescaler to full 16MHz
  TCCR1A |= (1 << COM1A1);  // pin low when TCNT1=OCR1A
  TCCR1A |= (1 << WGM10);   // use 8-bit fast PWM mode
  TCCR1B |= (1 << WGM12);

  // set up timer2 to call ISR
  TCCR2A = 0;             // no options in control register A
  TCCR2B = (1 << CS21);   // set prescaler to divide by 8
  TIMSK2 = (1 << OCIE2A); // call ISR when TCNT2 = OCRA2
  OCR2A = FREQ;           // set frequency of generated wave
  sei();                  // enable interrupts to generate waveform!
}

void loop() {
  // nothing to do here!
}

// called every time TCNT2 = OCR2A
ISR (TIMER2_COMPA_vect) {   // called when TCNT2 == OCR2A
  static byte index = 0;    // points to each table entry
  OCR1AL = wave[index++];   // update the PWM output
  asm("NOP; NOP");          // fine tuning
  TCNT2 = 6;                // timing to compensate for ISR run time
}


texts: expected unqualified id-before '/' token ------ can someone help, please

texts:
/* Multiple State Handling
* 05-22-2019
*/

#define button 3                        //Push button on D3
#define lowbeam 5                       //Low Beam on D5
#define highbeam 6                      //High Beam on D6
#define gate 7                          //Gate on D7

/------------------------------------------------------------------------

int state = 0;                          //integer to hold current state
int old = 0;                            //integer to hold last state
int buttonPoll = 0;                     //integer to hold button state
/-------------------------------------------------------------------------

void setup() {
  pinMode(button,INPUT);                //button set as input
  pinMode(lowbeam,OUTPUT);              //relays set as outputs
  pinMode(highbeam,OUTPUT);
  pinMode(gate,OUTPUT);

  digitalWrite(lowbeam,LOW);            //initial state as off
  digitalWrite(highbeam,LOW);           //initial state as off
  digitalWrite(gate,LOW);               //initial state as off

}
/-------------------------------------------------------------------------
void loop() {

                                        //debouncing routine to read button
  buttonPoll = digitalRead(button);     //poll state of button
  if(buttonPoll == 1){                  //check if it has been pressed
    delay(50);                          //wait 50msec
    buttonPoll = digitalRead(button);   //poll button again
    if(buttonPoll == 0){                //if it is 0 consider 1 press
      state = old +1;                   //increase state by 1
    }}
  else{                                 //if button has not been pressed
  deley(100);                           //wait 100ms
  }
  switch (state) {                      //react to button press & state
    case 1:                             //if state is 1
      digitalWrite(lowbeam,HIGH);       //lowbeam relay on
      digitalWrite(highbeam,LOW);       //highbeam relay off
      digitalWrite(gate,LOW);
      old = state;                      //set old state as current state
      break;
    case 2:
      digitalWrite(lowbeam,LOW);
      digitalWrite(highbeam,HIGH);
      digitalWrite(gate,LOW);
      old = state;
      break;
    case 3:
      digitalWrite(lowbeam,LOW);
      digitalWrite(highbeam,LOW);
      digitalWrite(gate,HIGH);
      old = state;
      break;
    default:                            //if state if no 1,2,3
      digitalWrite(lowbeam,LOW);        //all relays off
      digitalWrite(highbeam,LOW);
      digitalWrite(gate,LOW);
      old = 0;                          //reset to all off/state 0
      break;
  }
}


texts:
I'm using the 3715 RF arduino modules and a hc-sr04, and i'm trying to send the distance i get from the ultrasonic over to the arduino with the rf recieving module but i get something like this:

Instead of getting this:

Here are the code snippets for each arduino:

Arduino TX:

#include <VirtualWire.h>

const int led_pin = 11;
const int transmit_pin = 12;
const int receive_pin = 2;
const int transmit_en_pin = 3;
long distance;
long time1;
void setup()
{
   // Initialise the IO and ISR
   Serial.begin(9600);
   pinMode(9, OUTPUT);
   pinMode(8, INPUT);
   vw_set_tx_pin(transmit_pin);
   vw_set_rx_pin(receive_pin);
   vw_set_ptt_pin(transmit_en_pin);
   vw_set_ptt_inverted(true); // Required for DR3100
   vw_setup(2000);   // Bits per sec
}

byte count = 1;

void loop()
{
   digitalWrite(9,LOW);
   delayMicroseconds(5);
   digitalWrite(9, HIGH);
   delayMicroseconds(10);
   time1=pulseIn(8, HIGH);
   distance= int(0.017*time1);
   Serial.println("Distance ");
   Serial.println(distance);
   Serial.println(" cm");
   delay(1000);
   char msg[1] = {distance};

   msg[0] = count;
   digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
   vw_send((uint8_t *)msg, 3);
   vw_wait_tx(); // Wait until the whole message is gone
   digitalWrite(led_pin, LOW);
   delay(1000);

}

Arduino RX:

#include <VirtualWire.h>

const int led_pin = 6;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;

void setup()
{
   delay(1000);
   Serial.begin(9600);  // Debugging only
   Serial.println("setup");

   // Initialise the IO and ISR
   vw_set_tx_pin(transmit_pin);
   vw_set_rx_pin(receive_pin);
   vw_set_ptt_pin(transmit_en_pin);
   vw_set_ptt_inverted(true); // Required for DR3100
   vw_setup(2000);  // Bits per sec

   vw_rx_start();       // Start the receiver PLL running
}

void loop()
{
   uint8_t buf[VW_MAX_MESSAGE_LEN];
   uint8_t buflen = VW_MAX_MESSAGE_LEN;

   if (vw_get_message(buf, &buflen)) // Non-blocking
   {
      int i;

      digitalWrite(led_pin, HIGH); // Flash a light to show received good message
      // Message with a good checksum received, print it.
      Serial.print("Got: ");

      for (i = 0; i < buflen; i++)
      {
         Serial.print(buf[i], HEX);
         Serial.print(' ');
      }
      Serial.println();
      digitalWrite(led_pin, LOW);
   }
}

I'm open for pointers as i'm pretty much a noob at this, thank you very much for your help! :)


texts: RFID + LCD + Arduino Mega 2560 = RFID not printing correctly

texts:
My Arduino Mega isn't printing the RFID card's tag it simply prints the card's 2 digits at a time but deletes the previous prints. Can I get help with this?

#include <SPI.h>
#include <MFRC522.h>
#include <Servo.h>
#include <LiquidCrystal.h>

Servo myservo;  //creates servo to control

const int rs = 26, en = 27, d4 = 28, d5 = 29, d6 = 31, d7 = 30;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

#define SS_PIN 53
#define RST_PIN 5
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
int R=3;
int G=8;
int B=6;

void setup() {
  lcd.begin(16, 2);
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  Serial.println("Approximate your card to the reader...");
  lcd.print("Place your card");
  lcd.setCursor(0, 1);
  lcd.print("Near reader");
  lcd.setCursor(0, 0);
  myservo.attach(7);//attatches servo to pin 7
  myservo.write(179);
}

void loop() {
  analogWrite(B, 255);
  // Look for new cards
  if (!mfrc522.PICC_IsNewCardPresent()) {
    return;
  }
  // Select one of the cards
  if (!mfrc522.PICC_ReadCardSerial()) {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  byte letter;
  String content= "";
  for (byte i = 0; i < mfrc522.uid.size; i++) {
     lcd.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     lcd.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
     lcd.setCursor(0, 0);
  }
  delay(1000);
  lcd.clear();
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "4F 60 3C D9") {
    //change here the UID of the card/cards that you want to give access
    Serial.println("Authorized access");
    lcd.print("Authorized");
    analogWrite(B, 0);
    tone(4, 900, 100);
    lcd.clear();
    Serial.println("Unlocking...");
    lcd.print("Unlocking...");
    lcd.clear();
    analogWrite(R, 255);
    analogWrite(G, 127);
    delay(1000);
    myservo.write(100);
    delay(15);
    Serial.println("Unlocked");
    lcd.print("Unlocked");
    lcd.clear();
    analogWrite(R, 0);
    analogWrite(G, 255);
    delay(5000);
    Serial.println("Relocking...");
    lcd.print("Relocking...");
    lcd.clear();
    analogWrite(R, 255);
    analogWrite(G, 127);
    delay(1000);
    myservo.write(179);
    delay(15);
    Serial.println("Locked");
    lcd.print("Locked");
    lcd.clear();
    analogWrite(R, 0);
    analogWrite(G, 0);
    delay(100);
  } else {
    Serial.println("Checking Card");
    lcd.print("Checking Card");
    lcd.setCursor(0, 1);
    delay(100);
    lcd.clear();
    Serial.println("Access denied");
    lcd.print("Access denied");
    analogWrite(B, 0);
    tone(4, 900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 1900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 1900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 1900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 1900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(500);
    tone(4, 1900, 1000);
    analogWrite(R, 255);
    delay(500);
    analogWrite(R, 0);
    delay(100);
  }
 lcd.clear();
 Serial.println("Ready");
 lcd.print("Ready");
}


texts: I am using Arduino Uno. I want to control my room lamp both manually and over the network, so when I switch off my lamp manually, how do I get acknowledgement over the network that lamp is off ?


texts: Change operational mode of CAN transceiver

texts:
I have two MCP2515 stand-alone CAN controllers with SPI interface, two TJA1042 CAN transceivers and two Arduino Uno boards. As you may know TJA1042 have two operational modes:

Sleep mode
Normal mode.

If I want to change the mode of operation of one transceiver from sleep mode to normal mode(wake it up), I should send a wake up pattern waves from the other transceiver which is in normal mode. for example one of the wake up patterns is: 5.5 µS low, 5.5 µS high and again 5.5 µS low. Now I don't know how to send these patterns with Arduino because MCP2515 is SPI interface.

I use this library: MCP_CAN


texts: The Arduino Uno Page doesn't say the temperatures that it can operate in. I'm thinking about placing it outdoors. How can I make sure my Arduino Uno is safe in weather that can reach -20 to 105 degrees Fahrenheit? (-26 to 40 degrees Celsius).


texts: `LOW` being defined as `0` and `HIGH` being defined as `1` - is this a part of external specification?

texts:
Arduino.h defines LOW as 0x0 and HIGH as 0x1. Does the Arduino API intend to expose that fact? Does it guarantee that this will always be that way?

In other words, what is the intended purpose of these manifest constants: LOW and HIGH?

Is this purely cosmetic mnemonics added as an alternative for 0/1 and false/true, for those who like LOW/HIGH better?
Or is this an attempt to abstract/isolate the user's source code from the actual representation of LOW and HIGH (e.g. in case the representation changes in the future)?

The underlying reason for this question is to figure out whether code like

digitalWrite(some_pin, true);
digitalWrite(some_other_pin, !digitalRead(some_other_pin));

is a good programming practice. (If LOW and HIGH are there to abstract the user's code form their actual values then code like that is definitely a bad programming practice.)


texts:
I am trying to do voltage measurement using Arduino. I am using a voltage divider circuit to reduce the voltage to less than 5V. I measured the voltage on the 5V pin of Arduino and found out that its 4.279 V (I am powering through USB).  So, I am doing following calculations for voltage measurement:

int data1   = analogRead(A0);
float data2 = data1 * (4.279/1023.0);
float volts = data2 * (10 + 2.2)/2.2;  //R1=10k , R2=2.2k
Serial.println(volts);

if(volts > 12.00)
{
  digitalWrite(6,HIGH);
}
if(volts < 12.00)
{
  digitalWrite(6,LOW);
}

So I am getting exact values of voltage. Now I have put a condition like if volt is greater than 12V, turn on an output, else turn off the output. For output, I have a transistor and mosfet connected. As soon as the voltage increases above 12V, output get on but the problem is that when the output is on, Arduino displays wrong values. Like if the voltage is 12.3, it shows 13.6.

I looked it into more and found out that the voltage at 5V pin of Arduino (4.279) gets reduced to 3.865 and due to which calculation goes wrong and it displays wrong values of voltage.

Is there anything which I am doing wrong? Is there any function or keyword in Arduino libraries which can tell us the voltage or is there any way through which we can measure it? I tried putting the 5V pin to analog pins to read it and convert it into volts but again for this we need a reference voltage.
I hope I have explained the question clearly.

Schematic

A0 is the analog pin and PIN6 is digital output of arduino


texts: Default sketch working but arduino is not recognizing

texts:
I have an arduino UNO and when I connected the device through the USB to the PC (with windows 7 64 bit),

The default blinking sketch, which comes shipped with it, is working,

but the device recognition sound is not playing.

and the device driver installation dialog never appeared and no arduino entry in the device manager.

And when I tried to upload a successfully compiled sketch from the ide 1.8.4 ,

It just says, 'problem uploading to board'
More verbosely, ' avrdude: can't open device""\.\COM1": the system cannot find the file specified'

The device is getting power and running the sketch,
But device is not recognized, maybe it is connected charge only, can I install the drivers manually?

Thanks in advance for any help.


texts: If statement comparing array to value list throws error

texts:
In my program I have the following lines of code:

if (invest == {0, 1, 0, 0})
   {
      //code
   }

However, upon attempting to compile the code, I receive the following error:

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

"Invest" is a bool array originally defined with`

bool invest[] = {0, 0, 0, 0};

How can I prevent this error from ocurring?


texts:
Building a data logging and transmission system here. I've a RedBearLab Blend with built-in BLE capabilities and a (cheap) SD / Data logging shield that looks very suspiciously like it's copied from the Adafruit one.

Using a Stock Arduino Uno board, the Data logging shield works out of the box - both RTC TimeSet and cardinfo come back successfully.

Stacking the shield on the Blend, both examples lead nowhere. The TimeSet states that no connection could be made, and the cardinfo says it can't find the card.

I assume it's a pin conflict of some sort, but I'm really unsure what I should do to debug/fix it.

[edit] As I found out below, the SD Module works now - but I still face the problem of not getting the RTC to work. Neither on the shield nor a Tiny RTC module. Again, both work fine on the Arduino Uno.

[edit2] I had basically the same problem for the RTC module as well - see the answer below.


texts:
I would like to pass 3.3V and Ground to an component. How can I achieve such a thing?

I for example would like to let a wire get 3.3V when I for example do digitalWrite(pin, HIGH). It is hard for me to explain this, so I created an illustration in the hope of better clarifying it.

Edit: I have an product that I have dismantled. On the PCB, there is a push button. I would like to solder some wires to the place where the button is so it can be controlled with an arduino (probably wemos d1). When plugging a cable in the 3.3v of the arduino and a cable from the ground, when connecting it to the push button it will cause a boot of the dismantled product. This explains why I would like to give power to a component ONLY when a pin is set high, so I can for example boot the product via a website / app eventually.


texts: Problems with Arduino + IR + Raw code low memory

texts:
im having a problem with my new project with arduino + ir emitter + big raw codes.

I've tryed this way:

https://gist.github.com/jjmjr/41ed083c8229d0218c962641c5af27b0

As you can see each of my raw code from air conditioner is huge so i've tryed with progmem using "a" (as turn on) command on serial to send the first line from the ir raw codes but didnt work.

Any one can help me?

Thanks


texts:
Recently I bought a BT module from eBay which was very cheap. I didn't really noticed the image and I just bought it. When it came I couldn't find any holes to solder the headers. Also the specific module is pretty rare and I couldn't find anything.

Here is an image:

How do I wire up this chip?


texts: Hello I have just got my Arduino to read text from a text file and it is running perfectly. I was interested in being able to load a sketch into the Arduino and having it execute it, from and SD card. The Arduino wouldn't be connected to my laptop at all. I researched it and it is possible, with a different boot loader. Which is a bit annoying because I don't want to change the boot loader on my Arduino. I could put it on a standalone atmega chip but lets pretend I don't have those. So I was thinking if you had pre-compiled Arduino code. Which is in hex format and ready to be put on the board, would it be able to be loaded from the SD card? If so how would I go about doing this?


texts: How to add this old BASIC code snippet to work in Arduino C++ for FastLED?

texts:
I've been trying to implement this old code that randomly transitions to RGB color into my Arduino board that uses FastLED.

Static Col1, Col2, Col3 As Integer
Static C1, C2, C3 As Integer
If (Col1 = 0 Or Col1 = 250) And (Col2 = 0 Or Col2 = 250) And (Col3 = 0 Or Col3 = 250) Then
  C1 = Int(Rnd * 3)
  C2 = Int(Rnd * 3)
  C3 = Int(Rnd * 3)
End If
If C1 = 1 And Col1 <> 0 Then Col1 = Col1 - 10
If C2 = 1 And Col2 <> 0 Then Col2 = Col2 - 10
If C3 = 1 And Col3 <> 0 Then Col3 = Col3 - 10
If C1 = 2 And Col1 <> 250 Then Col1 = Col1 + 10
If C2 = 2 And Col2 <> 250 Then Col2 = Col2 + 10
If C3 = 2 And Col3 <> 250 Then Col3 = Col3 + 10
leds[x] = RGB(Col1, Col2, Col3)

Here is my Arduino setup:

#include <FastLED.h>

#define LED_COUNT 60
#define LED_OUT       13
#define BUTTON_IN     10
#define ANALOG_INPUT  A9
#define EXTRA_PIN_A    7
#define EXTRA_PIN_B   11

struct CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(57600);
  LEDS.addLeds<WS2812B, LED_OUT, GRB>(leds, LED_COUNT);
  LEDS.show();
}

void loop() {
  //where to implement
}


texts: Why do my Hall sensor readings change when I write them to the serial port?

texts:
I have a small project where I connected a Hall sensor (see picture) to an Arduino Mega. The blue wire is connected to pin 45, the red wire to +5V, and the black wire to GND.

At the beginning I initialize the pin used to read the sensor as follows.
#define HALL_PIN 45

void setup()
{
  pinMode(HALL_PIN, INPUT);
}

I have written a function to read out the sensor. While there is no magnet nearby, the sensor returns HIGH. If a magnet approaches in the correct orientation, the sensor returns LOW. The function should return true if a magnet is nearby, i.e. if the read value is LOW.
I have noticed that my program logic sometimes does not work reliably after seemingly irrelevant changes to the code. After commenting out more and more code to narrow down the problem, I came across the following discovery.
Implementation 1:
In the first implementation, I initially read out the value of the Hall sensor. Next, I send the value to the serial port. The serial monitor in the Arduino IDE outputs the number 1 (HIGH). This is the expected behavior as during testing there is no magnet nearby. Based on the subsequent program behavior I can confirm that the function returns false. I can let the Arduino run for minutes and the behavior remains stable.
bool readHallSensor()
{
  int s = digitalRead(HALL_PIN);

  Serial.println(s); // The serial monitor outputs 1 (HIGH)

  return s == LOW; // Returns false
}

Implementation 2:
With the second implementation I do not write the read value to the serial port. As expected, the serial monitor in the Arduino IDE remains empty. The function, however, now returns true. Apart from commenting out the marked line and flashing the sketch to the Arduino, I did not make any changes (again no magnet nearby). Also in this case I can let the Arduino run for minutes and the behavior is stable.
bool readHallSensor()
{
  int s = digitalRead(HALL_PIN);

  // Serial.println(s); // No output to the serial monitor

  return s == LOW; // Returns true
}

My first suspicion was that the delay caused by writing to the serial port is what makes the difference. I asked an electrical engineer whether Hall sensors might need short breaks between successive readings. He denied my assumption, and indeed, if I simply insert a delay(300); after reading the value (without writing to the serial port) the behavior does not change and is identical to implementation 2.
I can switch back and forth between the two implementations and flash them to the Arduino as many times as I like. The behavior is always as described above for both cases. I cannot make any sense of this, as the behavior seems to lack any (programming) logic. Has anyone ever made similar observations and can give me a hint what might cause this? Thank you in advance.

I haven't found the problem yet, but I have come a step closer. The issue has reappeared in a similar project on the same Arduino. I use a new Hall sensor with pull-up, which is read out wrong again under certain circumstances (always read out as LOW, no matter if a magnet is nearby). The problem seems to occur only when I use a certain pin. The pin in question on my Arduino Mega this time is pin 37. If I connect the Hall sensor to another pin (I have tested 34 and 36), it works fine. If I connect a previously working Hall sensor to pin 37, it will not work anymore (always evaluated as LOW). The only explanations that make sense to me at the moment are that either the Arduino Mega is damaged or that there are side effects, maybe caused by external libraries using certain pins without my knowledge and incorrectly initializing them.


texts: Deceleration time logger between frequencies

texts:
i need to measure the air resistance and roll resistance of a vehicle. I plan on using a toothed disc with a proximity sensor which will output a square wave signal in to an arduino. Then I will drive until I reach a certain speed, after which I will disconnect the drive from the wheels and let the vehicle roll until it has reached another certain speed (2 or 3 kph lower than the speed at which I started). By measuring the time it takes to decelerate I can calculate the air and rolling resistance.

I want to use an arduino as the brain box. Once the frequency of the sensor signal drops below a given value the arduino should start measuring time. Once the frequency drops below a second given value the arduino should stop measuring. For example between 25Hz and 20Hz. I would like to change the Frequency (that corresponds to a speed) so i can test at different speeds. I would then want to log the time it took to my pc on the serial monitor. I plan on using an Arduino Mega 2560.

My knowledge of coding in C is very limited so I'm a bit stuck on how I would write such a program. Anybody got any ideas on how to program something by using interrupts? The vehicle on which I want to do this is an Urban Concept car for the Shell Eco-marathon efficiency race.


texts: What is the difference between the digital temperature sensors SHT31 and DHT11 or DHT12?

texts:
I am looking for a digital temperature sensor with I2C interface.

I found the SHT31 and the DHT12 (compatible to DHT11). Both also include humidity sensors. And I found libraries for both of them. But I did not find a comparison.

https://sea.banggood.com/GY-SHT31-D-Digital-Temperature-and-Humidity-100-RH-I2C-Sensor-Module-For-Arduino-p-1167498.html

https://sea.banggood.com/KEYES-DHT12-Digital-Temperature-and-Humidity-Sensor-Module-Compatible-DHT11-For-Arduino-p-1400920.html

What are the (significant) differences between those sensors and libraries?

In the moment I want to use a sensor to measure the intake air temperature of a motorcycle. One degree celsius accuracy is good enough for this purpose. I don't want to calibrate them, this is why I looked for the digital sensors.


texts: How to connect arduino with local network

texts:
I am trying to connect Arduino with local network. This will act as a web server, client would be android mobile app or web browser. These are on same local network.

Do I need Ethernet Shield or ESP8266 to make Arduino accessible with local network IP ? Is there any way to connect without Ethernet Shield ?


texts:
I want to create a small position reporter for cars. I found some good GPS Modules with which i could collect data. But i'm unsure with what technology i should send the data.

A possibility would be to setup a service in the www which is feeded by the arduinos.

I want to track the data live. so i think GPRS should be the right choice ?
Or more better are there any shields which make this GPRS LOG and SEND as a package ?

Which GPRS hardware would you use ?
Would you use something else?

Any hints are very welcome


texts: Accelerometer readings on a moving object

texts:
I hope this stack is the right place for this question.
I have an accelerometer mounted securely on a swaying object -lets say a stick or pole-
this object is swinging back and forth in small angles (+- 20) with a frequency of about 2-3 times a second.
Im using the accelerometer output to calculate the tilt of the object, however since the frequency of the swings is relatively high the accelerometer readings are very high as well, and not reliable for calculating the tilt.

from my research i have seen that accelerometers work best in a stable environment.
Is there any way to improve the reliability of my accelerometer output in this setup?


texts: How can the Arduino Uno support up to 12 servos if it only has 6 digital PWM pins?

texts:
According to this:

  The Servo library supports up to 12 motors on most Arduino boards and
  48 on the Arduino Mega. On boards other than the Mega, use of the
  library disables analogWrite() (PWM) functionality on pins 9 and 10,
  whether or not there is a Servo on those pins. On the Mega, up to 12
  servos can be used without interfering with PWM functionality; use of
  12 to 23 motors will disable PWM on pins 11 and 12.

However, according to this:

  Digital I/O Pins 14 (of which 6 provide PWM output)

So how can the Uno control more than 6 servos if it only has 6 digital I/O pins that can provide PWM output?


texts: Setup J-K Flip-flop for logging on Arduino RESET

texts:
There are two events I plan to log; using no switches or requiring manual input of some kind.  One of the events is whenever the Arduino Serial Monitor is opened; the other, is when external event occurs that causes a Arduino RESET.  Second event produces a LOW pulse used to CLK the J-K Flip-flop.  digitalRead of J-K Flip-flop Q; using a conditional statement, if Q = HIGH log to SD Card as event1 date/time stamp else log to SD Card as event2 date/time stamp.  I need the J-K Output Q to be STORED thru the Arduino RESET, so Q can be read.

After reading Q, will need to clear Q; plan to do this from running sketch with a DigitalWrite

74HC73 is the chip I plan to use; it is triggered with a negative going CLK.

What needs to happen with the J and K inputs?  Will this work in toggle mode; with both J and K tried to +5 volts?


texts: Is it possible to write URLs to RFID tags with the RC522? If so, how?

texts: I've been trying to research to answer this question for a long time, but could not figure out the answer. I know how to code like bytes of information, but not URLs. More specifically, when you code information into a MiFare RFID tag with the RC522 device, each byte goes into separate byte blocks of a sector. They are not combined, meaning the link cannot be read. How do you overcome this and is this even possible?


texts: How many transistors can be connected to Arduino pins?

texts:
How many TIP122 transistors can I connect to the Arduino digital pins? The Atmega328p datasheet states that the pins can source a total of 200 mA, while other documents state 40 mA per pin.

In the following circuit layout, I connected six TIP122 transistors with 2.2  kΩ  base resistors. I used an LM338 regulator to power the Arduino IC and other functions.


texts:
I need to make use of the TimedAction library for a project. The Arduino website gave an example of how to use this library which you can see here:

#include <TimedAction.h>

//this initializes a TimedAction class that will change the state of an LED every second.
TimedAction timedAction = TimedAction(1000,blink);

//pin / state variables
#define ledPin 13
boolean ledState = false;

void setup(){
pinMode(ledPin,OUTPUT);
digitalWrite(ledPin,ledState);
}

void loop(){
timedAction.check();
}

void blink(){
ledState ? ledState=false : ledState=true;
digitalWrite(ledPin,ledState);
}

This example however does not work, the Arduino ide gives back an error stating that the blink function is declared outside the scope. What is the correct way to implement this?


texts: How to make 16 coin vibration motors and 5 servos work at the same time on a Arduino Mega?

texts:
I saw in Arduino Mega's datasheet that the sum of currents out of all input/output pins combined should be maximum 200mA. But I want to make 16 vibration motors and 5 servos work together on the same time. I made the circuit(NMOS, flyback diode, etc.) for every coin vibration motor.Also I'm thinking to power the servos with an external power source.Are the circuits enough so i dont pass the 200mA limit? How can I make the whole thing work together?
im using the following components:

NMOS
coin vibration motor
servo motor


texts: TFT menu system sometimes doesn't refresh the screen properly

texts:
I have a project in which I control a display using an Arduino Due microcontroller.
The user can navigate on the TFT display (RA8875 driver ic) with a rotary enconder/pushbutton.
The display shows a certain menu. You can the selected item in the menu by rotating the rotary encoder and you can move into a submenu by pressing the rotary encoder (because it is also a button).
This is how the menu looks like:

The problem is that sometimes when rotating the encoder the menu doesn't refresh the screen properly and seems to have gotten stuck while drawing the screen. Though when rotating the encoder some more the screen gets properly rendered so the code isn't actually 'stuck'.
This is een example of a bad rendering after rotating the encoder. (Sometimes no text gets written, sometimes some text gets written):

I also made a video to make my problem more clear:
Video with rendering problem.
The code for my menu is rather big so I'll try to explain the working principle and attach the used Arduino code.
I attached an interrupt to the encoder signal and to the push button.

attachInterrupt(digitalPinToInterrupt(BTN_ROT), push_button_interrupt, FALLING);
attachInterrupt(digitalPinToInterrupt(ROT_A), rotary_enc_int, LOW);

In the interrupt function I update a 'virtual position' value. In my main loop I run a function that checks if the virtual position is different from the last seen position and updates the 'current_index'-value of the menu accordingly. It also sets 'refresh_menu' to True.
In the main loop the variable 'refresh_menu' gets checked and if true the screen gets redrawn with the menu item selected according to the value 'current_index'.
Link to full project code: Arduino due code. All the relevant code for this problem is in 'Menus.h'.
[Side note] I am not sure if my approach to build a menu is 'good'. It's not super responsive and the code is hard to maintain (changing a menu-item from position requires a lote of changes in the code). Any advice in a better approach is appreciated!


texts:
I'm at the tail end of a project using a Leonardo, a HC-06 bluetooth module and a few cell phone vibration motors.  Everything is working fine except the serial communication between the Leonardo and the HC-06.  I've done some tests to rule out common mistakes

TX is connected to RX, and vice versa.
Using a multimeter I checked for continuity with the RX TX, no problem there
I can upload the script
I uploaded the exact same script to an Uno, using the same HC-06.  I was able to connect to the HC-06 with my phone and execute the script.  So I know it's not the script and I know it's not the HC-06.
The Leonardo is working properly because I can upload the script and execute it using the Arduino Serial Monitor.

The only clue I have is that I can upload the script with the RX/TX connected and that's not supposed to work.  However, I checked the connections and there is continuity.  So I'm stumped.  The only thing I can think of is that I damaged the RX/TX while I was soldering, but I'm hoping it's not that.  Is there a way to test for that.  Any suggestions?

/*
 * created by Rui Santos, http://randomnerdtutorials.com
 * Bluetooth App - Turn On and Off LED
*/

#include <SoftwareSerial.h>
SoftwareSerial mySerial(1, 0); // RX, TX

int led = 3;
int state;

void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

void loop() {
  if(Serial.available() > 0){
      state = Serial.read();}

  if (state == '1') {
      digitalWrite(led, HIGH);}   // turn the LED on (HIGH is the voltage level)

  else if (state == '2') {
      digitalWrite(led, LOW);}    // turn the LED off by making the voltage LOW

  delay(100);               // wait for 100ms

  //For debugging purpose
  //Serial.println(state);
}


texts:
I recently bought a new ESP8266 because I'm pretty sure I used 5V instead of 3.3V on my old one.
But it seems the new one behaves the same as the old one.

I'm using the sketch:

https://i.imgur.com/CY6YF4E.jpg

When I open up the serial monitor and type [b]AT [/b]I get not response (on the 115200 baud).
If I boot up the power supply while the device is connected I get this in the serial monitor:

load 0x40100000, len 1856, room 16
tail 0
chksum 0x63
load 0x3ffe8000, len 776, room 8
tail 0
chksum 0x02
load 0x3ffe8310, len 552, room 8
tail 0
chksum 0x79
csum 0x79

2nd boot version : 1.5
  SPI Speed      : 40MHz
  SPI Mode       : DOUT
  SPI Flash Size & Map: 8Mbit(512KB+512KB)
jump to run user1 @ 1000

Fatal exception 0(IllegalInstructionCause):
epc1=0x40215021, epc2=0x00000000, epc3=0x00000000, excvaddr=0x00000000, depc=0x00000000

When I googled the log it seems to be related to the voltage. Could it be the same problem again? If so, what did I do wrong?


texts:
I am trying to use Adafruit's ESP8266 implementation for a project of mine, which makes use of a bunch of sensors. The problem I have is the limited amount of pins available from ESP8266:

2 pins are currently being used by I2C (SCL & SDA, pins 4 & 5)
4 pins used by the SD card (MOSI,MISO,CLK & CS, pins 12,13,14,16)
1 as a button input (pin 15)
2 for a UART sensor (Tx and Rx)
2 used for LEDs (pins 0 & 2, using the onboard LEDs)

This leaves me with no serial debugging and no future expansion capabilities, which is quite problematic, as I will probably need to add 1 more UART sensor.

One solution would be to use the analog input pin as the button input and free up one of the LED pins to create a 2nd software UART (not ideal, but it is a solution indeed).

My question is, is it somehow possible to multiplex the pin functionality without using an external IC (space is already quite limited)? So for example, use 2 pins as UART, when I am not writing to the SD card. Or would this just cause more problems?

Thanks in advance!


texts:
I recently designed a board for an LED project. I am using WS2812B as the LED, and an ATMEGA328P-AU as the microcontroller. I also am using an arduino nano as my ISP and using "flash with programmer". When I flashed the FastLED blink example (Code below) the LED lit up as white and stayed white when it was supposed to flash red. I tried various examples and they all had the same outcome, just white. Am I missing a crucial component in my circuit (aside from some decoupling capacitors)? Is it a software problem?
#include <FastLED.h>

#define NUM_LEDS 1
#define DATA_PIN 5

// Define the array of leds
CRGB leds[NUM_LEDS];

void setup() {
     FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);  // GRB ordering is typical
}

void loop() {
  // Turn the LED on, then pause
  leds[0] = CRGB::Red;
  FastLED.show();
  delay(500);
  // Now turn the LED off, then pause
  leds[0] = CRGB::Black;
  FastLED.show();
  delay(500);
}


texts:
I'm trying to do a small test where I am using the ISR on the Arduino Pro Micro it up from sleep mode. I'm using a Force Sense Resistor (FSR, a resistor that changes it's resistance depending on how hard you press it) with a voltage divider circuit with the output of the voltage divider connected to an analog pin and the digital interrupt pin. I'm not able to get the interrupt to trigger no matter what condition I have. I don't believe the Vout on the voltage divider is too low since the ADC registers values between 0 to 1000 (0V to about 4.8V) when the FSR is pressed. Is there anything wrong with my code that is preventing my test from working properly?
uint8_t LED = 9;
uint8_t wakeup = 2;
uint8_t enable = 0;

void Wakeup(void);

void setup() {
  // put your setup code here, to run once:
  pinMode(LED, OUTPUT);
  pinMode(wakeup, INPUT);
  attachInterrupt(digitalPinToInterrupt(1), Wakeup, RISING);
  Serial.begin(115200);
}

void loop() {
  // put your main code here, to run repeatedly:
  //Serial.println(analogRead(A2));
  if (enable == HIGH)
    digitalWrite(LED, HIGH);
  else if (enable == LOW)
    digitalWrite(LED, LOW);
  if (analogRead(A2) < 700)
    enable = 0;
}

void Wakeup(void) {
  enable = 1;
  Serial.println("Interrupt");
}


texts: How do I wire a ground rail to a VEROboard?

texts:
I’m looking to move my project from a breadboard to a vero board. However, I’m not sure how to go about soldering in my ground and power connections as the veroboard doesn't seem to have dedicated ground and power rails like the breadboard.
I’ve also attached a photo of my schematic in its current state.
Also, I’m using an Arduino Nano Board as opposed to the UNO featured in the schematic. (I’ve just used it as a placeholder as I could find a component for the nano.
Any help would be greatly appreciated.

Here’s a photo of the type of veroboard I have:


texts: Arduino motor shield not compatible with nodemcu

texts: Hi to all first of All my english is not good I brought Arduino motor shield  and n..d. E.p 8266 but the connect pin are not compatible how i will connect to node i want to make robo car


texts: Does Arduino Uno R3 require cooling in a closure?

texts: I was looking at getting an enclosure to house my Arduino Uno R3, but I'm not sure if I should also attach a fan.  Does anyone have experience with this?  It doesn't look like much heat is being generated, but with no ventilation except some slits in the enclosure, there won't be much air circulation without a fan.  My concern with adding a fan was the fact that I'd need to power it.


texts: How can I work with two devices that use the SPI protocol?

texts:
I'm working with a project in which I need to use an SD card module and an RFID antenna simultaneously. The devices that I'm using are the MFRC522 and the CATALEX SD Card Adapter. Both have SPI Protocol, and they're using the libraries MFRC522.h and SD.h.

This is the pin layout that I'm using:

/////// For RFID //////////
             Arduino
             Mega
  Signal     Pin
  ---------------------
  RST/Reset  5
  SPI SS     53 (CUSTOM)
  SPI MOSI   51
  SPI MISO   50
  SPI SCK    52

//////// For SD ///////////
             Arduino
             Mega
  Signal     Pin
  ----------------------
  SPI SS     49 (CUSTOM)
  SPI MOSI   51
  SPI MISO   50
  SPI SCK    52

As you can see the only line that they are not sharing is the Slave Select (aside from the RST pin of the RC522 module), so I believe that my wiring is correct.
I tried setting in LOW the chip select of the device that I wanted to use and in HIGH the one that I didn't. But this didn't work.

Any help you could provide would be appreciated! Thanks!


texts:
I use  RH_RF24.h to control Si4463, and realize some simple communication between two Si4463 . But I don't know the mean of RH_RF24_MAX_MESSAGE_LEN in this example.

RH_RF24_MAX_MESSAGE_LEN is a constant ? If so , what decides it ? And if I need to sent and receive  a long  char string , how to do it ?


texts: Same Arduino Sketch when uploaded from a Linux machine does not work

texts:
I am trying out some code using the Arduino IDE. The code basically tries to connect to a server and push some data to it.

When I upload the sketch to the Arduino from Mac (Apple PC running on Mac OS) the code works as expected without an error.

However, when I upload the same code/sketch from a Linux machine on Ubuntu, the arduino does not operate as expected.

I tried taking a diff comparison of the HEX files created in both machines to check whether there are any differences (expecting very few). But found that there a lot of differences.

What am I missing? Why isn't my code working when uploaded via the Linux PC!!!!!


texts: I can change the led brightness when I connect the led's + pin to 74hc595. I use pwm with output enable pin.But I want to use 74hc595 with led's - pin(gnd). So figure this.Will this work ?


texts: Synchronous communication between two Arduino boards using two ESP8266 modules

texts: I am trying to establish communication between two Arduino boards to send data from sensors through a WIFI module. The problem is that I need them to connect to each other whenever they are in range of each other and send the sensor data.


texts: Implementing AT commands with Arduino and ESP8266

texts:
Being a newbie to Arduino, I'm trying to implement AT commands in the serial monitor, though in vain. After connecting the ESP8266 (01) module to an Arduino Uno, I tried to scan for the nearest network present [code link: https://github.com/esp8266/Arduino/blob/master/doc/esp8266wifi/scan-examples.md#simple-scan] and it worked perfectly.

But the moment I am trying to connect to send AT commands (even manually), it shows nothing. In addition, if(Serial.available()) and if(esp8266.available())< both are giving false value.

What am I doing wrong?


texts: What's wrong with my keypad and time program?

texts:
I really need help here. I'm a total noob in Arduino and this is my first Arduino project. I've been trying to get the keypad to be able to input time for my alarm clock project but I only managed to get the welcome part of the program. But then the display stuck at the welcome part only. I want to set alarm time by using the keypad only, and if the alarm time is the same as the time display, the buzzer should ring.

Plus, the deadline is in two days. I'm certain that there's no problem with hardware since all of the components (16x2 LCD, RTC DS1307, buzzer, 4x4 keypad) work properly when I use some basic tutorial coding for the components.

Please check what could be wrong in my code? I've tried to replace some of the codes but it had no change; the display's still stuck at the welcome part.

[Edit]I've added the "milli" code at the timedate() part. But I'm not sure, how to improve the alarm() part of this code? I can't input any key to insert the alarm time at this part.

If there's any update on what I've edit to my code later, I will edit this question's body. Thank you in advance.

#include <EEPROM.h>
#include <Keypad.h>
#include <DS1307.h>
#include <Wire.h>
#include <LiquidCrystal.h>
DS1307 rtc(SDA, SCL);
LiquidCrystal lcd(A3, A2, A1, A0, 5, 4);
Time t;

#define buz 3

int Hor, Min, Sec, h, m, s;
int ASCII = 48;
char* tim;
char* dat;
char buffer[3];
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {6, 7, 8, 9};
byte colPins[COLS]= {10, 11, 12, 13};
Keypad keypad= Keypad(makeKeymap(keys),rowPins, colPins, ROWS, COLS);

unsigned long previousMillis = 0;
const long interval = 1000;

void setup() {
Wire.begin();
rtc.begin();
pinMode(buz, OUTPUT);
lcd.begin(16, 2);
welcome();

rtc.setDOW(TUESDAY); //Set Day-of-Week to SUNDAY
rtc.setTime(18, 20, 00); //Set the time to 12:00:00     (24hr format)
rtc.setDate(18, 12, 2018); //Day, Month, Year
}

void loop() {
t = rtc.getTime();
Hor = t.hour;
Min = t.min;
Sec = t.sec;
tim = rtc.getTimeStr();
dat = rtc.getDateStr();
char key = keypad.getKey();

if(key == 'A'){
alarm();
}

if (key == 'C'){
digitalWrite(buz, LOW);
EEPROM.write(2, ASCII+6);
EEPROM.write(3, ASCII);
}
changealarm();
checkalarm();
timedate();
}

void checkalarm(){
if( Hor == h && Min == m)
{
delay(3000);
lcd.setCursor(0,1);
lcd.print("Hold C");
digitalWrite(buz, HIGH);
delay(3000);
}
}

void changealarm(){
buffer[2] = 0;
buffer[0] = EEPROM.read(0);
buffer[1] = EEPROM.read(1);
h = atoi(buffer);
buffer[0] = EEPROM.read(2);
buffer[1] = EEPROM.read(3);
m = atoi(buffer);
buffer[0] = EEPROM.read(4);
buffer[1] = EEPROM.read(5);
s = atoi(buffer);
}

void timedate(){
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Date: ");
lcd.print(rtc.getDateStr());

lcd.setCursor(0,1);
lcd.print("Time: ");
lcd.print(rtc.getTimeStr());
delay(3000);
lcd.setCursor(0,1);
lcd.print("Alarm: ");
lcd.print(h);
lcd.print(":");
lcd.print(m);
lcd.print(":");
lcd.print(s);
}
}

void welcome(){
lcd.setCursor(0,0);
lcd.print("Welcome");

lcd.setCursor(0,1);
lcd.print("To");
delay(2000);

lcd.setCursor(0,1);
lcd.print("TIMe Project");
delay(2000);
}

void alarm()
{
int j=0;
char key = keypad.getKey();
lcd.clear();
lcd.print("Enter Alarm Time: ");
lcd.setCursor(0,1);
while(j<4)
{
lcd.print(h);
lcd.print(":");
lcd.print(key);
lcd.print(m);
lcd.print(":");
lcd.print(key);
lcd.print(s);
lcd.print(key);
key=0;
}
delay(500);
}


texts: Follow black and white line simultaneously

texts:
I have a line following bot which uses IR sensors (LSA08, more specifically) to detect the white line on black surface and stay on track. For the project however, there is a trick in the track. At a certain point, the line changes from white to black and the bot is expected to follow the black line on the white surface.

My question is, how would I design the algorithm which will make the bot recognise that the track and conditions have changed.


texts:
I'm coding a library which handles sleep procedures.
Since I'm using both ESP826 and ESP32, which uses different sleep commands ( and WiFi ), I'm looking for a way to detect the MCU, while NOT using a boolean flag that indicates so.
Guy