text:
How do I make my LCD screen scroll text while allowing for button input?
Here's what I want my code to do: This is part of a tea infusing project that would automate the steeping of tea, part of this is initially having a selection of either Black/Herbal tea or White/Green tea, this will then set off several other factors down the timeline.
I want my LCD screen to display and scroll "Please select a tea" while still being able to take in pushbutton input.
I've been doing this all day, and I've tried several things. I firstly tried using a normal delay function so my text could scroll properly, but the problem with that is that it halts all the code and doesn't allow for any other input, so I quickly found millis() was likely what I needed to use. However, when I try to apply it to this specific example, it just scrolls all my text extremely quickly through the LCD.
Perhaps I'm being stupid and ignoring something obvious, but please let me know.

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

const int black_herbal_osb = 2;

int black_select;

//Timing
unsigned long prev_millis;
unsigned long current_millis;
const unsigned long LCD_delay = 500;

void setup() {

  //Tea selection buttons
  pinMode(black_herbal_osb, INPUT);

  //LCD screen setup
  lcd.init();
  lcd.backlight();

}

void loop() {

  lcd.autoscroll();
  lcd.setCursor(16, 0);
  lcd.print("Please");

  current_millis = millis();

  black_select = digitalRead(black_herbal_osb);

  if (black_select != HIGH) {

    if (current_millis - prev_millis >= LCD_delay) {
      lcd.print(" select ");
      prev_millis = current_millis;
    }
    if (current_millis - prev_millis >= LCD_delay * 2) {
      lcd.print("a ");
      prev_millis = current_millis;
    }
    if (current_millis - prev_millis >= LCD_delay * 3) {
      lcd.print("tea ");
      prev_millis = current_millis;
    }
  }

  else if (black_select == HIGH) {
    lcd.clear();
    lcd.autoscroll();
    lcd.setCursor(16, 0);
    lcd.print("Black/Herbal ");
    delay(500);
    lcd.print("tea ");
    delay(500);
    lcd.print("selected");
    delay(2000);
    lcd.noAutoscroll();
    lcd.clear();
  }

}

why don't you solve the scrolling problem before adding button code

That's what I did, I just added the button code for illustration reasons, with or without the button code the scrolling is still an issue

I figured it out. I was thinking about it all wrong, I just needed to figure out how the scrolling worked for the LCD and the rest was much easier. Only current issue with my code is that on the initial scroll of "Please select a tea" right after the "Booting..." process, it doesn't seem to start at (16,0) but nearer to the front which makes it not super easy to read initially but it corrects itself after a single scroll.
Here's the code for those interested:
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);

const int black_herbal_pin = 2;
const int white_green_pin = 3;
const int LCD_scroll = 200;

int black_select;
int white_select;

unsigned long current_millis = 0;    // stores the value of millis() in each iteration of loop()
unsigned long previous_scroll_millis = 0;

void setup() {
  Serial.begin(9600);
  //Tea selection buttons
  pinMode(black_herbal_pin, INPUT);
  pinMode(white_green_pin, INPUT);

  //LCD screen setup
  lcd.init();
  lcd.backlight();

}

void loop() {

  if (current_millis == 0) {
    lcd.setCursor (0, 0);
    lcd.print("Booting");
    delay(500);
    lcd.print(".");
    delay(500);
    lcd.print(".");
    delay(500);
    lcd.print(".");
    delay(1000);
    lcd.clear();
  }

  lcd.setCursor(16, 0);
  lcd.print("Please select a tea ");

  current_millis = millis();
  for (int position_counter = 0; position_counter < 16; position_counter++) {

    if (current_millis - previous_scroll_millis >= LCD_scroll) {
      lcd.scrollDisplayLeft();

      previous_scroll_millis += LCD_scroll;
    }
  }

  if (digitalRead(black_herbal_pin) == HIGH) {
    lcd.clear();
    lcd.setCursor (16, 0);
    lcd.print("Black/Herbal tea selecte");
    for (int position_counter = 0; position_counter < 26; position_counter++) {
      lcd.setCursor (0, 0); //This part is likely not necessary for you as it seems to be a bug within my own LCD
      lcd.print("d"); // without this it prints "d" on the second row
      lcd.scrollDisplayLeft();
      delay (150);
    }

    delay(2000);
    lcd.clear();
  }

  if (digitalRead(white_green_pin) == HIGH) {
    lcd.clear();
    lcd.setCursor (16, 0);
    lcd.print("White/Green tea selected");
    for (int position_counter = 0; position_counter < 26; position_counter++) {
      lcd.scrollDisplayLeft();
      delay (150);
    }

    delay(2000);
    lcd.clear();
  }

}

You could make the "Please select a tea" code a function instead. So `void selection() { lcd.setCursor(16, 0);
lcd.print("Please select a tea ");
current_millis = millis();
for (int position_counter = 0; position_counter < 16; position_counter++) {
if (current_millis - previous_scroll_millis >= LCD_scroll) {
  lcd.scrollDisplayLeft();

  previous_scroll_millis += LCD_scroll;
}

}
} and then addselection();` where the code used to be in the loop for a state machine look lmao

See my answer to a similar question - about motors but the idea is the same. You call a function for each piece of the job that needs to be done. The function itself decides whether it needs to be done yet, and if so, does it and returns, otherwise it just returns. The loop() function just calls all your other action functions and does nothing else -- all of the real work takes place in those functions.
Looking at your scrolling code, I think one function could print successive pieces of the message by remembering what did last. Another could read and debounce the button(s) and save its/their state.
And once you get to controlling the infusing process, one (or maybe more) functions could be used to control that.


text:
Calling a localhost php script from arduino
Is it possible to connect arduino uno to call a php script using ONLY an arduino uno board, and an esp8266-01 wifi module.? That is, I lack wifi shield such as node MCU.
I just need the setup to call a php script on my localhost server.
I'm using arduino IDE 1.8.13.
Gracias

You may want to see my blog where I use an ESP-01 as a wifi-shield of an Arduino. You can either communicate with ESP-01 via AT Command or have both Arduino and ESP-01 running its own Arduino code with a pre-defined communication states management between the two.

This seems like just what I want. Let me run  thru the tutorial and see. Thank you

You can program the ESP-01 module using the arduino IDE. There are instructions in the README here: https://github.com/esp8266/Arduino
You can program the ESP-01 to connect to WiFi and communicate with your arduino sketch using the serial port. Don't forget the ESP-01 runs at 3.3V while the arduino runs at 5V. You'll need to shift the voltages somehow, otherwise you'll burn the arduino uno.
Here's an example of code you can run on the ESP-01 to connect to WiFi and start a TCP connection: https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/WiFiClient/WiFiClient.ino
All that's missing is making an HTTP request instead of a "raw" TCP connection. You can probably find that in the examples. Then, add code for serial communication back to your arduino uno.
Good luck!

Much appreciated. I'm working on this. I'll get you feedback. Thanks again

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/

sort: votes


text:
ESP8266-01 WiFiEsp Timeout error
I am using WiFiEsp Library, ESP8266-01 Wifi Module, Arduino UNO and Arduino v.1.8.13.
ESP Details: AT version:1.2.0.0.
SDK version:1.5.4.1(39cb9a32)
v1.0.0.
The module is also in AT+CWMODE=1.
My module connection is as follows:
RX: Pin 6
TX: Pin 7
VCC: 3.3V
GND: GND
CH-PD: 3.3V
I have created a wifi hotspot on my phone which I try to connect to using the module, so that I can be able to pass some variables from arduino sensor to my php script which is hosted locally on phpMyadmin.
However, I can not seem to make the connection past connecting to wifi, since it says wifi shield is not present. Even the AT commands dont work.
What could I be doing wrong? Below is my code snippet:
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(6, 7); // RX, TX
#endif
char ssid[] = "Googz";            // your network SSID (name)
char pass[] = "********";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status
char server[] = "localhost/bella/espdata.php";

// Initialize the Ethernet client object
WiFiEspClient client;
void setup(){
  // initialize serial for debugging
  Serial.begin(115200);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

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

  // you're connected now, so print out the data
  Serial.println("You're connected to the network");

  printWifiStatus();

  Serial.println();
  Serial.println("Starting connection to server...");
  // if you get a connection, report back via serial
  if (client.connect(server, 80)) {
    Serial.println("Connected to server");
    // Make a HTTP request
    client.println("GET /asciilogo.txt HTTP/1.1");
    client.println("Host: arduino.cc");
    client.println("Connection: close");
    client.println();
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them
  while (client.available()) {
    char c = client.read();
    Serial.write(c);
  }

  // if the server's disconnected, stop the client
  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnecting from server...");
    client.stop();

    // do nothing forevermore
    while (true);
  }
}

