XModem problems

I am desperate to use the XModem protocal to send a SD .JPG over serial to a Python script.

I've been trying the library I found here http://mrp3.com/xmodem.html via this page http://arduino.cc/playground/Main/LibraryList

I have had no luck as I continually get an error.

Has anyone else tries this or have a working example?

Many thanks

I have had no luck as I continually get an error.

May we ask you to tell us that error? What sketch did you use to produce that error?

-3 means that the counterpart was not responding.

Don't post snippets, post full sketches.

It's a bit irritating that you're using the same channel for debugging as you're using for file transfer.

If -3 means the counterpart was not responding, shouldnt I have seen at least something sent in the serial monitor?

Are you using the Serial port to talk to the XModem OR to talk to the PC? It can't be used for both purposes. How is the XModem connected to the Arduino?

at the moment both are connected by the USB cable

What does this mean? You can only connect one USB cable to the Arduino at a time. You can not read from that cable connected to one device and write to another device using the same cable.

The concept of xmodem is to ensure the file arrives correctly.


Simple xmodem implementation for Arduino

So, you are mixing xmodem commands and regular print stuff on the same serial port.

No wonder the receiver gets confused.

Is the receiving application communicating over the serial port correctly? Is it running the right code? What happens if you quit mixing data on the serial port?

I expected to see something print in the serial monitor, but its blank.

IIRC the xmodem protocol requires that you have the protocol running at both ends. The serial monitor won't give the correct (or any) response to the xmodem running on the Arduino. I think you have to have xmodem running and listening on the computer and then start it up on the Arduino.


Look at the source tab on the page I linked. The tar.gz file you linked to is useless on Winders, so I can't see what the XSend(&SD, &Serial, f); call is actually doing.

You could, of course, add another Serial.print() to setup() before that call, to confirm that the serial port is, or is not, working correctly before trying to send the file.

I think the most likely problem has already been isolated, but maybe the subtlety of the explanation got lost somewhere in the dialog.

Xmodem, AFAIK (it's been a while) requires an up-front negotiation before it will transfer data. Typically, you can't have two programs on the PC claiming access to the serial port, so if you have the serial monitor open to read your debug printlns, then the Python Xmodem receiver script is probably not also running. This would cause a negotiation failure, resulting in an error.

It's a little like two people trying to talk over the telephone, but instead of party A calling to talk to party B, A calls C to demonstrate how party B won't say "hello" back, so there must be something wrong with the line. The obvious fault being that party B isn't on the line to hear "hello" and say "how do you do" back. I'm not sure if that analogy helps or makes things worse.

At any rate, stop listening with the serial monitor and start your Python script before you assume your library isn't working. Use diagnostic LEDs to show script progress, or if you're crafty, set up a second serial link with NewSoftSerial and a MAX232, or use SPI to a second Arduino and have it echo your messages back via its serial port.

As to why you didn't see anything in the monitor, there are possible explanations for that. I don't remember what Xmodem's conversation starter looks like, but it may not be printable. OR it could be a string followed by backspace characters. Remember, Xmodem was used back in the BBS days, where the server would send control sequences to the terminal client, which would be echoing everything to the screen until some protocol signature was detected and the transfer code took over. Given that heritage, it's also likely the Xmodem receiver script won't be bothered in the least by text preceding and following the file transfer. That would assume a proper and robust implementation, of course...

I'm the guy that wrote the library referenced in the original post, and I just found out about this thread so I'm a bit curious as to whether it's been resolved or not. As someone pointed out, once the transfer begins, you cannot interrupt it with serial printing or use something like the Arduino console without potentially causing problems. In any case, the library was written to work with POSIX-compatible systems or Arduino using the same code base. You could also make it work in windows, though the implementation may be non-trivial. Those of us who have done serial communications in windows before know what kind of pitfalls it might involve. If you compile 'xmodem.c' on a POSIX compliant system (I think Cygwin will work, though I haven't actually tried it) and define 'STAND_ALONE', it will build an executable that is capable of doing xmodem transfers. This is somewhat documented within the source (see function 'main()' at the end of xmodem.c which demonstrates the process of transmitting or receiving a file). To make it work the arduino would need to recognize 'XSEND' and 'XRECEIVE' commands, then call the appropriate library function. So there is a little bit of protocol work that needs to be done in the Arduino script, though it's minimal. Like any serial console you would need a command interpreter that would THEN initiate transfer on receipt of a specific command.

Hopefully I've clarified any issues here.