volts.py output problem

The more technical aspects of Spirit, and carry-over discussion from Kickstarter updates.
Kevin
Posts: 180
Joined: Tue Jul 28, 2015 12:56 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby Kevin » Sun Feb 18, 2018 6:35 pm

This is helpful. I can't dig into it right away but it's a start.

Let's try this now.....

Load up a sketch on the Arduino, and have it run the function PIC_ReadPower() in a loop with a delay of maybe 2 seconds between calls. Have that sketch print powerVoltage variable to the serial monitor on the loops. You should get good data on this and you should see it change somewhat over time. (you can also echo powerCurrent at the same time, it is updated by the same function and powerCurrent should be bouncing around a bit).

Then try to sniff the same trafic with the Arduino making the call. We should be getting the same response packet as it's basically doing the same thing as when the Pi calls it.

Also if anyone else reading this is able to get good data from the volts.py script please let me know. So strange several of you having this problem but I can't recreate it here.

Thanks!

gpvillamil
Posts: 75
Joined: Fri Jan 26, 2018 5:03 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby gpvillamil » Mon Feb 19, 2018 11:49 pm

Last edited by gpvillamil on Tue Feb 20, 2018 1:07 am, edited 1 time in total.

acojon
Posts: 6
Joined: Sat Feb 17, 2018 12:39 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby acojon » Tue Feb 20, 2018 12:57 am


Bastian
Posts: 21
Joined: Sun Oct 22, 2017 5:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby Bastian » Tue Feb 20, 2018 4:35 pm

In my case the Comm led doesn't blink. AS to the exact content of the message sen aand recied, with a small additiong in spirit:core:

┌────────────────────────────────────────────────────────────────────┐
│ • MobaXterm 10.4 • │
│────────────────────────────────────────────────────────────────────┘
Linux Rpi3bV1-2 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l

(rover) pi@Rpi3bV1-2:~/rover/democode $ python volts.py
Battery Voltage: i2C request = 50 21 5 (bus address, register, length)
i2C repy= [255, 255, 255, 255, 255]
0
i2C request = 50 21 5
i2C repy= [255, 255, 255, 255, 255]
0
i2C request = 50 21 5
i2C repy= [255, 255, 255, 255, 255]
0
(rover) pi@Rpi3bV1-2:~/rover/democode $

I've also tried different I2C-delay's and different I2C-speeds. All without any effect.

I wonder if the problem lies in the RPi using the I2C bus (which is not Rpi's strongest point overall)?? In my own projects I use ARduino I2C to send req's/revieve/data to/from sensors and have Arduino and RPI communicate through serial. (RX-tX/usb, spi, whatever) That alway works flawless up to 0.5 Mhz. Arduino and RPi using the same bus, seems asking for trouble to me.Halas I don't have time to recode the base sketch and helper files to try it out.

gpvillamil
Posts: 75
Joined: Fri Jan 26, 2018 5:03 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby gpvillamil » Tue Feb 20, 2018 6:25 pm


Kevin
Posts: 180
Joined: Tue Jul 28, 2015 12:56 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby Kevin » Tue Feb 20, 2018 6:42 pm

Okay thanks for the feedback.

Let's try something else....

We have a few pauses we can play with. We already tried setting the "i2c_process_delay(15)" in the main script and found it had no effect. This sets a response delay within the PIC itself.

There are two other delays that are inserted on the Pi side. Have a look at the spirit_core.py file.

The power_voltage function will return a cached value if it is called more quickly than the PIC is updating it's own local value. We are seeing the I2C Wrong Register error, so that tells me we're getting past this part and we are indeed attempting a bus transaction to read the value.

power_voltage calls PIC_ReadPower. You can see this function in this section of the file:
def PIC_ReadPower(self):

There is a line in that function "pause = 0.0016" Let's try changing that pause to some different values longer or shorter. This "pause" value is going to be passed to the actual function that does the read (it's pretty easy to see how the function works by just reading over it).

Then look at the actual function that does the bus work. It is near the bottom of the file and starts like this:
def i2cRead(self,register,length,pause):

Study this function - you can see where the error message is being printed from in this message. We can add an additional pause each time the function is called by changing the hard coded value of "i2c_read_extra_pause", which is one of the variables set up in the list just preceding this function. It is presently set to zero, but if you change this "i2c_read_extra_pause" value, it should insert an additional delay of the given number in microseconds.

If the bus on the Pi on your units is behaving more quickly than what I'm running here, it is possible the transaction is happening too quickly, and by changing the delay numbers above, we can force a longer delay here, which may solve our problem.



