myTonino / Tonino-Firmware

Open-Source Firmware for the Tonino Color Meter
http://my-tonino.com
BSD 3-Clause "New" or "Revised" License
8 stars 7 forks source link

Color value is always negative #2

Open r0bin-fr opened 5 years ago

r0bin-fr commented 5 years ago

Hi, I'm using the latest firmware (tag 1.1.7 i guess) on the open source hardware. the sketch compiles and run fine, the application detects when sensor is up and launch a calibration when dark. however the values are always negative : -137 or -136, wether the color is white, black, dark blue, light blue or red, on multiple materials. i got -60 when mesuring the air (nothing in front). (see picture attached) I am using the schematics provided in https://github.com/myTonino/Tonino-Hardware I have a TCS3200 bought here : https://www.amazon.fr/gp/product/B07DN2DVCV

Any idea why it doesnt provide a suitable value? I suspect the color sensor but i am not sure.

Many thanks in advance Rgds Matt

r0bin-fr commented 5 years ago

WhatsApp Image 2019-05-19 at 23 11 50

r0bin-fr commented 5 years ago

I switched to DFRobot board and sensor hardware, still negative readings. the DFR color sensor was better though : it returns 0 or 20 when measuring the red calibration (printed on inkjet printer), and -50 when measuring the grey or green calibration colors.

r0bin-fr commented 5 years ago

I tried with version 1.1.2 it is still same issue. updated libraries, same. when connecting to the Tonino app, it detects my old version. i upgraded to 1.1.7 through the app (thus it means no issue from my source code since the compiled firmware is flashed through the app) same issue: the DFR color sensor returns 0 or 20 when measuring the red calibration (printed on inkjet printer), and -50 when measuring the grey or green calibration colors :-(

when calibrating through the app it does not validate the grey color reading.

any clue where to look for ?

r0bin-fr commented 5 years ago

i have enabled the debug in the app, and figured out that the "readSingle" was returning a value that was way too high to be able to calibrate the sensor. with a few try and error i realized that dividing the returned valude by 30 was a fair fix (in torino_tcs3200.cpp) :

uint32_t TCS3200::readSingle(void) {
  delay(SENSOR_SWITCH_DELAY);
  FreqCount.begin(1000/_readDiv);    // start
  while (!FreqCount.available());   // wait
  FreqCount.end();                  // stop

  return ((FreqCount.read() * _readDiv)/30);
}

it is not very nice, but at least i am able to pass the calibration state... let's see for the rest :/

S0lvap commented 5 years ago

hi r0bin just read you comments and I was wandering if you fixed it at the end and if you would recommend the project, does it work properly now? cheers Pavlos

r0bin-fr commented 5 years ago

Hi Pavlos So far i am building a 3D print model for it, i did not test it "live" on my beans yet. I have the feeling it is not working as intended, and i am not sure it will do well. I'll let you know in the upcoming weeks. Cheers!

chung5116 commented 3 years ago

Hi, In the source code, pin S0,S1 are not set (OUTPUT FREQUENCY SCALING ),dose this cause any problem? Btw,I also face the problem about negative t-value , r0bin please tell me how you solve it. Otherwise why does ColorMode's default is equal to 10, this will cause green light frequency can't be read, isn't it important?

Any suggestion will be helpful

r0bin-fr commented 3 years ago

Hi glad to see I'm not alone :) well I did not manage to make it work it's been a while it is on my shelf. Maybe we are using a software version that is too recent and there are regressions brought by the 2nd hardware variant? Try with an older version perhaps. Maybe the hardware is not wired properly as you suggested we should check the datasheet and put some ground somewhere... Another hint might be the calibration disks that should have correct color but as far as I remember the 1st issue is negative return value.

chung5116 commented 3 years ago

Hi,thanks for reply In the function "fitValue" tonino_tcs3200.cpp,tval = _scale[0] vvv + _scale[1] vv + _scale[2] v + _scale[3] + 0.5 which _scale[0] and _scale[1] equals to 0, and _scale[2] equals to 102.2727 and _scale[3] equals to -128.409. v is equal to r/b * 1011949 - 0.094599. The problem is that the value of r/b is usually less than 1 ,even though I take sensor to scan red paper,the value of r/b is not greater enough to make tval greater than 5. I don't know why I can't get the "normal" tval. I will check the hardware again to make sure every thing is correct.

r0bin-fr commented 3 years ago

you are probably right the s0 and s1 should be initialized. Probably the sensor has wrong default value. I'll have a try !

BruciusL commented 3 years ago

Hello,

Having read through your very helpful comments above, and trying a few experiments of my own, perhaps the following can help:

So the trick is, I believe, to work out the exact shade of red and brown that the unit expects for calibration, as well as design a proper casing / 3D printable holder for it. Using a tin can like the original design is a simple, and good idea.

Cheers

r0bin-fr commented 3 years ago

Hi @BruciusL have you managed to do something about this issue ? another lead would be one of the pin of the DFRobot unit to be grounded, someone told me about it but i cannot remember who and which pin

r0bin-fr commented 3 years ago

Hi guys, i think i solved the issue \o/
i accidentally powered on the tonino while it was sitted on my crafted calibration pad. suddenly, the device entered in calibration mode, displaying CAL1 then CAL2 then DONE. after that, values are positive, and the coffee colors are in the tonino range ! (around 100) :
dark (passalacqua) coffee gives me 60 and medium roast gives me 120 value.

I think that the below change is not really necessary but if i dont do it, it wont calibrate. i guess it depends on the calibration pads your printer manages to print : change in hardware :


 Then, you need to ask your inkjet printer to print two calibration pads, one in brown color, the other in red color. i dont have the Pentone or RGV values so i built a powerpoint file with two circles and do try and error. i found those values words pretty well 
Brown color: R=84,G=0,B=0
Red color: R=204,G=51,B=0

One calibrated (first brown, second red), the device rember its values, so you should be fine.
It is possible to calibrate better with the application, but i am not expert in the exact values it should return. 
i'll now work on a better 3D shell, and start using it, if you have suggestions dont hesitate ;) 
BruciusL commented 3 years ago

Hi r0bin-fr,

I think that the below change is not really necessary but if i dont do it, it wont calibrate. i guess it depends on the calibration pads your printer manages to print : change in hardware :

* i wired S0 and S1 to the arduino, and initialized them to below :
  **change in software, sketch.c : **

Now there you hit the nail on the head!! Well done! The spec sheet for the color sensor clearly states that 20% scaling is what works best for Arduino, yet with the pins disconnected that is not what happens. I tested your suggestion, and indeed I was able to calibrate first time, and every time. The only suggestion that I have is that the error is not in the code, but rather in the wiring diagram. I just wired S0 to Vcc and S1 to Gnd, so the firmware remains original, but the sensor is hardwired to 20%.

I suspect that since we don't really know what shade of red and brown is used for calibration, that the reference you do with your calibration discs will only be for your tonino and your readings. So you'll be able to compare your own roast values months or years down the line if you still have the same discs, but not necessarily with other people unless they use the same discs. Also remember that these have to be matt, printing on gloss photo paper will probably not calibrate correctly as the light from the LED's will reflect on the sensor.

Well done again to spot that minor, yet very important omission. Hats off to you.

r0bin-fr commented 3 years ago

thanks :-) 100% agree with your analysis.