Swap your TX and RX pins. TX should connect to RX and RX should connect to TX.

Let me get this, so I should switch from using pins 6 and 7 and use 0 and 1 in arduino right?

No, you should switch from using 6 and 7 to using 7 and 6. The pin you designate as TX should connect to the RX of the ESP-01, not to the TX of the ESP-01. And vise-versa for the pin you designate as RX.

Still hits me with the same error. Even AT commands are not failing. Could it be the IDE version that's the problem?

Is there any other possible possibility of sending variables from Arduino to php local server.? considering I don't access internet since its localhost

Are you sure your ESP8266 runs at 9600 baud?

I tried on both 9600 and 115200. Doesnt work.

at what baud rate could you communicate with AT firmware from Serial Monitor and did you execute AT+UART=9600,8,1,0,0 to set the baud rate in AT firmware?

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Breaking out of the arduino fingerprint enroll loop
I am using the Arduino's Adafruit Finger Sensor library, and it has an example to enroll a fingerprint. I want it to enroll one print and exit/break out of the loop because it currently enrolls a user, then goes back to asking for a fingerprint.
Here is the code:
#include <Adafruit_Fingerprint.h>
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
uint8_t id;
void setup()
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);

  while (!  getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }

  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);

  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }

  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }
}

Output is that after storing the fingerprint, it requests for finger to enroll, but I want it to exit after storing. Is this possible?

You are missing a return statement, when the fingerprint was enrolled correctly. Though to what do you want to exit the enrollment loop? Your code does not have anything else in it. When getting out of the while loop, it will just as again for the next ID, because it is the only thing, that you have programmed it for

I want it to ask for the ID....back at the loop instead of calling the getFingerprintEnroll() method again

Your getFingerprintEnroll() function is missing a return statement. Inside the if (p == FINGERPRINT_OK) statement, you need to insert
return 0;

after the Serial print. Only when returning zero, you will exit the while loop inside the loop() function.


text:
Anyone have example code for ESP32 as media controller for Android/iPhone Media Apps
There's actually another post with this very same topic but no answers on that post. Back in January of 2020, the last commenter said he had sample code and then he went dark without posting the actually code. The thread is here:
Want to create bluetooth audio control (volume up/down, play, pause, etc.) for smartphone
My problem is the exactly the same as the original post. Amazon and Aliexpress have literally hundreds of these "media buttons" that you can buy and pair via bluetooth with your Android or iOS. You can then playback media on iOS/Android and the "media buttons" can control the playback. Pretty common controls are volume up/down, next, previous, play and pause.
I've written a lot of Arduino code for Nano, Uno and even MKR. I've written a bunch of ESP8266 and ESP32 code as well. Usually when I try and learn something, a few google searches will find an example that I can figure out. For this, I've been able to find nothing.
Every tutorial or sample code is about how to send commands to the ESP32 via Bluetooth or pair an ESP32 with a bluetooth joystick, etc. None of those examples help me understand what's needed for an ESP32 to pair with my Android and act as media buttons, sending volume up, down and play/pause commands via bluetooth.
Can anyone help with example code for doing this with an ESP32? (by the way, this forum would not let me comment on the original post or I would have. it said I didn't have enough karma points or something)

Have you googled for something like "ESP32 bluetooth HID"? I did and at the first glance the results seem really promising, for example this Arduino library for the ESP32. It also comes with an example on how to use it. If you have seen such results, how exactly are they not helping you?

Well after I posted this question, I kept googling. Literally hours of googling at this point. Then I stumbled across this example:
https://github.com/T-vK/ESP32-BLE-Keyboard
I wrote that sketch to my ESP32, paired my iPhone and it immediately starting controlling music playback on my phone. After looking at the code, it's so simple that I'm embarrassed I couldn't figure this out on my own. In case the link goes dead, I'll paste the code here:

#include

BleKeyboard bleKeyboard;

void setup() {
  Serial.begin(115200);
  Serial.println("Starting BLE work!");
  bleKeyboard.begin();
}

void loop() {
  if(bleKeyboard.isConnected()) {
    Serial.println("Sending 'Hello world'...");
    bleKeyboard.print("Hello world");

    delay(1000);

    Serial.println("Sending Enter key...");
    bleKeyboard.write(KEY_RETURN);

    delay(1000);

    Serial.println("Sending Play/Pause media key...");
    bleKeyboard.write(KEY_MEDIA_PLAY_PAUSE);

    delay(1000);

    Serial.println("Sending Ctrl+Alt+Delete...");
    bleKeyboard.press(KEY_LEFT_CTRL);
    bleKeyboard.press(KEY_LEFT_ALT);
    bleKeyboard.press(KEY_DELETE);
    delay(100);
    bleKeyboard.releaseAll();

  }
  Serial.println("Waiting 5 seconds...");
  delay(5000);
}


text:
Huzzah feather scl sda
Trying to hook up an hazzah feather to a pca9685 scl sda connection and have a bno055 connected to that.The 5 volts to power the PCA is not taken from feather. I have a GPS module connected to pin 12 of feather again not powered from feather. Gps interface works fine. I see it though web page interface.
Then I hook up the PCA. the wifi chip overheats and feather is fried

you talked about +5 V, but you said nothing about grounds

The grounds are the individual power supplies

that means nothing ... how are all of the grounds connected?


text:
Why does my Wemos D1 Mini stops working while charging via solar?
I'm using an battery shield to recharge my battery. I want to use a solar panel, so I bought one (5V 240mA). I'm pretty sure, it won't recharge my battery fully, but that's not the point.
I've assembled my board with my shield, soldered the solar panel together with an schottky-diode and put it on USB (since the shield allows charging via USB). All fine, I get some electric power in the sun - yeah!
But my Wemos D1 Mini only runs for say 2-3 minutes and than ... dead? Restarting works, but only lasts again 2-3 minutes. This only happens while the battery shield is charging via solar. I already tested using any USB charging (my computer) - this simply works.
Basically I rebuild the circuit like described on TheAustrian/Wemos-D1-Mini-BME280-Weather-Station but only one solar panel attached and using the Wemos D1 Mini Battery Shield instead of the TP4056.
Any hints what's going on? Why can't I run the board while charging via solar? Did I miss something?

I would hazard a guess that the solar panel needs to be big enough to both charge the battery and run the Wemos D1 at the same time. Lack of current will cause bad things to happen.

@Majenko how can I be sure? What specs do I need to read? :-D

The TP4056 Module will output a max of 4.2V which is less than the 5V the Wemos D1 Mini is expecting on its 5V connection (Assuming you have connected the circuit as shown in the Github guide). When the solar panel is charging it's likely that the TP4056 is causing a driving issue on the supply of the Wemos causing it to potentially Brownout .
I would not connect the solar panel to the Wemos like this, I would have it connected to the battery then the battery connected to a 5V Step Up Power Converter like shown below (This reduces efficiency but give the MCU a stable supply),

My recommendation for the wiring,

Thank you for explaining, but as far as I can see, this the Wemos D1 battery shield does provide a boost converter (step-up converter?). But I also just noticed: it states 0.5A or max. 1A charging current. Maybe my problems lies in using one solar providing 0.25A?

As I stated in my question: I'm using the Wemos D1 battery shield instead the TP4056.

Sorry I should have re-read you question, okay so the module is getting 5V which is good. The symptoms still sound like the Wemos is browning out. It's very possible the solar panel is not generating enough current to power the regulator (You could get a multi-meter on the output to see what's going on under load). Is the battery completely drained, do you have a way to fully charge it and repeat the test? In theory the solar panel should only be charging the battery not directly driving the 5V regulator.

Yes I do have one. I'm new to electronics, so: where do I need to measure output? On the solar panel or output of the shield (a.k.a input of Wemos)? V or A?

I would measure the voltage cross the 5V connection on the Wemos module (So Wemos 5V to GND). Keep measuring it while the Wemos run & see if it changes when the Wemos crashes (The voltage will likely drop < 5V then potentially jump back up to 5V once the crash has occured and the current load has dropped). If the 5V supply is stable during the crash you may need to switch to measuring current (Amps A). So in line 5V as shown here - https://www.electronics-notes.com/articles/test-methods/meters/how-to-measure-current.php


