0

I2C makecode cpx?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

I2C makecode cpx?

by Mathpun on Tue Nov 03, 2020 5:03 pm

Hello! I am trying to connect an external color sensor (https://www.adafruit.com/product/1356) to the CPX using makecode, I know there is one built-in to the CPX but I need to it to be external for my project !

I know I need to somehow use the i2C blocks under Advanced -> pins in makecode but can someone point me to a working example project or offer any advice on how to use these, I know I need the block that is "ambientcolor" once the color has been detected but can I use this i2C block to get these values from an external sensor?

I am so confused! Thanks so much!
Attachments
Screen Shot 2020-11-03 at 3.48.10 PM.png
Screen Shot 2020-11-03 at 3.48.10 PM.png (517.24 KiB) Viewed 361 times

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

Re: I2C makecode cpx?

by johnpark on Tue Nov 03, 2020 6:46 pm

I'm trying and failing to do a basic I2C read of a sensor with these blocks. I'll let you know if I get anything working.

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

Re: I2C makecode cpx?

by Mathpun on Tue Nov 03, 2020 7:30 pm

Hey John, thanks! Looking forward to your response! Any other ideas on how to use blockcode to do this would be great too!

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

do you think I could use this? Although I have no idea how I get this package into my makecode lol

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

Re: I2C makecode cpx?

by johnpark on Tue Nov 03, 2020 7:43 pm

OK, you could use maker.makecode.com with the CPX and add that color sensor extension. go to that URL, pick the CPX as your board and then go to Advanced > Extensions and click on color-sensor (it seems to have a typo in the sensor name maybe).

But I don't see any new blocks showing up once the extension is added, so maybe it is JaveScript only.

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

Re: I2C makecode cpx?

by Mathpun on Tue Nov 03, 2020 8:03 pm

Wow thanks for sending that - I have never used that website - what is the difference between that and the usual: https://makecode.adafruit.com/

It seems when you do what you said it does add 1 block (image attached) to the input options, one called "color sensor" -- but do you think this will access an external color sensor?
Attachments
Screen Shot 2020-11-03 at 6.50.40 PM.png
Screen Shot 2020-11-03 at 6.50.40 PM.png (434.17 KiB) Viewed 352 times

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

Re: I2C makecode cpx?

by Mathpun on Tue Nov 03, 2020 8:08 pm

Also this version of makecode doesn't seem to have the "ambient color" block - which is the bock in the adafruit make code version that reads in the color from the on board color sensor?

Does this code look right?
Attachments
Screen Shot 2020-11-03 at 6.56.09 PM.png
Screen Shot 2020-11-03 at 6.56.09 PM.png (101.18 KiB) Viewed 352 times

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

Re: I2C makecode cpx?

by johnpark on Tue Nov 03, 2020 8:12 pm

I believe that block is there by default for the on-board sensor.

Maker.makecode is a place for lots of different boards, while the makecode.adafruit site is solely for CPX. I'm not sure of all the differences between the two if you set your hardware to CPX on Maker, but I tend to stick w the Adafruit site for CPX.

(sorry, crossed the streams there!)

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

Re: I2C makecode cpx?

by johnpark on Tue Nov 03, 2020 8:17 pm

Oh, wow, I don't know what was going on, you're right, I don't see that block in the base application now either.

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

Re: I2C makecode cpx?

by johnpark on Tue Nov 03, 2020 8:20 pm

Try connecting a Flora color sensor to the CPX over I2C (SCL, SDA, GND, 3.3V).

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

Re: I2C makecode cpx?

by Mathpun on Tue Nov 03, 2020 8:35 pm

IT WORKS!!!!

The color sensor stays lit with a bright white light, is that normal? IT isnt detecting perfectly, fading the colors a bit BUT it is ceratinly reading them from the external flora color sensor! using block code !

We have a break-through~~~~~ :) thanks so much

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

Re: I2C makecode cpx?

by johnpark on Tue Nov 03, 2020 8:40 pm

Hurray!
That's a really good question about the onboard white LED it uses to illuminate the subject. I know in the Arduino library for that sensor you can turn the LED on and off, but it doesn't seem like that's an option from blocks in MakeCode. Possibly in JavaScript in MakeCode?

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

Re: I2C makecode cpx?

by Mathpun on Tue Nov 03, 2020 8:47 pm

If I edit it in the java script i think it wont let me go back to the block code if it doesnt convert?

also - do you know where I can find what the line of code is to that?

also this has been so helpful, thank you so much

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

Re: I2C makecode cpx?

by johnpark on Wed Nov 04, 2020 11:19 pm

My friend got an I2C sensor working in MakeCode blocks using this method: https://makecode.com/_F4sdMrFwi8dE

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

Re: I2C makecode cpx?

by Mathpun on Thu Nov 05, 2020 10:55 pm

OooooOOoOOooh ok will take a look, this is for that sepecific sensor, do you think I can do this with my flora color sensor?

Will try and post my results! Thanks so much!

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

Re: I2C makecode cpx?

by johnpark on Fri Nov 06, 2020 1:01 am

So, it really will vary from sensor to sensor how to get it going in MakeCode over I2C. According to my friend:
It sends the value 16 because the device expects a single configuration byte, as described on page 5 of the datasheet
https://www.mouser.com/datasheet/2/348/ ... 186247.pdf
It outputs two bytes when read (no "register") and those two bytes should be arranged as a 16-bit big-endian number.  thankfully, MakeCode has a function for that

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

Please be positive and constructive with your questions and comments.


cron