I suspect that since we don't really know what shade of red and brown is used for calibration, that the reference you do with your calibration discs will only be for your tonino and your readings.

exact, that's the issue here. if someone from Tonino could provide the pantone or color code of those discs, that would be great. otherwise that's stiil a good tool for your own roasts

The distance to the target is also very critical, as is consistency there. The unit needs to be fitted in a tin or holder of some sorts, so that it is stable. Anything else and you will not get anything that resembles consistency. According to the sensor specs, that optimal distance is around 10mm.

i tried 10mm but it didnt work well, so i went for 20mm which seems to work better on my discs.

here is my current design : 1fba1efc-a636-4e38-aab5-077965ac3b84 7f5120df-fbb7-4199-92ff-59ad7c52ede8 WhatsApp Image 2021-02-09 at 09 57 25 60972db8-a1c8-4baf-96b3-796610bb68dc

i painted the inside color in black afterwhile and added a 10mm more distance for better readings.
how about yours ?

BruciusL commented 3 years ago

Your design is very nice!

I've done some reading and enquiring, and yes, for calibration, the pads are approximately 26mm from the sensor. When the coffee puck is read, however, it rests against a little 3D printed well / container for the sensor, which places it somewhat closer, around 12-13mm.

Based on that, I am trying the following idea: image

image image

So I've worked it out to fit approximately into an 80mm downpipe, as tin sizes seem to differ quite drastically nowadays. The idea is to fit it so that the sensor is approx 26 mm from the bottom edge of the pipe, and then the puck will rest against the printed circle, to position the sensor for that. The 7 segment bit fits over the top part of the pipe, with enough length to accomodate the arduino and wiring. My sensor is not the DFrobot one, so I had to make some mods to get it to fit. You'll see the pins are all on one side, and I had to resolder the header as it was facing to the bottom, which won't work.

