Lego mindstorms bluetooth android

Bluetooth

This page describes the procedure to download MakeCode program to the EV3 brick over Bluetooth.

ВНИМАНИЕ: ЭКСПЕРИМЕНТАЛЬНЫЙ ФУНКЦИОНАЛ!

Support for Bluetooth download relies on Web Serial, an experimental browser feature. Web Serial is a work in progress; it may change or be removed in future versions without notice.

By enabling these experimental browser features, you could lose browser data or compromise your device security or privacy.

Supported browsers

  • Chrome desktop, version 77 and higher, Windows 10 or Mac OS.
  • Microsoft Edge Insider desktop, version 77 and higher, Windows 10 or Mac OS.

To make sure your browser is up to date, go to the ‘…’ menu, click “Help” then “About”.

Next you need to enable the experimental features (this may change in the future)

  • go to chrome://flags/#enable-experimental-web-platform-features and enableExperimental Web Platform features

A screenshot of the flags page in chrome

Machine Setup

Download over Bluetooth

  • go to https://makecode.mindstorms.com/
  • click on Download to start a file download as usual
  • on the download dialog, you should see a Bluetooth button. Click on the Bluetooth button to enable the mode.
  • make sure the EV3 brick is not running a program
  • click on Download again to download over bluetooth.

Choosing the correct serial port

Unfortunately, the browser dialog does not make it easy to select which serial port is the brick.

  • On Windows, choose Standard Serial over Bluetooth . There might be multiple of those but only one works. Try your luck! Once you know the COM port number, remember it for the next time around.
  • On Mac OS, choose cu.BRICKNAME-SerialPort

Known issues

  • We do not detect properly that the program is running on the brick. Make sure to stop the program before starting the download procedure.
  • The list of programs on the brick screen is not updated when uploading via bluetooth.

Источник

Android, NXT и Bluetooth

Уже многие распаковывали, описывали и программировали для Mindstorms NXT, поэтому круг поклонников данной серии довольно широк. Сегодня пришло время расширить этот круг описанием особенности данного конструктора — bluetooth, благодаря которому конструктор может спокойно управляться с телефона.

Статья будет полезна тем, кто хочет просто поиграть с чем-нибудь механическим в свободное от работы время.

Вступление

С детства люблю различные конструкторы, поэтому этим летом решил купить себе Mindstorms 8547, благо цена устраивала и в описании упоминался bluetooth. К моему великому разочарованию выяснилось, что абсолютно не интересно сидеть и складывать кубики вместе — чувствуешь бездарное расходование времени. Но программная сторона вопроса манила. Чтение User Guide показало, что должна быть возможность управления роботом с помощью bluetooth, хотя бы банальными движениями — вперёд/назад/вправо/влево. В Google Play уже достаточно программ управления, но задача в том, чтобы сделать такую самостоятельно.

Читайте также:  Bluetooth headset connection to phone

Дано:
1. Телефон на базе Android (LG P970)
2. Машинка из Mindstorms NXT 2.0

image

Реализация

После нескольких ночей в google выяснилось, что сайт Lego содержит всю необходимую информацию (не надеялся на такого подарок). Есть описание всего внутреннего содержимого блоков, сенсоров и протоколов передачи данных. Нас интересует только «Bluetooth Developer Kit». Внутри 4 файла:

• LEGO MINDSTORMS NXT Bluetooth Developer Kit.pdf
• Appendix 1-LEGO MINDSTORMS NXT Communication protocol.pdf
• Appendix 2-LEGO MINDSTORMS NXT Direct commands.pdf
• Appendix 3-LEGO MINDSTORMS NXT ARM7 Bluetooth Interface specification.pdf

Итого, вся задача сводится к тому, чтобы:
1. установить сопряжение телефона и блока управления NXT
2. подключиться к блок NXT
3. передать правильную команду.
4. получить ответ

Формат команды:

byte 0: младшая часть длины команды
byte 1: старшая часть длины команды
byte 2: тип команды
byte 3: команда
byte . аргументы, зависят от команды.

Примеры:

Получение заряда батареи:

GETBATTERYLEVEL
Byte 0: 0x00 or 0x80
Byte 1: 0x0B

Return package:
Byte 0: 0x02
Byte 1: 0x0B
Byte 2: Status Byte
Byte 3-4: Voltage in millivolts (UWORD)

код:

byte[]command = new byte[] 0x02, 0x00, 0x00, 0x0b
>;
mmOutStream.write(command);
mmOutStream.flush();

Движение вперёд:

byte[]command = new byte[] 0x0C,
0x00,

Запуск залитой программы:

Зная протокол обмена, реализация уже не представляет проблемы. Задача подключения к блоку управления тривиальна и описана на сайта Android, единственный интересный момент — это создание сокета. Создать его получилось, используя следующий код:

Method m = device.getClass().getMethod(«createRfcommSocket», new Class[] < int.class >);
BluetoothSocket sendSocket = (BluetoothSocket) m.invoke(device, 1);

Источник

Martin Vidner

The Lego Mindstorms EV3 robots can be controlled with an Android app (Lego Mindstorms Commander) communicating with the brick via Bluetooth. The command protocol is documented by Lego in the EV3 Communication Developer Kit and the commands themselves in the EV3 Firmware Developer Kit (get them from Mindstorms Downloads).

I wondered what exactly goes on and I decided to capture the communication and decode it, to learn both about Bluetooth and about the details of the EV3 protocol.

Good Robot. Good Robot!!

I succeeded and made a couple of useful tools along the way:

Outline

  1. Enable Android Bluetooth logging
  2. Run the Commander app and exercise the robot a bit
  3. Transfer the log to a PC
  4. Extract the serial data (RFCOMM) from the Bluetooth dump
  5. Decode the EV3 protocol
  6. Disassemble the EV3 instructions

1. Enable Android Bluetooth Logging

  • Open Settings
  • In the System section, choose Developers (this needs to be enabled first by tapping Build number 7 times)
  • Enable Bluetooth HCI Log

2. Run the Commander app and exercise the robot a bit

3. Transfer the log to a PC

Connect to the PC with a USB cable.

My older Android phone offered to mount its storage as a USB disk drive, but the newer one no longer has that option, offering MTP instead. I transfered the log file with a KDE tool:

$ kioclient cp 'mtp:/Xperia Z3/Interní úložiště/btsnoop_hci.log' .

4. Extract the serial data (RFCOMM) from the Bluetooth dump

The tool I made for this is btsnoop-decode.rb.

Читайте также:  Магнитола 310 фольксваген настройка блютуз

I learned the bare minimum needed about Bluetooth so it is very likely the tool only works for this specific use case.

Originally I opened the btsnoop log with Wireshark and guessed my way through the BT protocol layers. In the end the RFCOMM length field was harder than usual to guess and half of my packets were wrong. So I resorted to finding the appropriate part of the Linux kernel source to find out the format.

5+6. Decode the EV3 protocol and dissassemble the EV3 instructions

The people of the ev3dev project have already produced a disassembler which we will use in the next step. But that one assumes you start with a program file (RBF).

Here we have a log containing not only the usual RBF instructions but also System Commands.

I made an ugly hack of the lmsdisasm tool and arrived at a version that disassembles the log produced by the RFCOMM extractor.

Play time

The above experiments enabled me to put together a little script that can control the robot from a Linux terminal, having it ride around and even speak a custom sound file: lethargic-ministers/lms.py.

Источник

LEGO® MINDSTORMS® Education EV3

In EV3 Programming, you can connect your device with an EV3 Brick via Bluetooth in three ways:

ev3-bluetooth-connection-4adcd8136db992f9eee5974fb8d71095.jpg

  1. Start Block (on the Programming Canvas)
  2. No Brick Connected icon (in the top right hand corner of the Programming Canvas)
  3. Available Bricks button (on the Hardware Page)

