diff --git a/devs/samples/testrig.ts b/devs/samples/testrig.ts index 18629281ff..a5dc640af4 100644 --- a/devs/samples/testrig.ts +++ b/devs/samples/testrig.ts @@ -2,7 +2,7 @@ import * as ds from "@devicescript/core" import { SSD1306Driver, startBME680, - startCharacterScreen, + startCharacterScreenDisplay, } from "@devicescript/drivers" import { fetch } from "@devicescript/net" import { @@ -27,7 +27,7 @@ const servo = startServo({ pin: pins.A2 }) const potentiometer = startPotentiometer({ pin: pins.A0 }) const buzzer = startBuzzer({ pin: pins.A1 }) const { temperature, humidity, pressure } = await startBME680() -const display = await startCharacterScreen( +const display = await startCharacterScreenDisplay( new SSD1306Driver({ width: 64, height: 48 }) ) const btnA = new ds.Button() diff --git a/packages/drivers/src/characterscreen.ts b/packages/drivers/src/characterscreendisplay.ts similarity index 57% rename from packages/drivers/src/characterscreen.ts rename to packages/drivers/src/characterscreendisplay.ts index 0484c6c73a..c7eaa81215 100644 --- a/packages/drivers/src/characterscreen.ts +++ b/packages/drivers/src/characterscreendisplay.ts @@ -6,62 +6,30 @@ import { CharacterScreenServerSpec, assert, } from "@devicescript/core" -import { Image, fontForText, Font, Display } from "@devicescript/graphics" +import { fontForText, Display } from "@devicescript/graphics" class CharacterScreenServer extends Server implements CharacterScreenServerSpec { private _message: string - - private readonly _image: Image - private readonly _font: Font - private readonly _render: () => AsyncVoid + private readonly _render: (message: string) => AsyncVoid private readonly _columns: number private readonly _rows: number - /** - * Foreground color (palete index) - */ - color = 1 - // letter spacing - letterSpacing = 1 - // line spacing - lineSpacing = 1 - // outer margin - margin = 0 constructor( - options: { - display: Display - font: Font - } & CharacterScreenOptions & - ServerOptions + render: (message: string) => AsyncVoid, + options: CharacterScreenOptions & ServerOptions ) { super(ds.CharacterScreen.spec, options) - this._image = options.display.image - this._font = options.font - this._render = options.display.show + this._render = render this._columns = options.columns this._rows = options.rows - if (this._columns === undefined) - this._columns = Math.floor( - (this._image.width - 2 * this.margin) / - (this._font.charWidth + this.letterSpacing) - ) - if (this._rows === undefined) - this._rows = Math.floor( - (this._image.height - 2 * this.margin) / - (this._font.charHeight + this.lineSpacing) - ) - if (this._rows === undefined || this._columns === undefined) throw new Error("rows or columns is missing") this._message = "" - - // clear screen - if (this._image) this._image.fill(0) } message() { @@ -88,24 +56,68 @@ class CharacterScreenServer private async render() { assert(!!this._render) + await this._render(this._message) + } +} +export interface CharacterScreenOptions { + columns?: number + rows?: number +} + +/** + * Starts a character screen server. + */ +export async function startCharacterScreen( + render: (message: string) => AsyncVoid, + options: CharacterScreenOptions & ServerOptions = {} +) { + const server = new CharacterScreenServer(render, options) + return new CharacterScreen(startServer(server, options)) +} + +/** + * Starts a character screen server on a display. + */ +export async function startCharacterScreenDisplay( + display: Display, + options: CharacterScreenOptions & ServerOptions = {} +) { + const color = 1 + // letter spacing + const letterSpacing = 1 + // line spacing + const lineSpacing = 1 + // outer margin + const margin = 0 + + const font = fontForText("") + await display.init() + const image = display.image + await display.image.fill(0) + + let columns = options.columns + if (columns === undefined) + columns = Math.floor( + (image.width - 2 * margin) / (font.charWidth + letterSpacing) + ) + let rows = options.rows + if (rows === undefined) + rows = Math.floor( + (image.height - 2 * margin) / (font.charHeight + lineSpacing) + ) + + const render = async (message: string) => { // paint image - const img = this._image + const img = image const ctx = img.allocContext() - const columns = this._columns - const rows = this._rows - const message = this._message - - const cw = this._font.charWidth - const ch = this._font.charHeight - const letterSpacing = this.letterSpacing - const lineSpacing = this.lineSpacing - const margin = this.margin + const cw = font.charWidth + const ch = font.charHeight - ctx.font = this._font - ctx.fillColor = this.color - ctx.strokeColor = this.color + ctx.font = font + ctx.fillColor = color + ctx.strokeColor = color ctx.clear() ctx.translate(margin, margin) @@ -126,31 +138,8 @@ class CharacterScreenServer } // flush buffer - await this._render() + await display.show() } -} - -export interface CharacterScreenOptions { - columns?: number - rows?: number -} -/** - * Starts a character screen server on a display. - */ -export async function startCharacterScreen( - display: Display, - options: CharacterScreenOptions & ServerOptions = {} -) { - const font = fontForText("") - - await display.init() - - const server = new CharacterScreenServer({ - display, - font, - ...options, - }) - - return new CharacterScreen(startServer(server, options)) + return await startCharacterScreen(render, options) } diff --git a/packages/drivers/src/grovergblcd.ts b/packages/drivers/src/grovergblcd.ts new file mode 100644 index 0000000000..c0caa823a1 --- /dev/null +++ b/packages/drivers/src/grovergblcd.ts @@ -0,0 +1,182 @@ +import "@dsboard/seeed_xiao_esp32c3" +import * as ds from "@devicescript/core" +import { I2CDriver, startCharacterScreen } from "@devicescript/drivers" +import { delay } from "@devicescript/core" + +// Device I2C Arress +const LCD_ADDRESS = 0x7c >> 1 +const RGB_ADDRESS = 0xc4 >> 1 +const RGB_ADDRESS_V5 = 0x30 + +// color define +const WHITE = 0 +const RED = 1 +const GREEN = 2 +const BLUE = 3 + +const REG_MODE1 = 0x00 +const REG_MODE2 = 0x01 +const REG_OUTPUT = 0x08 + +// commands +const LCD_CLEARDISPLAY = 0x01 +const LCD_RETURNHOME = 0x02 +const LCD_ENTRYMODESET = 0x04 +const LCD_DISPLAYCONTROL = 0x08 +const LCD_CURSORSHIFT = 0x10 +const LCD_FUNCTIONSET = 0x20 +const LCD_SETCGRAMADDR = 0x40 +const LCD_SETDDRAMADDR = 0x80 + +// flags for display entry mode +const LCD_ENTRYRIGHT = 0x00 +const LCD_ENTRYLEFT = 0x02 +const LCD_ENTRYSHIFTINCREMENT = 0x01 +const LCD_ENTRYSHIFTDECREMENT = 0x00 + +// flags for display on/off control +const LCD_DISPLAYON = 0x04 +const LCD_DISPLAYOFF = 0x00 +const LCD_CURSORON = 0x02 +const LCD_CURSOROFF = 0x00 +const LCD_BLINKON = 0x01 +const LCD_BLINKOFF = 0x00 + +// flags for display/cursor shift +const LCD_DISPLAYMOVE = 0x08 +const LCD_CURSORMOVE = 0x00 +const LCD_MOVERIGHT = 0x04 +const LCD_MOVELEFT = 0x00 + +// flags for function set +const LCD_8BITMODE = 0x10 +const LCD_4BITMODE = 0x00 +const LCD_2LINE = 0x08 +const LCD_1LINE = 0x00 +const LCD_5x10DOTS = 0x04 +const LCD_5x8DOTS = 0x00 + +// https://wiki.seeedstudio.com/Grove-16x2_LCD_Series/#specification +// converted from https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight/ +export class GroveRGBLCD extends I2CDriver { + readonly columns: number + readonly lines: number + readonly dotsize: number + private _displayfunction: number = 0 + private _displaymode: number = 0 + private _displaycontrol: number = 0 + private _currline: number = 0 + + constructor( + readonly options: { + columns: number + rows: number + dotsize: number + devAddr?: number + } + ) { + super(options.devAddr || LCD_ADDRESS) + this.columns = options.columns + this.lines = options.rows + this.dotsize = options.dotsize + } + + async initDriver(): Promise { + if (this.lines > 1) { + this._displayfunction |= LCD_2LINE + } + this._currline = 0 + + // for some 1 line displays you can select a 10 pixel high font + if (this.dotsize !== 0 && this.lines === 1) { + this._displayfunction |= LCD_5x10DOTS + } + + // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! + // according to datasheet, we need at least 40ms after power rises above 2.7V + // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 + // delayMicroseconds(50000); + await delay(5) + + // this is according to the hitachi HD44780 datasheet + // page 45 figure 23 + + // Send function set command sequence + await this.command(LCD_FUNCTIONSET | this._displayfunction) + await delay(5) // wait more than 4.1ms + + // second try + await this.command(LCD_FUNCTIONSET | this._displayfunction) + await delay(1) + + // third go + await this.command(LCD_FUNCTIONSET | this._displayfunction) + + // finally, set # lines, font size, etc. + await this.command(LCD_FUNCTIONSET | this._displayfunction) + + // turn the display on with no cursor or blinking default + this._displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF + await this.display() + + // clear it off + await this.clear() + + // Initialize to default text direction (for romance languages) + this._displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT + // set the entry mode + await this.command(LCD_ENTRYMODESET | this._displaymode) + } + + private async command(value: number): Promise { + await this.writeBuf(Buffer.from([0x80, value])) + } + + private async display() { + this._displaycontrol |= LCD_DISPLAYON + await this.command(LCD_DISPLAYCONTROL | this._displaycontrol) + } + + async clear() { + await this.command(LCD_CLEARDISPLAY) // clear display, set cursor position to zero + await delay(2) // this command takes a long time! + } + + private async write(value: number) { + await this.writeBuf(Buffer.from([0x40, value])) + } + + async render(message: string) { + await this.clear() + if (message?.length > 0) + for (let i = 0; i < message.length; ++i) { + await this.write(message.charCodeAt(i)) + } + } +} + +/** + * Driver for the Grove RGB LCD 16x2 display. + * @devsParts Grove RGB LCD 16x2 + * @devsWhenUsed + */ +export async function startGroveRGBLCD16x2() { + const columns = 16 + const rows = 2 + + let render: (message: string) => ds.AsyncVoid = undefined + if (!ds.isSimulator()) { + const lcd = new GroveRGBLCD({ + columns, + rows, + dotsize: 0, + devAddr: LCD_ADDRESS, + }) + await lcd.init() + render = async (message: string) => await lcd.render(message) + } + return await startCharacterScreen(render, { + columns, + rows, + }) +} diff --git a/packages/drivers/src/index.ts b/packages/drivers/src/index.ts index 9e2cc47305..891c5b2dfc 100644 --- a/packages/drivers/src/index.ts +++ b/packages/drivers/src/index.ts @@ -8,7 +8,7 @@ export * from "./aht20" export * from "./ltr390" export * from "./bme680" export * from "./ssd1306" -export * from "./characterscreen" +export * from "./characterscreendisplay" export * from "./indexedscreen" export * from "./dotmatrix" export * from "./st7735" @@ -18,10 +18,12 @@ export * from "./ledserver" export * from "./accelerometer" export * from "./sh110x" export * from "./da213b" +export * from "./grovergblcd" export * from "./esp32c3fh4rgb" export * from "./picobricks" export * from "./xiaoexpansionboard" +export * from "./xiaogroveshield" export * from "./wavesharepicolcd114" export * from "./pimoronipicobadger" export * from "./kittenbotgrapebit" diff --git a/packages/drivers/src/xiaoexpansionboard.ts b/packages/drivers/src/xiaoexpansionboard.ts index 8669bccc76..3f265e3127 100644 --- a/packages/drivers/src/xiaoexpansionboard.ts +++ b/packages/drivers/src/xiaoexpansionboard.ts @@ -8,7 +8,7 @@ import { pins } from "@dsboard/seeed_xiao_esp32c3" /** * - * Drivers for the {@link https://wiki.seeedstudio.com/Seeeduino-XIAO-Expansion-Board/ | Seeed Studio XIAO Expansion Board } for Raspberry Pi Pico. + * Drivers for the {@link https://wiki.seeedstudio.com/Seeeduino-XIAO-Expansion-Board/ | Seeed Studio XIAO Expansion Board }. * * @devsPart Seeed Studio XIAO Expansion Board * @devsWhenUsed @@ -26,7 +26,7 @@ export class XiaoExpansionBoard { /** * Starts a server for the OLED display. - * @returns + * @returns */ async startDisplay() { const disp = new SSD1306Driver({ diff --git a/packages/drivers/src/xiaogroveshield.ts b/packages/drivers/src/xiaogroveshield.ts new file mode 100644 index 0000000000..544894b7d5 --- /dev/null +++ b/packages/drivers/src/xiaogroveshield.ts @@ -0,0 +1,21 @@ +import { configureHardware } from "@devicescript/servers" +import { pins } from "@dsboard/seeed_xiao_esp32c3" + +/** + * + * Drivers for the {@link https://www.seeedstudio.com/Grove-Shield-for-Seeeduino-XIAO-p-4621.html | Grove Shield for Seeed Studio XIAO } for Raspberry Pi Pico. + * + * @devsPart Grove Shield for Seeed Studio XIAO + * @devsWhenUsed + */ +export class XiaoGroveShield { + constructor() { + configureHardware({ + i2c: { + pinSCL: pins.SCL_D5, + pinSDA: pins.SDA_D4, + kHz: 400, + }, + }) + } +} diff --git a/packages/sampleprj/src/maincharacterscreen.ts b/packages/sampleprj/src/maincharacterscreen.ts index 0bd26985fa..aadbc25c9a 100644 --- a/packages/sampleprj/src/maincharacterscreen.ts +++ b/packages/sampleprj/src/maincharacterscreen.ts @@ -1,5 +1,8 @@ import { pins, board } from "@dsboard/pico_w" -import { SSD1306Driver, startCharacterScreen } from "@devicescript/drivers" +import { + SSD1306Driver, + startCharacterScreenDisplay, +} from "@devicescript/drivers" import { configureHardware } from "@devicescript/servers" import { delay } from "@devicescript/core" @@ -11,7 +14,7 @@ configureHardware({ kHz: 400, }, }) -const screen = await startCharacterScreen( +const screen = await startCharacterScreenDisplay( new SSD1306Driver({ width: 128, height: 64, diff --git a/packages/sampleprj/src/mainesp32characterscreen.ts b/packages/sampleprj/src/mainesp32characterscreen.ts index b07cab3f09..330770b87c 100644 --- a/packages/sampleprj/src/mainesp32characterscreen.ts +++ b/packages/sampleprj/src/mainesp32characterscreen.ts @@ -1,8 +1,11 @@ import { pins, board } from "@dsboard/seeed_xiao_esp32c3_msr218" -import { SSD1306Driver, startCharacterScreen } from "@devicescript/drivers" +import { + SSD1306Driver, + startCharacterScreenDisplay, +} from "@devicescript/drivers" import "@devicescript/graphics" -const screen = await startCharacterScreen( +const screen = await startCharacterScreenDisplay( new SSD1306Driver({ width: 128, height: 64, diff --git a/packages/sampleprj/src/maingrovelcd16x2.ts b/packages/sampleprj/src/maingrovelcd16x2.ts index 4b3b416127..d1386ddd8a 100644 --- a/packages/sampleprj/src/maingrovelcd16x2.ts +++ b/packages/sampleprj/src/maingrovelcd16x2.ts @@ -1,172 +1,16 @@ import "@dsboard/seeed_xiao_esp32c3" import * as ds from "@devicescript/core" -import { I2CDriver, XiaoExpansionBoard } from "@devicescript/drivers" -import { delay } from "@devicescript/core" -import { configureHardware } from "@devicescript/servers" +import { + XiaoGroveShield, + startGroveRGBLCD16x2, + startBME680, +} from "@devicescript/drivers" -// Device I2C Arress -const LCD_ADDRESS = 0x7c >> 1 -const RGB_ADDRESS = 0xc4 >> 1 -const RGB_ADDRESS_V5 = 0x30 +const board = new XiaoGroveShield() -// color define -const WHITE = 0 -const RED = 1 -const GREEN = 2 -const BLUE = 3 - -const REG_MODE1 = 0x00 -const REG_MODE2 = 0x01 -const REG_OUTPUT = 0x08 - -// commands -const LCD_CLEARDISPLAY = 0x01 -const LCD_RETURNHOME = 0x02 -const LCD_ENTRYMODESET = 0x04 -const LCD_DISPLAYCONTROL = 0x08 -const LCD_CURSORSHIFT = 0x10 -const LCD_FUNCTIONSET = 0x20 -const LCD_SETCGRAMADDR = 0x40 -const LCD_SETDDRAMADDR = 0x80 - -// flags for display entry mode -const LCD_ENTRYRIGHT = 0x00 -const LCD_ENTRYLEFT = 0x02 -const LCD_ENTRYSHIFTINCREMENT = 0x01 -const LCD_ENTRYSHIFTDECREMENT = 0x00 - -// flags for display on/off control -const LCD_DISPLAYON = 0x04 -const LCD_DISPLAYOFF = 0x00 -const LCD_CURSORON = 0x02 -const LCD_CURSOROFF = 0x00 -const LCD_BLINKON = 0x01 -const LCD_BLINKOFF = 0x00 - -// flags for display/cursor shift -const LCD_DISPLAYMOVE = 0x08 -const LCD_CURSORMOVE = 0x00 -const LCD_MOVERIGHT = 0x04 -const LCD_MOVELEFT = 0x00 - -// flags for function set -const LCD_8BITMODE = 0x10 -const LCD_4BITMODE = 0x00 -const LCD_2LINE = 0x08 -const LCD_1LINE = 0x00 -const LCD_5x10DOTS = 0x04 -const LCD_5x8DOTS = 0x00 - -// https://wiki.seeedstudio.com/Grove-16x2_LCD_Series/#specification -// converted from https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight/ -class RGBLCD extends I2CDriver { - readonly columns: number - readonly lines: number - readonly dotsize: number - private _displayfunction: number = 0 - private _displaymode: number = 0 - private _displaycontrol: number = 0 - private _currline: number = 0 - - constructor( - readonly options: { - columns: number - rows: number - dotsize: number - devAddr?: number - } - ) { - super(options.devAddr || LCD_ADDRESS) - this.columns = options.columns - this.lines = options.rows - this.dotsize = options.dotsize - } - - async initDriver(): Promise { - if (this.lines > 1) { - this._displayfunction |= LCD_2LINE - } - this._currline = 0 - - // for some 1 line displays you can select a 10 pixel high font - if (this.dotsize !== 0 && this.lines === 1) { - this._displayfunction |= LCD_5x10DOTS - } - - // SEE PAGE 45/46 FOR INITIALIZATION SPECIFICATION! - // according to datasheet, we need at least 40ms after power rises above 2.7V - // before sending commands. Arduino can turn on way befer 4.5V so we'll wait 50 - // delayMicroseconds(50000); - await delay(5) - - // this is according to the hitachi HD44780 datasheet - // page 45 figure 23 - - // Send function set command sequence - await this.command(LCD_FUNCTIONSET | this._displayfunction) - await delay(5) // wait more than 4.1ms - - // second try - await this.command(LCD_FUNCTIONSET | this._displayfunction) - await delay(1) - - // third go - await this.command(LCD_FUNCTIONSET | this._displayfunction) - - // finally, set # lines, font size, etc. - await this.command(LCD_FUNCTIONSET | this._displayfunction) - - // turn the display on with no cursor or blinking default - this._displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF - await this.display() - - // clear it off - await this.clear() - - // Initialize to default text direction (for romance languages) - this._displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT - // set the entry mode - await this.command(LCD_ENTRYMODESET | this._displaymode) - } - - private async command(value: number): Promise { - await this.writeBuf(Buffer.from([0x80, value])) - } - - private async display() { - this._displaycontrol |= LCD_DISPLAYON - await this.command(LCD_DISPLAYCONTROL | this._displaycontrol) - } - - async clear() { - await this.command(LCD_CLEARDISPLAY) // clear display, set cursor position to zero - await delay(2) // this command takes a long time! - } - - private async write(value: number) { - await this.writeBuf(Buffer.from([0x40, value])) - } - - async print(str: string) { - for (let i = 0; i < str.length; ++i) { - await this.write(str.charCodeAt(i)) - } - } -} - -const board = new XiaoExpansionBoard() - -console.log("start...") -const lcd = new RGBLCD({ - columns: 16, - rows: 2, - dotsize: 0, - devAddr: LCD_ADDRESS, -}) -await lcd.init() +const { temperature } = await startBME680() +const lcd = await startGroveRGBLCD16x2() setInterval(async () => { - const t = ds.millis() + "" - console.log(t) - await lcd.clear() - await lcd.print(t) + const temp = Math.round(await temperature.reading.read()) + await lcd.message.write(`temp: ${temp}C`) }, 1000) diff --git a/packages/sampleprj/src/mainwroomssd1306.ts b/packages/sampleprj/src/mainwroomssd1306.ts index f8dc2f1e1c..821ccc6621 100644 --- a/packages/sampleprj/src/mainwroomssd1306.ts +++ b/packages/sampleprj/src/mainwroomssd1306.ts @@ -1,5 +1,5 @@ // https://github.com/microsoft/devicescript/issues/559 -import { SSD1306Driver, startCharacterScreen } from "@devicescript/drivers"; +import { SSD1306Driver, startCharacterScreenDisplay } from "@devicescript/drivers"; import { configureHardware } from "@devicescript/servers"; // https://microsoft.github.io/devicescript/devices/esp32/esp32-devkit-c import { pins } from "@dsboard/esp32_devkit_c"; @@ -15,5 +15,5 @@ configureHardware({ // double check i2c addr const ssdDisplay = new SSD1306Driver({ height: 64, width: 128, devAddr: 0x3d }) -const characterScreen = await startCharacterScreen(ssdDisplay) +const characterScreen = await startCharacterScreenDisplay(ssdDisplay) await characterScreen.message.write("Hello world!") \ No newline at end of file diff --git a/vscode/src/server-info.json b/vscode/src/server-info.json index eede77a52b..d0429593e3 100644 --- a/vscode/src/server-info.json +++ b/vscode/src/server-info.json @@ -254,7 +254,7 @@ }, { "label": "Sensirion SHTC3", - "detail": "Start driver for Sensirion SHTC3 temperature/humidity sensor at I2C `0x70`.", + "detail": "Start driver for Sensirion SHTC3 temperature/humidity sensor at I2C `0x70`.\r", "startName": "startSHTC3", "classIdentifiers": [ 337754823, @@ -267,7 +267,7 @@ }, { "label": "Sensirion SHT30", - "detail": "Start driver for Sensirion SHT30 temperature/humidity sensor at I2C `0x44` or `0x45` (default is `0x44`)", + "detail": "Start driver for Sensirion SHT30 temperature/humidity sensor at I2C `0x44` or `0x45` (default is `0x44`)\r", "startName": "startSHT30", "classIdentifiers": [ 337754823, @@ -280,7 +280,7 @@ }, { "label": "AHT20", - "detail": "Start driver for AHT20 temperature/humidity sensor at I2C address `0x38`.", + "detail": "Start driver for AHT20 temperature/humidity sensor at I2C address `0x38`.\r", "startName": "startAHT20", "classIdentifiers": [ 337754823, @@ -293,7 +293,7 @@ }, { "label": "LITEON LTR-390UV-01", - "detail": "Start driver for LITEON LTR-390UV-01 UV/ambient light sensor at I2C address `0x53`.", + "detail": "Start driver for LITEON LTR-390UV-01 UV/ambient light sensor at I2C address `0x53`.\r", "startName": "startLTR390", "classIdentifiers": [ 527306128, @@ -306,7 +306,7 @@ }, { "label": "Bosch BME68", - "detail": "Start driver for Bosch BME680 temperature/humidity/pressure/gas sensor at I2C `0x76` (default) or `0x77`.", + "detail": "Start driver for Bosch BME680 temperature/humidity/pressure/gas sensor at I2C `0x76` (default) or `0x77`.\r", "startName": "startBME680", "classIdentifiers": [ 337754823, @@ -321,7 +321,7 @@ }, { "label": "Pico Bricks for Raspberry Pi Pico", - "detail": "Drivers for the {@link https://shop.robotistan.com/products/pico-bricks | Pico Bricks } shield for Raspberry Pi Pico ({@link https://github.com/Robotistan/PicoBricks/tree/main/Documents | datasheets}).", + "detail": "Drivers for the {@link https://shop.robotistan.com/products/pico-bricks | Pico Bricks } shield for Raspberry Pi Pico ({@link https://github.com/Robotistan/PicoBricks/tree/main/Documents | datasheets}).\r", "startName": "PicoBricks", "imports": { "PicoBricks": "@devicescript/drivers" @@ -330,16 +330,25 @@ }, { "label": "Seeed Studio XIAO Expansion Board", - "detail": "Drivers for the {@link https://wiki.seeedstudio.com/Seeeduino-XIAO-Expansion-Board/ | Seeed Studio XIAO Expansion Board } for Raspberry Pi Pico.", + "detail": "Drivers for the {@link https://wiki.seeedstudio.com/Seeeduino-XIAO-Expansion-Board/ | Seeed Studio XIAO Expansion Board }.\r", "startName": "XiaoExpansionBoard", "imports": { "XiaoExpansionBoard": "@devicescript/drivers" }, "snippet": "const shield = new XiaoExpansionBoard()\n" }, + { + "label": "Grove Shield for Seeed Studio XIAO", + "detail": "Drivers for the {@link https://www.seeedstudio.com/Grove-Shield-for-Seeeduino-XIAO-p-4621.html | Grove Shield for Seeed Studio XIAO } for Raspberry Pi Pico.\r", + "startName": "XiaoGroveShield", + "imports": { + "XiaoGroveShield": "@devicescript/drivers" + }, + "snippet": "const shield = new XiaoGroveShield()\n" + }, { "label": "WaveShare Pico LCD114 for Raspberry Pi Pico", - "detail": "Driver for WaveShare Pico-LCD-1.14 inch.", + "detail": "Driver for WaveShare Pico-LCD-1.14 inch.\r", "startName": "WaveSharePicoLCD114", "imports": { "WaveSharePicoLCD114": "@devicescript/drivers" @@ -348,7 +357,7 @@ }, { "label": "Pimoroni Pico Badger", - "detail": "Support for Badger 2040 W (Pico W Aboard)", + "detail": "Support for Badger 2040 W (Pico W Aboard)\r", "startName": "PimoroniBadger2040W", "imports": { "PimoroniBadger2040W": "@devicescript/drivers" @@ -357,7 +366,7 @@ }, { "label": "KittenBot Grape:bit ESP32-C3", - "detail": "Support for KittenBot Grape:bit ESP32-C3", + "detail": "Support for KittenBot Grape:bit ESP32-C3\r", "startName": "KittenBotGrapeBit", "imports": { "KittenBotGrapeBit": "@devicescript/drivers" diff --git a/website/docs/api/drivers/aht20.mdx b/website/docs/api/drivers/aht20.md similarity index 100% rename from website/docs/api/drivers/aht20.mdx rename to website/docs/api/drivers/aht20.md diff --git a/website/docs/api/drivers/bme680.mdx b/website/docs/api/drivers/bme680.md similarity index 100% rename from website/docs/api/drivers/bme680.mdx rename to website/docs/api/drivers/bme680.md diff --git a/website/docs/api/drivers/grovergblcd16x2.mdx b/website/docs/api/drivers/grovergblcd16x2.mdx new file mode 100644 index 0000000000..dda76f5776 --- /dev/null +++ b/website/docs/api/drivers/grovergblcd16x2.mdx @@ -0,0 +1,20 @@ +# Grove RGB LCD 16x2 + +Driver for Grove RGB LCD 16x2 Character screen at address `0x3e`. + +- Services: [character screen](/api/clients/characterscreen/) +- [Seeed Wiki](https://github.com/Seeed-Studio/Grove_LCD_RGB_Backlight/) + +## Usage + +```ts +import { startGroveRGBLCD16x2 } from "@devicescript/drivers" +const screen = await startGroveRGBLCD16x2() + +await screen.message.write(":)") +``` + +## Configuration + +- Configure I2C throught the [board configuration](/developer/board-configuration) +- Check that you are using the correct I2C address diff --git a/website/docs/developer/graphics/display.mdx b/website/docs/developer/graphics/display.mdx index fa3789de07..2238368922 100644 --- a/website/docs/developer/graphics/display.mdx +++ b/website/docs/developer/graphics/display.mdx @@ -47,9 +47,12 @@ Using the service is compatible with the simulator. - [Source](https://github.com/microsoft/devicescript/blob/main/packages/drivers/src/characterscreen.ts) ```ts -import { SSD1306Driver, startCharacterScreen } from "@devicescript/drivers" +import { + SSD1306Driver, + startCharacterScreenDisplay, +} from "@devicescript/drivers" -const screen = await startCharacterScreen( +const screen = await startCharacterScreenDisplay( new SSD1306Driver({ width: 128, height: 64 }) ) await screen.message.write(`hello diff --git a/website/docs/devices/shields/xiao-expansion-board.mdx b/website/docs/devices/shields/xiao-expansion-board.mdx index 386e7aa1dc..3442caec51 100644 --- a/website/docs/devices/shields/xiao-expansion-board.mdx +++ b/website/docs/devices/shields/xiao-expansion-board.mdx @@ -18,10 +18,13 @@ click the **wand** icon on the file menu and select "Seeed Xiao ESP32-C3 Expansion board". ```ts -import { XiaoExpansionBoard, startCharacterScreen } from "@devicescript/drivers" +import { + XiaoExpansionBoard, + startCharacterScreenDisplay, +} from "@devicescript/drivers" const shield = new XiaoExpansionBoard() -const display = await startCharacterScreen(await shield.startDisplay()) +const display = await startCharacterScreenDisplay(await shield.startDisplay()) const buzzer = await shield.startBuzzer() const button = await shield.startButton() ``` diff --git a/website/docs/devices/shields/xiao-grove-shield.mdx b/website/docs/devices/shields/xiao-grove-shield.mdx new file mode 100644 index 0000000000..9479627437 --- /dev/null +++ b/website/docs/devices/shields/xiao-grove-shield.mdx @@ -0,0 +1,23 @@ +--- +title: Grove Shield for Seeed Studio XIAO ESP32-C3 +--- + +# Grove Shield for Seeed Xiao ESP32-C3 + +- Device: [Seeed Xiao ESP32-C3](/devices/esp32/seeed-xiao-esp32c3) or [Adafruit QT Py C3](/devices/esp32/adafruit-qt-py-c3) +- [Home](https://www.seeedstudio.com/Grove-Shield-for-Seeeduino-XIAO-p-4621.html) + +![Photograph of shield](/img/shields/grove-shield-xiao.webp) + +## DeviceScript import + +You must import `XiaoGroveShield` to access the shield services. + +In [Visual Studio Code](/getting-started/vscode), +click the **wand** icon on the file menu and +select "Grove Shield for Seeed XIAO". + +```ts +import { XiaoGroveShield } from "@devicescript/drivers" +const shield = new XiaoGroveShield() // configure i2c +``` diff --git a/website/docs/samples/weather-dashboard.mdx b/website/docs/samples/weather-dashboard.mdx index fa0193eaaa..c9074d4abc 100644 --- a/website/docs/samples/weather-dashboard.mdx +++ b/website/docs/samples/weather-dashboard.mdx @@ -50,7 +50,6 @@ setInterval(async () => { }, 1000) ``` - ## Xiao + Expansion board + BME680 The generic sample above can be specialized to run on a Xiao ESP32-C3 with expansion board. @@ -58,17 +57,17 @@ The generic sample above can be specialized to run on a Xiao ESP32-C3 with expan ```ts import { XiaoExpansionBoard, - startCharacterScreen, + startCharacterScreenDisplay, startBME680, } from "@devicescript/drivers" import { ValueDashboard } from "@devicescript/runtime" const board = new XiaoExpansionBoard() const { temperature, humidity } = await startBME680({ - address: 0x76 + address: 0x76, }) const display = await board.startDisplay() -const screen = await startCharacterScreen(display) +const screen = await startCharacterScreenDisplay(display) const dashboard = new ValueDashboard(screen, { temperature: { digits: 1, unit: "C" }, @@ -80,4 +79,5 @@ setInterval(async () => { dashboard.values.humi = await humidity.reading.read() await dashboard.show() }, 1000) -``` \ No newline at end of file +``` + \ No newline at end of file diff --git a/website/docs/samples/weather-display.mdx b/website/docs/samples/weather-display.mdx index 3e753ccef4..cbf4a08ee9 100644 --- a/website/docs/samples/weather-display.mdx +++ b/website/docs/samples/weather-display.mdx @@ -25,9 +25,12 @@ Let's start by mounting a `sensor` client and logging each sensor reading to the ```tsx import { startSHT30 } from "@devicescript/drivers" -import { SSD1306Driver, startCharacterScreen } from "@devicescript/drivers" +import { + SSD1306Driver, + startCharacterScreenDisplay, +} from "@devicescript/drivers" -const screen = await startCharacterScreen( +const screen = await startCharacterScreenDisplay( new SSD1306Driver({ width: 128, height: 64 }) ) const { temperature, humidity } = await startSHT30() diff --git a/website/static/img/shields/grove-shield-xiao.webp b/website/static/img/shields/grove-shield-xiao.webp new file mode 100644 index 0000000000..d495db6657 Binary files /dev/null and b/website/static/img/shields/grove-shield-xiao.webp differ