It's still work in progress, but getting there. Since soldering the S0 and S1 wires for initialisation as per your findings, and using this, I've been getting stable readings from the different coloured printouts I've got. Definitely a step in the right direction.

Cheers

kilbinger commented 3 years ago

I have just finished building my own tonino with the help of the awesome posts from r0bin-fr and BruciusL. Thanks guys! The tonino currently lives in a 3d printed tube and the sensor has a distance of about 20mm from the coffee/calibration disks. I actually printed out the calibration disks that you find right here: Tonino-App/src/icons/calib_high.png and Tonino-App/src/icons/calib_low.png. I start with "low" for calib1 and then "high" for calib2. It works every single time. Re-measuring the values of "low" and "high" after the calibration gives the values 25 and 250 for low and high. Of course the exact calibration very much depends on your printer settings. For a more "universal" calibration I was wondering if we could find a common calibrand, like a book cover, magazine ad or some other consumer product that is printed the same way in different countries. Once found, someone with the original calibration disks could give us the "real values" of these calibrands, allowing us to compare values between each other. Just a thought. Here's what my tonino looks like: IMG_4229 IMG_4230

r0bin-fr commented 3 years ago

well done guys ! @kilbinger thanks for the tip about calibration discs that's a great find ! i'm wondering if we can convert RGB to Pantone values, that would be the best to have a similar base and order some cheap calibration discs for example : https://codebeautify.org/rgb-to-pantone-converter

edit: @kilbinger are you sure the calibration file "calib_low.png" should be used here ? i thought the black disk is only for tonino "new model", while old model uses the red and green disk ?

kilbinger commented 3 years ago

Thanks for the fast reply @r0bin-fr. I tried the red and green ones but they are not recognized by my tonino. Would be great to see how your tonino reacts to any of those calibration discs. Finding close Pantone values could be really helpful for the red (hex:b00023, dec:176 0 35) and dark brown (hex:2e1f1a, dec:46 31 26) discs. That way we could simply buy those colors online. Finding close colour matches, esp. with the red tones is not really my strength... Pls let me know what you think is the closest match.

BossPitbull commented 2 years ago

Hej! I'm new to home roasting and the construction of the roaster also introduced me to the arduino-world. Now I'm really interested to build the tonino in order to evaluate the roast degree of my home roasted coffee. I don't know anything about 3d printing or rather creating own objects and unfortunately, I couldn't find any designs for the tonino casing on thingiverse. Would one of you be willing to share the design? That would be great!

BossPitbull commented 2 years ago

After doing some reading and browsing through forums etc. I can also add a little more constructive comments to the thread

@kilbinger The calibration values of 25 for low and 250 for high should be correct. These are at least the calibration values someone posted in a German forum who used the calibration pads from the manufacturer.

@r0bin-fr I'm relatively sure that the green calibration is only used with the new version. The green and red is shown in the official video whereas I saw the red and brown one posted by users who own the old version (might also interest @BruciusL).

keilr commented 2 years ago

thanks for the helpful comments. Were you able to get the serial debugging print output working? I'm able to send commands via serial port, this works perfectly. to debug the calibration procedure I set DODEBUG = true but it didn't help.

Serial port config: https://github.com/myTonino/Tonino-Firmware/blob/4b58f2ef4c23166587ebb26da851e580547f4a4d/Tonino-Serial.md?plain=1#L11-L14

keilr commented 2 years ago