When clicking/tapping on any of the above, a “Connect EV3 Brick to device” dialog box appears with connection instructions. Once done and the blue Connect button is clicked, a small empty “Select An Accessory/Device” dialog appears. This indicates that your device is searching for any available EV3 Bricks. If your device and EV3 Brick have not been connected before, this may take a minute. Please do not close the dialog. When your EV3 Brick appears as available, select it and click Pair. Confirm the pairing on your EV3 Brick. After a few seconds, your EV3 Brick and device should be connected.

Troubleshooting — iOS

If your EV3 Brick is not listed in the “Select An Accessory/Device” dialog box, please make sure Bluetooth is enabled and visible on your EV3 Brick and that you have checked the iPhone/iPad/iPod mode as shown below.

If your EV3 Brick still does not appear in the “Select An Accessory” dialog box, try to connect your EV3 Brick to your iPad from the Settings menu on the iPad by using the following steps:

  1. Go to Settings >> Bluetooth
  2. Make sure Bluetooth is turned on and let your iPad search for a minute or until your EV3 Brick is listed under My Devices
  3. Select your EV3 Brick and click Pair
  4. Confirm the pairing on your EV3 Brick
  5. After a few seconds, your iPad and EV3 Brick should be connected
Читайте также:  Bluetooth динамик jbl charge

You can now go back to the EV3 Programming app. The app will automatically target the EV3 Brick you just connected, if this EV3 Brick is the only one connected to your iPad.

ev3-enable-bluetooth-3e452edb6ed34f0023d94ed01f1aba16.jpg

Troubleshooting — Windows 10

If your EV3 Brick is not listed in the “Select An EV3 Brick” dialog box, please make sure Bluetooth is enabled and visible on your EV3 Brick and that you have unchecked the iPhone/iPad/iPod mode as shown below.

If your EV3 Brick still does not appear in the “Select An EV3 Brick” dialog box, try to connect your EV3 Brick from your device by using the following steps:

  1. Go to Settings >> Bluetooth >> Show Bluetooth Devices
  2. Make sure Bluetooth is turned on and let your tablet search for a minute, or until your EV3 Brick is listed under Bluetooth Devices
  3. ”When your EV3 brick appears and writes ’ready to pair’ you should click ’pair’
  4. A “Connect? (name of your device)” dialog box will appear on your EV3 Brick >> Accept >> A “PASSKEY” dialog box will appear on your EV3 Brick >> accept >> Enter the passcode on your device and click “Next” and it is connected

You can now go back to the EV3 Program Available Bricks >> Connect >> “Select An EV3 Brick” dialog box and click on the device.

If there are troubles connecting to Bluetooth the user should go to the native settings (settings of the tablet) and then remove the device (EV3) and reconnect

ev3-brick-bluetooth-c45b688540befb31203a1d443f31b28d.png

Troubleshooting — Android

If your EV3 Brick is not listed in the “Select An EV3 Brick” dialog box, please make sure Bluetooth is enabled and visible on your EV3 Brick and that you have unchecked the iPhone/iPad/iPod mode as shown below.

If your EV3 Brick still does not appear in the “Select An EV3 Brick” dialog box, try to connect your EV3 Brick to your device from the native settings by using the following steps:

  1. Go to Settings >> Bluetooth >> Available devices
  2. Make sure Bluetooth is turned on and let your tablet search for a minute, or until your EV3 Brick is listed under Bluetooth Devices
  3. Select your EV3 Brick and click it to Pair
  4. “Bluetooth pairing request” dialog box will appear >> Enter the code for your device, which is shown on the EV3 Brick “PASSKEY” >> click “OK”5 After a few seconds, your tablet and EV3 Brick should read

You can now go back to the EV3 Programming app. The app will automatically target the EV3 Brick you just connected, if this EV3 Brick is the only one connected to your tablet.

Источник

Оцените статью
Adblock
detector