kaluma-project / kaluma

A tiny JavaScript runtime for RP2040 (Raspberry Pi Pico)
https://kalumajs.org
Apache License 2.0
632 stars 38 forks source link

Onboard LED not blinking in Pico W #624

Closed kashyap1113 closed 10 months ago

kashyap1113 commented 11 months ago

Version: kaluma-rp2-pico-w-1.1.0-beta.4.uf2 kaluma-cli version: 1.4.0

I am trying to blink LED using Quick Start guide code. But its not working because in Pico W, the LED is not connected to pin 25. It is connected to WL_GPIO0 on the Infineon 43439 wireless chip for Pico W.

Check the official docs

I tried to replace 25 with 'WL_GPIO0' in code as shown below but it didn't work:

// index.js
const led = 'WL_GPIO0';
pinMode(led, OUTPUT);
setInterval(() => {
  digitalToggle(led);
}, 1000);

For reference, following is the equivalent python code that works with micropython

from machine import Pin
from time import sleep

led = Pin('WL_GPIO0', Pin.OUT)
while True:
    led.toggle()
    sleep(1)
jpacora commented 10 months ago

Use this code (as shown in https://kalumajs.org/docs/boards/pico-w):

const { PicoCYW43 } = require('pico_cyw43');
const pico_cyw43 = new PicoCYW43();

// Blink on-board LED
setInterval(() => {
  if (pico_cyw43.getGpio(0)) {
    pico_cyw43.putGpio(0, false); // turn-off LED
  } else {
    pico_cyw43.putGpio(0, true); // turn-on LED
  }
}, 1000);
kashyap1113 commented 10 months ago

My sincere apologies for creating an unnecessary issue. I'm unsure how I overlooked the documentation section.