New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codatex RFID on EV3 #913
Comments
It seems that the Codatex sensor as a LED that turns ON when it detects a tag. Never saw any kind of light on mine and I'm using the two tags that came with it. |
Did you try starting the firmware? /**
* Start the firmware on the RFID device.
* NOTES: It seems that you need to issue this command (or some other
* firmware command), prior to attempting to read the version number etc.
* Does not wake up the device or contain any delays.
*/
public void startFirmware()
{
sendData(REG_CMD, CMD_STARTFIRMWARE);
}
|
Yes, I think so, at least that is the purpose of this part:
I can also start the bootloader (writing 0x81 instead of 0x83 to the command register 0x41) and read the serial number (a block of 16 bytes starting at 0xA0), I get
that's probably correct since there is nothing at 0xA0...0xAF in normal operation mode, as seen in my first dump. i found here that |
Ah, ha! ev3dev does not turn on 9V unless the sensor needs it, so it means you will have to write a kernel driver for it - or we have to a new port mode, e.g. The input ports are capable of outputting 9V (battery voltage really) on pin 1. |
Hi @JorgePe, it is a classic syntax to define the Port type but you are checking
Later, once you have connected, you have to review the technical documentation from the manufacturer to play with the registers. In the past, more or less, we had the same way run to with /** The default I2C address of the sensor */
public static final int DEFAULT_I2C_ADDRESS = 0x22;
protected static final int ACCEL_DATA = 0x45;
protected static final int COMPASS_DATA = 0x4b;
protected static final int MAG_DATA = 0x4d;
protected static final int GYRO_DATA = 0x53;
protected static final int COMMAND = 0x41;
protected static final int GYRO_FILTER = 0x5a;
protected static final byte SENSITIVITY_BASE = 0x31;
protected static final byte START_CALIBRATION = 0x43;
protected static final byte END_CALIBRATION = 0x63;
public static final int LOW = 0;
public static final int MEDIUM = 1;
public static final int HIGH = 2;
public static final int VERY_HIGH = 3; Example of usage of the method to write a I2C register: public void setRange(int range) {
byte cmd = SENSITIVITY_BASE;
switch (range) {
case LOW:
case MEDIUM:
case HIGH:
case VERY_HIGH:
break;
default:
throw new IllegalArgumentException("Range setting invalid");
}
cmd += range;
sendData(COMMAND, cmd);
// update gyro scale to match new setting
gyroMode.setScale(gyroScale[range]);
} To send a register, you use: //Example
sendData(0x41, 0x31); How to read a I2CSensor?: @Override
public void fetchSample(float[] sample, int offset) {
// fetch the raw data
getData(baseReg, buffer, 0, buffer.length);
for (int i = 0; i < sampleSize; i++) {
int rawVal = (buffer[i * 2] & 0xff) | ((buffer[i * 2 + 1]) << 8);
sample[i + offset] = rawVal * scale[i];
}
} You use this method: getData(baseReg, buffer, 0, buffer.length); You set the register for the mode, in this case and you store in a buffer: protected byte[] buffer;
buffer = new byte[sampleSize * 2]; and finally, you operate with the result from the i2c output. Technical docs about I2CSensor: Take a look this doc, is a bit old but with this notes, I developed some drivers in the past for NXT: Besides, if you check other I2C sensors, you could get common factor: It is not complex, but it is necessary to play a bit with the sensors :D Cheers Juan Antonio |
Thanks @dlech and @jabrena And I can also make my own cable with an external 9V source :) |
Hints:
|
Thanks. Will read and try not to burn my last neurons. |
Still trying to understand, evently I will get there. At least the Codatex sensor is working - I used LeJOS and could read my 2 tags (and finally see the LED turning on):
It doesn't always work, maybe 3/5 - so even with LeJOS the timings are damn crazy. |
If the sensor relies on exact timings, that isn't going to happen with Linux (at least not on the EV3 - maybe a faster multi-core processor). What is really needed though is a logic analyzer to see exactly what is really happening. |
Yeap, it would be great if I had one but those aren't cheap here in Portugal. But I have a feeling that the timings don't need to be so exact, I've been reading Daniele Benedettelli "Codatex RFID sensor library for NXC" source and he didn't use half of the timings defined by LeJOS driver. I'm stubborn so I also made a cable, pin 1 and 2 to a PP3 9V battery. Doesn't work. But it also doesn't work with LeJOS so probably cable is wrong. I guess I really have to read your hints a few times more and get my hands dirty. |
Pin 2 is not ground on the EV3!!!! Use Pin 3 for ground. |
Bad days these we can't even trust the web ... thanks, I was really going to ask for the pinout. |
Working!!!
Singleshot reading:
tag1: [80, 0, 129, 70, 33] (LED blinks) And it works 5/5!!!! |
Now I no longer have a strong reason to learn how to make a driver :) |
Closing this issue. |
Anyone interested in a driver can make further comments on #174. |
I modified the |
@dlech David, you are my hero!!! It works!!!
just need to set mode and my scripts work with a standard cable and no code modification at all. |
I would appreciate some hints with the Codatex RF ID Sensor for NXT:
http://www.codatex.com/lego-sensor.html
I'm running
ev3dev 4.4.68-20-ev3dev-ev3
(still jessie, not stretch yet)
I've read some code from LeJOS and RobotC but it seems I don't still understand all of it.
When I have it on Input 1
echo other-i2c > /sys/class/lego-port/port0/mode
dmesg:
i2c-legoev3 i2c-legoev3.3: registered on input port 1
The device needs a dummy I2C write to wake up, I can read the basic information fine:
But when trying to read the RFID tags I always get five zeros - usually a symptom of improper timings.
As everybody say that timings are important I tried python and smbus:
I'm using same timings as LeJOS and RobotC
https://github.com/SnakeSVx/ev3/blob/master/Lejos/src/main/java/lejos/hardware/sensor/RFIDSensor.java
http://botbench.com/driversuite/codatech-rfid_8h_source.html
but clearly not doing it right. Also tried Continuous Read, same result.
The text was updated successfully, but these errors were encountered: