Skip to content

Improve performance and add ability to sleep #41

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

Merged
merged 8 commits into from
Sep 18, 2020

Conversation

dunkmann00
Copy link
Contributor

After looking more into #40 it seemed that there was some potential to improve this library more substantially than by just removing some of the I2C delays.

This adds support to put the PN532 into a low power state (which reduces the current draw by up to ~60mA from my testing). It also better handles waking up the PN532 from this low power state, which resulted in not needing many of the delays that were present in all of the communication subclasses.

The responsiveness of the PN532 is much better with these changes. I tested this with both an itsybitsy m4 express and an itsybitsy m0 express for all 3 communication methods (I2C, SPI, & UART) on the Adafruit PN532 Shield but would welcome if someone else could also verify these changes!

`_wakeup` also puts the pn532 back into normal mode.
`_wakeup` also puts the pn532 back into normal mode.

Also removed some delays that aren't necessary.
- Update `_wakeup` to come out of power_down and put the pn532 back into
  normal mode.
- `_wait_ready` now actually checks to see if the pn532 is ready
- improve how data is written out
@tannewt
Copy link
Member

tannewt commented Sep 17, 2020

@nitz Do you have a PN532? I know you've been doing other NFC stuff.

@nitz
Copy link

nitz commented Sep 17, 2020

Uh, you'll have to let me check when I get home. I definitely bought something for that side of the NFC equation, but it's in a box at the house and I don't remember if I've even taken it out 😂! Poke me if I don't update here in a few hours!

Edit: I do have one! Hurray for drunken amazon purchases.

2020-09-17_17-31-42

I think my only boards with CP on them right now are the two @dunkmann00 has tried, but I've got something around here I can put CP back on other than those, just gotta... find it.

I've also got to put a header or some leads on this thing.

@nitz
Copy link

nitz commented Sep 17, 2020

Okay, I'm back, with news!

Via i2c and spi, I was able to run pn532_simpletest.py and waved whatever cheapy RFID chips this PN532 came with in front of it, and it spit up their UIDs. I was also able to test with a handful of different NTAG215s I have, and that went peachy too.

