View unanswered posts | View active topics It is currently Wed Jul 23, 2014 12:52 pm






Reply to topic  [ 13 posts ] 
Arduino + NXShield 
Author Message
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Arduino + NXShield
Hey guys,

I played around with my ArduinoMega and NXShield-M today and managed to make it work with a motor and a touch sensor. I had it working with the Magic Wand too but that was just blinking lights stuff, not very exciting.
Anyway, go check it out: http://botbench.com/blog/2012/05/20/rob ... ld-test-1/

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun May 20, 2012 2:38 pm
Profile WWW
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Arduino + NXShield
Very nice Xander.

It appears that all access to the sensor ports on the NXShield are made through I2C calls as well as setting speed/direction of the motors. Is that correct?

I wonder if all the ports are on the same I2C bus. If so... there would be a problem if you tried accessing the motors and the sensors from two separate RobotC tasks, right?

Say your main task set the speed & direction of the motors, and another task was constantly reading from sensors. Both tasks running at the same time would end up "doubling" the clock signals on the bus. Also both tasks would be attempting to write/read from the SDA line at the same time.

The only way around this problem would be to make all I2C calls on the same task... OR somehow make the I2C calls "thread safe" (or in RobotC terminology "task safe").

Is what I am asking making sense?


Sun May 20, 2012 3:52 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Arduino + NXShield
Dennis,

The shield is made up of two sub devices called banks. Each bank has 2 sensor ports and 2 motor ports. Each bank has its own I2C address, which is accessible through the hardware I2C pins (20/21, IIRC). ROBOTC does not support HW I2C yet but I am sure it's on the road map.
Anyway, you can access each sensor port separately via its own pins when using them as digital sensors, or read them as analogue sensor via that specific bank's I2C registers. When accessing the sensors through I2C, you'll need to bit bang it because there's only pins 20/21 that are hardware "accelerated".
You can only control one bank at a time through I2C since they use the same pins. Normally on a standard Arduino that is not a problem because it's so fast. When bit banging I2C it may pose a bit of an issue. Since this was just an experiment, I didn't really care.
In any case, multitasking is a no no if you're going to do any kind of function sharing anyway, so it's best to have a single task handle all the bank stuff.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Sun May 20, 2012 4:21 pm
Profile WWW
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Arduino + NXShield
Ok. I only mention this because normally one doesn't think about setting motors and reading sensors as possibly conflicting with each other.


Sun May 20, 2012 5:18 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Arduino + NXShield
The motors can be given commands such as "move this many encoder ticks", "run for X seconds" or "brake when done". So there is not a whole lot you need from the motors. Unless you're keen to continuously poll the motor encoders, there's not a whole lot you need to talk to the motors about :)
Maybe when I understand the internals of the NXShield a bit better, I will write a tutorial on how to use it. It's not an overly complicated device when using it normally but it does have a lot of parameters that you can tweak to get it setup just the way you want it, especially when it comes to the motor's PID stuff.

Right now I am really just biding my time until HW I2C is implemented.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon May 21, 2012 1:02 am
Profile WWW
Senior Roboticist
User avatar

Joined: Wed Sep 28, 2011 10:13 pm
Posts: 630
Location: If I told you, I'd have to kill you.
Post Re: Arduino + NXShield
Awesome. :bigthumb: Wish I could afford that stuff.

_________________
A.K.A. inxt-generation
Self-proclaimed genius, and future world dominator.
My Brickshelf Folder
"Don't they teach recreational mathematics anymore?" - The Tenth Doctor
Bow down to Nikola Tesla, King of the Geek Gods.


Mon May 21, 2012 10:13 am
Profile WWW
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Arduino + NXShield
I wouldn't be able to afford it if I had to buy that stuff. I am lucky that certain companies see fit to let me play with their products.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon May 21, 2012 10:19 am
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Arduino + NXShield
Would this work (and how much effort if you know) with one of the .net adruino clones? I started to look at putting the .net framework on the NXT, which I understand is doable, but has 0 left over for user space. So, wanting to stick with NXT accessories, I am now thinking http://www.sparkfun.com/products/10749 with something like the NXTShield (http://www.openelectrons.com/index.php? ... &PAGE_id=7). Question is how much works out of the box if anyone knows?

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon May 21, 2012 3:05 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Arduino + NXShield
Spiked3,

The most important thing is the pinout, if they're roughly equal where it matters then it would most likely work. It would be a very nice platform, I think. I'm a big fan of C#.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon May 21, 2012 3:14 pm
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Arduino + NXShield
mightor wrote:
Spiked3,

The most important thing is the pinout, if they're roughly equal where it matters then it would most likely work. It would be a very nice platform, I think. I'm a big fan of C#.

- Xander


I will probably try it soon. Not to take away any from RobotC, it is absolutely my preferred NXT environment so far, but I did really enjoy one small .Net MF project I did a while back. The IDE, the debugger, mature Object Oriented Language, it's just hard to beat.

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon May 21, 2012 3:19 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3162
Location: Rotterdam, The Netherlands
Post Re: Arduino + NXShield
Just had a quick look and it looks like the FEZ has its I2C pins on a totally different spot than the Arduino UNO, so that may be a problem.
The pins marked as red on the UNO image are the ones actually used as HW I2C to communicate with the NXShield.
Attachment:
Screenshot-2012-05-21_21.43.27.png
Screenshot-2012-05-21_21.43.27.png [ 273.85 KiB | Viewed 5494 times ]

Attachment:
Screenshot-2012-05-21_21.43.45.png
Screenshot-2012-05-21_21.43.45.png [ 474.83 KiB | Viewed 5494 times ]


You could work-around it using your own bit banged master code as a piece of unmanaged native code that you load as a library.

- Xander

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]


Mon May 21, 2012 3:48 pm
Profile WWW
Expert

Joined: Tue Feb 28, 2012 3:10 pm
Posts: 195
Post Re: Arduino + NXShield
sigh. So much for 'compatible'. thanks for looking.

_________________
Mike aka Spiked3
http://www.spiked3.com


Mon May 21, 2012 3:56 pm
Profile
Rookie

Joined: Mon May 14, 2012 3:24 pm
Posts: 43
Post Re: Arduino + NXShield
Well it looks like pins 2 and 3 on the Fez would need to be reassigned to the analog pins 4 & 5 on the NXShield. Normally you could use a Go Between shield from Mayhew Labs ($14) which allows reassigning pins (very useful). In this case it would be a little more difficult to do since the pins are going from the Digital to Analog side. The Go Between is made for mapping one digital pin to another digital pin or one analog to another analog.

You could take a simple proto shield and clip the 4 & 5 pins on it and run wires from 2 & 3 pin over. In the end that is how most people end up reassigning pins and it works though it would make your device a bit larger.


Mon May 21, 2012 8:23 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 13 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.