Hello, I have tried to read through some of the other posts but can't seem to figure out the right method to get my sensor readings to send over bluetooth to my Mac. I have been told WiFi might be better, but I will be using my sensor in an area with no wifi, or in an area I dont have access to the wifi.
Obviously this is a DIY project but how would larger companies send data wirelessly from their devices to their software on a computer/phone or tablet app?
I have a string potentiometer attached to a Nano 33 IoT, the Arduino sketch is below and works fine when plugged into my Mac.
I am sending the readings to serial at the moment, I have a python program that reads serial and prints the data on a graph if that factors into the equation for Bluetooth.
How can I change the sketch below to send wirelessly to serial or to my python app?
#include <Encoder.h>
// Change these two numbers to the pins connected to your encoder.
Encoder myEnc(2, 9);
// Variables
unsigned long currentTime;
unsigned long prevTime;
const float pi = 3.14159; // pi definition
const float steps = 1024; // encoder steps per turn total encoderpos 14871 14.522
const float diameter = 0.0657574;
float distance = 0;
float prevDistance = 0;
float velocity = 0;
void setup() {
Serial.begin(115200);
currentTime = micros();
}
long oldPosition = 0;
void loop() {
long newPosition = myEnc.read();
if (newPosition != oldPosition) {
currentTime = micros();
oldPosition = newPosition;
distance = (newPosition * pi * diameter) / (4 * steps);
velocity = (distance - prevDistance) / (currentTime - prevTime) * 1000000.0;
// Send distance and velocity as a single string separated by a delimiter
Serial.print(velocity);
Serial.print("-");
Serial.println(distance);
prevDistance = distance;
prevTime = currentTime;
}
}
Thank you for your time and thoughts!