Skip to content
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

Esphome native and NDEF #52

Merged
merged 12 commits into from
Feb 4, 2021
Merged

Esphome native and NDEF #52

merged 12 commits into from
Feb 4, 2021

Conversation

jesserockz
Copy link
Collaborator

@jesserockz jesserockz commented Oct 12, 2020

This PR uses native esphome components that have been recently developed and requires that you use ESPHome 1.16.0.

closes #41

What is this?

This PR switches to use the ESPHome native version of pn532_i2c and also as an extension to that NDEF reading and writing.

jesserockz and others added 3 commits October 11, 2020 20:53
I2C-version of the schematics screenshot

Delete tag_reader_schematics_v1.png

Update README.md

Using relative links for schematics screenshot
@RichieFrame
Copy link

RichieFrame commented Oct 31, 2020

Testing this now with a custom yaml, working much better than the non-native i2c version, which would only read a tag if it was on the reader during boot, then not read anymore once it was removed (#54 on steroids).

Thanks to a bad reader board this took 2 days to get working, with the non-native code, there was no error, this actually reports the board bad:

[01:39:46][C][pn532:015]: Setting up PN532...
[01:39:46][W][i2c:076]: Unknown transmit error 4 for address 0x24
[01:39:46][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
..
[01:39:46][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[01:39:46][E][pn532:019]: Error sending version command
[01:39:46][E][component:092]: Component was marked as failed.

@RichieFrame
Copy link

ESP32 test did not go so hot, it did work using SPI, but this is what I get with native i2c:

[03:21:49][C][pn532:015]: Setting up PN532...
[03:21:49][D][pn532:030]: Found chip PN532
[03:21:49][D][pn532:031]: Firmware ver. 1.6

[03:21:49][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[03:21:49][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[03:21:49][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[03:21:49][E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=0
[03:21:49]
[03:21:49][E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=0
[03:21:49][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[03:21:50][E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=0
[03:21:50][W][i2c:086]: Requesting 1 bytes from 0x24 failed!

[03:21:50][E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=0
[03:21:50][W][i2c:076]: Unknown transmit error 5 for address 0x24
[03:21:50][E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=0
[03:21:50][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[03:21:50][E][esp32-hal-i2c.c:1426] i2cCheckLineState(): Bus Invalid State, TwoWire() Can't init sda=1, scl=0
[03:21:50][W][i2c:086]: Requesting 1 bytes from 0x24 failed!
[03:21:50][W][pn532:087]: Requesting tag read failed!

With that final block of 7 lines repeating every second after until i kill the serial connection

I am using GPIO 21 and 22 for SDA and SCL, tested with 5V and 3.3V power, 100KHz and 200KHz
Not sure if that is a board issue or not, those were the same pins I was using for SPI CLK and MISO and they worked

@jesserockz
Copy link
Collaborator Author

Oh man, thats going to be hard to look into as I do not have an esp32 to test with...
A very quick google brings this: espressif/arduino-esp32#3079 Might need pullups on the esp32?

@RichieFrame
Copy link

Interesting, when I get time I will try that. I have 2.2K and 1K that I can put in series to get pretty close, or I can do 22K x 2 + 4.7K and that will get me to 3.293K

@RichieFrame
Copy link

Actually, I just went through the NXP electrical bus specs for I2C and the Espressif I2C driver parameters... there are pullups on those pins, but they are not sufficient for I2C, and they have to be enabled in the driver, and tuned to both the bus frequency and capacitance.

I calculated a minimum of 1K and a max of 3.6K @ 400KHz. 4.7K @ 200KHz is confirmed working now on a breadboard.

It might also be recommended to add an inline current limiting resistor, for the device, I cant find a board schematic but I can see resistors on the SPI bus pins only

@jesserockz jesserockz marked this pull request as ready for review November 2, 2020 19:27
tagreader.yaml Outdated
std::string uri = "https://www.home-assistant.io/tag/";
for (int i = 0; i < 8; i++)
uri += alphanum[random_uint32() % (sizeof(alphanum) - 1)];
uri += "-";
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is optional. For HA any random string works. I guess it makes it more readable / mimics what iOS and Android write.

@balloob
Copy link
Collaborator

balloob commented Nov 3, 2020

Do we need to update the README to specify the version of ESPHome that is needed?

@adonno
Copy link
Owner

adonno commented Nov 3, 2020

Do we need to update the README to specify the version of ESPHome that is needed?

Wouldn't hurt ?

@balloob
Copy link
Collaborator

balloob commented Nov 3, 2020

This is not about hurting. This is about if the native integration requires a minimum version of ESPHome.

@RichieFrame
Copy link

I would suggest increasing the polling rate, with the old SPI it was always on and responded instantly, now there can be a delay that exceeds the amount of time someone is willing to hold when 'tapping' a card to the reader.

I would also suggest moving the polling rate control from static code in the driver python file and into the config yaml code, having a default of 500ms unless changed, (with 0 for no sleep), I set it to 250ms to test, and it is getting warmer (less than +10c), but not hot like SPI did (+30c)

@jesserockz
Copy link
Collaborator Author

Hi @RichieFrame
You can change the polling rate by using the below

pn532_i2c:
  update_interval: 500ms
  ...

@RichieFrame
Copy link

and that works!

I did do more testing, 350ms seems to be the best balance of power/responsiveness so far, temp is about +6.5c over ambient

@jesserockz jesserockz changed the title Esphome native Esphome native and NDEF Nov 5, 2020
@RichieFrame
Copy link

To confirm, the code is not in place to write MIME records correct? I assume it can read them with the correct esphome code?

What about checking the tag capacity prior to writing data? What happens if we try to write more data than the tag can hold?

@jesserockz
Copy link
Collaborator Author

At the moment, there are helpers in the NdefMessage in ESPHome to message.add_text_record and message.add_uri_record but you can always make a new NdefRecord(...) with the data that you want and just call message.add_record(record).

Currently there is no capacity check for a mifare classic card. The ultralight/type 2 cards do check the capacity first as they are known to be smaller. Im not sure what happens if you do try to write more

@dcjona
Copy link

dcjona commented Nov 26, 2020

hi, is it possible to install your branch on docker?

laithalsunni and others added 6 commits December 15, 2020 00:48
Added restore_state: true to both the Buzzer switch and the LED switch so the user doesn't have to create an automaton just to keep the visual and audible feedback on.
Added restore_state to the switches
@adonno adonno merged commit 193dd73 into master Feb 4, 2021
@jesserockz jesserockz deleted the esphome-native branch October 18, 2021 20:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose Ndef to act as a tag
7 participants