Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

External color sensor on CPX with makecode?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

External color sensor on CPX with makecode?

by Mathpun on Wed Apr 01, 2020 3:41 pm

Hello! I am struggling on how to add a color sensor (https://www.adafruit.com/product/1356) to a CPX in make code? I can make it work hardware wise with ardunio code but I want to teach my kids using make code? I also can see how you make it work using the built-in sensor (from the flora color changing umbrella example, see attached)


So I have an LED strip + CPX + added color sensor

I think it should have something to do with adding it to a pin, say A7 -- but how do I get it to do the color sense? I see how I change the red block that reads "On Pin 7" but then how do I add the ambient color to that? So that it can sense the color from the external sensor and then turn the LEDs that color?

Thanks so much !
Attachments
Screen Shot 2020-04-01 at 12.35.50 PM.png
code for color changing umbrella
Screen Shot 2020-04-01 at 12.35.50 PM.png (370.17 KiB) Viewed 120 times

Mathpun
 
Posts: 43
Joined: Mon Feb 19, 2018 1:35 pm

Re: External color sensor on CPX with makecode?

by mikeysklar on Wed Apr 01, 2020 7:05 pm

Hi Mathpun,

We don't have any working examples of i2c sensor usage with MakeCode at this time. I did some searching around and it does seems like there are some extension library examples around the Microbit which might kind of work, but it is safe to say this would be a lot of headache.

You can of course totally make this work with CircuitPython on your CPX and you have already seen the Arduino code function. The support example you would be looking for to make this go with MakeCode would be TCS34725 i2c SDL / SDA.

mikeysklar
 
Posts: 1730
Joined: Mon Aug 01, 2016 8:10 pm

Re: External color sensor on CPX with makecode?

by Mathpun on Wed Apr 01, 2020 7:22 pm

Thanks for your reply -- I am just confused about your last sentence "The support example you would be looking for to make this go with MakeCode would be TCS34725 i2c SDL / SDA." -- does that mean there is a way to do it or not so much?

Is there a way to get any external sensor working with CPX on makecode?

Thanks!!

Mathpun
 
Posts: 43
Joined: Mon Feb 19, 2018 1:35 pm

Re: External color sensor on CPX with makecode?

by mikeysklar on Thu Apr 02, 2020 11:28 am

Mathpun,

To clarify. Adafruit offers limited support for MakeCode, but Microsoft has been extending abilities with their own libraries. It is worth digging around to see what Makecode packages are being exported in the experimental libraries being offered by third parties.

Makecode package for the TCS34725 Color Sensor.
https://github.com/microsoft/pxt-maker/ ... CS34725.ts

mikeysklar
 
Posts: 1730
Joined: Mon Aug 01, 2016 8:10 pm

Re: External color sensor on CPX with makecode?

by Mathpun on Thu Apr 02, 2020 1:57 pm

Thanks for posting that -- could you point me in the direction of how I would get this to work? Not sure how I go from downloading code off github phase --> makecode?

thanks!

Mathpun
 
Posts: 43
Joined: Mon Feb 19, 2018 1:35 pm

Re: External color sensor on CPX with makecode?

by mikeysklar on Thu Apr 02, 2020 2:01 pm

They have some instructions on their github page. Scroll down.

https://github.com/microsoft/pxt

mikeysklar
 
Posts: 1730
Joined: Mon Aug 01, 2016 8:10 pm

Re: External color sensor on CPX with makecode?

by Mathpun on Thu Apr 02, 2020 2:06 pm

Awesome, thanks!!!

Mathpun
 
Posts: 43
Joined: Mon Feb 19, 2018 1:35 pm

Re: External color sensor on CPX with makecode?

by Impkeys on Thu Apr 16, 2020 1:39 am

The Adafruit Circuit Playground Express comes equipped with an analog light sensor, but it can be used for much more than just sensing light or darkness! The light sensor has a similar spectral response to the human eye. Its connected to analog pin A8 and will return a value between 0 and 1023. A normal indoor light level reading is about 300, with higher numbers being brighter.

With a light sensor you can obviously read ambient light, but did you know you could also use it to sense color or to measure your heartbeat? For this tutorial, we will use the light sensor and the buttons to make a color matching ring of NeoPixels!

To use a light sensor to read color you just need a NeoPixel near the light sensor. Lucky for us there is one already there on the Circuit Playground Express! When we see something that’s blue, its because it is reflecting blue light back at us from the full spectrum. If we light up our pixel near the light sensor each primary color and take a reading from each, we can calculate how much of each color was reflected and duplicate it on the NeoPixels. It's not a perfect system, as our NeoPixel cannot create true primary colors, and our NeoPixel ring won’t be able to perfectly duplicate every color we try to match. Lighter colors will tend to look a little washed out and curve toward white, however, we can expect to accurately replicate at least 12 colors! Just hold the object that you want to color match very close to the sensor! Press button B to take a reading, Press Button A to clear the NeoPixel ring!
Last edited by johnpark on Fri Apr 17, 2020 7:43 pm, edited 1 time in total.
Reason: spam link

Impkeys
 
Posts: 1
Joined: Thu Apr 16, 2020 1:37 am

Re: External color sensor on CPX with makecode?

by mikeysklar on Sat Apr 18, 2020 5:46 pm

Awesome use of the onboard light sensor for color detection on the CPX. Thank you for sharing this.

mikeysklar
 
Posts: 1730
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.