News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Impliment I2C

Started by Mike, Apr 11, 2023, 09:26 AM

Previous topic - Next topic

Mike

Well Guys again thanks for ALL of the help you have given me.  :D

I tried all kinds of scenarios with the sample codes that were posted to no avail. :'(

In the end I dug out my Arduino UNO (sorry for swearing!!), and loaded the code in and got some results through the Arduino's Serial Monitor.
So I played around with the code and eventually got a couple of LED's to light when Low and High levels were reached.
All was looking promising. ;D

However, I happended to power up when the container was about half full and the results came back as zero's instead of something about 50%.
This would obviously be a major problem as BOTH LED's were lit.

I eventually found a Forum on the SEEED wbsite and it turns out that there is a major bug in the code that doesn't allow for Power Loss.
This post was from 2020 and they still haven't fixed it. :o
So I have now dumped that idea and it's back to the drawing board.

Again thanks for the help.
Mike

RGV250

Hi Mike,
Did you try the code I posted?

I have also noticed the issue after power up, on mine the readings were all positive with half covered. This happened after downloading an updated program.
I agree it might be an issue for some but in my application it will probably be battery powered and I will have to remove the sensor to empty the vessel so not an issue.
I doubt they can do anything about it as it is probably inherent with the design but it would be nice to see the code as the hardware is what you are paying for.

Bob

Mike

Hi Bob
I have only recently noticed your post and I am taking another look at this sensor as it's ideal for my use.
I found this on the SEED forum Grove Capacitive Water Sensor fails to work after power cycle
In a reply on May 2020 this was posted https://github.com/Pillar1989/water_level
I beleive it is the Source code for the 2 ATTiny1616's.

Also in the same post a guy named Jens Keiner posted this fix https://github.com/jenskeiner/water_level

Some parts of it I don't understand, so I contacted him and he sent me this link for the HEX files that he developed. He's very busy so I don't want to pester him too much. Anyway I am going to give his method a try but am now waiting on a UPID programmer. (Cheap from ALIExpress).

Maybe you can have a quick look at the source code for the 2 ATTINY's  ::) and see what you can make of it.

I myself am totally lost with it all.

My use for the sensor is to automatically fill a container when empty using a 5V solenoid water valve.
During my playing around with the Arduino code I discovered that if there is some water in the vessel and then a loss of power, if I can drain the vessel (use all of the water) and press an override button to turn on the solenoid, once it gets above 5 it reverts to it's proper use. I have attached a copy of my Arduino code. It uses a couple of LED's. Red for indication and Green for solenoid. Also I inserted a couple of routines that respond to the levels. If it's a 0, (loss of Power), then the solenoid is switched OFF. (Don't want water everywhere). If it's 5 then turn solenoid on. (Fill the container). If it's 100, turn solenoid OFF. (Container is Full).

Next I am going to have a look at your code and see whether it helps me.

Thanks again
Mike

RGV250

#23
Hi Mike,
I had a quick look at your code but cannot see how it can work. It the value is 0 then shut the solenoid, how it it ever going to get to 5 to open it up as the level will not rise.

I did look at the link for the fix that the person has posted but gave up as there are so many files it is hard to know where to start. This is typical Arduino garbage which is why I prefer Positron, you have one file and that is it which is how it should be. OK, you can get INC files but they are all written the same, Arduino just seems to be a badly thought out mess.
Why on earth there are 7 files and 8 folders with even more files is beyond me. I also find this is the problem with github and invariably just ignore anything there.

When I get time I am going to dig out a descent ammeter and see what current the sensor draws, my thought is just to supply the sensor with a small battery and as long as the grounds are connected it should work whatever the PIC/Arduino are powered with. This should allow the sensor to maintain its operation during a loss of power. You could also feed the battery to an analog pin to monitor the voltage.
I did see someone ask about saving to eeprom, I did think of that but it has one flaw, what happens if the level changes during the power loss, when it comes back the level would be inaccurate just as bad as it was before.

One more point, you say at the bottom of your post you will look at my code to see if it helps you. My only thought on that is that it should be easier to modify and if you have any issues you are more likely to get help on this forum. If you compare Positron to Arduino you can see that they seem to make easy tasks hard work. I have tried modifying Arduino code and do not normally get very far, they seem to make things that work individually but try to actually adapt to include several things it is a non starter. In my opinion it is an awful language and without Proton/Positron I would prably have given up long ago.

Bob

trastikata

Quote from: RGV250 on May 05, 2023, 06:55 AMWhy on earth there are 7 files and 8 folders with even more files is beyond me. I also find this is the problem with github and invariably just ignore anything there.

That's typical, another "no-go" is the compulsion in C-programmers to write as much as possible in one line statement with most complex structures as possible.  I've been fighting dsPIC USB libraries in C for couple of months (true only a couple of hours a week) and still no-where. ;D


John Lawton

It's a programmers thing isn't it, there's an award for the most obscure C code :)

I rather doubt this results in better assembler than in writing more lines of simpler, understandable code. But that isn't 'clever' is it?

TimB


Just to chip in my 2p worth on coding style

In the long past I spent a lot of time looking at the ASM produced by Proton as it was known then and concluded that making really long statements like

If myvar x (xvar/yvar) > 1043 or  myvar x (xvar/yvar) - 10 < 35 then

Would produce a massive amount of code as the compiler had to wrangle variable left right and center.

I could greatly reduce code usage just by doing a little thinking and breaking the code up into smaller chunks. And as JL said very much easier to read.