Vinz1911
Eurobricks Vassals-
Posts
16 -
Joined
-
Last visited
Content Type
Profiles
Forums
Gallery
Everything posted by Vinz1911
-
Hub to Hub communication
Vinz1911 replied to Glaysche's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I discovered something really strange. I wrote a lib to connect to the powered up remote. I have two programs on the hub, one is for connecting and dealing with my remote and the other program was just a test with the hub2hub feature from lego. If I run first the program which connects to my remote, then disconnecting and stopping the program and after that running the other program with the "when hub receives signal" block. the hub is reconnecting to my handset. This is so weird I tried other programs without the "when hub receives signal" block and then it's NOT reconnecting (which I expect). I'm not sure what happens here, it seems that my class for connecting to my remote is still in memory and the lego block seems to trigger the connection process again, very strange. Seems that this is written with the ubluetooth library or something gets strange with the Nimble stack. :D -
Hub to Hub communication
Vinz1911 replied to Glaysche's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
I tried and there is a hard cut. I received 23 Bytes of content and the rest was lost. -
2020 Mindstorms set
Vinz1911 replied to Coder Shah's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
The only thing I really don't like on Spike Prime HUB is not the less powerful processor or something else BUT, it's the small amount of Memory :( If I create a bit more bigger python program, I ran really fast out of memory and then I need to restart the hub. This is the most annoying thing for me. 1Mb instead of 320Kb would have been much more convenient for me -
2020 Mindstorms set
Vinz1911 replied to Coder Shah's topic in LEGO Technic, Mindstorms, Model Team and Scale Modeling
In Germany I saw several Shops has listed the set. I saw two release dates, one said the 01.10.2020 and one other said the 15.10.2020. I think it won't be long now, then we will se the set in the lego store for pre ordering :) -
With the 1.1.4 version of the App, it was possible to downgrade my Spike Prime from 1.12 to 1.10 Firmware. I need someone who can provide me an earlier version of the Spike Prime Software for Mac/Windows. I cannot download a earlier version as 1.1.4 from the Lego Page. It would be nice if someone can provide me a 1.0.0 or 1.1.0/1.1.1 Version of the Spike Prime Software for Mac/Windows
-
Hi Guys, I have a question, I want to downgrade my Spike Prime to version 1.9.3 to test out some things with the old BLE class which does not work in higher Versions. Is it possible to downgrade to that firmware ? I tried to modify the download link from lego to get a earlier version of the Prime App. But the Latest Version I could get was the 1.1.4 Version and the Firmware which is delivered with that App Version ist 1.10 for the Prime. Does anyone have the 1.1.0 or 1.1.1 App Version of the Spike Prime App for Mac or Windows for me ? So that I could downgrade the Firmware of my Spike to 1.9.3 ? Thanks and best Regards Vinz
-
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
For Everyone who is interested in Lego Spike Prime + PowerUP Remote, I created an example here: Spike Prime + Power UP Remote - The Remote is automatically detected and connected (just copy this to your spike prime, run it and start at the same moment the advertising on the remote) - After a successfully created connection, the remote‘s LED is changed to GREEN - Every button let's light up a different dot on the Spike Prime, releasing it turn it off -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
@GianCann With your Help I could finished my little Class today, which automatically detects der PowerUP Remote, connects to it and the spike got notified about the pressed buttons. I also could understand with the help of the LWP 3.0 Documentation what the bytes enable in the Remote. But I have one last Question, that's a thing I could not find in the Docu. It's about the last byte packet you send bt.gattc_write(conn_handle,0x0C,struct.pack('<BB',0x01,0x00),1) What is enabled here ? The 0x0C is the "Value Handle" byte but I can't find any reference about it. Can you explain me what is triggered here in the remote ? It seems that this is a very necessary part because if I don't send this packet, my program will not start receiving updates from the remote. Greetings Vinz -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
Ah alright thank you :) Is there any tutorial how to read out console output with uPyCraft or is this Possible if I put the Spike in REPL mode via console ? -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
I figured out the problem. It's related to the bus where the lego app reads out the console output. I wrote a litte code which should enable a light matrix dot if I press a button on the remote. After uploading it to the spike and disconnecting it from my pc and directly execute it on the prime. It work as intended. This makes debugging a bit more complicated, but now it works *_* Just one Question, can explain me this block here, the packets you send after the connection ? Or have you any reference to the LWP 3.0 Documentation what is done here ? ar=struct.pack('<BBBBBBBBBB', 0x0A,0x0,0x41,0x00,0x00,0x01,0x00,0x00,0x00,0x01) bt.gattc_write(conn_handle,0x0B,ar,1) utime.sleep(2) print('aaaaaa complete..0x0B write 0x0A,0x0,0x41,0x00,0x00,0x01,0x00,0x00,0x00,0x01') al=struct.pack('<BBBBBBBBBB', 0x0A,0x0,0x41,0x01,0x00,0x01,0x00,0x00,0x00,0x01) bt.gattc_write(conn_handle,0x0B,al,1) utime.sleep(2) print('aaaaaa complete..0x0Bwrite 0x0A,0x0,0x41,0x01,0x00,0x01,0x00,0x00,0x00,0x01') bt.gattc_write(conn_handle,0x0C,struct.pack('<BB',0x01,0x00),1) print('connect complete.activate notifications.write Handel 0x0c data0100... starting write') -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
@GianCann Yes I directly connected it to my PC with the USB Cable, I also tried it out with my Mac and the latest Spike Prime App and also with my Windows 10 PC, also with the latest Spike Prime App -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
Hi @GianCann I tried out your example and I got some problems. I Uploaded it with the Spike Prime App and got connected successfully to my remote. But the first Problem I had is, that I'm receiving notifications very slowly and my second problem is, after I press a button I got the bytes in format you presented but then it stoped working :( I don't receive anything else then. Here my Logs, maybe you can help me again ? Thanks [13:57:43.801] > event == _IRQ_PERIPHERAL_CONNECT [13:57:44.804] > 1025 0 b'\x00\x81\xf9\xea\xc1\x9f' [13:57:47.805] > aaaaaa complete..0x0B write 0x0A,0x0,0x41,0x00,0x00,0x01,0x00,0x00,0x00,0x01 [13:57:50.809] > aaaaaa complete..0x0Bwrite 0x0A,0x0,0x41,0x01,0x00,0x01,0x00,0x00,0x00,0x01 [13:57:51.812] > connect complete.activate notifications.write Handel 0x0c data0100... starting write [13:57:54.815] > event == _IRQ_GATTC_WRITE_STATUS [13:57:55.818] > 0 [13:57:56.819] > event == _IRQ_GATTC_WRITE_STATUS [13:57:57.820] > 0 [13:57:58.821] > event == _IRQ_GATTC_WRITE_STATUS [13:57:59.824] > 0 [13:58:00.825] > event == _IRQ_GATTC_NOTIFY [13:58:01.827] > b'\n\x00G\x00\x00\x01\x00\x00\x00\x01' [13:58:02.828] > event == _IRQ_GATTC_NOTIFY [13:58:03.831] > b'\x0f\x00\x04\x00\x017\x00\x00\x00\x00\x10\x00\x00\x00\x10' [13:58:04.833] > event == _IRQ_GATTC_NOTIFY [13:58:05.837] > b'\x0f\x00\x04\x01\x017\x00\x00\x00\x00\x10\x00\x00\x00\x10' [13:58:06.839] > event == _IRQ_GATTC_NOTIFY [13:58:07.842] > b'\x0f\x00\x044\x01\x17\x00\x00\x00\x00\x10\x00\x00\x00\x10' [13:58:08.843] > event == _IRQ_GATTC_NOTIFY [13:58:09.846] > b'\n\x00G\x01\x00\x01\x00\x00\x00\x01' [13:58:10.847] > event == _IRQ_GATTC_NOTIFY [13:58:11.849] > b'\x05\x00E\x00\xff' -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
Hi @GianCann Awesome, Thank you for the Code and the Explanation. i will try it out later and give you feedback:) Thank you so much -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
Hey @GianCann No Problem :) Im looking forward for tomorrow. Thank you and best regards Vinz -
Spike Prime + PowerUP Remote in Python - Noob needs Help
Vinz1911 replied to Vinz1911's topic in LEGO Train Tech
Hi @GianCann WoW this is insane !!!! Thank You :) -
Hi Everyone :) My Name is Vinz, im new in this Forum, I found it after deeper looking in Coding with my Spike Prime. With the latest Firmware for Spike Prime we got full access to the Micropython ubluetooth library and I startet to try out some things to make my PowerUP Remote working with my Spike Prime. The Current State is, that i can successfully connect the remote to the spike prime and I also can read some Data. So but here I started struggling, I'm not an expert in BLE and I don't understand (also with the help of the LWP 3.0 Documentation) What I need to do now to read out which button I pressed on the remote. I also see the same bytes reading from my remote. Is it necessary to send a "start" command to the PowerUP Remote to gather the data which button is pressed ? Maybe someone can light me up :) Here is also my current WIP Code, that I run on my spike prime. Thank you and best regards Vinz import utime import ubluetooth import ubinascii import struct from micropython import const _IRQ_CENTRAL_CONNECT = const(1 << 0) _IRQ_CENTRAL_DISCONNECT = const(1 << 1) _IRQ_GATTS_WRITE = const(1 << 2) _IRQ_GATTS_READ_REQUEST = const(1 << 3) _IRQ_SCAN_RESULT = const(1 << 4) _IRQ_SCAN_COMPLETE = const(1 << 5) _IRQ_PERIPHERAL_CONNECT = const(1 << 6) _IRQ_PERIPHERAL_DISCONNECT = const(1 << 7) _IRQ_GATTC_SERVICE_RESULT = const(1 << 8) _IRQ_GATTC_CHARACTERISTIC_RESULT = const(1 << 9) _IRQ_GATTC_DESCRIPTOR_RESULT = const(1 << 10) _IRQ_GATTC_READ_RESULT = const(1 << 11) _IRQ_GATTC_WRITE_STATUS = const(1 << 12) _IRQ_GATTC_NOTIFY = const(1 << 13) _IRQ_GATTC_INDICATE = const(1 << 14) _IRQ_GATTC_SERVICE_DONE = const(10) _ADV_TYPE_UUID16_COMPLETE = const(0x3) _ADV_TYPE_UUID32_COMPLETE = const(0x5) _ADV_TYPE_UUID128_COMPLETE = const(0x7) _COMPANY_IDENTIFIER_CODES = { "0397": "LEGO System A/S" } _LEGO_SERVICE_UUID = ubluetooth.UUID("00001623-1212-EFDE-1623-785FEABCD123") _LEGO_SERVICE_CHAR = ubluetooth.UUID("00001624-1212-EFDE-1623-785FEABCD123") class PowerUPRemote: """Class to deal with LEGO(R) PowerUp(TM) Remote Control for Spike Prime""" def __init__(self): self._ble = ubluetooth.BLE() self._ble.active(True) self._ble.irq(handler=self._irq) self._decoder = Decoder() self._reset() def _reset(self): self._addr = None self._addr_type = None self._adv_type = None self._services = None self._man_data = None self._name = None self._conn = None self._value = None # start scan for ble devices def scan_start(self, timeout): self._ble.gap_scan(timeout, 30000, 30000) # stop current scan def scan_stop(self): self._ble.gap_scan(None) # connect to ble device def connect(self, addr_type, addr): self._ble.gap_connect(addr_type, addr) # disconnect from ble device def disconnect(self): if not self._conn: return self._ble.gap_disconnect(1025) self._reset() def read(self): self._ble.gattc_read(self._conn, self._value) # ble event handler def _irq(self, event, data): # called for every result of a ble scan if event == _IRQ_SCAN_RESULT: addr_type, addr, adv_type, rssi, adv_data = data self._addr_type = addr_type self._addr = bytes(addr) self._adv_type = adv_type self._name = self._decoder.decode_name(adv_data) self._services = self._decoder.decode_services(adv_data) self._man_data = self._decoder.decode_manufacturer(adv_data) # called after a ble scan is finished elif event == _IRQ_SCAN_COMPLETE: print("scan finished!") # called if a peripheral device is connected elif event == _IRQ_PERIPHERAL_CONNECT: print("connected peripheral device") conn, addr_type, addr = data self._conn = conn self._ble.gattc_discover_services(self._conn) # called if a peripheral device is disconnected elif event == _IRQ_PERIPHERAL_DISCONNECT: conn, _, _ = data print("disconnected peripheral device") elif event == _IRQ_GATTC_SERVICE_RESULT: # Connected device returned a service. conn, start_handle, end_handle, uuid = data print("service", data, "uuid", uuid, "Conn", conn) if conn == self._conn and uuid == _LEGO_SERVICE_UUID: self._ble.gattc_discover_characteristics(self._conn, start_handle, end_handle) elif event == _IRQ_GATTC_CHARACTERISTIC_RESULT: # Connected device returned a characteristic. conn, def_handle, value_handle, properties, uuid = data print("Got Charachterisitic", uuid, value_handle) if conn == self._conn and uuid == _LEGO_SERVICE_CHAR: self._value = value_handle elif event == _IRQ_GATTC_READ_RESULT: # A read completed successfully. conn_handle, value_handle, char_data = data print("Got Data Read", data, ubinascii.hexlify(char_data)) # called on notification elif event == _IRQ_GATTC_NOTIFY: conn, value_handle, notify_data = data print("Notification") class Decoder: """Class to decode BLE adv_data""" def decode_manufacturer(self, payload): man_data = [] n = self._decode_field(payload, const(0xff)) if not n: return [] company_identifier = ubinascii.hexlify(struct.pack('<h', *struct.unpack('>h', n[0]))) company_name = _COMPANY_IDENTIFIER_CODES.get(company_identifier.decode(), "?") company_data = ubinascii.hexlify(n[0][2:]) man_data.append(company_identifier.decode()) man_data.append(company_name) man_data.append(company_data) return man_data def decode_name(self, payload): n = self._decode_field(payload, const(0x09)) return str(n[0], "utf-8") if n else "parsing failed!" def decode_services(self, payload): services = [] for u in self._decode_field(payload, _ADV_TYPE_UUID16_COMPLETE): services.append(ubluetooth.UUID(struct.unpack("<h", u)[0])) for u in self._decode_field(payload, _ADV_TYPE_UUID32_COMPLETE): services.append(ubluetooth.UUID(struct.unpack("<d", u)[0])) for u in self._decode_field(payload, _ADV_TYPE_UUID128_COMPLETE): services.append(ubluetooth.UUID(u)) return services def _decode_field(self, payload, adv_type): i = 0 result = [] while i + 1 < len(payload): if payload[i + 1] == adv_type: result.append(payload[i + 2: i + payload[i] + 1]) i += 1 + payload[i] return result remote = PowerUPRemote() remote.connect(0, b'\x00\x81\xf9\xea\xc1\x9f') utime.sleep(10) print("Start Read") while True: remote.read() utime.sleep(0.100) #remote.disconnect()