I'm working on BLE(BlueTooth Low Energy) on an Embedded Linux board. We use BlueZ and Python. I need to create EddyStone Beacon. I found there is a way to create iBeacon: https://scribles.net/creating-ibeacon-using-bluez-example-code-on-raspberry-pi/. I tried it. It worked.
But we need to create EddyStone Beacon. So I use the Beacon data format from here(https://ukbaz.github.io/howto/beacon_scan_cmd_line.html) to create the manufacturer data.
But my code doesn't work. What is wrong with my code? Here is my code:
def __init__(self, bus, index):
eddystone_id = 0xAAFE
beacon_type = [0x14, 0x16] # Length = 0x14, EddyStone type = 0x16
uuid = [0xAA, 0xFE] # EddyStone UUID = 0xAAFE
frame_type = [0x10] # Frame Type = 0x10
power = [0x00] # Power = 0x00
prefix = [0x02] # URL scheme = 0x02 (http://)
url = [0x73, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x77, 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x07]
Advertisement.__init__(self, bus, index, 'peripheral')
self.add_manufacturer_data(eddystone_id, beacon_type + uuid + frame_type + power + prefix + url)
However, if I use this command, the EddyStone Beacon is created. I can see it shows EddyStone Beacon in nRF mobile app:
sudo hcitool -i hci0 cmd 0x08 0x0008 1c 02 01 06 03 03 aa fe 14 16 aa fe 10 00 02 73 61 6d 70 6c 65 77 65 62 73 69 74 65 07 00 00 00
As you can see, the data I put in the add_manufacturer_data() function is the same as the data in the command. But why the Python code doesn't work?
iBeacon uses manufacturer_data while Eddystone beacons use service_data so I would expect your code to look more like this:
def __init__(self, bus, index):
Advertisement.__init__(self, bus, index, 'broadcast')
self.add_service_uuid('FEAA')
frame_type = [0x10] # Eddystone frame Type = 0x10
power = [0x00] # Beacon broadcast power = 0x00
prefix = [0x02] # URL scheme = 0x02 (http://)
url = [0x73, 0x61, 0x6D, 0x70, 0x6C, 0x65, 0x77, 0x65, 0x62, 0x73, 0x69, 0x74, 0x65, 0x07]
eddystone_data = frame_type + power + prefix + url
self.add_service_data('FEAA', eddystone_data)
As a side note, hcitool is one of the tools that has been deprecated by the BlueZ developers. The currently supported way to create the Eddystone beacon from the command line would be with bluetoothctl. The sequence of commands would be:
bluetoothctl
menu advertise
uuids 0xFEAA
service 0xFEAA 0x10 0x00 0x02 0x73 0x61 0x6D 0x70 0x6C 0x65 0x77 0x65 0x62 0x73 0x69 0x74 0x65 0x07
back
advertise broadcast
discoverable on
I changed the advertisement type from peripheral to broadcast because typically people don't want beacons to be connectable, but it depends on your application.
Related
I'm following a tutorial and it says the UUID is 65210001-28D5-4B7B-BADF-7DEE1E8D1B6D then he adds it to the code in this format, without explaining how the conversion happened:
// Simple Service UUID: 65210001-28D5-4B7B-BADF-7DEE1E8D1B6D
static struct bt_uuid_128 simple_service_uuid =
BT_UUID_INIT_128(0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b,
0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65);
I'm curious, what format is 0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b,0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65 exactly? Hex?
How can I get from the UUID to the array? I've tried hex conversions and some other python encoding, but I can't create anything close. I'm looking to do the conversion in python.
Here is the python solution thanks to Patrick Artners help:
uuid = input('Enter a UUID: ')
uuid = uuid.replace('-', '')
uuid = uuid[::-1] #reverse the string
hexArrayStr = ''
splitToTwos = map(''.join, zip(*[iter(uuid)]*2))
count = 0
for v in splitToTwos:
count+=1
hexArrayStr = hexArrayStr + ('0x'+(v[::-1]).lower())
if count != 16:
hexArrayStr = hexArrayStr + ', '
print(hexArrayStr)
prints 0x6d, 0x1b, 0x8d, 0x1e, 0xee, 0x7d, 0xdf, 0xba, 0x7b, 0x4b, 0xd5, 0x28, 0x01, 0x00, 0x21, 0x65
I am trying to send a command to the command register from my TMF8701 sensor from AMS with Python code from a Raspberry Pi. I have to of these sensors connected to the I2C Bus of the Raspberry Pi. One for channel 1 and one for channel 0. I am writing the 0x10 register with 0x0A and trying to do the factory calibration. But after this command is written, the 0x1E register does not have the correct value. I also tried to write another command, for example 0x0B, but also the 0x1E register does not return the correct value. Can anyone help me?
import smbus
from time import sleep
CMD_DATA0=0x0F
CMD_DATA1=0x0E
CMD_DATA2=0x0D
CMD_DATA3=0x0C
CMD_DATA4=0x0B
CMD_DATA5=0x0A
CMD_DATA6=0x09
CMD_DATA7=0x08
CMD_DATA8=0x07
CMD_DATA9=0x06
#14 Byte
FACTORY_CALIBRATION=0x28
class tmf8701_distanceSensor():
# by default, this assumes that the device is at 0x41
def __init__(self, channel, address=0x41):
self.address = address
self.channel = channel
self.bus = smbus.SMBus(self.channel)
#self.reset()
sleep(1) # wait 1 sec
self.setup()
#def reset(self):
#0x10 - command
#factoryCalibrationValue=""
def factoryCalibration(self):
sleep(2)
self.bus.write_i2c_block_data(self.address, 0x10, [0x0A])
#while (self.bus.read_byte_data(self.address, 0x1E))!=0x0A:
#sleep(1)
#print("while")
sleep(10)
#print("factory calibration")
#print(str(int(self.bus.read_byte_data(self.address, 0x1E))), str(int(0x0A)))
#Factory Calibration begins 0x20 und dann 14 byte
block=self.bus.read_i2c_block_data(self.address, 0x20, 14)
print(block)
print(self.bus.read_byte_data(self.address, 0x2c))
print(self.bus.read_byte_data(self.address, 0x2d))
print(self.bus.read_byte_data(self.address, 0x01))
"""def bootloaderReadyForNewCommand(self):
#CMD_STAT register - 0x0 - READY
#0x10-0xFF - busy - davor error und gut !
read0x10Register=self.bus.read_byte_data(self.address, 0x10)
if read0x10Register == 0:
return("ready")
elif read0x10Register < int(0x10):
return read0x10Register
else:
print("try again later??? ")
return "busy"""""
def readResults(self):
print("erst 0x20")
print(self.bus.read_byte_data(self.address, 0x20))
print("dann 0x1D")
print(self.bus.read_byte_data(self.address, 0x1D))
print("dann 0x20")
print(self.bus.read_byte_data(self.address, 0x20))
print("zuletzt 0x1E")
print(self.bus.read_byte_data(self.address, 0x1E))
def setDeviceInStandBy(self):
self.bus.write_i2c_block_data(self.address, 0xE0, [0x00])
def setup(self):
###bootloader settings:
if not self.bus.read_byte_data(self.address, 0x00)==0x80:
self.bus.write_i2c_block_data(self.address, 0x00, [0x80])
#wake up sensor
self.bus.write_i2c_block_data(self.address, 0xE0, [0x01])
sleep(3)
###
read0xE0Register=self.bus.read_byte_data(self.address, 0xE0)
print("register 0xE0, if 65 => perfect!")
print(read0xE0Register)
### app0 settings:
if not self.bus.read_byte_data(self.address, 0x00)==0xC0:
self.bus.write_i2c_block_data(self.address, 0x00, [0xC0])
self.bus.write_i2c_block_data(self.address, 0x10, [0x0B])
#read serial number
self.bus.write_i2c_block_data(self.address, 0x10, [0x47])
#while (self.bus.read_byte_data(self.address, 0x1E))!=0x0A:
#sleep(1)
#print("while")
sleep(10)
print("serialdata")
print(self.bus.read_byte_data(self.address, 0x1E))
block=self.bus.read_i2c_block_data(self.address, 0x28, 3)
print(block)
#print("factory calibration")
#print(str(int(self.bus.read_byte_data(self.address, 0x1E))), str(int(0x0A)))
#Factory Calibration begins 0x20 und dann 14 byte
#block=self.bus.read_i2c_block_data(self.address, 0x1E, )
#print(block)
self.factoryCalibration()
print("currently running SW register: 128 = 0x80 - bootloader, 192 = 0xC0 - App0 ")
print(self.bus.read_byte_data(self.address, 0x00))
###algorithm state and factory calibration is provided
self.bus.write_i2c_block_data(self.address, CMD_DATA7, [0x03])
###
self.bus.write_i2c_block_data(self.address, CMD_DATA6, [0x23])
### no GPIO control used
self.bus.write_i2c_block_data(self.address, CMD_DATA5, [0x00])
self.bus.write_i2c_block_data(self.address, CMD_DATA4, [0x00])
### needs to be always 00
self.bus.write_i2c_block_data(self.address, CMD_DATA3, [0x00])
### repetition period in ms 64 hex = 100ms
self.bus.write_i2c_block_data(self.address, CMD_DATA2, [0x64])
### needs to be always ff
self.bus.write_i2c_block_data(self.address, CMD_DATA1, [0xFF])
self.bus.write_i2c_block_data(self.address, CMD_DATA0, [0xFF])
import csv,os
import numpy as np
import threading
#import max30102
import TMF8701_distanceSensor
import datetime
import time
from numpy import number
print("start")
print("sensor finger")
sensorTMF_finger=TMF8701_distanceSensor.tmf8701_distanceSensor(0)
#sensorTMF_finger.factoryCalibration()
print("sensor hand")
sensorTMF_hand=TMF8701_distanceSensor.tmf8701_distanceSensor(1)
#sensorTMF_hand.factoryCalibration()
number=0
while number<10:
print("hand")
#sensorTMF_hand.readResults()
print("finger")
sensorTMF_finger.readResults()
number=number+1
The output I get on the Raspberry Pi looks like that:
start
sensor finger
register 0xE0, if 65 => perfect!
65
serialdata
0
[0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
0
0
16
currently running SW register: 128 = 0x80 - bootloader, 192 = 0xC0 - App0
192
sensor hand
register 0xE0, if 65 => perfect!
65
serialdata
0
[0, 0, 0]
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
0
0
16
currently running SW register: 128 = 0x80 - bootloader, 192 = 0xC0 - App0
192
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
hand
finger
erst 0x20
0
dann 0x1D
0
dann 0x20
0
zuletzt 0x1E
0
Bluez Question:
I have a Raspberry Pi Z W, an 8bitdo SF30 bluetooth controller and a robot my employer mass produces. I am looking to control the robot from the RPI through the remote.
I have the RPi connecting to the controller using bluetoothctl, and I can see the messages from the controller through btmon (bluetooth monitor).
It becomes obvious that the four "80" values below correspond to the two joysticks at their mid points.
> ACL Data RX: Handle 11 flags 0x02 dlen 15 #30 [hci0] 2.555574
Channel: 65 len 11 [PSM 0 mode Basic (0x00)] {chan 65535}
a1 03 0f 80 80 12 31 00 00 00 00 ......1....
> ACL Data RX: Handle 11 flags 0x02 dlen 15 #31 [hci0] 2.587293
Channel: 65 len 11 [PSM 0 mode Basic (0x00)] {chan 65535}
a1 03 0f 80 80 27 4b 00 00 00 00 .....'K....
> ACL Data RX: Handle 11 flags 0x02 dlen 15 #32 [hci0] 2.613543
Channel: 65 len 11 [PSM 0 mode Basic (0x00)] {chan 65535}
a1 03 0f 80 80 61 7b 00 00 00 00 .....a{....
> ACL Data RX: Handle 11 flags 0x02 dlen 15 #33 [hci0] 2.615552
Channel: 65 len 11 [PSM 0 mode Basic (0x00)] {chan 65535}
a1 03 0f 80 80 80 80 00 00 00 00 ...........
> ACL Data RX: Handle 11 flags 0x02 dlen 15 #34 [hci0] 74.653567
Channel: 65 len 11 [PSM 0 mode Basic (0x00)] {chan 65535}
a1 03 0f 80 80 80 80 00 00 00 08 ...........
I have also been reading in data from the two resulting /dev/input/ files (/dev/input/js0 and /dev/input/event0) in python using format LLHHQ.
I thought that the same data from btmon (which is easy to interpret) would be represented in the Q section of that format (the last number below).
(470898350, 155732, 22190, 7185, 16919435)
(470898350, 160124, 22190, 7185, 16916057)
(470898380, 162488, 22220, 7185, 163502)
(470898380, 16915382, 22260, 7185, 16910652)
(470898420, 16908288, 22290, 7185, 161137)
(470898450, 16971797, 22300, 7185, 155732)
(470898460, 16966392, 22330, 7185, 154043)
(470898490, 16966054, 22340, 7185, 147287)
(470898500, 16967405, 22340, 7185, 131072)
(470898500, 16908288, 22740, 7185, 151060481)
(470899070, 151060480, 22970, 7185, 134283265)
(470899320, 134283264, 23200, 7185, 117506049)
(470899550, 117506048, 23420, 7185, 100728833)
(470899750, 100728832, 23590, 7185, 117506049)
(470899910, 117506048, 23930, 7185, 134283265)
(470900310, 134283264, 25110, 7185, 100728833)
(470901380, 117506049, 25250, 7185, 134283265)
(470901490, 100728832, 25390, 7185, 117506048)
(470901710, 134283264, 25580, 7185, 100728833)
(470901750, 117506049, 25720, 7185, 117506048)
(470901940, 134283265, 25810, 7185, 100728832)
(470902160, 100728833, 26070, 7185, 134283264)
(470902400, 100728832, 26690, 7185, 134283265)
(470903070, 134283264, 27130, 7185, 151060481)
(470903430, 151060480, 27360, 7185, 100728833)
However these outputs don't appear to correspond when read into binary, for example the two joysticks seem to change the same bits.
The basic of my question is how do I get the same data which is read in the btmon in a bluez-based code.
This is the python code I am using at the moment.
f = open( "/dev/input/js0", "rb" ); # Open the file in the read-binary mode
EVENT_SIZE = struct.calcsize("LLHHQ")
while 1:
data = f.read(EVENT_SIZE)
unpacked_data = struct.unpack('llHHQ',data)
# print("Length:" + str(len(unpacked_data)))
# print(unpacked_data)
remote_data = unpacked_data[4]
print(format(remote_data, '064b'))
It might be helpful to use a library like evdev as it will do much of the heavy lifting for you.
Example of using this might be:
from time import sleep
from pydbus import SystemBus
import evdev
# For testing
# python3 -m evdev.evtest
class Controller:
def __init__(self, adapter_int=0):
adapter_path = '/org/bluez/hci{}'.format(adapter_int)
self.dbus = SystemBus()
self.adapter = self.dbus.get('org.bluez', adapter_path)
# Use bluetoothctl to find out what the path is for your controller
self.controller = self.dbus.get('org.bluez', '/org/bluez/hci0/dev_DC_0C_2D_20_DA_E8')
print('Waiting for connection from DC:0C:2D:20:DA:E8')
# self.controller.Discoverable = True
while not self.controller.Connected:
sleep(1)
print('Connected')
sleep(6)
# https://python-evdev.readthedocs.io/en/latest/tutorial.html to get path of your controller
self.device = evdev.InputDevice('/dev/input/event2')
self.max_value = 0
self.min_value = 255
self.max_throttle = 1
self.min_throttle = -1
self.right_steering = 1
self.left_steering = -1
def map_throttle(self, value):
input_range = self.max_value - self.min_value
output_range = self.max_throttle - self.min_throttle
input_percentage = (value - self.min_value) / input_range
output_value = (output_range * input_percentage) + self.min_throttle
return round(output_value, 2)
def map_steering(self, value):
input_range = self.max_value - self.min_value
output_range = self.right_steering - self.left_steering
input_percentage = (value - self.min_value) / input_range
output_value = (output_range * input_percentage) + self.left_steering
return round(output_value, 2)
def get_events(self):
for event in self.device.read_loop():
ly = None
rx = None
btn = None
if event.type == evdev.ecodes.EV_ABS:
if event.code == 1:
# print('Left:', event.value)
ly = self.map_throttle(event.value)
if event.code == 3:
# print('Right:', event.value)
rx = self.map_steering(event.value)
if event.type == evdev.ecodes.EV_KEY:
if event.code == evdev.ecodes.BTN_SOUTH and event.value == 0:
btn = 'BTN_SOUTH'
elif event.code == evdev.ecodes.BTN_WEST and event.value == 0:
btn = 'BTN_WEST'
elif event.code == evdev.ecodes.BTN_NORTH and event.value == 0:
btn = 'BTN_NORTH'
elif event.code == evdev.ecodes.BTN_EAST and event.value == 0:
btn = 'BTN_EAST'
yield ly, rx, btn
if __name__ == '__main__':
ctrl = Controller()
for speed, steer, action in ctrl.get_events():
print('Speed: {}, Steer: {}, Button: {}'.format(speed, steer, action))
If you wanted to go a little higher level, then a library like https://github.com/ApproxEng/approxeng.input is a popular one.
I am new to Stackoverflow. I have searched for answer, but didn't find anything.
I have two Raspberry Pi 2B+, each with nRF24l01 connected. I found few libraries to make this connect, only one give any results, but not connections. This one: Github BLavery
I write script to send and to recv:
send.py:
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_2MBPS)
radio.setPALevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openWritingPipe(pipes[1])
radio.printDetails()
while True:
message = list("Hello World")
radio.write(message)
print("We sent the message of {}".format(message))
# Check if it returned a ackPL
if radio.isAckPayloadAvailable():
returnedPL = []
radio.read(returnedPL, radio.getDynamicPayloadSize())
print("Our returned payload was {}".format(returnedPL))
else:
print("No payload received")
time.sleep(1)
recv.py:
import RPi.GPIO as GPIO
from lib_nrf24 import NRF24
import time
import spidev
GPIO.setmode(GPIO.BCM)
pipes = [[0xe7, 0xe7, 0xe7, 0xe7, 0xe7], [0xc2, 0xc2, 0xc2, 0xc2, 0xc2]]
radio = NRF24(GPIO, spidev.SpiDev())
radio.begin(0, 17)
radio.setPayloadSize(32)
radio.setChannel(0x60)
radio.setDataRate(NRF24.BR_2MBPS)
radio.setPAlevel(NRF24.PA_MIN)
radio.setAutoAck(True)
radio.enableDynamicPayloads()
radio.enableAckPayload()
radio.openReadingPipe(1, pipes[1])
radio.printDetails()
radio.startListening()
while True:
ackPL = [1]
while not radio.available (0):
time.sleep(1/100)
receivedMessage = []
radio.read(receivedMessage, radio.getDynamicPayloadSize())
print("Received: {}".format(receivedMessage))
print("Translating the receivedMessage into unicode characters...")
string = ""
for n in receivedMessage:
# Decode into standard i=unicode set
if (n >=32 and n <= 126):
string += chr(n)
print(string)
radio.writeAckPayload(1, ackPL, len(ackPL))
print("Loaded payload reply of {}".format(ackPL))
Everything seems to be alright, below are code returned by both scripts:
send:
STATUS = 0x03 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=1
RX_ADDR_P0-1 =
0xf8f8f8f8f8 0xf8f8f8f8f8
RX_ADDR_P2-5 =
0xf8
0xf9
0xf9
0xf9
TX_ADDR =
0xf8f8f8f8f8
RX_PW_P0-6 =
0x0c
0x00
0x00
0x00
0x00
0x00
EN_AA =
0x0f
EN_RXADDR =
0x00
RF_CH =
0x1c
RF_SETUP =
0x00
CONFIG =
0x03
DYNPD/FEATURE =
0x03
0x01
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN
We sent the message of ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']
No payload received
recv.py:
STATUS = 0x03 RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=1 TX_FULL=1
RX_ADDR_P0-1 =
0xf8f8f8f8f8 0xf8f8f8f8f8
RX_ADDR_P2-5 =
0xf8
0xf9
0xf9
0xf9
TX_ADDR =
0xf8f8f8f8f8
RX_PW_P0-6 =
0x0c
0x0c
0x00
0x00
0x00
0x00
EN_AA =
0x0f
EN_RXADDR =
0x00
RF_CH =
0x1c
RF_SETUP =
0x00
CONFIG =
0x03
DYNPD/FEATURE =
0x03
0x01
Data Rate = 1MBPS
Model = nRF24L01
CRC Length = Disabled
PA Power = PA_MIN
Received: []
Translating the receivedMessage into unicode characters...
Loaded payload reply of [1]
I don't really understand why it won't connect one to other,
Both have the same wiring:
nRF24L01-Raspberry Pi (Pin#)
GND - GND (6)
VCC - 3,3V (1)
CE - GPIO17 (11)
CSN - GPIO08(24)
SCK - GPIO11 (23)
MOSI - GPIO10 (19)
MISO - GPIO25 (22)
IRQ - unconnected
I need to send information from one RPi to second to control engine via PWM.
Can i ask for help
I'm confused about this. how to print hexadecimal bytes:
[0x05, 0x06, 0x40, 0xFD, 0x05]
as this in the console:
05 06 40 FD 05
And how would I use this in a to_string function:
def to_string(bytes):
cmd = '%02X'.join(chr(b) for b in self.bytes) #does not work obviously
return cmd
print to_string([0x05, 0x06, 0x40, 0xFD, 0x05])
I thought I could generalize from your answer.
Use the %02X string formatter:
>>> print '%02X' % 0x05
05
>>> for i in [0x05, 0x06, 0x40, 0xFD, 0x05]:
... print '%02X' % i,
...
05 06 40 FD 05
or to make it one string:
>>> ' '.join(['%02X' % i for i in [0x05, 0x06, 0x40, 0xFD, 0x05]])
'05 06 40 FD 05'
Martijn's answer is the right answer, but here are some related functions you may not be familiar with.
With the python format string operator:
>>> for i in [0x05, 0x06, 0x40, 0xFD, 0x05]:
... print "{:02X}".format(i),
...
05 06 40 FD 05
If you actually had the data as bytestrings you could use binascii.hexlify to do the same.
>>> import binascii
>>> data = ["\x05", "\x06", "\x40", "\xFD", "\x05"]
>>> for d in data:
... print binascii.hexlify(d),
...
05 06 40 fd 05
You could also use the builtin hex() with your existing data if you don't mind the data not being padded.
>>> data = [0x05, 0x06, 0x40, 0xFD, 0x05]
>>> for i in data:
... print hex(i),
...
0x5 0x6 0x40 0xfd 0x5
>>>
>>>
>>> # Or use the slice operator to cut off the initial "0x"
>>> for i in data:
... print hex(i)[2:],
...
5 6 40 fd 5