Skip to content
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

Test existing micro bit LED project and upgrade it to work with micro bit V2 if needed. #51

Open
ellelili2025 opened this issue Jul 22, 2021 · 4 comments
Assignees

Comments

@ellelili2025
Copy link
Contributor

Please make sure the attached micro bit LED project work with latest micro bit V2.
MicrobitLED.aia.zip

Instructions:
http://iot.appinventor.mit.edu/assets/howtos/MIT_App_Inventor_Microbit_LED.pdf

@xyyshh
Copy link
Collaborator

xyyshh commented Aug 5, 2021

Dear Li,

I found that the function of showing text on the LED matrix on micro:bit doesn't work. I tried to fix it by using the blocks in Microbit_Uart extension instead of Microbit_Led extension. But I didn't find the reason why the blocks in picture 1 do not work.

May I ask whether it is ok to use the blocks in Microbit_Uart extension (picture 2) to realize the function of scrolling text on the LED matrix? It can achieve the expected result in the document.

picture 1:
image

picture 2:
image

Thank you!

Best regards,
Ying

@ellelili2025
Copy link
Contributor Author

@xyyshh I would like to at least get a full understanding of why writeLEDText doesn't work. I will take a look and let you know.

@xyyshh
Copy link
Collaborator

xyyshh commented Aug 12, 2021

@ellelili2025 Hi Li. I find a way to make writeLEDText work by editing the source code. I changed two parts of the file "Microbit_Led.java" at appinventor-extensions/appinventor/components/src/com/bbc/microbit/profile/.

  1. I changed some variables from type "String" to type "Integer". The code segments are from line 57 to line 63.

Initial code:

private final BluetoothLE.BLEResponseHandler<String> lEDTextHandler = new BluetoothLE.BLEResponseHandler<String>() {
@OverRide
public void onWrite(String serviceUuid, String characteristicUuid, List<String> values) {
WroteLEDText(values.get(0));
}
};

Revised code:

private final BluetoothLE.BLEResponseHandler<Integer> lEDTextHandler =
new BluetoothLE.BLEResponseHandler<Integer>() {
@OverRide
public void onWrite(String serviceUuid, String characteristicUuid, List<Integer> values) {
WroteLEDText(values);
}
};

  1. I changed the method of sending data to Micro:bit from sending String to sending Bytes. The code segments are from line 194 to line 200.

Initial code:

public void WriteLEDText(final String LED_Text_Value) {
if (bleConnection != null) {
bleConnection.ExWriteStringValuesWithResponse(LED_SERVICE_UUID, LED_TEXT_CHARACTERISTIC_UUID, false, LED_Text_Value, lEDTextHandler);
} else {
reportNullConnection("WriteLEDText");
}
}

Revised code:

public void WriteLEDText(final String LED_Text_Value) {
if (bleConnection != null) {
bleConnection.ExWriteByteValuesWithResponse(LED_SERVICE_UUID, LED_TEXT_CHARACTERISTIC_UUID, false, LED_Text_Value, lEDTextHandler);
} else {
reportNullConnection("WriteLEDText");
}
}

I think the main bug is that the BLE extension cannot directly send strings to microbit. Instead, it can send characters by sending bytes. That is also how the microbit Uart extension works. I tried to find why function "ExWriteStringValuesWithResponse()" in BLE extension doesn't work but I still have no idea about it.

I generated an .aix file from the revised code and tested it in app inventor. It works well to scroll text on micro:bit with no need to change the app inventor code and the tutorial. The initial code, revised code, .aix file are also attached: code_and_.aix.zip

I'm not sure whether my changes to the code are proper, while it works well. Could you please take a look at my code? Thank you very much.

Regards,
Ying

@xyyshh
Copy link
Collaborator

xyyshh commented Aug 25, 2021

@ellelili2025 Hi Li. I've tested the LED extension on microbit V1. For the writeLEDText function, the V1 also doesn't work with the original extension, while it works well with modified version. The other functions works well. Thanks.

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

No branches or pull requests

2 participants