• Hi.

    I'm currently doing a school project including an Espruino, LEDs and the color sensor. It has worked out great, but suddenly an error message occurs. Please help us - we have to show our project to the whole University in 3 days!

    /Jakob, IT-University, Copenhagen

    The error code is shown in the picture!


    1 Attachment

    • 13153328_10154243903303619_1232977014_n.png
  • Looks like the color sensor has come disconnected? Check Power, GND, and the I2C wires.

    Depending on the sensor, you might need pullup resistors on SDA and SCL too.

  • It has worked so far...

    this is the code we are using;

    I2C1.setup({scl:B6, sda:B7});
    var tcs=require("TCS3472x").connect(I2C1, 1 /integration cycles/, 1 /gain/);

    var v = tcs.getValue();

    The Color sensor is lighting up, but won't read any value. Do you think it's broken?

  • No, I think it's probably wiring, or you're missing pullups (which would make it unreliable).

    Also check the voltage on the 3.3v line - if you had a Pico rev 1.3 board and shorted it out then you might have damaged a diode on it, in which case it might not be able to provide enough power to light the lights and provide enough voltage to make the sensor work.

  • Do you think the Tcs3200 would work?

    http://softgenie.dk/sensor/362-farve-sen­sor.html

    We might have to get a new one..

  • No, I'm afraid it's a totally different (non-I2C) interface on it - you'd have to get one of the same type as before.

  • ah okay..
    We are currently testing the sensor on an arduino, to check if any numbers will be shown on the screen. We have a little trouble finding a "trigger" code.
    Any chance you have an idea?

    Thank you for your help!

  • No, I have no idea what code you'd want for Arduino - I'd imagine Google should turn something up quite quick though.

  • How does a color sensor "light up" ? Are you using one on a breakout board with additional parts, including leds? Which one?

  • Chances are it's this one: https://www.adafruit.com/product/1334

    I think the LED just comes on when you add power to it (or maybe you have to with the 'light' pin up - either way it doesn't need I2C)

  • Hi Gordon
    We actually the tcs3200 work with the Espruino. If you share your email address with me I can send you a video with our project and the code.

    /Jakob

  • Great - glad you got it working! If you didn't mind sharing in publicly it'd be good if you could just post the code up here?

  • Oh nice, you got a TCS3200 working with Espruino?

    Shame you couldn't figure out what went wrong with the 3472, but I'm sure people would love to see code for a TCS3200 - those are a lot more common, and they're easier to build into a home-made board as well; that DFN-6 package is no fun to solder down.

  • Hello, tell a beginner: TCS3472x I2C Color Sensor Library https://www.espruino.com/TCS3472x

    How does it work?
    Is it already installed in the Espruino ide or do I need to create a library as a separate file? Or do I need to download it(where)?

    Thank you in advance.

  • Hello, tell a beginner: TCS3472x I2C Color Sensor Library https://www.espruino.com/TCS3472x

    How does it work?
    Is it already installed in the Espruino ide or do I need to create a library as a separate file? Or do I need to download it(where)?

    Thank you in advance.

  • Hello, tell a beginner: TCS3472x I2C Color Sensor Library https://www.espruino.com/TCS3472x

    How does it work?
    Is it already installed in the Espruino ide or do I need to create a library as a separate file? Or do I need to download it(where)?

    Thank you in advance.

  • Hi - I'm pretty sure it's working and I have used it in the past myself.

    Espruino doesn't have the modules built in to the IDE, but loads them on demand when they are referenced - see http://www.espruino.com/Modules#espruino­-modules

  • Thank you for the answer.)
    But I didn't understand how to use this library? ((
    I assume that:
    a) I need to download this library and put it in a folder with libraries on my computer.
    b) I just need to copy the code from this page and add it to my firmware code.
    Which of the options is correct, "a" or "b"?

    Thank you in advance.

  • b. You just copy the example code from https://www.espruino.com/TCS3472x into the right-hand side of the Web IDE and click 'upload'

    This is all you need to have for code, no module download is required:

    I2C1.setup({scl:B6, sda:B7});
    var tcs=require("TCS3472x").connect(I2C1, 1 /*integration cycles*/, 1 /*gain*/);
    
    var v = tcs.getValue();
    print(v);
    
  • Got it, thanks! Kind man =)

    Just confused by the designation "TCS3472x" in "var tcs=require("TCS3472x").connect(I2C1, 1 /integration cycles/, 1 /gain/);", and I did not understand how I could access a library that I did not find in the libraries connected in espruino/modules, and did not understand how it works inside the program.

    Now, at least I know that I don't need to install anything extra, thanks to you.
    I will continue to study JS and Espruino.)

  • Great! the actual library that gets loaded automatically is http://www.espruino.com/modules/TCS3472x­.js

  • Hello, the sensor works when you press the RAM key, but when you enter save() in the left window, and disconnect the device from the power supply and reconnect (com), it gives an error:

    in function called from system
    Uncaught Error: I2C device not responding
    at line 1 col 24
    this.i2c.writeTo(41,179);var a=this.i2c.readFrom(41,9);if(a[...
    ^
    in function "getValue" called from line 12 col 34
    var color = colorSensor.getValue();

                                               ^
    

    What to do, how to continue reading data to the console again after restarting the power supply?
    The code I used is as follows:

    PrimaryI2C.setup({sda: SDA, scl: SCL, bitrate: 100000});

    var colorSensor = require("TCS3472x").connect(PrimaryI2C, 1, 1);

    var PIN_BACKLIGHT = P5;

    digitalWrite(PIN_BACKLIGHT, true);

    setInterval(function() {
    var color = colorSensor.getValue();
    var r = Math.floor(color.red / color.clear * 255);
    var g = Math.floor(color.green / color.clear * 255);
    var b = Math.floor(color.blue / color.clear * 255);

    if ((r > g) && (r > b))

    print("RED");
    

    else if ((g > r) && (g > b))

    print("GREEN");
    

    else if ((b > g) && (b > r))

    print("BLUE");
    

    }, 100);
    // d-sda, c-scl, g-gnd, v-vin, l-P5

  • See the save() section of https://www.espruino.com/Saving

    When power is next applied, Espruino will load the information back out of flash and will resume where it left off. You can think of this a bit like 'hibernate' on a PC.

    However, this means that any code that was executed at upload time will not be re-executed. For instance you may have some external hardware like an LCD display connected to Espruino - after applying power, the LCD will need to be initialised (since it can not remember its state). In this case you can create a function called onInit (or add a E.on('init', function() { ... }) listener) that is automatically called by the interpreter when it initialises.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

ColorSensor (TCS3472X I2C COLOR SENSOR) Libary error???

Posted by Avatar for Jaksi @Jaksi

Actions