Hey, this is a little project of mine I've been working on for the past week. Its an Arduino script that sets up an AP and hosts a website that you can use to control a RS485 device.
- Arduino MKR 1010 Wifi
- Arduino MKR 485 Shield
- RS485 device
- RS485 to USB Converter (for debugging and testing)
- Cables
Libraries:
The first step is to test if the Arduino works as it should.
- Plug the MKR Wifi 1010 in your PC and boot up the Arduino IDE
- Install the WiFiNINA library
- Open the WiFiNINA example "AP_SimpleWebServer"
- Upload the example to the board
- Connect to the AP and open the website to make sure, that everything is working correctly
- Plug the RS485 shield directly on top of the Arduino
For testing:
- Connect the other ends of the Y and Z cables to your USB adapter.
- Install the ArduinoRS485 library and upload this code:
#include <ArduinoRS485.h>
int counter = 0;
void setup() {
RS485.begin(9600);
}
void loop() {
RS485.beginTransmission();
RS485.print("hello ");
RS485.println(counter);
RS485.endTransmission();
counter++;
delay(1000);
}
- After the upload was successful, open a serial monitor on the port of your RS485 to USB device (don't forget to use matching Baud rates)
- If everything is set up correctly, you should see a bunch of "hello xx"
(for more details, visit -> Arduino RS485 Shield Tutorial)
- Open the given files and change the AP Settings to your liking.
- In the main file change the serial (line 25) and RS485 (line 58) Baud rates to your needs.
- Upload the code to your Arduino and open the website. The IP address is printed in the serial monitor.
- Now you should see the website I made. Explanation of the website.
- To change it to your needs, check out Personalize.
In the basic configuration, the website works this way, everything you put in or click is being send via RS485. In the Request(1) List it shows the action you have clicked and in the Response(2) it shows the response.
Note, the webserver runs on the Arduino itself, so it's not very fast. You have to manually refresh after every interaction to see a response
-
Set Position: Sends a f0<-given number-> used for setting the destination position
-
Send Anything: Sends your input
-
Current Motor Mode: Live updated value for current Motormode
-
The 8 Buttons: They send the command which is labeled on them used for said things
-
Clear List (The ninth button): Clearing the list
-
Request(1): Shows the action you have clicked
-
Response(2): Shows the response for your command
You can customize the code so that it fits your needs.
The whole website to server communication works with /something calls. For example:
<div class="flex-row">
<a href="/hardwareversion" class="btn">a0: Hardwareversion</a>
<a href="/productiondate" class="btn">a6: production date</a>
<a href="/currentsetpoint" class="btn">e0: Current setpoint</a>
</div>
If you click the one of the buttons, a /something is being sent. This will be caught by the httphandler script.
The handleClientRequest
function checks if the request is for a specific endpoint (e.g., /RT, /BT, /hardwareversion, etc.) and performs corresponding actions like toggling LEDs or sending data.
The variable values are marked with %something% in the website code. These values are replaced by the sendHttpResponse
function in the httpHandler.
The website's Code can be edited with HTML and CSS.
Source code for the website -> webpageCode.h. The websites code has to be saved in the webpage char.
To change for example the a0: Hardwareversion
button, you would:
- Change the
/hardwareversion
in WebpageCode to something else. - Give the entry in the
handleClientRequest
funktion from httpHandler a new name. - Then either put your code directly in the else if or call a function.
- Open webpageCode.h.
- Navigate to the body and find the H1 section.
- Change AG05 Control to something different.
<h1>AG05 Control</h1>