View unanswered posts | View active topics It is currently Wed Sep 17, 2014 9:34 am






Reply to topic  [ 3 posts ] 
Hitechnic colour sensor for EV3? 
Author Message
Rookie

Joined: Wed Jul 30, 2014 12:10 pm
Posts: 3
Location: Gallifrey
Post Hitechnic colour sensor for EV3?
Hello :)

I'm new to Lego Mindstorms and RobotC and I was wondering if anyone could help me with something. I'm currently working on a robot using EV3 and the RobotC beta. I'm trying to get a Hitechnic colour sensor to see colours coming down from an overhead projector. I've done some research into it, and it seems like I need to set the sensor to passive mode so the LED is off. I've looked into how to do this, and the only way I can see is to use the Driver Suite, which doesn't support EV3 at the moment. Also, I can't find a way to access the raw colour values that the sensor is receiving, instead of the numbered colours. If anyone knows of any way that I can do either of these in code, I'll be grateful :)

Here's the code I'm using at the moment. It uses the numbered colours to change the speed of the motors:

Code:
#pragma config(Sensor, S1,     colour,         sensorEV3_GenericI2C)
#pragma config(MotorPidSetting,  motorA,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorB,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorC,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
#pragma config(MotorPidSetting,  motorD,  255, 255, 65535, 255, 255,   65535, 65535, 65535)
//*!!Code automatically generated by 'ROBOTC' configuration wizard               !!*//

int current_speed;

task main()
{
   while(true)   //forever
   {
      if(SensorValue(colour) > 10)
      {
         current_speed = 0;
      }
      else
      {
         current_speed = SensorValue(colour)*10;
      }

      motor[motorB] = current_speed;
      motor[motorC] = current_speed;

      if(current_speed == 0)
      {
         setLEDColor(ledOrange);
      }
      else
      {
         setLEDColor(ledOff);
      }

      wait1Msec(100);
   }
}


Thanks in advance :)))


Wed Jul 30, 2014 12:21 pm
Profile
Rookie

Joined: Wed Jul 30, 2014 12:10 pm
Posts: 3
Location: Gallifrey
Post Re: Hitechnic colour sensor for EV3?
Doesn't matter, I found a solution. You can communicate with the brick via I2C in Robot -> LEGO Brick -> Test I2C Sensors Utility. In here, you can send commands and receive data to the EV3 brick.

In the picture I've attached, it shows a screenshot of what it looks like. The different commands are:

0X02 0X41 $01 - Turns the LED off/ sets the sensor to passive mode. The "41" is to send a command and the "$01" is the command that's being sent.

0X02 0X41 $00 - Turns the LED on/ sets the sensor to active mode. Again, the "$00" is the command.

0X02 0X42 - Returns the colour value that the sensor sees. The value is sent back in hex, so some of them need to be converted back to decimal (eg bright pink(10) would be sent as 0A).


The command for the raw values is "0X02 0X41 $03", but it leaves the LED on, which isn't what I was looking for.

I hope this helps anyone with the same problem as me! :D


EDIT - I forgot to say: you need to set the menu level to Super User to be able to choose Test I2C Sensors Utility as an option! To do this, just go into Window -> Menu Level. :wink:


Attachments:
screenshot.png
screenshot.png [ 203.5 KiB | Viewed 197 times ]
Thu Jul 31, 2014 8:21 am
Profile
Moderator
Moderator
User avatar

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3221
Location: Rotterdam, The Netherlands
Post Re: Hitechnic colour sensor for EV3?
I am also working very hard to make the Driver Suite work with the EV3. This includes a driver for the HT Colour Sensor

= 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]


Fri Aug 01, 2014 4:34 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


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.