Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

make code microbit and crickit signals
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

make code microbit and crickit signals

by nickine9 on Mon May 11, 2020 6:04 am

I am trying to use 6 signal connectors linked to tilt switches for a nerf shooting game. I prototyped one target and got in working so i wired up the other five and its doesn't work as expected.

if all switches are on the program works and lights a led on a neopixel ring for each contact but if one switch is off it seems the other are ignored.

I am using restistors for the switches

I saw a note at the top of the signals page of your cricket guide that they can sometimes lock using a circuit playground but that they can be used with a microbit.

it is more than likely i have done something silly with my wiring, which is a bit spaghetti like, but before i do another teardown and rebuild I thought i would check if anyone else has experienced similar problems and found a workaround.

thanks in advance for any help and may i say how totally impressed I am by your covid related efforts.

nickine9
 
Posts: 139
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Fri May 15, 2020 3:46 pm

Sounds fun! Please upload clear photos of your wiring setup and code so we can try to help troubleshoot.

johnpark
 
Posts: 758
Joined: Wed Mar 25, 2009 2:15 pm

Re: make code microbit and crickit signals

by nickine9 on Sat May 16, 2020 7:30 am

Hi John,

Thanks for the reply. I have done my best to provide a clear photo but lighting conditions in my work room are not great.

IMG_1024.jpeg
IMG_1024.jpeg (97.17 KiB) Viewed 170 times


the javascript code from make code is
Code: Select all | TOGGLE FULL SIZE
let strip = neopixel.create(DigitalPin.P16, 7, NeoPixelMode.RGB)
basic.forever(function () {
    if (crickit.signal1.digitalRead()) {
        strip.setPixelColor(2, neopixel.colors(NeoPixelColors.Red))
        strip.show()
        basic.pause(1000)
    }
    if (crickit.signal2.digitalRead()) {
        strip.setPixelColor(1, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
        basic.pause(1000)
    }
    strip.clear()
    strip.show()
    basic.pause(500)
    strip.showColor(neopixel.colors(NeoPixelColors.Green))
    basic.pause(1000)
})


The symptoms are

if both switches are on two leds light up on the neopixel ring, but if only one switch is on neither Led lights up. I get the same symptoms if i connect more switches (and change the code appropriately). I have also tried with analogue reads (different code) and got the same symptoms.

stay safe

nick

nickine9
 
Posts: 139
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Mon May 18, 2020 4:28 pm

I'm wondering if you want the logic to look more like this:
Code: Select all | TOGGLE FULL SIZE
let strip = neopixel.create(DigitalPin.P16, 7, NeoPixelMode.RGB)
basic.forever(function () {
    if (crickit.signal1.digitalRead()) {
        strip.setPixelColor(2, neopixel.colors(NeoPixelColors.Red))
        strip.show()
        basic.pause(1000)
    } else if (crickit.signal2.digitalRead()) {
        strip.setPixelColor(1, neopixel.colors(NeoPixelColors.Blue))
        strip.show()
        basic.pause(1000)
    } else {
        strip.clear()
        strip.show()
        basic.pause(500)
        strip.showColor(neopixel.colors(NeoPixelColors.Green))
        basic.pause(1000)
    }
})

johnpark
 
Posts: 758
Joined: Wed Mar 25, 2009 2:15 pm

Re: make code microbit and crickit signals

by nickine9 on Tue May 19, 2020 3:47 am

Hi John

thanks for the reply. I test each button with a separate if statement (without the else if) because in some scenarios I need to check all the buttons in one pass. In terms of this project I have a similar version of my code running on a CPX but would really like to run it on the microbit/crickit combo as I want to use servos to move the targets but only if i can make the signals work.

nick

nickine9
 
Posts: 139
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by nickine9 on Sat Jun 13, 2020 8:22 am

I migrated the project to a cox and got it working (without moving targets) and now have had a bit of time to revisit the microbic/crickit combination

having tried multi[ple combinations of buttons i still find

if one button is pressed the rest also respond as being pressed even if they are not

Also all the previous tests i did were with the usb connected to the microbit. if the system is powered through the mains via the crickit without the usb connection to the microbit I find that using a single button causes the microbit to reboot. again i have tried this with different switches and the switch is recognised if there is a usb connection to the microbit.

in all cases the switches have had a resistor connected to 3v with the data fed off that.

all the other bits of the crickit that i have tested seem to work (neopixels servos speaker.)

nickine9
 
Posts: 139
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Tue Jun 16, 2020 6:02 pm

Those are some odd symptoms. I'm going to try to replicate the hardware and software and try this soon.

johnpark
 
Posts: 758
Joined: Wed Mar 25, 2009 2:15 pm

Re: make code microbit and crickit signals

by nickine9 on Wed Jul 01, 2020 5:42 am

hi john,

I don't want to seem like a nag and I realise that you all have many calls on your time but have you managed to get any feedback yet?

nickine9
 
Posts: 139
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Mon Jul 06, 2020 3:47 pm

Hi, I just hooked up four buttons w resistors to four Crickit signal inputs, and they are working fine without conflict. These are the buttons I used https://www.adafruit.com/product/4431. I powered the Cricket with three 1.5V Alkaline AA batteries.
Here's my test code
Code: Select all | TOGGLE FULL SIZE
basic.forever(function () {
    if (crickit.signal1.digitalRead()) {
        led.plot(0, 0)
        led.unplot(1, 0)
    } else if (!(crickit.signal1.digitalRead())) {
        led.plot(1, 0)
        led.unplot(0, 0)
    }
    if (crickit.signal2.digitalRead()) {
        led.plot(0, 1)
        led.unplot(1, 1)
    } else if (!(crickit.signal2.digitalRead())) {
        led.plot(1, 1)
        led.unplot(0, 1)
    }
    if (crickit.signal3.digitalRead()) {
        led.plot(0, 2)
        led.unplot(1, 2)
    } else if (!(crickit.signal3.digitalRead())) {
        led.plot(1, 2)
        led.unplot(0, 2)
    }
    if (crickit.signal4.digitalRead()) {
        led.plot(0, 3)
        led.unplot(1, 3)
    } else if (!(crickit.signal4.digitalRead())) {
        led.plot(1, 3)
        led.unplot(0, 3)
    }
})

johnpark
 
Posts: 758
Joined: Wed Mar 25, 2009 2:15 pm

Re: make code microbit and crickit signals

by nickine9 on Tue Jul 07, 2020 6:48 am

John, many thanks its now working as it should. I'm not sure what i was doing wrong but now i know it can work I can get on with my project. I don't suppose you've got a spare clone of yourself that i could keep in a cupboard until I hit another problem?

thanks again

nick

nickine9
 
Posts: 139
Joined: Fri Jan 06, 2017 4:14 am

Re: make code microbit and crickit signals

by johnpark on Thu Jul 09, 2020 11:47 am

Awesome!
I'll check with my other clones, but they think it may be getting out of hand and we need to stop at eleven so we can field an entirely us soccer team.

johnpark
 
Posts: 758
Joined: Wed Mar 25, 2009 2:15 pm

Please be positive and constructive with your questions and comments.