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!
I2C makecode cpx?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
I2C makecode cpx?
- Attachments
-
- Screen Shot 2020-11-03 at 3.48.10 PM.png (517.24 KiB) Viewed 553 times
- johnpark
- Posts: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
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.
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
Re: I2C makecode cpx?
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
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
- johnpark
- Posts: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
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.
But I don't see any new blocks showing up once the extension is added, so maybe it is JaveScript only.
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
Re: I2C makecode cpx?
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?
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 (434.17 KiB) Viewed 544 times
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
Re: I2C makecode cpx?
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?
Does this code look right?
- Attachments
-
- Screen Shot 2020-11-03 at 6.56.09 PM.png (101.18 KiB) Viewed 544 times
- johnpark
- Posts: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
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!)
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: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
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: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
Try connecting a Flora color sensor to the CPX over I2C (SCL, SDA, GND, 3.3V).
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
Re: I2C makecode cpx?
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
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
- johnpark
- Posts: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
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?
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?
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
Re: I2C makecode cpx?
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
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
- johnpark
- Posts: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
My friend got an I2C sensor working in MakeCode blocks using this method: https://makecode.com/_F4sdMrFwi8dE
- Mathpun
- Posts: 71
- Joined: Mon Feb 19, 2018 1:35 pm
Re: I2C makecode cpx?
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!
Will try and post my results! Thanks so much!
- johnpark
- Posts: 985
- Joined: Wed Mar 25, 2009 2:15 pm
Re: I2C makecode cpx?
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
Please be positive and constructive with your questions and comments.