bromagosa / Snap4Arduino

Binding Snap! and Arduino together
http://snap4arduino.rocks
GNU Affero General Public License v3.0
133 stars 85 forks source link

Is there a way to use a RFID device such as "PN532"? (Part 2) #242

Closed seteahconnoc closed 1 year ago

seteahconnoc commented 6 years ago

Sorry, but obviously I am not able to re-open this issue: #229 I would appreciate some help on that issue. Thank you.

seteahconnoc commented 6 years 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.

jguille2 commented 6 years ago

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...

seteahconnoc commented 6 years ago

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.

jguille2 commented 6 years ago

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...

seteahconnoc commented 6 years ago

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.

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.

seteahconnoc commented 6 years ago

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:

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"?
jguille2 commented 6 years ago

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!

Two considerations.

Joan

seteahconnoc commented 6 years ago

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.

seteahconnoc commented 6 years ago

I just checked it...


Again: Many thanks for your patient help. For me, this is just "heavy lifting".

jguille2 commented 6 years ago

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...

seteahconnoc commented 6 years ago

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.

jguille2 commented 6 years ago

Hi,

seteahconnoc commented 6 years ago

Thanks. I tried a few things, but I only got a lot of 128s in return. It 's not obvious for me, which lines from the Adafruit code are the important ones. I 'll continue & hopefully learn.

seteahconnoc commented 5 years ago

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.