Welcome! Log In Create A New Profile

Advanced

Adding WiFi support to Marlin with RAMP1.4

Posted by pfinucan 
Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 10:33AM
So I am currently editing Marlin to make a simple wifi serial connection to a computer so I don't have to use a usb cable. I am using this cheap ($35) wifi module from sparkfun. I guess you could use it to download the gcode to a SD cards too, but I need to get it working first.

It occurred to me that I couldn't be the first person to do this. Anyone know if someone has posted this already? I am looking for a cheap (opensource) wifi solution for ramps1.4 / marlin. I did a little googling but nothing really poped out.

Anyway, when I have it working I will post it to the wiki.

Thanks,
Patrick
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 11:16AM
yay!
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 12:05PM
What about OctoPrint running on a raspberry pi?

Ben
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 12:27PM
Ya, that looks interesting. And with the Rasp Pi low cost it might be worth it. (I have a rasp Pi sitting on my shelf) But it is a lot of added software / hardware complication, if you just want to remove the usb cable.

I havn't seen a Rasp Pi printer shield (for stepper drivers etc). But I think the Rasp Pi might be a great way forward with the Reprap project. It has so much power, easy to network etc.

But for now a simple addon for RAMPS would be very useful because so many people have it already.
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 12:36PM
I spent some time looking for an ethernet solution for RAMPS/Arduino, the ones I found were all very limited. In addition often the ethernet chip was a faster processsor than the atmel CPU.

I'm now of the opinion that ARM boards are the way to go, as well as being faster an LPC1768/9 is cost comparable to the Atmel controllers, has sufficient IO and has built in support for Ethernet among other things. The Smoothie board is a good starting point.

Edited 1 time(s). Last edit at 04/03/2013 01:43PM by Polygonhell.
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 01:08PM
I hadn't looked into that smoothy board (~$120). It looks promoising. And I agree that faster is the way to go. It looks more geared to CNC than 3D printing. One problem for me is the firmware is writen in C++. I think one thing that helps reprap (specifically Marlin) is that the arduino has a large active following. So if you are not a professional programer, it isn't that hard to find all kinds of code examples and libs to use free on the web. And with all the support online, getting the programing environment running on our computer isn't a major issue. You don't need to compile the software, etc. That can but daunting to a non-programer. If something goes wrong with the build is hard to know how to fix it.
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 01:50PM
Arduino sketches are all basically C/C++ with a wrapper to specify a main loop, so it's no easier. And all they do is rename compile to verify.....

I think one of the advantages of ARM is that you could probably get rid of all the edit configuaration.h stuff, since there really isn't a need to optimize the math by having constants defined at compile time. I think the MBed drivers will give you drag and drop firmware programming and you'd provide a programming utility to set up the configuration variables like steps per etc.
Making binary firmware distribution practical.

I don't want to speak for the smoothy people but given the thermistor inputs and Mosfet outs, I'd assume it was designed specifically for printing with an eye to CNC.
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 04:07PM
pfinucan Wrote:
-------------------------------------------------------
> So I am currently editing Marlin to make a simple
> wifi serial connection to a computer so I don't
> have to use a usb cable. I am using this cheap
> ($35) wifi module from sparkfun. I guess you
> could use it to download the gcode to a SD cards
> too, but I need to get it working first.
>
> It occurred to me that I couldn't be the first
> person to do this. Anyone know if someone has
> posted this already? I am looking for a cheap
> (opensource) wifi solution for ramps1.4 / marlin.
> I did a little googling but nothing really poped
> out.

Not sure exactly what you are looking for here, how would it be different to the module you already have?

I have been playing with RN171 modules at work to "wifi enable" our products (marketing think it is a good idea). I know that people have used Raspberry Pi and the Olimex board to create a wifi-serial bridge for Repraps. It may seem like a pricey method, and running Linux seems overkill, but the cheapest wifi modules like RN171 are in the $30 region anyway. USB wireless modules are a few $. So when you add it up, it is a similar cost.