@BruciusL, @r0bin-fr: it would be nice to see your 3d models online (https://www.thingiverse.com/ or any other site)

r0bin-fr commented 2 years ago

hi @keilr i just uploaded mine here : https://www.thingiverse.com/thing:5158781

"Were you able to get the serial debugging print output working?" => i don't know, i directly added some debug prints in the code where i wanted to. perhaps you need to define some global variables in the code to enable it ? it shouldnt be difficult to figure out if you dig in the source ;)

JJost90 commented 2 years ago

@r0bin-fr Thanks a lot for 3D Models do you have also STEP file that I can modify it? That would be great. Which discs and color do you use now to calibrate? Thanks a lot Jan

janoschsimon commented 1 year ago

Hi guys, i think i solved the issue \o/ i accidentally powered on the tonino while it was sitted on my crafted calibration pad. suddenly, the device entered in calibration mode, displaying CAL1 then CAL2 then DONE. after that, values are positive, and the coffee colors are in the tonino range ! (around 100) : dark (passalacqua) coffee gives me 60 and medium roast gives me 120 value.

I think that the below change is not really necessary but if i dont do it, it wont calibrate. i guess it depends on the calibration pads your printer manages to print : change in hardware :

  • i wired S0 and S1 to the arduino, and initialized them to below : change in software, sketch.c :
#define CS_S0 9 //put your S0 pin here (mine is D9)
#define CS_S1 10 //put your S1 pin here (mine is D10)
[...]
  // color sensor init
  //***r0bin hack, before calling colorSense.init()
  pinMode (CS_S0,OUTPUT);
  pinMode (CS_S1,OUTPUT);
  // Setting frequency scaling to 20%
  digitalWrite(CS_S0,HIGH);
  digitalWrite(CS_S1,LOW);
  // call now initialize
  colorSense.init();

Then, you need to ask your inkjet printer to print two calibration pads, one in brown color, the other in red color. i dont have the Pentone or RGV values so i built a powerpoint file with two circles and do try and error. i found those values words pretty well Brown color: R=84,G=0,B=0 Red color: R=204,G=51,B=0

One calibrated (first brown, second red), the device rember its values, so you should be fine. It is possible to calibrate better with the application, but i am not expert in the exact values it should return. i'll now work on a better 3D shell, and start using it, if you have suggestions dont hesitate ;)

hey there i just printed your design and looks great hehe my setup works but it wont enter calibration i have the orginal fur pad in red and brown can you point me where to put the code above? and how you connect s0 s1? thx Janosch

janoschsimon commented 1 year ago

@BruciusL, @r0bin-fr which nano board are you guys using? i use a random one from amazon de and i cant get into the calibration mode hope you can help :) Chees janosch

BruciusL commented 1 year ago

Hi, if you don't want to change the code, just hardwire it like I detailed in the post below the one you quoted. The original circuit and code doesn't enter calibration mode as is.

BossPitbull commented 1 year ago

Hi, if you don't want to change the code, just hardwire it like I detailed in the post below the one you quoted. The original circuit and code doesn't enter calibration mode as is.

Hej everyone! This project has been in my drawer for far too long, so one the weekend I gave it another try. I managed to get the code running and to get some readings about -50 for brown and about 70 for red. However, I also have the issue that it won't enter calibration mode. I have tried the solution described by @r0bin-fr but unfortunately it doesn't work for me.

@BruciusL: Do you maybe have a picture or sketch of how to hardwire the sensor? I can't figure out from my setup what to connect. Sorry for asking this rather stupid question but I'm quite a newbie - this is just my second arduino project. Would be great if you could help!

Cheers

BruciusL commented 1 year ago

Hi BossPitbull, If you managed to build the circuit, this shouldn't be too hard:

I just wired S0 to Vcc and S1 to Gnd, so the firmware remains original, but the sensor is hardwired to 20%.

Those refer to the S0 and S1 pins on the color sensor. I simply soldered wires directly on the sensor to bridge the pin labelled S1 to ground, and the pin labelled S0 to VCC, as you can see from this pic posted earlier:

image

Just bear in mind my sensor is a slightly different one, so the layout is different than the DFrobot one, but you can see what I did. Hope that helps?

BossPitbull commented 1 year ago

Hej BruciusL, thanks for your quick reply! That definetly helps, thanks for the clarification! I guess that the pin labelled VCC in your case is the supply voltage which is labelled VDD for the DFrobot sensor, correct? So, I would connect the pins on opposite sides as I tried to illustrate in the sketch (of course I would not place the cables in front of the sensor):

tonino-fritzing_v2

BruciusL commented 1 year ago

Yes, you are spot on. For some reason the connection of those two pins seem to be omitted on the original diagram. You should see an immediate improvement. Enjoy!

BossPitbull commented 1 year ago

Thanks for your reply! As discussed I hardwired the sensor and used the original sketch. Unfortunately, it still won't calibrate. As soon as I plug it in, I just receive the first reading and number. So, both approaches didn't work out for me and I can't really figure out why...

BruciusL commented 1 year ago

Are you powering it on with the sensor on the calibration pad? Try both colours - neither works? Try via the software?

BossPitbull commented 1 year ago

Yes, I'm powering it on with the sensor on the calibration pad and did try both colours. I tried it with the software but it doesn't recognize the Tonino. I also reinstalled the software and the drivers but the app still can't find the Tonino.

