transmit_variable_length.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import logging
  2. import time
  3. import cc1101
  4. logging.basicConfig(level=logging.INFO)
  5. with cc1101.CC1101(lock_spi_device=True) as transceiver:
  6. print("defaults:", transceiver)
  7. transceiver.set_base_frequency_hertz(433.5e6)
  8. transceiver.set_symbol_rate_baud(600)
  9. # transceiver.set_sync_mode(cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD)
  10. # transceiver.set_preamble_length_bytes(2)
  11. # transceiver.set_sync_word(b"\x12\x34")
  12. # transceiver.disable_checksum()
  13. transceiver.set_output_power((0, 0xC0)) # OOK modulation: (off, on)
  14. print(transceiver)
  15. print("state", transceiver.get_marc_state().name)
  16. print("base frequency", transceiver.get_base_frequency_hertz(), "Hz")
  17. print("symbol rate", transceiver.get_symbol_rate_baud(), "Baud")
  18. print("modulation format", transceiver.get_modulation_format().name)
  19. sync_mode = transceiver.get_sync_mode()
  20. print("sync mode", sync_mode)
  21. if sync_mode != cc1101.SyncMode.NO_PREAMBLE_AND_SYNC_WORD:
  22. print("preamble length", transceiver.get_preamble_length_bytes(), "bytes")
  23. print("sync word", transceiver.get_sync_word())
  24. print("output power settings (patable)", transceiver.get_output_power())
  25. print("\nstarting transmission")
  26. transceiver.transmit(b"\xff\xaa\x00 message")
  27. time.sleep(1.0)
  28. transceiver.transmit(bytes([0, 0b10101010, 0xFF]))
  29. for i in range(16):
  30. time.sleep(1.0)
  31. transceiver.transmit(bytes([i, i, i]))