However, switching to UART, the initialization went fine and it was able to read the FW Version from the PN532, but as soon as I'd wave any tag near it, it'd freeze. I'd like to have more info on where or why, but I don't have that yet (and I'm starving, so I gotta go eat dinner.)

My test board is this nRF52840 kit. I'm not using the TX/RX pins on the board there, as I'm pretty sure they're default bound to something else, and I didn't feel like shaving that particular yak.

I also ran into this very bizarre thing, where I had my FTDI TTL to USB 232 attached to those TX/RX pins, and while the board was completely unpowered, the LED on the PN532 board was lit, as long as I had TX connected. But only while the PN532 was in I2C mode. Yeah, I've got no idea for that, but seems to be a hardware thing, and not a code thing.

Anyways: after I get something to eat I'll see if I can figure out -- woah, okay. Literally as I'm typing this I'm staring at the frozen output and it spits out the UID of the card I waved in front of it at least a few minutes ago, and it's running again. Waving another in front freezes it, and after a minute or two it spits the UID and keeps going. So I guess it's not a hard lock.

Stay tuned!

@dunkmann00
Copy link
Contributor Author

@nitz I might know why you saw that long delay.

What timeout value are you using when you initialize the uart object? For the old examples I think the values were never updated. So the example code sets the timeout=100, which for the newer CP that is 100 seconds, not milliseconds.

Try setting timeout=0.1 and see if that works better. I put this value in correctly for the new example I added, pn532_low_power.py, but I didn't change it in the old ones as I figured it wasn't really a part of this pull request.

Let me know how that goes!

@nitz
Copy link

nitz commented Sep 18, 2020

Well that's a bingo! Yeah I just copied and pasted the old ones into my code.py, mega timeout and all!

Everything else seems solid to me, including all three methods in your pn532_low_power.py. I don't have a Pi set up with blinka, but I imagine the addition of a reset/req won't hurt 🙂

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thanks @dunkmann00 and @nitz! The code looks good and @nitz confirmed it works.

@tannewt tannewt merged commit b741c77 into adafruit:master Sep 18, 2020
@dunkmann00 dunkmann00 deleted the performance-and-sleep branch September 18, 2020 17:57
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Sep 22, 2020
Updating https://github.com/adafruit/Adafruit_CircuitPython_PN532 to 2.3.0 from 2.2.1:
  > Merge pull request adafruit/Adafruit_CircuitPython_PN532#41 from dunkmann00/performance-and-sleep

Updating https://github.com/adafruit/Adafruit_CircuitPython_SharpMemoryDisplay to 1.2.3 from 1.2.2:
  > Update adafruit_sharpmemorydisplay.py

Updating https://github.com/adafruit/Adafruit_CircuitPython_FeatherWing to 1.13.0 from 1.12.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_FeatherWing#64 from FoamyGuy/keyboard_featherwing

Updating https://github.com/adafruit/Adafruit_CircuitPython_framebuf to 1.4.3 from 1.4.2:
  > Merge pull request adafruit/Adafruit_CircuitPython_framebuf#37 from mdroberts1243/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_MatrixPortal to 1.5.1 from 1.5.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_MatrixPortal#20 from makermelissa/master

Updating https://github.com/adafruit/Adafruit_CircuitPython_Pixel_Framebuf to 1.1.1 from 1.1.0:
  > Merge pull request adafruit/Adafruit_CircuitPython_Pixel_Framebuf#3 from makermelissa/main

Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA:
  > Added the following libraries: Adafruit_CircuitPython_74HC595, Adafruit_CircuitPython_ADS1x15, Adafruit_CircuitPython_ADT7410, Adafruit_CircuitPython_ADXL34x, Adafruit_CircuitPython_AHTx0, Adafruit_CircuitPython_AM2320, Adafruit_CircuitPython_AMG88xx, Adafruit_CircuitPython_APDS9960, Adafruit_CircuitPython_AS726x, Adafruit_CircuitPython_AS7341, Adafruit_CircuitPython_ATECC, Adafruit_CircuitPython_BD3491FS, Adafruit_CircuitPython_BH1750, Adafruit_CircuitPython_BluefruitSPI, Adafruit_CircuitPython_BME280, Adafruit_CircuitPython_BME680, Adafruit_CircuitPython_BMP280, Adafruit_CircuitPython_BMP3XX, Adafruit_CircuitPython_BNO055, Adafruit_CircuitPython_CAP1188, Adafruit_CircuitPython_CCS811, Adafruit_CircuitPython_CharLCD, Adafruit_CircuitPython_CircuitPlayground, Adafruit_CircuitPython_CLUE, Adafruit_CircuitPython_Crickit, Adafruit_CircuitPython_DHT, Adafruit_CircuitPython_DisplayIO_SSD1305, Adafruit_CircuitPython_DisplayIO_SSD1306, Adafruit_CircuitPython_DotStar, Adafruit_CircuitPython_DPS310, Adafruit_CircuitPython_DRV2605, Adafruit_CircuitPython_DS1307, Adafruit_CircuitPython_DS1841, Adafruit_CircuitPython_DS18X20, Adafruit_CircuitPython_DS2413, Adafruit_CircuitPython_DS3231, Adafruit_CircuitPython_DS3502, Adafruit_CircuitPython_DymoScale, Adafruit_CircuitPython_EPD, Adafruit_CircuitPython_ESP_ATcontrol, Adafruit_CircuitPython_ESP32SPI, Adafruit_CircuitPython_Fingerprint, Adafruit_CircuitPython_FocalTouch, Adafruit_CircuitPython_FONA, Adafruit_CircuitPython_FRAM, Adafruit_CircuitPython_FXAS21002C, Adafruit_CircuitPython_FXOS8700, Adafruit_CircuitPython_GPS, Adafruit_CircuitPython_HCSR04, Adafruit_CircuitPython_HT16K33, Adafruit_CircuitPython_HTS221, Adafruit_CircuitPython_HTU21D, Adafruit_CircuitPython_HX8357, Adafruit_CircuitPython_ICM20X, Adafruit_CircuitPython_IL0373, Adafruit_CircuitPython_IL0398, Adafruit_CircuitPython_IL91874, Adafruit_CircuitPython_ILI9341, Adafruit_CircuitPython_INA219, Adafruit_CircuitPython_INA260, Adafruit_CircuitPython_IRRemote, Adafruit_CircuitPython_IS31FL3731, Adafruit_CircuitPython_L3GD20, Adafruit_CircuitPython_LIDARLite, Adafruit_CircuitPython_LIS2MDL, Adafruit_CircuitPython_LIS331, Adafruit_CircuitPython_LIS3DH, Adafruit_CircuitPython_LIS3MDL, Adafruit_CircuitPython_LPS2X, Adafruit_CircuitPython_LPS35HW, Adafruit_CircuitPython_LSM303, Adafruit_CircuitPython_LSM303_Accel, Adafruit_CircuitPython_LSM303DLH_Mag, Adafruit_CircuitPython_LSM6DS, Adafruit_CircuitPython_LSM9DS0, Adafruit_CircuitPython_LSM9DS1, Adafruit_CircuitPython_MatrixKeypad, Adafruit_CircuitPython_MAX31855, Adafruit_CircuitPython_MAX31856, Adafruit_CircuitPython_MAX31865, Adafruit_CircuitPython_MAX7219, Adafruit_CircuitPython_MAX9744, Adafruit_CircuitPython_MCP230xx, Adafruit_CircuitPython_MCP3xxx, Adafruit_CircuitPython_MCP4725, Adafruit_CircuitPython_MCP4728, Adafruit_CircuitPython_MCP9600, Adafruit_CircuitPython_MCP9808, Adafruit_CircuitPython_MLX90393, Adafruit_CircuitPython_MLX90614, Adafruit_CircuitPython_MLX90640, Adafruit_CircuitPython_MMA8451, Adafruit_CircuitPython_MPL115A2, Adafruit_CircuitPython_MPL3115A2, Adafruit_CircuitPython_MPR121, Adafruit_CircuitPython_MPRLS, Adafruit_CircuitPython_MPU6050, Adafruit_CircuitPython_MS8607, Adafruit_CircuitPython_MSA301, Adafruit_CircuitPython_NeoPixel, Adafruit_CircuitPython_NeoPixel_SPI, Adafruit_CircuitPython_NeoTrellis, Adafruit_CircuitPython_Nunchuk, Adafruit_CircuitPython_PCA9685, Adafruit_CircuitPython_PCD8544, Adafruit_CircuitPython_PCF8523, Adafruit_CircuitPython_PCF8591, Adafruit_CircuitPython_PCT2075, Adafruit_CircuitPython_Pixie, Adafruit_CircuitPython_PM25, Adafruit_CircuitPython_PN532, Adafruit_CircuitPython_PyPortal, Adafruit_CircuitPython_RA8875, Adafruit_CircuitPython_RFM69, Adafruit_CircuitPython_RFM9x, Adafruit_CircuitPython_RGB_Display, Adafruit_CircuitPython_RockBlock, Adafruit_CircuitPython_RPLIDAR, Adafruit_CircuitPython_SD, Adafruit_CircuitPython_Seesaw, Adafruit_CircuitPython_SGP30, Adafruit_CircuitPython_SharpMemoryDisplay, Adafruit_CircuitPython_SHT31D, Adafruit_CircuitPython_SHTC3, Adafruit_CircuitPython_SI4713, Adafruit_CircuitPython_SI5351, Adafruit_CircuitPython_SI7021, Adafruit_CircuitPython_SSD1305, Adafruit_CircuitPython_SSD1306, Adafruit_CircuitPython_SSD1322, Adafruit_CircuitPython_SSD1325, Adafruit_CircuitPython_SSD1327, Adafruit_CircuitPython_SSD1331, Adafruit_CircuitPython_SSD1351, Adafruit_CircuitPython_SSD1608, Adafruit_CircuitPython_SSD1675, Adafruit_CircuitPython_ST7735, Adafruit_CircuitPython_ST7735R, Adafruit_CircuitPython_ST7789, Adafruit_CircuitPython_STMPE610, Adafruit_CircuitPython_TC74, Adafruit_CircuitPython_TCA9548A, Adafruit_CircuitPython_TCS34725, Adafruit_CircuitPython_TFmini, Adafruit_CircuitPython_Thermal_Printer, Adafruit_CircuitPython_Thermistor, Adafruit_CircuitPython_TLC5947, Adafruit_CircuitPython_TLC59711, Adafruit_CircuitPython_TLV493D, Adafruit_CircuitPython_TMP006, Adafruit_CircuitPython_TMP007, Adafruit_CircuitPython_Touchscreen, Adafruit_CircuitPython_TPA2016, Adafruit_CircuitPython_Trellis, Adafruit_CircuitPython_TrellisM4, Adafruit_CircuitPython_TSL2561, Adafruit_CircuitPython_TSL2591, Adafruit_CircuitPython_US100, Adafruit_CircuitPython_VC0706, Adafruit_CircuitPython_VCNL4010, Adafruit_CircuitPython_VCNL4040, Adafruit_CircuitPython_VEML6070, Adafruit_CircuitPython_VEML6075, Adafruit_CircuitPython_VEML7700, Adafruit_CircuitPython_VL53L0X, Adafruit_CircuitPython_VL6180X, Adafruit_CircuitPython_VS1053, Adafruit_CircuitPython_Wiznet5k, Adafruit_CircuitPython_WS2801, Adafruit_CircuitPython_AWS_IOT, Adafruit_CircuitPython_GC_IOT_Core, Adafruit_CircuitPython_AdafruitIO, Adafruit_CircuitPython_AirLift, Adafruit_CircuitPython_AVRprog, Adafruit_CircuitPython_AzureIoT, Adafruit_CircuitPython_binascii, Adafruit_CircuitPython_BitbangIO, Adafruit_CircuitPython_Bitmap_Font, Adafruit_CircuitPython_BitmapSaver, Adafruit_CircuitPython_BLE, Adafruit_CircuitPython_BLE_BroadcastNet, Adafruit_CircuitPython_BLE_Radio, Adafruit_CircuitPython_BLE_Adafruit, Adafruit_CircuitPython_BLE_Apple_Media, Adafruit_CircuitPython_BLE_Apple_Notification_Center, Adafruit_CircuitPython_BLE_BerryMed_Pulse_Oximeter, Adafruit_CircuitPython_BLE_Cycling_Speed_and_Cadence, Adafruit_CircuitPython_BLE_Eddystone, Adafruit_CircuitPython_BLE_Heart_Rate, Adafruit_CircuitPython_BLE_iBBQ, Adafruit_CircuitPython_BLE_Magic_Light, Adafruit_CircuitPython_BLE_MIDI, Adafruit_CircuitPython_BoardTest, Adafruit_CircuitPython_BusDevice, Adafruit_CircuitPython_CursorControl, Adafruit_CircuitPython_Debouncer, Adafruit_CircuitPython_Debug_I2C, Adafruit_CircuitPython_Display_Button, Adafruit_CircuitPython_Display_Shapes, Adafruit_CircuitPython_Display_Text, Adafruit_CircuitPython_Display_Notification, Adafruit_CircuitPython_FancyLED, Adafruit_CircuitPython_FeatherWing, Adafruit_CircuitPython_framebuf, Adafruit_CircuitPython_Gizmo, Adafruit_CircuitPython_hashlib, Adafruit_CircuitPython_HID, Adafruit_CircuitPython_Hue, Adafruit_CircuitPython_ImageLoad, Adafruit_CircuitPython_JWT, Adafruit_CircuitPython_LED_Animation, Adafruit_CircuitPython_LIFX, Adafruit_CircuitPython_Logging, Adafruit_CircuitPython_MatrixPortal, Adafruit_CircuitPython_MIDI, Adafruit_CircuitPython_miniesptool, Adafruit_CircuitPython_MiniMQTT, Adafruit_CircuitPython_miniQR, Adafruit_CircuitPython_Motor, Adafruit_CircuitPython_MotorKit, Adafruit_CircuitPython_NTP, Adafruit_CircuitPython_OneWire, Adafruit_CircuitPython_Pixel_Framebuf, Adafruit_CircuitPython_ProgressBar, Adafruit_CircuitPython_PyBadger, Adafruit_CircuitPython_PYOA, Adafruit_CircuitPython_Pypixelbuf, Adafruit_CircuitPython_Register, Adafruit_CircuitPython_Requests, Adafruit_CircuitPython_RGBLED, Adafruit_CircuitPython_RSA, Adafruit_CircuitPython_RTTTL, Adafruit_CircuitPython_ServoKit, Adafruit_CircuitPython_SimpleIO, Adafruit_CircuitPython_Slideshow, Adafruit_CircuitPython_TinyLoRa, Adafruit_CircuitPython_turtle, Adafruit_CircuitPython_Waveform, Adafruit_CircuitPython_WSGI
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants