RS485 and non NXT devices

Post your NXJ projects, project ideas, etc here!

Moderators: 99jonathan, roger, imaqine

RS485 and non NXT devices

Postby mdsmitty » Mon Jan 06, 2014 3:43 am

Greeting,
I'm working on a motor controller that drives 4 NXT motors. I have the hardware and firmware along far enough that i would like to start working on interfacing the controller with something other than my pc. I have chosen RS485 since i can interface it with anything that has a UART, speed, distance...

Anyways I'm trying to get some very basic communications going between the NXT and the controller with very little luck. I tried the code below to establish a connection I used the mode RAW since the documentation said that there would be no headers or anything. I did not expect it to work because its looking for a NXT still.

Code: Select all
NXTConnection con = RS485.getConnector().connect("NXT", NXTConnection.RAW);


I also tried some low level code

Code: Select all
byte[] buf = {'T','e', 's', 't'};
RS485.hsEnable(115200, 128);
RS485.hsWrite(buf,0,4);


I opened the port at 115200 so i could look at the traffic on a debugger on my pc. I saw 2 bytes not 4 and they were no the right ones.
I did read something about the baud rate being hard coded at 921600 in firmware i'm hoping thats not the case.

I found some documentation on this using NCX between an NXT and an Arduino i'm basically doing the same thing. But i want to use LeJOS.

Any help would be greatly appreciated.

Mike
mdsmitty
Novice
 
Posts: 78
Joined: Tue Feb 27, 2007 3:07 am

Re: RS485 and non NXT devices

Postby gloomyandy » Mon Jan 06, 2014 12:12 pm

Hi,
You can't use the high level methods like connect etc. They make use of the Bitbus protocol. You will need to use the basic read/write methods provided by the RS485 class. See the hsEnable, hsRead, hsWrite methods in:
https://sourceforge.net/p/lejos/code/HE ... .java#l927

I'm not sure that you can view the output on a PC (unless you have special hardware), as RS485 is different to the normal UART based RS232 supported on most PCs. Are you using RS485 specific hardware to debug this?

Different baud rates should work fine.

You may want to reconsider using RS485. It is not particularly well supported on the NXT and is not available at all on the EV3...

Andy
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3965
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RS485 and non NXT devices

Postby mdsmitty » Fri Jan 10, 2014 6:40 am

Hi Andy thanks for getting back to me.

I'm using a rS285 to RS232 converter so i can watch the data on my pc. I have an idea where things are going wrong. What are the start, data and parity bits that LeJOS uses. I looked in the RS485 class in the API and i did not see a method that would allow me to change these settings. I put something together in NXC and I sent "Hello World!" to my pc so i know i and good hardware wise.

Thanks again,
Mike
mdsmitty
Novice
 
Posts: 78
Joined: Tue Feb 27, 2007 3:07 am

Re: RS485 and non NXT devices

Postby gloomyandy » Fri Jan 10, 2014 10:45 am

Sorry can't remember you will have to look in the source of the VM. I'm pretty sure they are exactly the same as the Lego firmware uses. I know that we have drivers that use RS485 to talk to some of the Dexter sensors so I'm pretty sure that the low level routines all work and can talk to other devices without issue. As I said before I wouldn't use RS485 for this, more trouble than it is worth and a dead end in terms of the EV3.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3965
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RS485 and non NXT devices

Postby mdsmitty » Tue Jan 14, 2014 1:24 am

Hi Andy,
I have left the i2C pins on the micro free for communications I have been thinking about switching or giving my self both options. But now the rS485 in LeJOS has been eating at me. Looking at the code below do you see anything i'm missing or doing wrong? it should put "Test" out on the wire.

Code: Select all
   public static void main(String[] args){
      byte[] buf = {0x54,0x65,0x73,0x74};

      RS485.hsEnable(9600, 1024);
      RS485.hsWrite(buf,0,4);
   }
mdsmitty
Novice
 
Posts: 78
Joined: Tue Feb 27, 2007 3:07 am

Re: RS485 and non NXT devices

Postby gloomyandy » Tue Jan 14, 2014 8:52 am

I would not use 1024 as the buffer size (use 0 and let the firmware choose), also you need to check the return value from the write to see how many bytes have actually been written, if the hardware was not able to accept data you may have to loop until it is. Other than that can't see any problem.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3965
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RS485 and non NXT devices

Postby mdsmitty » Thu Jan 16, 2014 4:22 am

Andy that did it thank you very much.
mdsmitty
Novice
 
Posts: 78
Joined: Tue Feb 27, 2007 3:07 am

Re: RS485 and non NXT devices

Postby skoehler » Thu Jan 16, 2014 6:19 pm

You switch from buffer size 1024 to buffer size 0, and now the 4 byte example works?
Or was the problem that you forgot to check the return value of hsWrite?
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm

Re: RS485 and non NXT devices

Postby mdsmitty » Fri Jan 17, 2014 4:00 pm

Not sure I did both.
mdsmitty
Novice
 
Posts: 78
Joined: Tue Feb 27, 2007 3:07 am

Re: RS485 and non NXT devices

Postby jackhogan11 » Wed Aug 20, 2014 9:28 pm

I have a EV3, NXT, and am going to get one or a few RCX 2.0s or probably RCX 1.0s since they have the charging port. But I want to have the EV3 and NXT communicate over RS485 and bluetooth. If it is possible I need to know how to do some basic programs with it since I am just getting started with leJOS/Java. Also, does a RCX 1.0 work with the 2.0 IR beacon/2.0 original firmware and leJOS firmware?
jackhogan11
New User
 
Posts: 10
Joined: Thu Jun 12, 2014 12:50 am

Re: RS485 and non NXT devices

Postby gloomyandy » Wed Aug 20, 2014 9:38 pm

No idea about the RCX. The Ev3 does not support RS485, it can talk to the NXT via Bluetooth, but I'm not sure how much that code has been used so you may run into a few problems.
User avatar
gloomyandy
leJOS Team Member
 
Posts: 3965
Joined: Fri Sep 28, 2007 2:06 pm
Location: UK

Re: RS485 and non NXT devices

Postby skoehler » Wed Aug 20, 2014 10:45 pm

I assume that it is possible to come up with an adapter board that converts the RS485 of the NXT to whatever the EV3 expects. If you're talented in that area, you might try to come up with such a board. I have not much hope that such a adapter board will be released by manufacturers such as Mindsensors, HiTechnic, or others. I believe, the next version of leJOS is the only one that allows "raw" access to the sensor port UARTs. I'm not sure what the other firmwares have to offer. AFAIK, the Lego firmware only allows access to UART sensors which speak a specific protocol.
skoehler
leJOS Team Member
 
Posts: 1405
Joined: Thu Oct 30, 2008 4:54 pm


Return to NXJ Projects

Who is online

Users browsing this forum: No registered users and 1 guest

more stuff