Hi guys, I've seen a few of posts similar to this one. But I'm struggling to get my head around it and wondering if anyone has an straight forward answer for a newbie like myself and others.
I'm trying to get my Arduino Nano 33 IoT to send a new reading every 100ms to a mobile app to then be graphed. The mobile app is set to receive and graph whatever is being printed by the Arduino. The code I have written so far on Arduino IDE is just to take my readings, no Bluetooth code has been made so far.
I've attempted the steps DanielKopiec has made in this forum (link), however I get to the bit where you must hold the reset button and it just tells me the device has lost connection as soon as I press the RESET button.
Any help on this would be great. Like I said, big newb here but I love learning about this stuff (even though I don't understand most of it) and would be more then welcome to answer any questions.
You don't have to press any buttons. I'm currently using the ESP32 as a main MCU and programming it works if you follow those steps (I will repeat all of them):
Make sure you have the WiFiNINA Library and SAMD / ESP32 Cores installed in the IDE
Set the board to Arduino Nano 33 IoT
Open the sketch Examples -> WiFiNINA -> Tools -> SerialNINAPassthrough and upload it to the board
Change the board to: ESP32 Dev Module and adjust the following:
Flash Size: 2MB
Flash Mode: DIO
Partition Scheme: minimal OR simply use: u-blox NINA-W10 series which has the settings already configured.
Open Examples -> BluetoothSerial -> SerialToSerialBT and upload it to the same COM port, but making sure one of the above boards is selected
(I deleted the delay(20) from the sketch to speed up the communication)
Now change the board back to Nano and upload the sketch you want, you can use SerialNina serial to send data through the NINA module
For me this process works correctly, just make sure you don't have the ports opened somewhere else.
As an extra, I have used the NINA_ACK pin to signal if a client is connected or not. This is the code I have uploaded to the NINA module (you might want to delete the print statements):
Thank you so much! I can now see the Arduino in my Bluetooth listing and can pair to it!
How does one use SerialNINA? Is there an example I can see to understand how to use it? and another question; Is the Arduino now permanently like this or do I have to perform all the steps again when I restart my computer for example?
Again, thank you so much. I've been spending the past few weeks trying to get my head around it and getting it to work with no success, this is the closest I've been!
You can use SerialNina exactly as you would use Serial:
SerialNina.begin(baudrate), SerialNina.print(...), etc.
The NINA module will remain programmed, you have to change the board back to Nano 33 IoT and program it the way you want. What reading do you want to send? I for one use the IMU and read it directly with the NINA module as it's also connected to I2C.
If you ever want to reprogram the NINA module, you have to go through the steps again.
If you want to revert back to the official firmware, you simply upload the FirmwareUpdater sketch from the examples and use WiFiNINA Firmware Updater from the tools menu. Edit: corrected to SerialNina instead of SerialNINA.
I'm sending a float, which can then be read and graphed using an app I made on MIT app inventor. The app is ready, the electronics are working and I'm receiving values, I've just been stumped with the Bluetooth side of it.
Giving this a go and getting an error message saying it SerialNINA is not declared in this scope. Am I doing this correctly? Here is my code, followed by my error message:
#include <ArduinoBLE.h>
#include <WiFiNINA.h>
// Arduino With Load Cell
// Put 2 loads on load cell that that have a known mass, take the readings from both loads
float aR = 353;
float aL = 0; // kg
float bR = 1023;
float bL = 50; // kg
// float inputLoad = WeightLoad // Possible future development. WEIGHTLOAD IS USER INPUTTED. SHOULD BE DONE ON THE APP.
void setup() {
Serial.begin(9600);
SerialNINA.begin(9600);
}
void loop() {
float curReading = 1023 - analogRead(0); // Take reading of analog pin 0 of Arduino
// Interpolate new reading taken from previously known loads.
float load = ((bL - aL)/(bR - aR)) * (curReading - aR) + aL;
// This will give an answer of 0 to 50kg as 50 is the maximum load you can apply.
// using serial.println, we can send the data in a 'text' format
SerialNINA.println(load);
Serial.println(load);
delay(100);
}
Arduino: 1.8.13 (Windows 10), Board: "Arduino NANO 33 IoT"
D:\University\Year 3\Project\Code\Loadcell_Hand\Loadcell_Hand_New\Loadcell_Hand_New.ino: In function 'void setup()':
Loadcell_Hand_New:17:3: error: 'SerialNINA' was not declared in this scope
SerialNINA.begin(9600);
^~~~~~~~~~
D:\University\Year 3\Project\Code\Loadcell_Hand\Loadcell_Hand_New\Loadcell_Hand_New.ino:17:3: note: suggested alternative: 'SerialNina'
SerialNINA.begin(9600);
^~~~~~~~~~
SerialNina
D:\University\Year 3\Project\Code\Loadcell_Hand\Loadcell_Hand_New\Loadcell_Hand_New.ino: In function 'void loop()':
Loadcell_Hand_New:31:3: error: 'SerialNINA' was not declared in this scope
SerialNINA.println(load);
^~~~~~~~~~
D:\University\Year 3\Project\Code\Loadcell_Hand\Loadcell_Hand_New\Loadcell_Hand_New.ino:31:3: note: suggested alternative: 'SerialNina'
SerialNINA.println(load);
^~~~~~~~~~
SerialNina
exit status 1
'SerialNINA' was not declared in this scope
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Sorry, my bad, remembered it poorly. It's SerialNina.
Also, you don't need to include the WiFi and BLE libraries as the FW on the module is no longer the original one.
Those two files contain configuration for that particular board if you ever want to go deeper, but it's a bit more complicated. SerialNina and the pins are defined in those.
Ok so here's where I'm at with this. I am able to pair to the Arduino with my smartphone. However, I cannot keep the two connected. Then when I upload my code, I believe the connection fails as when I select the device on my app, it cannot find it. (When I select the Arduino before I upload my code, my app says nothing, implying it can connect).
Not entirely sure where to go from here, I've asked a few lecturers and they're stumped too haha.
Here is my code:
float aR = 353;
float aL = 0;
float bR = 520;
float bL = 2.5;
void setup() {
Serial.begin(115200);
SerialNina.begin(115200);
delay(5000); //Delay 5 seconds to allow for user to get ready
}
void loop() {
SerialNina.begin(115200);
float curReading = 1023 - analogRead(0); // Take reading of analog pin 0 of Arduino
float load = ((bL - aL)/(bR - aR)) * (curReading - aR) + aL;
SerialNina.println(load);
delay(100);
}
You shouldn't be doing anything else while programming.
The WiFi module should be only programmed once with the SerialToSerialBT sketch, through serial passthrough. It will remain programmed no matter what sketch you upload to the main MCU, as long as you change the board to Nano.
The BT connection can be established after the board powers on and will be lost on any reset.
Once I finish uploading the SerialToSerialBT sketch (using the ESP board), the Arduino is available to pair with on the list of scanned devices. I then upload my sketch (the one above, using the Nano 33 IoT board) and the Arduino's availability disappears, I cant find it when I scan for devices.
Not sure why if the board should remain programmed to be available.
Oh, right, you have to enable the module by setting a pin HIGH, forgot about that.
Insert this in setup before doing anything related to the NINA module.
digitalWrite(NINA_RESETN, HIGH);
The pin is set as an output already in the initVariant function from the variant.cpp file.
I can connect and I get a signal coming through to my mobile device, but it's not the one I was expecting! I'll look further into it and find out what I'm actually graphing haha. I think it's an app problem though. I'll attach a photo anyway
This is a great, cleaned up tutorial on how to do this. I wish this could be stickied someplace!
I'd suggest one edit, which is when selecting the u-blox NINA-W10 series in Part 3, ensure the baudrate is set to 115200, otherwise it may not work (it didn't for me at 9600)
I was able to update the firmware on my nano iot 33 and I can pair to it from Windows. My question is how can I pair to another device that doesn't have a UI? More specifically, I'm trying to communicate with GPS receiver that only communicates via bluetooth RFCOMM. Any way to pair based on the GPS device's bluetooth ID?
Hi, I found this forum while trying to connect my Arduino mkr wifi 1010, I followed all thee steps but when I try and upload the SerailToSerialBT sketch I keep on getting this upload errer can someone help? can you do it on a mkr? This is my errer code:
Sketch uses 1009573 bytes (51%) of program storage space. Maximum is 1966080 bytes.
Global variables use 33364 bytes (10%) of dynamic memory, leaving 294316 bytes for local variables. Maximum is 327680 bytes.
Serial port /dev/cu.usbmodem144101
Connecting.....................................An error occurred while uploading the sketch
.
A fatal error occurred: Failed to connect to ESP32: No serial data received.
For troubleshooting steps visit: https://docs.espressif.com/projects/esptool/en/latest/troubleshooting.html```