When I compile the code I also get the following informtation: `C:\Users\Juju\Documents\Tonino\Tonino-Firmware-master\Tonino-Firmware-master\Tonino\tonino_lcd.cpp: In member function 'LCD::numberFromEights(unsigned int)': C:\Users\Juju\Documents\Tonino\Tonino-Firmware-master\Tonino-Firmware-master\Tonino\tonino_lcd.cpp:449:16: warning: iteration 5 invokes undefined behavior [-Waggressive-loop-optimizations] eight[led] = 0b01111111;


C:\Users\User\Documents\Tonino\Tonino-Firmware-master\Tonino-Firmware-master\Tonino\tonino_lcd.cpp:448:25: note: within this loop
   for (int led = 0; led < 6; led++) {
                     ~~~~^~~
C:\Users\User\Documents\Tonino\Tonino-Firmware-master\Tonino-Firmware-master\Tonino\tonino_lcd.cpp: In member function 'LCD::numberFromEmpty(unsigned int)':
C:\Users\User\Documents\Tonino\Tonino-Firmware-master\Tonino-Firmware-master\Tonino\tonino_lcd.cpp:496:16: warning: iteration 5 invokes undefined behavior [-Waggressive-loop-optimizations]
     eight[led] = 0b0;
     ~~~~~~~~~~~^~~~~
C:\Users\User\Documents\Tonino\Tonino-Firmware-master\Tonino-Firmware-master\Tonino\tonino_lcd.cpp:495:25: note: within this loop
   for (int led = 0; led < 6; led++) {
                     ~~~~^~~
`
So far, I didn't really care about as it didn't appear as error to me and the compilation was still successful. Is this normal behaviour, though? 
BruciusL commented 1 year ago

That doesn't sound right... I do recall having to change a few things to compile mine, but I don't recall compilation errors like what you've got. The problems I had were related to library inclusion. If your software don't recognise the tonino that could also be a problem - perhaps check the specs of the DFRobot arduino nano, vs the one you're using? Perhaps they use a different USB to serial chipset?

BossPitbull commented 1 year ago

Yeah, I also hat problems related to library inclusion. In the original code it, e.g., said: #include <SerialCommand.h> which I simply had to replace by: #include "SerialCommand.h" . Thanks for your hint towards the arduino nano. I checked again and the error doesn't occur when I compile the code but just when I upload it to the arduino nano - so you're right it must be related to this special one (which is btw some clone, not a original one). I also tried another arduion nano (clone) which was lying around and the error doesn't occur when I upload the sketch to this one. Unfortunately, afterwards nothing happens once I power it up - the LCD display doesn't light up nor do the sensor's LEDs. I just ordered the suggested DRRobot arduino nano and hope that this will solve the problem. I keep you posted and once again, thanks for your help!

BossPitbull commented 1 year ago

The new DFRobot arduino nano arrived today. Now the computer recognises the arduino/tonino (nice!) but I still get the above error regarding the LCD code when I upload the sketch and I still can't calibrate (not so nice!)...

BossPitbull commented 1 year ago

After doing some research, I learned that the warnings regarding undefined behaviour are often caused bay accessing out of array bounds. Although, in my understanding (int led = 0; led < 6; led++) should be fine for a 7-digit display because the 0 also counts, I changed all occurences of < 6 to < 5. The warnings disappeared but the tonino still won't access calibration mode. Any thoughts or ideas? I don't really know what to do anymore and find the tonino's behaviour rather strange, considering that you guys didn't run into these troubles.

BruciusL commented 1 year ago

Hi, Ive checked again, and loaded the sketch on a different computer, not the one I compiled it on when I did.
I had to install the libraries again, make sure all the files that came with the sketch are in the same folder, change the < to " as described above for the include statements, and then it compiled with no problems Don't you possibly have some settings changed in your compiler? For example aggressive optimization, or similar? Perhaps just double check you're using sketch 1.1.7, and perhaps try it on a different computer with a fresh arduino install? If you start changing loops you're bound to have interesting side-effects.

BossPitbull commented 1 year ago

perhaps try it on a different computer with a fresh arduino install

omg, that was the solution! A freshly installed arduino IDE 2.0 on a different computer and the warnings/errors were gone - sometimes it really is simple like that, I would have never guessed that! Now the arduino enters calibration mode without problems either when started on the calibration pads (/printouts) or via the app's calibration mode. Thank you so much for your help, I'm super excited that it finally works now!

d0tcc commented 1 year ago

I'm running into the same issue as you all before: it won't enter calibration mode. I already connected S0 to VCC and S1 to GND but it does not change anything. The brown color always shows -55 and the red 27. The plates are printed on a laser printer, so it's definitely not true to the color but probably in the correct range. I'm using the same parts as in the description expect for the board which is a Nano from AZ-Delivery. The case I used is this one.

@BossPitbull, @BruciusL, @r0bin-fr, @kilbinger did you change anything else in the code to make it work or is wiring S0 and S1 really enough?

I already checked the wiring many times, took everything apart and tried again. I tried 2 different Nanos and compiled the code on two different machines (without errors or warnings).

Any help is highly appreciated :)