Hello!
As it stands now, when I export my findings as a CSV, I get results every second. I wanted to see if BLYNK allowed for me to get data every half second.
To get more specific: I’m trying to capture finger pressure in as granular a fashion as possible. I want to try to see the exact moment pressure stops being applied to something; if I can output data every half second as opposed to every second, that’d be very helpful.
Thank you for any help!
Hardware: Arduino MKR 1010 WiFi; one force sensor and wiring
Using BlynkSimpleWiFiNINA
Before creating the topic
- Search forum for similar topics
- Check http://docs.blynk.cc and http://help.blynk.cc/
- Add details :
• Hardware model + communication type. For example: Arduino UNO with Ethernet Shield
• Smartphone OS (iOS or Android) + version
• Blynk server or local server
• Blynk Library version
/*Description:
Circuit:
Arduino Component
mkr1010 wifi
A0 -------> FSR0
A1 -------> FSR1
A2 -------> FSR2
A3 -------> FSR3
A4 -------> FSR4
*/
// Libraries
#include <SPI.h>
#include <WiFiNINA.h>
#include <BlynkSimpleWiFiNINA.h>
// Pins definitions
#define force1SensorPin A0 // the FSR and 10K pulldown are connected to A0
//#define force2SensorPin A3 // the FSR and 10K pulldown are connected to A1
//#define force3SensorPin A2 // the FSR and 10K pulldown are connected to A2
//#define force4SensorPin A3 // the FSR and 10K pulldown are connected to A3
//#define force5SensorPin A4 // the FSR and 10K pulldown are connected to A2
int analogReading_FSR1=0;
//int analogReading_FSR2=0;
//int analogReading_FSR3=0;
//int analogReading_FSR4=0;
//int analogReading_FSR5=0;
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
/* Fill in information from Blynk Device Info here */
#define BLYNK_TEMPLATE_ID "TMPLTcmcwxfq"
#define BLYNK_DEVICE_NAME "Finger Pressure"
#define BLYNK_AUTH_TOKEN "TSUhqRhOhdaFi62Pr56vrK_qcZvuLxNY"
BlynkTimer timer;
// Declaring variables
char ssid[] = "ATT2YaCIwK"; //** your network SSID (name) between the " "
char pass[] = "psxg9#9922#u"; // your network password between the " "
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS; // connection status
String ipAdress;
WiFiServer server(80); // server socket
WiFiClient client = server.available();
unsigned long timeSensor=0;
void setup()
{
Serial.begin(9600);
while (!Serial);
enable_WiFi();
connect_WiFi();
server.begin();
printWifiStatus();
// Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
// You can also specify server:
Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, "blynk.cloud", 80);
//Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass, IPAddress(192,168,1,100), 8080);
}
void loop(){
Blynk.run();
if(millis()-timeSensor>50){
readSensors();
timeSensor=millis();
}
client = server.available();
printWEB(analogReading_FSR1);
}
void readSensors(){
analogReading_FSR1 = analogRead(force1SensorPin); //**
Serial.print(analogReading_FSR1); Serial.println();
Blynk.virtualWrite(V0, analogReading_FSR1);
}
void printWifiStatus(){
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
Serial.print("To see this page in action, open a browser to http://");
Serial.println(ip);
}
void enable_WiFi(){
// check for the WiFi module:
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}
String fv = WiFi.firmwareVersion();
if (fv < "1.0.0")
{
Serial.println("Please upgrade the firmware");
}
}
void connect_WiFi(){
// attempt to connect to Wifi network:
while (status != WL_CONNECTED)
{
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
}
void printWEB(int sensor1)
{
if (client)
{ // if you get a client,
Serial.println("new client"); // print a message out the serial port
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected())
{ // loop while the client's connected
if (client.available())
{ // if there's bytes to read from the client,
char c = client.read(); // read a byte, then
Serial.write(c); // print it out the serial monitor
if (c == '\n')
{ // if the byte is a newline character
// if the current line is blank, you got two newline characters in a row.
// that's the end of the client HTTP request, so send a response:
if (currentLine.length() == 0)
{
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
// and a content-type so the client knows what's coming, then a blank line:
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println("Refresh: 0.50"); // refresh the page automatically every 1 sec
client.println();
// this part is the content of web site
client.println("<!DOCTYPE html><html>");
client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
client.println("<link rel=\"icon\" href=\"data:,\">");
// CSS to style the table
client.println("<style>body { text-align: center; font-family: \"Trebuchet MS\", Arial;}");
client.println("table { border-collapse: collapse; width:35%; margin-left:auto; margin-right:auto; }");
client.println("th { padding: 12px; background-color: #0043af; color: white; }");
client.println("tr { border: 1px solid #ddd; padding: 12px; }");
client.println("tr:hover { background-color: #bcbcbc; }");
client.println("td { border: none; padding: 12px; }");
client.println(".sensor { color:white; font-weight: bold; background-color: #bcbcbc; padding: 1px; }");
// Web Page Heading
client.println("</style></head><body><h1>Finger Pressure Reading</h1>");
client.println("<table><tr><th>MEASUREMENT</th><th>VALUE</th></tr>");
client.println("<tr><td>FSR 1</td><td><span class=\"sensor\">");
client.println(sensor1);
client.println(" g</span></td></tr>");
// The HTTP response ends with another blank line:
client.println();
// break out of the while loop:
break;
}
else
{ // if you got a newline, then clear currentLine:
currentLine = "";
}
}
else if (c != '\r')
{ // if you got anything else but a carriage return character,
currentLine += c; // add it to the end of the currentLine
}
}
}
// close the connection:
client.stop();
Serial.println("client disconnected");
}
}