Closed seteahconnoc closed 1 year ago
Today, I 'm giving my RFID device another try. As a start, I used the block read i2c register _ from address _
. Sadly, I got this error:
Inside: TypeError
this.arduino.board.i2cConfig is not a function
Any suggestions would be welcome.
Hi @seteahconnoc,
I'm testing... I guess you are using Snap4Arduino online version, aren't you?
I see there is a problem with i2c lib in this version. I'm sorry. I will try to fix it (there is an issue with their firmata version).
You can use desktop Snap4Arduino in the meantime.
Continue...
Thank you. You guessed right: I was using the online version. In the offline version, it 's working just fine.
But there 's still a lot to do, since I have to find out how to get a rfid tag's uid. Right now, it 's about reading datasheets and trying out. Any suggestions would still be welcome.
Hi @seteahconnoc,
-About RFID, your guide must be Adafruid library. With Snap! and its live programming, you can skip from rewriting all the code and test i2c messages and responses... and get what you need... but I have not this device to test and help you.
-And the problem with the i2c in chromium version is really a bug. The communication with the plugin has not the i2c methods definitions. I'll fix this... but I need some time, because I want to recheck all the i2c communication (also for desktop version).
Still continue...
That sounds quite promising. I think, I have to do this step by step. My first approach should be to read out a RFID tag's UID.
The read block from Snap4Arduino's I2C library uses the JavaScript function i2cReadOnce(address, register, bytesToRead, handler(arrayOfBytes))
. So, I have to figure out, the appropriate address and register.
I successfully used Adafruit's example readMifare
using the Arduino IDE. So, I am trying to implement the function nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);
using Snap4Arduino.
In order to find out, what readPassiveTargetID
is doing, I took a look into the source file of the library Adafruit_PN532.cpp
And this is the point where I cannot manage to "tie the strings together".
I was expecting any kind of information regarding address and register. But I guess, I have to dig deeper in order to find this low level information. Since it contains addresses, this file got my interest: https://iotdk.intel.com/docs/master/upm/pn532_8hpp_source.html
But (as mentioned above), I would be thankful, if someone could help me with the first "hello world" in I2C programming with Snap4Arduino. All the results, I am getting is a list filled with with the number 128 regardless of the block's input.
OK, I had no further idea in I2C programming with Snap4Arduino. So, I thought of another way to use my RFID device with Snap!
.
Here 's my "quick & dirty" approach:
Use the Arduino IDE with Adafruit's example readMifare
.
Use this bash script to write the serial out data to a file:
#!/bin/bash
for (( ; ; )) do mv temp.txt thisfile.txt screen -d -m -L temp.txt /dev/ttyACM0 115200 sleep 1 screen -X quit done
- The file `thisfile.txt` is situated in the folder `/var/www/html` of a `lighttp` web server.
- Start a local (http and not https) version of snap and use a block with this `JavaScript` code:
var response; if (!proc.httpRequest) { proc.httpRequest = new XMLHttpRequest(); proc.httpRequest.open("GET", 'http://localhost/'+url, true); proc.httpRequest.send(null); } else if (proc.httpRequest.readyState === 4) { response = proc.httpRequest.responseText; proc.httpRequest = null; return response; } proc.pushContext('doYield'); proc.pushContext();
---
It 's working, but (as mentioned above): it's not quite elegant. For the application isn 't time critical, it 's OK. I just wanted to play around with the RFID hardware and `Snap!`.
Do you know an alternative to this workaround "from the Arduino IDE to a `Snap!` application"?
Hi @seteahconnoc , As you know, I haven't any i2cRFID to test. But I try to show you how you can take the info from Arduino lib and play (and test) that in Snap!
You tested readMifare script and you want to test readPassiveTargetId function. Let's see...
I look for the i2c address in Adafruit_PN32.h. It sets (0x48 >> 1). So i2c address is 0x24
First, it creates nfc object. Only define pins... nothing must be done with code. But it sets your hadware config: IRQ->pin 2 and Reset->pin 3.
In line 80, there is a nfc.begin. This is done in _Adafruit_PN532.ccp So, here I need to do (only one time, at the beginning).
As we said, we want to play with success report, just readPassiveTargetId function. See this function definition and it uses readdata function passing 20 as value... So let's go to readdata function definition
At last, there is only a i2c read function, WIRE.requestFrom. So, you only have to play with ...
Two considerations.
Joan
That sounds pretty straight forward - if you know, where to look and what to do. It seems that you 've done this kind of work before... ;) So, thank you for your patience with a newbie in this field. I 'll give it a try and I 'll post my results.
I just checked it...
... using the offline version 1.2.6 with it's own I2C library:
read i2c register 22 from address 0x24
leads to a list with many 128
s. I was expecting a difference whether the RFID transponder is nearby or not. But that's not the case. It may be my fault, since (for me) the mentioned source code carries a lot of pitfalls. I hope, that "playing around" with the Snap!
script leads to some success.
... using the offline version 1.2.6 with the file i2c.xml.zip
that you offered (thanks):
I get this
Inside: TypeError
board.checkArduinoBoardParam is not a function
Again: Many thanks for your patient help. For me, this is just "heavy lifting".
Oh, yes! Mistake of mine about the new i2c. It only works with the next version, because I've introduced some other changes in the core. I've made another with the new changes that it works in 1.2.6 (not in the online version). But it's better (in current version, the read reporter reports an old value (the value has the sensor in the last reading) i2cTest.xml.zip
And the problems with the RFID... It needs test, watching the code again and test again...
Continue...
Again: Thanks. I'll keep on trying. It 's no surprise, that I have to do the work line by line. - I wonder, why no one seems to use an RFID device with Snap!
. Wouldn 't it be nice to build a model of a RFID controlled locker?
Regarding the address, you wrote: "It sets (0x48 >> 1). So i2c address is 0x24" - Just out of curiousity: Why do they use the bit shift?
2.
I don 't get the function of the read i2c ...
block. Using register 1
, I 'll get a list with 1 row. Using register 22
, I 'll get a list with 22 rows. I was expecting something like this: Using register 1
gives me the first entry, and register 22
gives me the 22nd entry. - Looking up appropriate I2C literature is quite difficult for me. Obviously, someone who 's interested in this topic is usually quite experienced in coding. So, some lines of documentation would be helpful. Or am I missing some obvious located reference manual?
Please, don 't get me wrong: I am thankful for being able to use Snap!
, Snap4Arduino
, the I2C blocks, etc. It 's wonderful to see the work in progress. Keep it up.
Hi,
I don't know much about i2c devices. I guess the internal chip is configured to 0x48, and this chip has pins to configure different addresses. I guess the hardware configuration is similar to a bit wise... and then, software writer is reflecting the hardware actions. I'm not sure. And I would test other addresses (like 0x48). But reading the code I saw 0x48>>1 and this is 0x24.
I think the bus is sending all the bytes. And to read one byte, I must read all the previous (it is a bus... and I count byte by byte). So, just readed, it is better to report them... and we can select one byte with Snap! blocks... and we can do more things with all the list. So, when you want to read only one byte, you must to call
Thanks. I tried a few things, but I only got a lot of 128
s in return. It 's not obvious for me, which lines from the Adafruit code are the important ones. I 'll continue & hopefully learn.
After some time, I just gave this topic another try. Sadly, I didn't make any progress. - But since it offers a lot of possibilities, I am quite eager to get things running with RFID and Snap4Arduino (or Microblocks with Snap?). Just to remind you: If it 's not too expensive, a solution with another RFID device is also welcome. So, here 's another idea: I also own a MFRC522 device. The description says: "chip supports I2C and UART protocols but not implemented on library". So, I kept on searching and found this encouraging article:
https://www.npmjs.com/package/rc522-i2c
But since I am not quite experienced in this field, a little help (e. g. on where to put which wire or how to implement the algorithm in Snap4Arduino) would be great.
Sorry, but obviously I am not able to re-open this issue: #229 I would appreciate some help on that issue. Thank you.