Justblair's DIY Audio and Electronics Pages

Connect to your RepRap Wirelessly or Via the Internet Using the HLK-RM04

DSCN4390Recently my attention was drawn to a UART-ETH-WIFI module (serial port - Ethernet - Wireless network) that is incredibly cheap and incredibly flexible.  I have been playing around with it and have managed to use it to connect my Reprap printer to a wireless network.  It have it tested and can confirm that it works between Pronterface and the RAMPS board running Marlin firmware.  What is cooler still is that with a little port forwarding I can upload files and control my 3D printer from anywhere in the world!

It took a little fiddling around to achieve this so i thought that i would produce a simple guide for anyone who wants connected!  This guide uses software designed to work on Microsoft Windows, though I am sure that Linux and Mac have equivalent packages that could also be used.

Materials

Materials wise for this hack you are going to need the following:

  • A HLK-RM04 UART-ETH-WIFI module (For simplicity spend a little more and get yourself the Dev. kit)
  • Some fine Kynar Wire, I had some AWG 30 Gauge in my spares box (preferably in a selection of colours to keep things simple
  • Some thicker wire or ribbon cable
  • Some female/male headers for attaching to your Ramps board (Though I am sure that most Reprap Controllers could also be used)
  • Soldering Tools
  • Crimping Tools

If you wish to do this with the minimum of soldering, purchase a Development Kit.  Shop around for these and expect to pay between $25 – $30 USD including delivery of you are buying just one.  I got mine a little cheaper as I bought them from AliExpress as a pair.  However if you are handy with a little solder you can pick up just the module for around $15 delivered if you shop around.  The components included in the Development Kit are not required if you intend to use this just for your Reprap.

Getting Started

The first hurdle that I experienced when working with these modules was the documentation.   There is actually plenty of documentation available, though some of the key pieces of info required are not obvious.  

Once you have received delivery of your HLK-RM04 then you will need to test it by powering it up.  If you have purchased the Development Kit, you will have all you need to do this with the exception of perhaps a plug adaptor for the power supply depending on which part of the world you live in.  The HLK-RM04 requires 5v to power it up. The Development kit comes supplied with a 1A wall wart style power supply and that is what i used initially to test the unit.  Looking at the Data sheets however the power consumption is listed as between 140ma and 160ma depending on the mode that you choose to operate it in.  Assuming these to be reasonably accurate I have powered it directly from the Arduino’s own 5v Power supply rather than the wall wart though I have not tested this extensively at the time of writing this article

Mode

Current Notes

Only Wi-Fi

140mA

Wife to serial,AP mode or Client mode

One rj45

120mA

Serial to RJ45.

Two rj45

135mA

One is Wan another is LAN

Wi-Fi and two rj45

160mA

Default Mode/Factory Mode

I have used the device in several modes.  The HLK-04 is essentially a Linux powered router with a UART output.  The firmware on board has lots of different modes so you can use it as a Wi-Fi booster, a router, or a serial device or combinations of these modes. 

Accessing the Web Interface

Once you have tested that the board is powered correctly you will probably wish to log in.  The manuals suggest that before you do you reset the device by holding down both the buttons on the Dev. board together (well it said something like that but that is what it means).  This is in case the board has presumably been tested and left in one of the numerous configurations.  It is probably worth doing, though my HLK-RM04 seemed to be at factory settings when delivered.

You now have a few choices as to how to connect and setup the device.  I am going to suggest using the wireless interface, though you can use a the second Ethernet port or a serial port and AT commands to do this.

image

If you are using Windows, click on your network icon on the bottom right hand side of the screen.  You will see your wireless connections and a list of networks that you can join.  You are looking for a network with the name Hi-Link in it’s name.  Click to connect to it

You will probably be asked for a network password.  The documentation is scant here.  The default on mine (Which I discovered by connecting by Ethernet) was 12345678.  Yours is likely to be the same.  If not you will need to use an Ethernet connection to gain first access.

Once you are connected you can try and gain access to the Web interface for the HLK-RM04.  To do this open a browser and attempt to connect to 192.168.16.254.  you will be asked for a User name and password.  The default settings are Admin and Admin.

With a bit of luck we can access the web interface and see the settings.

image

The first screen that you will be take to is the Serial2Net Settings.  Here we can see what settings are set as default.  Notice the serial configure setting is set to 115200 Baud.  imageIf you are using the Marlin Firmware on your Reprap, you will need to reinstall it with a small change to the configuration.h file. 

The line you need to change is near the top of the configuration.h file it should read:

// This determines the communication speed of the printer
// #define BAUDRATE 250000
#define BAUDRATE 115200

This is going to slow the Serial port down on your printer to 115200 Baud.  The HLK-RM04 does not support the 250000 speed that is default for Marlin.  Theoretically the 250000 Baud is better (though only if you print via Serial rather than SD card) but Linux users usually use the slower speed with no apparent issues, so don’t worry.

Once that has uploaded you may wish to test the printer using a USB cable and Pronterface (or whatever software you use on your pc).  Remember to change the port speed to 115200.

Connecting the HLK-RM04 to the Ramps Board.

imageWe need to connect the HLK-RM04 UART-ETH-WIFI module to the Ramps board and for this you will need some cables.  The cables that you will need will depend on the headers you have on your Ramps Board.  We are going to connect our module to the Aux-1 Port on the Ramps Board.  In the Reprap.org Wiki pins 5 and 6 of the Ramps 1.3 board are listed as connected to D1 and D2 of the Arduino Mega.  This is wrong, they are connected to D0 and D1 which is the serial port for the Arduino.  We could also use the last two pins of the Aux-4 Port for this, as the Ardiuno Mega has more than one serial port.  I have already used these for something else though.

DSCN4392

I already had male headers fitted to my Ramps board, so from my offcuts bin I found some ribbon cable that had some female headers already crimpled on.  I used this for one end of my cable.  To the other end I soldered 30 AWG single core Kynar wire.  Ideally I would have used four different colours for this task, but I only had red, white and black left. 

The reason I used such fine cable is that I did not want to have to solder anything to my module.  The pin spacing on the module is not 0.1’ it is smaller than that and a little bit of a fiddle to solder to.  You will see in a moment how I connect to the module. DSCN4393

Once I had soldered the fine Kynar wire to the other ribbon cable and heat-shrunk the joins I stripped the fine kynar ends of the cables. 

The Development kit comes in two parts, the actual HLK-RM04 module and a peripheral board that has RJ45 connectors for the Ethernet connections as well as a power socket and RS232 connector.  On board this peripheral board there is a Sipex SP3232EEN RS-232 Interface IC that forms a buffer between the 3.3 v pins on the module with the higher voltages RS232 interface.  There are also two switches that can be used together to reset the device if you get into trouble.

The good news is that the UART pins on the HLK-RM04 appear (through experimentation) to be 5v tolerant.  Though I could find no reference to this in the documentation.

DSCN4398As I used very fine wire, I attached the cables to the HLK-RM04 in a non destructive way by removing the module from the peripheral board and inserting the exposed ends of the AWG 30 Kynar Cable into the female sockets.

The pin numbers are indicated on the board and you need to attach a minimum of three cables to the module to get it working (four are needed if you want to power the module from the Arduino). You can see on the image to the left how this done.  When they were in place I then re-inserted the HLK-RM04 module in place.  The friction of the male pins of the HLK-RM04 into the female sockets of the peripheral board hold the cables very tightly

The Pins are connected as follows:

HLK-RM04 Aux-1 Pin Number Arduino Equivalent
1 8 (Marked +) 5 V
2 7 (Marked –) GND
20 (Uart_RX) 6 (Marked S) D1 (TX)
21 (Uart_TX) 5 (Marked S) D0 (RX

I will eventually mount this properly to my 3D printer, for the moment it sits on top with some foam tape to prevent it accidentally falling off.  I have taped the antenna (Note that some versions of the HLK-RM04 have a built in antenna) that came with the Dev. kit to the top as well.

Setting Up the Software

Ok so hopefully what you have at this point is a tested HLK-RM04 Module which is connected to your 3D printer via the Aux-1 port of the RAMPS board to your Arduino Mega.  You have changed the Baud rate to 115200 in the Marlin Firmware and there are lights on the HLK-RM04. 

From your network icon in the bottom right corner of the desktop (For Windows Users) you can see the Hi-Link Wireless network.

We have to do a couple of more things to be able to print via the HLK-RM04 module.  First we will set the router up into Wi-Fi Client – Serial Mode and then we will install some software onto the PC that will create a Virtual Com Port that will allow the 3D printers software to talk to the Printer.

Settingimage Wi-Fi Client Mode

  1. Log back onto the Hi-Link labelled network with your PC.  It will probably remember the pass phrase from before.
  2. Open your browser and type in 192.168.16.254 into the address bar
  3. In the NetMode: Setting select “WIFI(CLIENT)-SERIAL”
  4. In SSD Put in the name of your wireless network
  5. Encrypt type will probably be WPA2 AES though your network may differ
  6. Password should be the password you use to connect to your household wireless network.  Often this can be found on a sticker somewhere on your router
  7. For IP type I recommend using a Static IP (Pick an address that doesn’t get used by anything else).  This will mean that every time the HLK-RM04 is connected it should have the same address.  This is handy as we need to point the Virtual serial port to this address.  We don’t want it changing from time to time.
  8. Fill in the rest of the details for your static IP.  You can type this sequence in to a windows PC to find them when connected to your home network:
    1. WinKey+R
    2. CMD then Enter
    3. ipconfig /all
  9. For the serial settings the only one you are likely to need to change is the Network Protocol.  This needs to be set to TCP.
  10. Click Apply.
  11. The Web interface should at this point become non-responsive.  The HLK-RM04 module should now be connecting to your home wireless network.  Give it a minute to do it’s business and then type into your browsers address bar the static IP address that you have just given the browser at step 8.  If all has gone well, you should be able to log back into the web interface again.  Don’t panic if you can’t access the web interface.  Hold down the two buttons on the peripheral board for 5 seconds and then let go.  The router will reset to it’s default settings and you can try again. 

Congratulations.  You should now have a working TCP/IP to Serial Connection.  Now we have to create a Virtual Com port.

Creating a Virtual Com Port

Assuming that you are using a Windows equipped PC, we are going to go to use a piece of software called HW Virtual Serial Port – HW SP3.  You can download a freeware version from http://www.hw-group.com/products/hw_vsp/index_en.html.  It is the Singleport version that you need.  When you have downloaded install and run the installer.  Windows might need additional permissions to let it do it’s work.  If you are asked for a firewall exclusion say yes.

image

When you are asked what components are required, Choose the Standalone Application

Once you have it running, we will change a setting or two:

  1. Click the settings tab, from there set the following  boxes:
    image
  2. In the Virtual Serial Port Tab fill in the details that you set up on the HLK-RM04.  Make sure you select the correct IP address and Port number (8080 if you left the defaults)
    image
  3. Click Create Com.  The VSP status should go to Created after a few seconds.  You can minimise the dialogue box now.

Connecting to your Printer

It’s time for the big one now.  One thing to watch out for just before we get started.  Hit the reset button on your Ramps Board before we start.  Sometimes the serial link between the Arduino and the HLK-RM04 gets a bit messed up when you are playing with settings.  A reset of the Arduino normally fixes it.

Now open Pronterface (other software will normally work) and try and connect to whatever port you created in HW Virtual Serial Port.  If all goes well the printer should connect.  Normally when you connect via USB you get a wordy report from the Marlin Firmware.  This does not happen when you connect over Wi-Fi.  But the printer should come online.

If all has worked well, place a shortcut to the HW Virtual Serial Port software into your Startup Menu.  Then the Virtual Serial Port will be created each time you log in to your PC.

Connecting Via the Internet

Lastly.  For the most brave or most stupid (Think what people could do to your printer!) you can now go to your home routers interface and create a port forward.  Have a look at http://portforward.com/ for instructions on how to do this with your own router.  Beware though.  TCP/IP has no password protection.  Quite simply any Tom Dick and Harry with your IP address and port information could reek havock with your printer. 

I hope that you find this article handy.  Please give feedback if anything is unclear.