-
Notifications
You must be signed in to change notification settings - Fork 247
Open
Description
I've tried to communicate with the STEPPER MOTOR module using the following code, it kept getting 0xFF response from the device. I've tried changing the bus speed slower/faster, but no avail. For sending, it doesn't work as well, with exceptions thrown (except for i2c.write() without parameters).
I've compared the MicroPython driver and this, they don't look that different to me.
Then I looked at their GRBL firmware and schematics - which the only curiosity I could spot is the GPIO16, GPIO17 connection, possible for the alternative UART firmware.
import I2C from "pins/i2c";
import Poco from "commodetto/Poco";
import Resource from "Resource";
import Timer from "timer";
const render = new Poco(screen);
const font = new Resource("8x8font.dat");
const i2c = new I2C({ address: 0x70 });
const black = render.makeColor(0, 0, 0);
const white = render.makeColor(255, 255, 255);
let lines = [""];
let renderedLines = 0;
let blink = true;
let question = false;
render.begin();
render.fillRectangle(black, 0, 0, render.width, render.height);
render.end();
Timer.repeat(() => {
while (1) {
let arr = i2c.read(1);
if (arr === undefined) {
question = false;
break;
}
if (arr[0] == 0xFF) {
question = true;
blink = !blink;
break;
} else if (arr[0] == 0x00) {
question = false;
blink = !blink;
break;
} else {
lines[lines.length - 1] += String.fromCharCode(arr[0]);
if (String.fromCharCode(arr[0]) == "\n") {
lines.push("");
break;
}
}
}
for (let i = renderedLines, y = renderedLines * 9; i < lines.length; i++ , y += 9) {
render.begin(0, y, render.width, 8);
render.fillRectangle(black, 0, 0, render.width, render.height);
render.drawText(lines[i], font, white, 0, y, render.width);
render.end();
}
let s = lines[lines.length - 1];
let c = question ? "?" : "_";
if (s[s.length - 1] == "\n") {
renderedLines = lines.length;
let y = renderedLines * 9;
render.begin(0, y, 8, 8);
render.fillRectangle(black, 0, 0, render.width, render.height);
render.drawText(blink ? c : "", font, white, 0, y, render.width);
render.end();
} else {
renderedLines = lines.length - 1;
let y = renderedLines * 9;
let x = lines[renderedLines].length * 9;
render.begin(x, y, 8, 8);
render.fillRectangle(black, 0, 0, render.width, render.height);
render.drawText(blink ? c : "", font, white, x, y, render.width);
render.end();
}
}, 500);It's supposed to grab the GRBL header when the (Arduino) module boots up. The same hardware has been tested on the MicroPython firmware with the following (similar) code, which they worked fine:
from m5stack import *
from m5ui import *
import i2c_bus
clear_bg(0x222222)
btnA = M5Button(name="ButtonA", text="ButtonA", visibility=False)
btnB = M5Button(name="ButtonB", text="ButtonB", visibility=False)
btnC = M5Button(name="ButtonC", text="ButtonC", visibility=False)
label1 = M5TextBox(15, 16, "Text", lcd.FONT_Default,0xFFFFFF, rotate=0)
i2c = i2c_bus.get(i2c_bus.PORTA)
s = ""
blink = True
while True:
while True:
c = i2c.readfrom(0x70, 1)
if c[0] == 0x00:
blink = not blink
break
else:
s = s + c.decode()
label1.setText(s + ("_" if blink else ""))
wait(1)Metadata
Metadata
Assignees
Labels
No labels