Skip to content

tsch1198/Arduino-RS485-AP

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Arduino RS485

Arduino hosted website control for RS485 commands used to control a RS485 device



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.

Items used

  1. Arduino MKR 1010 Wifi
  2. Arduino MKR 485 Shield
  3. RS485 device
  4. RS485 to USB Converter (for debugging and testing)
  5. Cables

Apps and tools

   

Libraries:

Instructions

Step 1: Test the Arduino

The first step is to test if the Arduino works as it should.

  1. Plug the MKR Wifi 1010 in your PC and boot up the Arduino IDE
  2. Install the WiFiNINA library
  3. Open the WiFiNINA example "AP_SimpleWebServer"
  4. Upload the example to the board
  5. Connect to the AP and open the website to make sure, that everything is working correctly

Step 2: Connect and test the RS485 shield

  1. Plug the RS485 shield directly on top of the Arduino

Pluged in RS485 Shield

(Ignore the black cable) 2. Make sure that the switches are in the following Position: 1. OFF 2. OFF 3. ON 3. Then connect your Y and Z cables to your RS485 device

For testing:

  1. Connect the other ends of the Y and Z cables to your USB adapter.
  2. 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);
}
  1. 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)
  2. If everything is set up correctly, you should see a bunch of "hello xx"

(for more details, visit -> Arduino RS485 Shield Tutorial)

Step 3: Set up the main code

  1. Open the given files and change the AP Settings to your liking.
  2. In the main file change the serial (line 25) and RS485 (line 58) Baud rates to your needs.
  3. Upload the code to your Arduino and open the website. The IP address is printed in the serial monitor.
  4. Now you should see the website I made. Explanation of the website.
  5. To change it to your needs, check out Personalize.

Website:

Default Website

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

Personalize

You can customize the code so that it fits your needs.

How it works

Buttons and Inputs

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.

Variable Values

The variable values are marked with %something% in the website code. These values are replaced by the sendHttpResponse function in the httpHandler.

Website

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.

Example: Change a button

To change for example the a0: Hardwareversion button, you would:

  1. Change the /hardwareversion in WebpageCode to something else.
  2. Give the entry in the handleClientRequest funktion from httpHandler a new name.
  3. Then either put your code directly in the else if or call a function.

Example: Change header

  1. Open webpageCode.h.
  2. Navigate to the body and find the H1 section.
  3. Change AG05 Control to something different.
    <h1>AG05 Control</h1>

Releases

No releases published

Packages

No packages published