You could maybe get just the wireless transceiver, but you then still need an MCU to drive it plus all the software. That is a LOT of dev work to save $20. TI have a new chip "Simplelink" which is about $12, the interface on the MCU side is SPI so needs a little work on the Reprap code.

On the host side, there are virtual comm port drivers available so you don't need to change application code, at least there are for Windows, not sure about Unix.

Bluetooth is a cheaper wireless alternative, although maybe not as flexible as Wifi. I've also got some bluetooth modules, haven't got round to wiring them up to a printer yet.
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 05:11PM
I posted here to see if anyone has already updated Marlin to interact with the roving networks modules. I find that almost any 3D printer project I start, someone has already done almost the same thing. So I was just checking.

I basically want a networked printer. And I already like marlin and ramps14. I think that RN module is a reasonable and cheap way to network a printer, but obviously not the only way.

I will continue working on it, and post the code, and a diagram when I am done.
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 05:14PM
What code is needed? Doesn't it just connect as a UART interface?
Re: Adding WiFi support to Marlin with RAMP1.4
April 03, 2013 11:17PM
I have used the RN modules in other hobby projects, and I needed to add #include SoftwareSerial.h (for a arduino UNO, I guess I don't need that here). The mega has 4 UARTS, all but one, UART2 (pin 16 and 17) are used for other things. So I can connect to the ramps pins aux 17 and 18. Ramps AUX 17 = Mega 17 (RX2), and Ramps AUX 18 = Mega 16 (TX2). So that part is pretty easy.

I also need a logic level converter and 3.3 volts to run the RN. The 3.3 V pin isn't connected on the RAMPS 1.4. So I will have to figure out how to get that connected.

On other projects I did some handshaking to get the RN running like this (it uses a wifly lib):