A couple quick thoughts on the notes above....

It shouldn't matter that the Arduino and the Raspberry Pi are sharing the same I2C bus. I2C is designed to be shared. As long as you don't have both devices trying to run a lot of traffic all at once, it should be okay. (Under the I2C specification, it shouldn't matter, but due to the hardware bug in the Pi, it causes problems).

Speed issues with the Arduino - this could happen by selecting the wrong Board in the Arduino software as it will compile for a different clock speed. The Arduino we use is running at 8MHz, where the standard UNO uses the same chip but running at 16MHz.

If the "shake head" python example works, this is a good sign because this also uses the I2C bus, except it is not requesting a response from the PIC, but rather is telling the PIC to set a value.

Off top of my head, when a query is made, the master (in this case the Pi) sends a short packet to the PIC telling it what "register" it wants to read. A handler on the PIC goes and gets the voltage or whatever then populates it into the reply buffer. A short time later the Pi tries to call the PIC again in "read" mode, and the PIC then takes control of the bus and sends the reply back to the Pi.

It looks like we're getting all 255's for response values. It sounds to me like something isn't being timed correctly.

I don't think anything is hanging the bus, because I2C is very picky about the two signal lines going up and down in very specific patterns. If one of those lines is being held by the other side, the opposite side will refuse to do anything and you should get a hung program or some other kind of error. One of you did a data grab above, and I am seeing the register numbers change, so it looks like the bus is still physically functioning, it's just maybe something is out of timing. On the volts query, it should only take that PIC a couple microseconds to populate the outgoing packet, and it does respond properly when the Arduino calls it (from what I'm understanding from the above anyway).

One of you mentioned the shake head works, but seems delayed. Can you expand on that? Is it more than the expected delay between movements, or does it just take a long time to start running after the terminal command is issued?

I am hand building a unit for another person right now using one of the backer kits. When I complete that, I'll go through the setup steps I listed again from a fresh card and see if I'm able to repeat the issue. If I can, I will at least be able to look on the scope and try to figure out what is going on.

It would be an ugly work-around but very worst case, we could have the Arduino do the comms with the PIC then use SPI between the Arduino and Pi to relay the data (and we know this process works because the motors functions work).

I tested every board, but I did test them all with a single Pi, and as far as I remember, that Pi came from the same batch I sent to the backers. So if it's something that can't be worked around, it would be some freak thing that the 2 robots I have as prototypes and the 1 unit I have as a test fixture all work fine, and the test fixture works fine with all the boards that were shipped, but somehow all the Pi's that went out (but not the ones I'm testing with) are having some issue. I find that unlikely so I'm pretty sure we'll get this solved at some point.

gpvillamil
Posts: 75
Joined: Fri Jan 26, 2018 5:03 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby gpvillamil » Wed Feb 21, 2018 12:56 am


gpvillamil
Posts: 75
Joined: Fri Jan 26, 2018 5:03 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby gpvillamil » Wed Feb 21, 2018 1:12 am

Kevin, I wonder if this might have something to do with the Raspberry Pi firmware (that was updated with rpi-update, NOT apt-get).

I noticed the build of Raspbian that shipped was out of date, so when I did apt-get dist-upgrade I got the latest Jessie build (with Pixel GUI, VNC, etc). I believe this version no longer requires rpi-update, it will update firmware by itself to the latest STABLE build, on the first partition of the SD Card.

So perhaps our firmware is out of sync? Could you have updated to a more recent firmware, more current than the latest?

I am on firmware 4.9.35-v7+, and rpi-update proposes updating to 4.14.y

Can you check which one you have?

acojon
Posts: 6
Joined: Sat Feb 17, 2018 12:39 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby acojon » Wed Feb 21, 2018 1:38 am


Kevin
Posts: 180
Joined: Tue Jul 28, 2015 12:56 am
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: volts.py output problem

Postby Kevin » Wed Feb 21, 2018 2:39 am

What commands should I run in terminal to check versions?

Actually it may be a good idea for me to check versions of all kinds of stuff. If you can maybe make a list of commands, I can run and post the results. I'm thinking anything relevant - the Pi firmware, Linux version, etc. Also the SMBUS package I believe is important. Let me know and I'll give it a shot. I don't think I did anything to my unit other than what I listed in the guide but it's certainly possible something is different.

I can do lists of packages installed, etc, just let me know what to run.

Thanks!


[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 4 guests