text:
What sensors do I need to detect magnetic "take off"?
I want to build a sensor using arduino (or any other esp) measuring the release of a leg on a floor panel. I've build a prototype using copper plates and a BBC Micro:bit, which works fairly well. But I want to use magnetic sensors, determining release of the leg.
My education on magnetic is - simple. I know it exists. I know it's one of four basic forces in nature (ha!). But I don't know how to measure it using electronic circuits (I'm new to this topic).
Imagine one person stands on a plate, wearing magnets on his foot (say "magnetic socks"). I want to immediately detect when the person raises his leg. What kind of sensors do I need?

Hall sensor is the keyword here (it measures the magnetic field strength). Though this question is not really about Arduino. You can find many tutorials online on how to use a hall sensor with Arduino.

@chrisl where else could I ask such things? (thanks for the tip on Hall sensor)

The range of magnetism isn't great, so you'd have to place your foot at a very precise position, for the hall-effect sensor to "see" the magnet. I think your original idea is a lot better.

You have two options here, either a Hall Effect sensor or an Inductive Sensor. The hall effect sensor is probably the best option. This will likely need some calibration on your end to identify the exact value you record at "Take Off" for your setup.

@Michael Hirschler (OP) Out of curiosity why do you need the solution to be magnetic? I'm struggling to visualise the setup you described and why you wouldn't consider pressure sensors or a simple tactile button to detect when the leg in in contact with a surface? I'm just not certain if the Hall Effect sensor with give you a clean and constituent reading compared to other potential solutions. Deepening on the setup you may even be able to use the metal plate and leg as a large switch, closed when in contact & open at the moment of "Take Off". Just spit balling some ideas :)

A third (simpler) option: reed switches.

@JackSoldano at my sport (Taekwondo) we're wearing magnetic socks for detecting impact on vests for triggering a point (see olympic sports). The idea was to re-use these socks, so any athlete can test his speed on leaving the floor plate, and hitting a target. Maybe simple tactile buttons may do also - but I'm not an engineer, so I can't think about how to use them, without destroying them :-D
I need to read some books about this topic, an hall-/inductive-sensors (and reed switches), too.

I understand now! makes sense, yeah, I would probably scrap the inductive sensor as they are big. A hall effect / Reed switch might be the way forward If you really want to go the magnetic route. If you are already wearing magnetic socks that may be conductive?, I think it would be possible to create open/close a circuit from the persons foot through the ground metal plate and detect this from an Arduino, that would give you instantaneous detection of contact.

I managed to get a reed-switch. I'll try in next few days and keep you updated ;-)

Sadly the reed-switch isn't sensitive enough to detect those socks. I need to try something else. Thank you anyway!


text:
Can I use an internal clock on Wemos D1 Mini?
I have a working Wemos D1 Mini setup measuring temperature and sending it over wifi to my server. Now I'm using a battery powered unit, and playing around with power consumption optimization and how to reduce it.
One thing I need is time (current, either epoch or DST) - so I implemented NTP, but everytime my ESP is waking up after deep-sleep, it needs to reconnect to wifi, gather time, measure temperature, send results.
This pdf states that ESP8266 has an internal clock. I'm having troubles finding anything beside "RTC shields on Wemos/Arduino" or "NTP on ESP8266" on the internet about something that is like an internal clock. There must be something, because otherwise it could not work (my understanding about clock and hardware is limited by now).
My question is: can I use NTP to update my internal clock, using it for some minutes (I think it will drift after some minutes), updating via NTP once in a while - to simply reduce network traffic and still use deep-sleep mode?
Any hints are welcome!

this is not an answer, but I want to show you how to simply  get NTP time in esp8266 Arduino: https://github.com/jandrassy/TelnetStream/blob/b1a24a033f84a9811a99d02389cc6b64c02c69c0/examples/TelnetStreamEsp8266Test/TelnetStreamEsp8266Test.ino#L27 This will set the time in the internal RTC (there is no other way)

I think the answer to your question can best be summed up by one word: "Kinda".
The best reasoning is the NodeMCU Lua documentation which states:

Time keeping on the ESP8266 is technically quite challenging. Despite being named RTC, the RTC is not really a Real Time Clock in the normal sense of the word. While it does keep a counter ticking while the module is sleeping, the accuracy with which it does so is highly dependent on the temperature of the chip. Said temperature changes significantly between when the chip is running and when it is sleeping, meaning that any calibration performed while the chip is active becomes useless mere moments after the chip has gone to sleep. As such, calibration values need to be deduced across sleep cycles in order to enable accurate time keeping. [...]

So while it's called RTC it's not an RTC in the traditional sense - it's merely a timer that runs even when sleeping, but not with any degree of accuracy.
You can access the current RTC count with the Non OS SDK function
uint32_t system_get_rtc_time()

You can combine that with
uint32_t system_rtc_clock_cali_proc()

which gives you the number of uS per tick of the RTC timer.
There's no way to change the RTC timer count, so you will have to work out some "delta magic" to update your own internal time value (an epoch value is simplest) from the difference between successive calls to get the RTC count.
All somewhat tricky and the accuracy won't be great anyway, so you'll be wanting to use NTP to update that epoch value regularly.
But it could give you a "rough idea" of how long you've been asleep for, etc.
You would have to run some experiments to know how much the time drifts compared to the NTP value in real usage.

Kinda, if you don't call deepSleep. Quoting the 3.0.2 SDK API Reference, "If an external hardware reset the chip via EXT_RST or CHIP_EN (such as timed wakeup from Deep-sleep), the RTC timer will be reset." Arduino sketch ported from mentioned reference.


text:
digitalwrite with function parameter as parameter
Firstly, excuse my poor English, this is not my native langage.
I'm trying to use an Arduino Uno to drive an 8 relay board from an MQTT Subscription. I ask for help because i'm some kind of beginner in arduino, i'm just a Linux addict.
The idea is to get a payload from PubSubclient and use it to manage relays.
For example, the payload '71' ask the relay 7 to turn on and '42' make the relay 4 to turn off.
All works fine until I wanted to write a function with two parameters : 'relay_number' and 'Action'
All parameters are received but the relay never goes up or down.
My code :
void callback(char* topic, byte* payload, unsigned int length) {

  Relay_Nb = (char)payload[0];
  Action = char(payload[1]);

  Serial.println(Relay_Nb);
  Serial.println(Action);

  RelayControl(Relay_Nb, Action);
}

void RelayControl(char Relay_Nb, char Action) {
  Serial.println(Relay_Nb);   // for debugging purpose
  Serial.println(Action);

  if ( Action == '0') {
    Serial.print("Bringing down Relay ");
    Serial.println(Relay_Nb);
    digitalWrite(Relay_Nb, LOW);
  } else if (Action == '1') {
    Serial.print("Bringing up Relay ");
    Serial.println(Relay_Nb);
    digitalWrite(Relay_Nb, HIGH);
  } else if (Action == '2') {
    // Relay temporisé (ouverture portail par ex)
    Serial.println("Bringing up, and down Relay ");
    digitalWrite(Relay_Nb, HIGH);
    delay(750);
    digitalWrite(Relay_Nb, LOW);
  }
}

I'm sure an old maker have the solution i'm searching for hours now.
Please help and don't hesitate to show me others ways.
Thanks.

What is the serial output?

Relay_Nb is the character 1 or 0, not the value 1 or 0?

The serial output is for debugging purpose.
Character or value is probably the problem, but what have i to do to change this?

your callback function makes an assumption about the data ... there is no check for unexpected data

You're right.I'll write it after the relay issue.

You are sending the parameter Relay_Nb as a character, and then using it as an integer.
You need to turn the character into an integer - and the simplest way is to subtract the ASCII value of 0 from it:
Relay_Nb = payload[0] - '0';

But with that said, a note on how you have written your callback:

You aren't checking the data is valid.

You should really be doing, at the very least, the following:

Check that the length parameter is at least 2,
Check that the two data values are within the correct range for your function

It works fine, you're my hero.
I just don't understand how. Where can I find some explaination ?
I can now start the security checks.

@Pwol: man ascii, and look for the code points of the digits.

@EdgarBonet You're assuming he's using a real operating system, not some toy like Windows.

@Majenko: He wrote “i'm just a Linux addict”.

@EdgarBonet True. I tuned out at "I ask for help because..."

Any reason ot use '0' subtraction in preference to the atoi() function? i.e. int Relay_Nb = atoi(payload[0]);

@PeterFeerick atoi() expects a string, not a character.

Or Relay_Nb = payload[0] & byte(0x0f); That's why ASCII for 0 to 9 was encoded as 0x30 to 0x39, i.e. easy conversion between bytes and characters.


text:
How do I control the speed of a 2-wire fan with an Arduino and only a potentiometer?
I am trying to vary the speed of a 2-wire fan by using a Arduino Uno and only a potentiometer.
Initially, I assumed that I could go about doing so by using a code that I used for dimming an LED. When I have run the code and varied the potentiometer, the LED on the power supply changed but, the fan did not come on. I assume that this was due to an error in the first code.
In the second code, the fan also did not come on. I am unsure if it was my wiring. I have an voltage supply connected to a breadboard to power the fan.
Additionally, would I require a mosfet or transistor despite using a potentiometer? This could have also be the problem regarding my second attempt.
First Code Attempt:
int potPin=A2;
int gPin=9;
int potVal;
float LEDVal;
int dt=250;
void setup() {
  // put your setup code here, to run once:
pinMode(potPin, INPUT);
pinMode(gPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
potVal=analogRead(potPin);
LEDVal=(255./1023.)*potVal;
analogWrite(gPin,LEDVal);
Serial.println(LEDVal);
delay(dt);
}

Second Code:
int reading;
int value;

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

void loop() {
  reading = analogRead(POTENTIOMETER);
  value = map(reading, 0, 1024, 0, 255);
  analogWrite(CONTROL, value);
}```

Assuming, that it is generally possible to control your fan via PWM (which is absolutely not guaranteed), you absolutely need a MOSFET to control it. A digital output pin cannot provide enough current for a fan (max 20mA)

would I require a mosfet or transistor despite using a potentiometer? ... what do you think that a potentiometer does?

@chrisl I see, thank you

@jsotola it varies the voltage output.

I guess jsotolas point is, that the potentiometer doesn't habe anything to do with the motor and the need for a MOSFET. The poti provides the input for the Arduino. The MOSFET/motor is the output. Input and output are only connected logically by the code

@chrisl If I am understanding this correctly, if I adjusted the pot the results produced by the code would change the output i.e. the fan speed varying?

@AI09 yes, you are understanding it correctly ... the pot only generates a numeric value ... the program uses that value ... the numeric value could just as easily come from a temperature sensor, or a light sensor, or from a mathematical calculation

Like people have already mentioned in the comments, you likely need to add a FET to drive the fan. The Arduino simply can't put provide the current required to drive the fan. According to the Arduino documentation, the microcontroller can only provide 20mA per output pin, which is enough to drive LEDs but not fan motors.
Luckily, there is a tutorial on the Arduino website for driving motors with PWM through a FET.
https://docs.arduino.cc/learn/electronics/transistor-motor-control
The following program is adapted from the "Analog In, Out Serial" built-in example and should be sufficient to control the speed of the motor.
// These constants won't change. They're used to give names to the pins used:

const int analogInPin = A0;  // Analog input pin that the potentiometer is attached to

const int analogOutPin = 9; // Analog output pin that the FET is attached to

int sensorValue = 0;        // value read from the pot
int outputValue = 0;        // value output to the PWM (analog out)

void setup() {

// declare the ledPin as an OUTPUT:
pinMode(analogOutPin, OUTPUT);
}

void loop() {

// read the analog in value:
sensorValue = analogRead(analogInPin);

// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 255);

// change the analog out value:
analogWrite(analogOutPin, outputValue);

// wait 2 milliseconds before the next loop for the analog-to-digital
// converter to settle after the last reading:
delay(2);
}

This program has not been tested and is intended as an example. Make sure that the output for the FET is wired to a pin that can output PWM. Then make sure that your program is referencing the correct pin.
Make sure that your power supply has enough power to control the fan motor as well.
Here are some wiring diagrams from the tutorial webpage.

Note: The particular fan that you are using might not be able to be driven by PWM and you should seek out and read the relevant documentation for the fan.


text:
How to unload a sketch
I've loaded a sketch onto Arduino using the Ardunio IDE and it works but when I press the reset button I realize it doesn't remove the program. Is there a way to unload the program? Why? Because when I take it apart to put it away I don't know if having that program turning pins on or off and having nothing connected to it would break anything.

how can a device turn pins on and off when there is no power to run the device?

@jsotola right correct. i'm looking at it as if i'm going through examples for training purposes. for the case where, if i disconnect everything and put it away (but the program is not removed) then later i plug it back in where i don't have anything else connected to it then i was concerned what would have happened

Frist: The Arduino cannot break when nothing is connected to it, doesn't matter what the code does.
If you want to remove the current code from the Arduino, you have to overwrite it with an empty sketch (one with only setup() and loop(), both empty). So upload an empty sketch.
The reset button is not meant for erasing the code. It is meant to return the Arduino in a definited starting state (not erasing program space or EEPROM) and executing the program on the Arduino (including the bootloader) from its start.

OK Thank you. So pressing reset cuts the power, clears the memory and runs the setup and then loop function again.

It doesn't cut the power. The reset is a hardware function of the microcontroller on the Arduino. The controller will then start program executing from programm address zero. So first the bootloader gets executed (which enables to you program via USB/Serial), then your program starts, which also includes building the stack in memory for your variables. The memory is not actually erased (as in overwritten with zeros or ones), but your program implicitly will initialize the used memory with the defined values (the compiler creates such machine code from your C++ code). Then setup and co runs

You can't remove a program by resetting the Arduino. If you want to be sure that it can't activate any pins in your next experiment, then just before you finish with it, upload a new program that does nothing, such as the Basics | Bare Minimum example program. It will effectively replace the previous program.
At power-up, all of your pins[*] get configured as inputs during power-up. With the Bare Minimum program, nothing will change those pins, until you start writing & uploading new code that modifies them.
[*] Note that the bootloader will re-configure pin-1, the serial transmitter pin, as an output.


text:
74HC595N breaks when not connected to 5V
I'm trying to build a simple LED controller using this shift register, however when I remove the 5V power source, the device breaks down. The error message was : "This device broke because of: Voltage at pin STCP is 5v, while maximum is Vcc = 0v". There isn't any current in the circuit to break it down. Can anyone explain to me why it behaves that way?
Basically, I connected the output of the register to resistors and LEDS. Here is my wiring diagram:

Here is my code:
const int SER  =8;   //Serial Output to Shift Register
const int LATCH =9;  //Shift Register Latch Pin
const int CLK  =10;  //Shift Register Clock Pin

void setup()
{
 //Set pins as outputs
 pinMode(SER, OUTPUT);
 pinMode(LATCH, OUTPUT);
 pinMode(CLK, OUTPUT);

 digitalWrite(LATCH, LOW);                //Latch Low
 shiftOut(SER, CLK, MSBFIRST, B10101010); //Shift Most Sig. Bit First
 digitalWrite(LATCH, HIGH);               //Latch High - Show pattern
}

void loop()
{
 //Do nothing
}

Where are you getting this error message? Are you using a simulator? Which one? This is probably because the voltage limits on the signal pins depend on Vcc (supply voltage). Having powered signal lines connected to an unpowered chip can backfeed the power through the signal pins, which is bad.

This set up doesn't work in real life so I rebuild it in TinkerCad and get that error message. So next time if I want to rewire something, should I just turn all the power off?

Are you talking about a real life circuit? Yes, you should turn the power off when rewiring. The circuit in your question does not work because it is not complete and unpowered, hence the error message when you try to build it in a simulator. What is the actual problem?

@StarCat I intentionally disconnect the shift register from the 5v power source. This makes the shift register breaks down and I'm trying to understand why.

Yes, you should not disconnect Vcc from a chip as long as you have active signal lines running to it, which have a voltage level different than ground. To be safe: Just remove the power from your whole circuit before removing the power lines - or only remove the power lines once you have removed all other connections.
This depends on the used chip. But most chips with digital data/signal lines have internal protection diodes connected to the pins. If you provide a voltage above the limit, then a current can flow through the protection diode into the Vcc line of the chip. This is done to protect the internal hardware connected to the pin (since the whole chip can endure more than a single pin by its own).
With removing the Vcc connection to the chip you are lowering Vcc to ground level, so way below the level of a HIGH signal line. Thus the current can flow through the pins protection diode to Vcc and feed power to the chip through the signal pin. But the protection diodes are not made for enduring a significant power draw for more than very short spikes. So when doing that you can fry the protection diodes. And you cannot predict, if it will fail short (creating a short between the pin and Vcc, preventing further communication through this pin) or fail open, in which case the chip might still work (if the pins internal hardware is still OK).
For that reason some datasheets will define the voltage limits of the digital input pins dependent on Vcc. In the datasheet of the 75HC595 section 7.3 "Recommended Operating Conditions" you will see the "V_I Input voltage" with the limits to be 0V and Vcc.


text:
How to improve the sampling rate of Arduino due ADC?
I am now working on a project, which needs a cheap analog acquisition device with a sampling rate of no less than 5MHz. Before, I only used Arduino, and rarely operated the registers on Arduino. I hope to use Arduino due to complete it. I spent a lot of time researching and querying solutions, but it didn't succeed. I hope someone can help me.

Or is there any other solution?

To help us come up with a possible solution, please tell us exactly what you are trying to do. Why 5 MHz?  That's rather a lot.  How many bits of resolution?  Also, at that sample rate you will be getting a flood of data; what will you do with it?

I want to collect the pulse signal of the scintillator detector. The duration of this pulse is less than 1 us. In order to maintain the accuracy, the sampling rate must be higher than 5 MHz. The more data bits, the better. I will temporarily store the obtained data in Arduino, stop sampling after accumulating a certain amount, and then start analysis. After the analysis, I will discard the sampling data.

I haven't used the Due, but I understand its ADC is rated for 1 MHz sampling.  If that's its absolute limit then you can't expect 5 MHz.  However, judging by the Unos which I have used, you may be able to push things by limiting the number of bits.  This gives a speed boost two ways, by shortening the time the ADC uses to acquire the data, and if you limit to 8 bits you have half as many bytes to move into memory.
Do not try to use more than one channel, since then you have multiplexer delays as well.
Also, you may want to skip interrupts and just sample in a tight loop. Using this loop trick doubles the useful ADC rate of the Uno, from 50 kHz to over 100 kHz. (You'll need to figure out the actual sample rate by reading the timer before and after the loop, then divide by the loop size and take the reciprocal.)

Thank you very much for your reply. After your reminding, I have turned off my interrupt. It's really effective, but it's still far from enough. I think 12 digits are offline to ensure accuracy.，so It seems that I may have to find another way.


text:
Connecting BMP280 sensor to microcontroller
I am building my own board with integrated pressure sensor.
(microcontroller is 3V3 logic)
I want to know which parts do i need. In datasheet there are only 2 capacitors but on breakout board there are also 4 resistors.
Also in datasheet are 2 100 nF capacitors and on breakout board are 1uF and 0,1uF.
schematics from datasheet:

breakout board schematics:

The capacitors are just decoupling capacitors. The value is not that critical. 100nF are good values to use.  On the breakout they have used just one pair of decoupling capacitors but use that pair for both power pins. The datasheet has one decoupling capacitor for each pin. You can do it either way. Personally I'd do it the datasheet way, but for a small board it really doesn't make much difference.
The resistors are a different matter. The BMP280 can work in a number of communication modes, and which mode you have it in dictates what resistors are needed.
R1 is used to place it into I2C mode. R4 is used to set the I2C address. R2 and R3 are the pullup resistors on the I2C bus. They aren't really part of the BMP280 circuit, but part of any I2C circuit in general.
R1 and R4 could be replaced by direct connections to VCC and GND respectively, but by having resistors gives you the ability to override them and use SPI instead of I2C should you wish it.


text:
How do I instruct the L293D to operate a motor at full speed when using 3.3V GPIO pins?
If the L293D enable and input pins expect [up to] 5V inputs; what is the best way to deliver full power to the output pins when using an ESP32 or any other microcontroller which uses 3.3V GPIO pins?
I've seen several projects which combine the L293D with the ESP32, but none of them seem to mention whether or not this is even an issue.  Am I missing something?  Or should one always use level shifting when using 3.3V logic and the L293D

There is a good discussion of this issue at Quora. They note that the logic levels on the L293D is compatible with either 3.3 or 5v mcus but that you need to supply >4.5v power. https://www.quora.com/How-do-I-connect-an-L293D-motor-shield-to-Arduino-Duo-which-operates-at-3-3v

The voltage level on the control pins does not have any relation to the power provided to the motor.
The inputs are all digital. Above a threshold they are on, and below a threshold they are off.  Those thresholds are compatible with both 3.3V and 5V logic.
What controls the power delivered to the motor is the duty cycle of the PWM signal provided to the EN pin.


text:
Reading a json file from SPIFFS and displaying the info it contains on an embedded web page
I am working on a smart IR receiver that reads an IR signal, decodes it and saves that decoded info in a json file stored on the NodeMCU's SPIFFS. This info is then displayed on the embedded web server in a table.
Now my problem is that even though I correctly save the signal's info in the json file (and when I try to print it in console it looks perfect), the son file is not correctly passed to my web server and the table remains empty. I am using jQuery to read the file and make the changes in the HTML. All the web server files (HTML, css & JavaScript) were tested first on my local machine with an example Json file of the same structure I am using on my SPIFFS so I know for sure the problem is not in there.
It is worth noting that I faced this problem when developing on my local machine, where the table would remain empty even though the json file is not, but it was fixed when I used the Live Server extension on VSCode. However, I don't understand if this is the problem how is it that there is no server to pass the json file on when all my web interface files are correctly passed and loaded from the SPIFFS.
I will include a portion of my code, and of course all help is appreciated.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266mDNS.h>
#include <ESP8266WebServer.h>
#include <Arduino.h>
#include <IRremoteESP8266.h>
#include <IRrecv.h>
#include <IRutils.h>
#include<FS.h>   // Include the SPIFFS library
#include <NTPClient.h>
#include <WiFiUdp.h>
#include <ArduinoJson.h>

ESP8266WiFiMulti wifiMulti;     // Create an instance of the ESP8266WiFiMulti class, called 'wifiMulti'

ESP8266WebServer server(80);    // Create a webserver object that listens for HTTP request on port 80

String getContentType(String filename); // convert the file extension to the MIME type
bool handleFileRead(String path);       // send the right file to the client (if it exists)

// Declaring a variable to hold JSON object size
//const size_t capacity = JSON_OBJECT_SIZE(10);

// Creating a JSON document to hold signal entry
//DynamicJsonDocument doc(capacity);

// Declaring array size
const size_t array_capacity = JSON_ARRAY_SIZE(16) + JSON_OBJECT_SIZE(1) + 16*JSON_OBJECT_SIZE(9);

// Creating a JSON document to hold all signal entries in a nested array
DynamicJsonDocument array_doc(array_capacity);

// Creating a nested JSON array to hold all signal entries
JsonArray signals = array_doc.createNestedArray("signals");

// Declaring a JSON object to hold single signal entry
JsonObject signal_entry;

// Declaring method that save JSON object to JSON file stored on SPIFFS
void saveJSON();

// Declaring method that prints JSON file stored on SPIFFS
void printJSON();

void setup(void){
  Serial.begin(115200);         // Start the Serial communication to send messages to the computer
  delay(10);
  Serial.println('\n');

  Serial.println("Connecting ...");
  int i = 0;
  while (wifiMulti.run() != WL_CONNECTED) { // Wait for the Wi-Fi to connect: scan for Wi-Fi networks, and connect to the strongest of the networks above
    delay(250);
    Serial.print('.');
  }

SPIFFS.begin();                           // Start the SPI Flash Files System

  server.begin();                           // Actually start the server
  Serial.println("HTTP server started");

  server.onNotFound([]() {                              // If the client requests any URI
    if (!handleFileRead(server.uri()))                  // send it if it exists
      server.send(404, "text/plain", "404: Not Found"); // otherwise, respond with a 404 (Not Found) error
  });

void loop(void){
  server.handleClient();                    // Listen for HTTP requests from clients

//Creating a JSON object from the JSON document
    signal_entry = signals.createNestedObject();

    //Assigning correct values to keys in JSON object
    signal_entry["date"] = currentDate;
    signal_entry["protocol_type"] = protocol_type;
    signal_entry["bitNr_device"] = bitNr_device;
    signal_entry["bitNr_op"] = bitNr_op;
    signal_entry["codeDec_device"] = codeDec_device;
    signal_entry["codeDec_op"] = codeDec_op;
    signal_entry["codeHex_device"] = codeHex_device;
    signal_entry["codeHex_op"] = codeHex_op;
    signal_entry["codeBin_device"] = codeBin_device;
    signal_entry["codeBin_op"] = codeBin_op;

    serializeJsonPretty(signal_entry, Serial);
    Serial.println("");

    saveJSON();
   }
}

String getContentType(String filename) { // convert the file extension to the MIME type
  if (filename.endsWith(".html")) return "text/html";
  else if (filename.endsWith(".css")) return "text/css";
  else if (filename.endsWith(".js")) return "application/javascript";
  else if (filename.endsWith(".ico")) return "image/x-icon";
  return "text/plain";
}

bool handleFileRead(String path) { // send the right file to the client (if it exists)
  Serial.println("handleFileRead: " + path);
  if (path.endsWith("/")) path += "index.html";         // If a folder is requested, send the index file
  String contentType = getContentType(path);            // Get the MIME type
  if (SPIFFS.exists(path)) {                            // If the file exists
    File file = SPIFFS.open(path, "r");                 // Open it
    size_t sent = server.streamFile(file, contentType); // And send it to the client
    file.close();                                       // Then close the file again
    return true;
  }
  Serial.println("\tFile Not Found");
  return false;                                         // If the file doesn't exist, return false
}

void saveJSON(){
  File jsonFile = SPIFFS.open("signals.json", "w");
  if (serializeJsonPretty(array_doc, jsonFile) == 0) {
    Serial.println("Failed to write to file");
  }
  jsonFile.close();
}

void printJSON(){
  uint8_t* pBuffer;
  File testFile = SPIFFS.open("signals.json", "r");
  if(testFile){
    unsigned int fileSize = testFile.size();
    pBuffer = (uint8_t*)malloc(fileSize + 1);
    testFile.read(pBuffer, fileSize);
    pBuffer[fileSize] = '\0';
    Serial.println((char*)pBuffer);                // Print the file to the serial monitor.
    testFile.close();
  }
  else{
    Serial.println("Failed to read to file");
  }
  free(pBuffer);
}

I think you messed your copying and pasting up. Your loop() function seems to be in the middle of your setup() function.

It sound like you are running the webpage on you PC, but getting the json from the ESP. Browsers don't like that, as it's some form of cross-site scripting. It can work if the ESP also sends the correct permission headers. Access-Control-Allow-Origin: * to be specific. You also might want to open the developer console in your browser to see if any errors pop up. Also check the network tab to see if the json gets requested.

@Gerben I am not quite sure I understand what you mean, my web page is hosted on the ESP and I access it via the IP address, however, in the JS file linked to my HTML (Both stored on SPIFFS btw) I look for the json file in the same folder as my web page, is this the problem?   And I checked the dev tools, yes the json file is requested and the request has a status 200 OK.

Never mind. The VSCode extension part threw me of, but apparently that's not the issue here.

Besides the somewhat strange problem of loop() being nested inside setup() (which I will put down to a copy-and-paste error) I think your main problem is that of a lack of content-type.
The function getContentType() is supposed to guess the content type by the filename extension. However there is nothing there to handle a .json file. So it will just default to text/plain - which won't be interpreted as JSON data.
You need to add a bit in there to look for JSON files and set the content-type accordingly:
...
} else if (filename.endsWith(".json")) {
    return "application/json";
}

I tried it, but sadly this was not it. In the browser dev tools, the json file is requested and the request is accepted, however, the table remains empty even though the json file is not.

Then there is something wrong with your website code.

try coping the response and manually parsing it with JSON.parse().


text:
The Pfieffer Vacuum Protocol for RS485
i am working on a control Interface for serveral Components including turbo Pumps from the company Pfeiffer.
The communication will be done according to the The Pfieffer Vacuum Protocol for RS485.
Does any one have experience with this Protokoll or is there a library that can be used for this art of communication.
I will use a MAXCHIPRS485 for the communication between Arduino (SerialPorts) and the Pumps RS485 Port.
the Wiring is clear .
I want to ask if someone already has done a similar Code that sends and reads from the Pump continuously.
Thanks in advance

please ask a question that is about an Arduino


text:
Ardunio wireless voice transmission
I made a project based on calling with gsm module and arduino and  now i want to transmit to voice wirelessly to my bluetooth earphone which module should i use for this purpose.

google "arduino bluetooth sound module"

An ESP32 could to that


text:
Trigger ESP8266 reset pin on broken connection
I have an ESP8266 which I wish to place in deep sleep until a reed switch senses a door being opened. The ESP8266 is woken from deep sleep by briefly raising the RESET pin high.
In my original design, I thought that raising the RESET pin would wake the device instantly. Instead raising the pin holds the device in a reset state until it goes low again. This means that the 8266 currently wakes after the door is opened and closed again.
I'm looking for a way to briefly trigger the RESET pin after the reed switch connection is broken with minimal additional hardware, and minimal power drain while in deep sleep. I can use either NC or NO Reed switches.
Any suggestions?

the reset pin is HIGH for normal run, it must be pulled LOW for reset. I don't know what is the state of the pin in deep sleep

A simple capacitor can be used to convert a level change into a short pulse - just like the Arudino UNO etc use for the DTR->RESET signal.

why not power it through the switch and seleep once the message is sent? that uses no power in standby.


text:
"No I2C devices found" Arduino Nano Every
I was able to set up a Arduino Nano with an I2C board very easily, but the Arduino Nano Every is giving me a much harder time (my project required low profile).
Just to test, I stripped some wires, and looped them into the board, I'm not sure I want to solder on the pins as they may be too tall. Anyways, just trying to get a proof of concept going right now.
Here's how it's connected:

based on this pin diagram: https://i2.wp.com/rosmianto.com/wp-content/uploads/2019/05/Untitled-Diagram-4.png?fit=1506%2C1974&ssl=1
The screen lights up so I know the 5v and Ground connections work, but when I scan for I2C devices with i2c_scanner, it sees no devices.
18:20:56.254 -> Scanning...
18:20:56.289 -> No I2C devices found
18:20:56.289 ->
18:21:01.265 -> Scanning...
18:21:01.265 -> No I2C devices found
18:21:01.300 ->

Looping the wires through the board and not soldering them is probably your problem.  That's not going to make a very good connection.  You may get power and ground that way, but digital signals like I2C comms are going to see a LOT of noise.

Ah, okay, I'll solder it then and see if that helps

@Delta_G Yup that was it!

stick toothpicks into the holes to tighten up the connections

@Delta_G, make that an answer so we can mark it as such.

Looping the wires through the board and not soldering them is probably your problem. That's not going to make a very good connection. You may get power and ground that way, but digital signals like I2C comms are going to see a LOT of noise.


text:
Modbus TCP/IP using Arduino uno and ENC28J60 module
I have this project where I need a modbus tcp server that will host a series of sensor data for other modbus client devices to read. I use this Library by Andresoarmento
This is the code i am using from the library example:
#include <EtherCard.h>
#include <Modbus.h>
#include <ModbusIP_ENC28J60.h>

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

//ModbusIP object
ModbusIP mb;

long ts;

void setup() {
    // The media access control (ethernet hardware) address for the shield
    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
    // The IP address for the shield
    byte ip[] = { 192, 168, 1, 120 };
    //Config Modbus IP
    mb.config(mac, ip);

    // Add SENSOR_IREG register - Use addIreg() for analog Inputs
    int i = 2200;
    mb.addIreg(SENSOR_IREG,i);

    ts = millis();
}

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

   //Read each two seconds
   if (millis() > ts + 2000) {
       ts = millis();
       //Setting raw value (0-1024)
       int i = 0;
       i++;
       mb.Ireg(SENSOR_IREG, i);
   }

The enj28j60 module is working as i tested it. So, I used a modbus scanner(CAS SCANNER) which was unable to detect it. Can anyone tell me how to get this all working and test it?
Thank you in advance.


text:
How to rotate servo every 12 hours using RTC module?
I am trying to make a auto fish feeder to feed my fish every 6hours. I want to implement RTC module to my code. So far I've been using only an arduino and a servo using this as a code:
#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

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

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
      // Wait for 12h
    delay(6 * 3600000);
}

The RTC module I have is the DS1302. It's library cn be downloaded here
The code for the clock is this:
// DS1302_Serial_Hard
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// A quick demo of how to use my DS1302-library to
// retrieve time- and date-date for you to manipulate.
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 4);

// Init a Time-data structure
Time t;

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);

  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  rtc.setDOW(FRIDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(6, 8, 2010);   // Set the date to August 6th, 2010
}

void loop()
{
  // Get data from the DS1302
  t = rtc.getTime();

  // Send date over serial connection
  Serial.print("Today is the ");
  Serial.print(t.date, DEC);
  Serial.print(". day of ");
  Serial.print(rtc.getMonthStr());
  Serial.print(" in the year ");
  Serial.print(t.year, DEC);
  Serial.println(".");

  // Send Day-of-Week and time
  Serial.print("It is the ");
  Serial.print(t.dow, DEC);
  Serial.print(". day of the week (counting monday as the 1th), and it has passed ");
  Serial.print(t.hour, DEC);
  Serial.print(" hour(s), ");
  Serial.print(t.min, DEC);
  Serial.print(" minute(s) and ");
  Serial.print(t.sec, DEC);
  Serial.println(" second(s) since midnight.");

  // Send a divider for readability
  Serial.println("  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -  -");

  // Wait one second before repeating :)
  delay (1000);
}

So the question here is, how can I set up my code to work with RTC, in order to move the servo every 6 hours?

if you can print the time, then you can operate a servo when the time is equal to a predetermined value ... it is unclear what is giving you trouble

I have trouble coding, to be honest. Do you think you could help me with that?

start with the bottom code ... insert a line that prints "hello" when seconds is equal to 10

Thanks for your help, I'll try to figure it out with your tips...

stary by doing the simplest modification to existing code ... printing a message when second is at particular value teaches you how to run a command when a variable contains a specific value ... choosing seconds means that you do not have to wait very long for results ... next, you add code that moves a servo ... that will also move every 60 seconds ... when it works correctly, then change the watched variable to hours

This is my first time trying to code, those codes you see are found open source hahaha... What you said, sounds hard for me. But I guess this would be my best shot if no one else shows up to help me out of that hahaha. Thanks buddy.

If you think you can help me further by modifying this code for me, it would be really appreciated! By me and my fish! hahaha

start by trying out the example codes that are included with the arduino IDE ... learn how conditional code works using if statements

Does this answer your question? How do you combine 2 different sketches together

Does this answer your question? Code for fish auto feeder not working

You have to spend some time and practice coding, it does not come over night. As far as your timing look up for an alarm clock sketch that will do what you want.  Once you understand that you should only have to add a few lines of code. As far as open source the tools you are using are open source. Remember there are people out there that are expertes and there people just starting so expect what you find to fall some in that range of quality.


text:
what is wrong with this code? It doesn't work
#include <DS1302.h>
#include <Servo.h>
Time t;
Servo myservo;
int Hour;
int Min;
int Sec;
// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
myservo.attach(9);
myservo.write(45);
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);
Serial.begin(9200);
// The following lines can be commented out to use the values already stored in the DS1302
//rtc.setDOW(SUNDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(8, 59, 50); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(8, 25, 2019); // Set the date to August 25th, 2019
}

void loop()
{
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;
 Serial.print(Hour);
 Serial.print(":");
 Serial.print(Min);
 Serial.print(":");
 Serial.println(Sec);

//set the time for fish feeding
if ((Hour== 2 && Min== 0 && Sec== 2)||(Hour== 21 && Min== 0 && Sec== 2)) {
myservo.write(0);
delay (300);
myservo.write(45);
delay (300);}
}

did the intermediate code work?

Nope, nothing seems to work hahaha

You need to define "doesn't work". What output are you expecting? What output do you get? What happens? It's like going to a doctor and saying you feel sick. S/he needs more details than that.

on your previous post, i suggested that you print a message when the seconds is 10 ... did that work?

Serial.begin(9200) ? and depending on the library, the rtc.get time may get stuck in a bad connection to the rtc chip.

It would be helpful if you could answer Nick Gammon's question. "Doesn't work" is not a useful description of a problem. Also Serial.begin(9200); will very likely not give any useful output on the serial console.

Nick, I was expecting the servo to rotate when the defined time. It doesn't do that. The servo doesn't move at all.

I've changed the serial.begin(9200) to (9600) but it doesn't seem to make a difference in the output.

I would break this down to individual problems by 1st commenting out the servo code and making sure the time code works AS EXPECTED. Then doing the same for the servo code.  If the clock does not work AS EXPECTED double check things such as using the correct pins to interface the RTC board to the ARDUINO UNO or if the RTC battery is still good.  If the servos do not work AS EXPECTED double check things such as using the correct pin to control the servo, the servo ground and power wires are correctly connected and if the poser supply is powerful enough to operate the servo.

@st2000 I think that the only thing I didn't cover so far is if the correct pins are being used. How do I check that?

Quit re-posting (3 times so far) your question!  People are going to start closing them down.  Instead - edit your original question.

In the line "DS1302 rtc(2, 3, 4);" you are tellng the program you will be connecting the Dallas Semiconductor clock chip to pins 2, 3 and 4.

Comments are not for extended discussion; this conversation has been moved to chat.

Explanation about the multiple time execution
if ((Hour== 9 && Min== 14)||(Hour== 21 && Min== 0)) {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15ms for the servo to reach the position
  }
 }

Assume the time is 9:14:00 (9 hours, 14 minutes, 00 seconds).. the if condition passes.

The for loop will get executed. The duration needed to complete the loop is roughly 5 seconds.

Later, it will again go to the if condition. The time will be now 9:14:06.. it means, the condition will pass again.. the motor will again rotate.. this will repeat for about 11 times.. until the time changes to 9:15:00 or more.

So the solution is to give a delay, before exiting the if loop if you wait for a minute with
delay(60000);

then, the next 'if' condition will fail and works as per your expectation.

Part 2:
debugging:
        if ((Hour== 9 && Min== 14)||(Hour== 21 && Min== 0)) {
          for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
            // in steps of 1 degree
            myservo.write(pos);              // tell servo to go to position in variable 'pos'
            delay(15);
            Serial.println("moving");
    ....

Like this?
`void loop() {
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;
// Serial.print(Hour);
// Serial.print(":");
// Serial.print(Min);
// Serial.print(":");
Serial.println(Sec);
//set the time for fish feeding
if ((Hour== 11 && Min== 46 && Sec== 0)||(Hour== 21 && Min== 0 && Sec== 0)) {
for (pos = 0; pos <= 180; pos += 1) {
// in steps of 1 degree
myservo.write(pos);
delay(15);
}
for (pos = 180; pos >= 0; pos -= 1) {
myservo.write(pos);
delay(15);
}
delay(60000);
}
}`

But anyways, the issue here is that the servo doesn't even start either way!

you should check the Servo connections once. I doubt on that

It's all fine with the connections, I just tested the servo with the servo sweep exemple code

I just added the simulation snapshot. I created using the wokwi Arduino simulator.. it works just fine.. nevertheless, can you use some print statements to see whether the IF condition is passing ever?

I am a total noob in arduino and coding. I understant what you suggest by using some print statements to see if the IF condition is passing, but I have no idea on how to do it. I'm sorry for bothering you with so much. :\

@TiagoKotryk insert Serial.println("moving"); into the brackets of the if statements. Though at that point you should step back a bit and first do some basic Arduino tutorials to learn the basics. I don't think, that you really understand the code, that you wrote there, but that you just copy&pasted it together. It will get easier, when you understand the basics

@chrisl You are right about the point you made. Thank for your suggestion. I've inserted the code into the brackets and it shows here "Moving" on every second of the clock! Does it mean that the servo is trying to move every sec?

Yes. Though it is nor clear, what code you are currently using. Add the new code version to your question (leaving the old part intact)

@chrisl have updated this thread with the current code and results so you can take a look. Thanks for the huge help!

you have put the print statement outside the for loop. Please put it inside the for loop. you can put it after the line delay(15)

@goodarduinocode I have made the change:
 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees     myservo.write(pos);              // tell servo to go to position in variable 'pos'     delay(15);                       // waits 15ms for the servo to reach the position     Serial.println("moving");   }  } }
But as result, the monitor serial displays nothing

The condition to drive the motor is never passing. Please take time and try to understand. Is the RTC running? Can you debug the time? Print the time and see

I think the problem is that you have given the baud rate as 9200 but the minimum baud rate is 9600(Serial.begin(9600)). And change the baud rate in the serial monitor.

4 hours before you posted your answer, Tiago Kotryk already replied in the comments that changing the baud rate to 9600 didn't make a difference. So why post this as an answer?


text:
log STK500v2 commands while flashing a Mega
My final goal is to replicate the process with which the PC programs the arduino.
I have gone through the commands.h file and made a couple of attempts to get the logic right. But no success at flashing the arduino.
Is there any way to view the Hex commands that are written to the arduino from the PC? Something like verbose but list every hex command.
My idea is that I will just replicate the same commands and try uploading hex files from SD card.

have you examined the bootloader source code?

http://www.gammon.com.au/bootloader

Add the flag -vvvv to the avrdude command. That will show you the flow of data between the computer and the Arduino.
You can copy and paste the executed command from the IDE and run it in a terminal / command window adding the flag manually. Or you could modify the platform.txt file for the AVR core.


text:
ESP32 and the Microsoft Azure Device Provisioning Service
I am currently experimenting the the ESP32. In general connecting to WLAN and also to the Microsoft Azure IoT Hub works fine. But unfortunately i coulnt find any information on using the ESP32 with the Microsoft Azure Device Provisioning Service. That means connecting and registering an ESP32 to the Microsoft Azure IoT Hub with a certificate.
Has anyone did this before? Maybe some guiding links etc.?

a Google search returns what appear to be valid examples ... what search terms did you use?

"esp32 azure device provisioning service" was my search

that's close to what i searched and found this https://docs.microsoft.com/en-us/samples/azure-samples/esp32-iot-devkit-get-started/sample/

Thank you, but i know this page and this is only about "Starting with ESP32 and the IoT Hub" in VS Code. Thats not what i am looking for. Sorry.

You can open an issue in https://github.com/Azure/azure-iot-arduino to ask I guess, if that's the ilbrary you're using for connecting. Microsoft people should know their products best.


text:
Esp 32 keeps disconnecting from com port
I was trying to upload a blinking coding that was in Arduino IDE but the Arduino IDE can not detect my Esp32 but when i press "EN" i manage to get connection but when i letgo the esp32 disconnect again

What is wired to your ESP32?

Nothing is wired to my esp32

What ESP32 board are you using?

Esp 32 DOIT DEVKIT V1 board

I would suggest that you have a dodgy USB cable or socket on that board. Pressing the EN can not do anything to USB, since it has no connection to USB. But it is right by the USB socket, so you may be pressing down on that at the same time, or otherwise moving the connector.

I have use multiple  cable still the same result

And if you hold the board completely still with one hand and press EN with the tip of something like a pen does it still exhibit the same symptoms?

By doing that the Arduino IDE detect my board on com port 3 but when i letgo of "EN" button it disconnect


text:
How to connect a LiFePO4 battery directly to an esp32?
If I want to connect a LiFePO4 battery (as the power supply) directly to an esp32 - would this be the correct way: the plus of the battery to the 3.3 volt pin and the minus to a ground pin?

No. Absolutely not.
A LiFePO4 battery is 4.2V when fully charged. The absolute maximum voltage of an ESP32 is 3.6V.
You will kill the ESP32.
Instead you need to have a voltage regulator with a very low dropout. Ideally a switching ("buck") regulator with a zero-dropout "pass" mode to give the maximum life from your battery.
Even better is a "buck/boost" battery regulator that will boost the voltage up to a stable 3.3V once the battery voltage drops too low.
If all this is beyond you then you're better off using a powerbank to do the regulation to 5V for you then convert that back down to 3.3V with a simple buck regulator.

The maximum charge voltage is specified here as 3.65 Volt.

@sid_com That's the recommended maximum. They can go up to 4.2V if you want about 1% extra capacity. 3.65 is still above the absolute maximum of an ESP32 anyway.

4.2v is typical of lithium chemistries other than lithium IRON phosphate batteries. One can use a radio control type battery charger and set a maximum charge level to lower than the max for the ESP32. Some capacity may be lost in so doing, but with care, it could be accomplished.

@fred_dot_u https://www.evworks.com.au/page/technical-information/lifepo4-care-guide-looking-after-your-lithium-batt/#:~:text=Tip%201%3A%20Never%20over%20charge%2Fdischarge%20a%20cell!&text=In%20the%20case%20of%20LiFePO4,3.5V%20and%204.2V.

from that page: In the case of LiFePO4 chemistry, the absolute maximum is 4.2V per cell, though it is recommended that you charge to 3.5-3.6V per cell, there is less than 1% extra capacity between 3.5V and 4.2V.

Exactly. Up to 4.2V. If you have that you will fry the ESP32. You really really should have a battery controller on there to keep it at a regulated 3.3V regardless of the battery voltage (above the lower cutoff voltage of course).

The charging voltage for lifepo4 used to be 4.2V but that was killing battery's now it's 3.65V and a fully charged battery is 3.6V which is perfect for the esp32. https://electronics.stackexchange.com/questions/365440/what-is-the-maximum-static-voltage-of-lifepo4-batteries
https://en.m.wikipedia.org/wiki/Lithium_iron_phosphate_battery

I know this question is two years old but it still pops up on research. I just wanted to add something from my experience with this:
If you take an Enerpower HTCFR18650 for example datasheet you see that the maximum voltage isn't 4.2V but 3.65V +/- 0.05V. While this technically is a little bit above the absolute maximum rating of the ESP32 (3.6V), in a non critical environment you can absolutely use the battery without voltage regulator. Just keep in mind that you also will not have any undervoltage protection in this case.
I'm not a fan of this negativity ("you will fry", "you kill you ESP", "Everyone will die"). An ESP32 costs $1. Just try it and if it works its great (it does) and if it doesn't, don't blame me ;)

You are correct. 3.6V is 100% charge. https://electronics.stackexchange.com/questions/365440/what-is-the-maximum-static-voltage-of-lifepo4-batteries

Where are you getting your esp32's for $1 please.


text:
Can I use LiFe PO4 batteries in a 18650 battery shield?
Is it safe to use LiFe PO4 batteries in a 18650 Battery Shield (sometimes called Lithium-Battery Shield)?

In my opinion it is NOT SAFE, if your 18650 Battery Shield also charges the battery.
Anyhow some pages state that it is possible to charge LiFePo4 batteries with 4.2V instead of the recommended 3.65V. https://www.powerstream.com/lithium-phosphate-charge-voltage.htm
LiFePo4 batteries have a smaller energy density and therefore capacity. Thus those are not as explosive as Li-Ion batteries. But you are risking damaging the battery and shorten its lifespan.


text:
Can AccelStepper accelerate non-linearly?
I am running a Nema 23 motor with an Arduino Uno and a microstepper driver. I am making a torsional vibration demo, which uses a series of springs connected to the motor driveshaft to spin gears. These gears, as changes in shaft speed occur, should begin to weave in- and out-of-phase with one another. In my particular case, I am using three potentiometers, which read 0-1023, to read speed, amplitude, and frequency.
The changes in motor speed are where I run into my issues. I need the speed of the stepper to be a sinusoidal function - of the form "Speed - Amplitude x sin(frequency x time)".
Below is some rudimentary code I put together with the AccelStepper library, which does not work:
#include <AccelStepper.h>

/* Using a stepper motor,
  rotate a vibrational model using gears interconnected by springs
  in such a way as to induce torsional vibration, which should be visible by comparing
  movement of juxtaposed rotating gears with markers painted on. */

AccelStepper stepper(AccelStepper::DRIVER);
void setEnablePin(int enablePin = 8);

int Microstepping = 8; /* Microstepping factor, as set on the ST-M5045 control board.
                          Multiplies the number of steps per revolution on the stepper motor.
                          Reference controller manual for adjustments to this number. */
int Steps = 200; /* Number of steps on your stepper motor.*/
int SPS;
int Amp;
int Freq;
// int SC;
int n = 2;
int i;
int totalSteps = Microstepping * Steps;
int currentPosition();

/* It should be noted that the Microstepping and Steps factors are not necessary, and adjusting the microstepping factor
    on the fly will not break the code. However, be aware that changing the microstepping factor by more than one interval
    at a time can cause the motor to not keep up with the sudden changes, i.e. losing torque or vibrating/stuttering. */

void setup() {               // THIS RUNS ONCE //

  Serial.begin(9600);

  // read potentiometers; raw inputs from 0 to 1023 //
  SPS = analogRead(0) * 0.5; // MAX steps per second should be <1000. Speeds above 1000 unreliable, according to AccelStepper docs.//
  Amp = analogRead(1) / 20;   // MAX AMP ~51//
  Freq = analogRead(2) / 170; // MAX FREQ ~12 Hz//

  stepper.setMaxSpeed(1000);
  stepper.setAcceleration(SPS / 1.5);

  int nextStop = totalSteps / Freq;

  stepper.moveTo(nextStop);
  stepper.run();
  Serial.println("INITIALIZED");
}

void loop() {
  SPS = analogRead(0) * 0.95;
  Amp = analogRead(1) / 20;
  Freq = analogRead(2) / 170;

  float spd = SPS + (Amp*sin(Freq*millis()));
  stepper.setSpeed(spd);
  stepper.run();
  Serial.print("speed:  ");
  Serial.println(spd);
}

The issue I am having with the above code is that it enters the loop but does not vary the speed, despite the serial output showing me a speed which oscillates about the desired value several times a second.
And now, folks, what you've all been waiting for: The Point.
Does AccelStepper actually support non-linear accelerations not as the result of an error? I cite the following excerpt from the AccelStepper documentation,
 /// Sets the maximum permitted speed. The run() function will accelerate
 /// up to the speed set by this function.
 /// Caution: the maximum speed achievable depends on your processor and clock speed.
 /// The default maxSpeed is 1.0 steps per second.
 /// \param[in] speed The desired maximum speed in steps per second. Must
 /// be > 0. Caution: Speeds that exceed the maximum speed supported by the processor may
 /// Result in non-linear accelerations and decelerations.
 void    setMaxSpeed(float speed);

which makes the only mention of non-linear acceleration in all of the documentation - in the context of an overflow error.
I've thought of possibly using a modified version of the easydriver example program from reply #3 to this post if AccelStepper isn't capable of doing what I need it to do. Included is also an image of the system (minus the arduino and controller).
Thanks for your help in advance

I appreciate the votes for exposure! Here is the answer I got from Mike, the creator of AccelStepper himself: link
Short answer: no!
I've posted the program I'm using now, which accelerates nonlinearly using pulse timing variation, in the linked thread.
Happy stepping!