wifiSerial.begin(9600);
    if (!wifly.begin(&wifiSerial, &Serial)) {
        Serial.println("Failed to start wifly");
	terminal();
    }

    /* Join wifi network if not already associated */
    if (!wifly.isAssociated()) {
	/* Setup the WiFly to connect to a wifi network */
	Serial.println("Joining network");
	wifly.setSSID(mySSID);
	wifly.setPassphrase(myPassword);
	wifly.enableDHCP();

	if (wifly.join()) {
	    Serial.println("Joined wifi network");
	} else {
	    Serial.println("Failed to join wifi network");
	    terminal();
	}

Will the Mega see the input on a UART the same as on the usb cable in this code? Without any extra coding?

void get_command() 
{ 
  while( MYSERIAL.available() > 0  && buflen < BUFSIZE) {
    serial_char = MYSERIAL.read();
    if(serial_char == '\n' || 
       serial_char == '\r' || 
       (serial_char == ':' && comment_mode == false) || 
       serial_count >= (MAX_CMD_SIZE - 1) ) 
    {

I didn't really have any time to work on this today. It's not connected yet...


Edited 2 time(s). Last edit at 04/03/2013 11:19PM by pfinucan.
Attachments:
open | download - rn_mega (1).jpg (117.5 KB)
Re: Adding WiFi support to Marlin with RAMP1.4
April 08, 2013 10:38PM
Okay I have the printer executing GCODES sent over telnet to the WiFi module. I am still updating the Marlin firmware to make the UART selectable, so you can switch between the WiFi and the USB cable on the fly. Right now I just updated the registers in the Serial file to point to UART2. Easy peasy.

   FORCE_INLINE void write(uint8_t c)
    {
      while (!((UCSR2A) & (1 << UDRE2)))                                 // Changed
        ;

      UDR2 = c;
    }


I started a wiki page here [reprap.org]

I still need to get pyserial working on the computer end, so pronterface (or whatever you use) can connect directly to a IP address.

What is a good way to find a unused M code? I was thinking about using a couple in the 600's. Are there any rules/guidelines for that sort of thing?

I will be working on it here: (nothing is uploaded yet, but should be but the end of the week)
[github.com]
Re: Adding WiFi support to Marlin with RAMP1.4
April 09, 2013 09:16AM
So I just forked the Marlin Fireware and someone has already added serial port switching. The copy I had on my computer was a little old and didn't have it. This is great because that means no software changes are needed to the most recent Marlin Firmware to use a WiFi module.
Re: Adding WiFi support to Marlin with RAMP1.4
April 10, 2013 01:26PM
I tested wireless and SD a while a ago: [fightpc.blogspot.com.es]

I settled with Bluetooh 'cause it was cheaper. Unfortunately it was slower too. That proved to be a problem when printing parts with lots of very short segments (print would slow down).

Using the SD card printing feature looked like a possible solution to that problem. Unfortunately 3kbps was not a reasonable upload speed for me, so I quit. Please note that USB link won't give you much faster SD write speed because the bottleneck seems to be on the Arduino side. Therefore, while printing from SD works nicely and without extra delays or slow-downs, getting the data to the SD card will require lots of time and patiente (or unplugging the card, plugging it to the computer and back to the Arduino).

Selecting Wifi might be an answer as being faster than Bluetooth (I hope you get better average thoughtput) you may not experience slow-downs in your prints, and then you won't need to upload code to a painfully slow SD card.
Re: Adding WiFi support to Marlin with RAMP1.4
April 10, 2013 09:58PM
i love this whole wireless printing idea, but has anyone used one of those fancy high speed sd cards to see if that makes it any faster, im sure it would write faster.
Re: Adding WiFi support to Marlin with RAMP1.4
April 11, 2013 08:56AM
So it turned out that a quick change on the marlin firmware side was the easy part. I have been playing with printcore.py. I think that is the heart of Printrun / Pronterface. The idea is that you can point pronterface at a ip and port number of the wifi module to print. And the user experience of pronterface will be the same.

In the printcore class "printer" is the serial connection. I think that I can just add a python socket connection to an ip and port, and it work the same way. The one problem I see is that Tcp/ip connections are typically short lived, they open send, recieve and close. I not sure if I need to add some overhead of opening the socket each call or just try to leave it open.

I beleive there is only really 3 function that I need to add a socket call to, I posted them below.

def connect(self, port = None, baud = None):
      # This opens a connection from printrun/pronterface to the serial port
      self.printer = Serial(port = self.port, baudrate = self.baud, timeout = 0.25)


def _readline(self):
     try:
            #This reads a line from the serial port
            line = self.printer.readline()
def _send(self, command, lineno = 0, calcchecksum = False):
      try:
              #This writes a line to the serial port
             self.printer.write(str(command+"\n"))

Example of a python socket (aka connection to IP address)

# Echo client program
import socket

HOST = '192.168.1.100'    # The remote host
PORT = 23
# The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)


I was hoping I could do something like this:
def connect(self, port = None, baud = None):
      #self.printer = Serial(port = self.port, baudrate = self.baud, timeout = 0.25)
     self.printer = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
     self.printer.connect(('192.68.1.100', '23'))  # this is the address my wifi module is tuned to

def _readline(self):
     try:
            #line = self.printer.readline()
            line = self.printer.recv(1024)

def _send(self, command, lineno = 0, calcchecksum = False):
      try:
             #self.printer.write(str(command+"\n"))
             self.printer.sendall(str(command+"\n"))

Anyway, I will try it out tonight.
Re: Adding WiFi support to Marlin with RAMP1.4
April 11, 2013 09:21AM
Quote
The one problem I see is that Tcp/ip connections are typically short lived, they open send, recieve and close. I not sure if I need to add some overhead of opening the socket each call or just try to leave it open.

I disagree: TCP connections do not need to be short-lived. You can keep it open as long as you want (as far as the other end is cool with that too).

You should use a readline when you want to read a line, if you try to read more than that your program may get stuck there. I am not familiar with sockets in Python but I might be if needed.
Re: Adding WiFi support to Marlin with RAMP1.4
April 11, 2013 12:13PM
Since the transfer speed is limited by the microcontroller and not the USB connection, what do you really gain from using a wifi connection? I expect that printing directly would be as unreliable as printing directly through USB and uploading the gcode through the wifi connection would be just as slow as through USB.
Re: Adding WiFi support to Marlin with RAMP1.4
April 11, 2013 01:30PM
Only trying to move the printer away from my computer. It is basically the same reason you would want a networked paper printer. In an office or computer lab you may want to have multible computers with access to the printer. But that would be another step beyond what I am trying to do, because you would need to handle the traffic somehow. With an arduino that might start to be a challenge.
Re: Adding WiFi support to Marlin with RAMP1.4
April 11, 2013 03:26PM
Has anyone seen botqueue?
[www.hoektronics.com]

Hoeken has added Raspberry Pi to the stack, so wireless printing may soon be available, via the internet no less.


- akhlut

Just remember - Iterate, Iterate, Iterate!

[myhomelessmind.blogspot.com]
Re: Adding WiFi support to Marlin with RAMP1.4
April 14, 2013 06:03AM
Nice work on the project. Just a thought but a more reliable and faster connection would be through a hardwired ethernet cable no? Is there a ethernet controller shield that can be connected to RAMPS 1.4?
Re: Adding WiFi support to Marlin with RAMP1.4
April 14, 2013 07:25AM
There is an Arduino ethernet shield, but due to transfer overhead it is slower than a serial connection. You really need a faster CPU to make use of these faster connections.
SoftwareSerial.h with Marlin
August 01, 2013 10:56AM
Hi everybody,

I want to use an RFID module to my mega 2560!!
For this, I write a program which used SoftwareSerial.h, and it works fine!!
When I add it to Marlin, I cannot connect my boardto pronterface " I think I have a bug".
I have this configuration :
//==========================================//
#define rxPin 50
#define txPin 24

SoftwareSerial rfserial(rxPin, txPin);
//==========================================//


If I omit the line SoftwareSerial rfserial(rxPin, txPin); my Marlin works fine.
If I omit Marlin, and I use read and write program, it works fine!!!

Please help, I spend a lot of time on it!!!!
Re: SoftwareSerial.h with Marlin
August 01, 2013 11:03AM
Why would you want to use SoftwareSerial?

Mega has four serial ports. Use pins 16,17 instead.
Re: Adding WiFi support to Marlin with RAMP1.4
August 01, 2013 11:11AM
Think you for reply!!

Yes I tested that, but I arduino don't accept directly this. Look the line behind
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

I try it with the (50,24) and it works fine, but when I add Marlin, it does not work???
Re: Adding WiFi support to Marlin with RAMP1.4
August 01, 2013 11:14AM
It worked nicely for me as Serial2: [fightpc.blogspot.com.es]

It is a regular serial port, just do Serial2.begin(9600); and then you can do Serial2.write ...
Re: Adding WiFi support to Marlin with RAMP1.4
August 01, 2013 11:58AM
Think you misan for your reply.

But I have an UART interface "my RFID has UART interface", and these ports are used for TTL!!

Look the line behind :
Serial: 0 (RX) and 1 (TX); Serial 1: 19 (RX) and 18 (TX); Serial 2: 17 (RX) and 16 (TX); Serial 3: 15 (RX) and 14 (TX). Used to receive (RX) and transmit (TX) TTL serial data. Pins 0 and 1 are also connected to the corresponding pins of the FTDI USB-to-TTL Serial chip.

I just want to add SoftwareSerial.h on Marlin and work with!
SoftwareSerial.h alone works fine, I don't know why it does not accept the declaration :

SoftwareSerial rfserial(rxPin, txPin);

Any idea?!! Please!!
Re: Adding WiFi support to Marlin with RAMP1.4
August 01, 2013 12:15PM
why use wifi, why not bluetooth?
Re: Adding WiFi support to Marlin with RAMP1.4
August 01, 2013 12:23PM
These ports are UARTs. You can use them ... I did, and it worked,
Re: Adding WiFi support to Marlin with RAMP1.4
August 01, 2013 01:22PM
Hi misan,

I retested alone and it works very good!!!! A lot of Thinks,

But on Marlin, it does not accept Serial2, or Serial!!

Why?

I add "hardwareSerial.h" in my main, but it does not accept Serial or Serial2!! It said, does not exist in the scope!!
Sorry, only registered users may post in this forum.

Click here to login