Fighting with computers

Computers are not always friendly.

Tuesday, March 29, 2016

Software I2C for Arduino

While the Wire library allows you to get I2C working right off the bat with Arduino, there are times when the built-in Wire library does not do it. For some people this happens because they need to do a repeated start condition or to receive a large number of bytes, tasks that seemed to be not possible with Wire library. But for me the problem this time is a bit odd: I had to overcome the limitation of each I2C device to have a different address.

It turns out that I am using a magnetic encoder chip that responds to a given address that cannot be changed. Because I want to be able to access at least two similar encoders from on Arduino board I find myself in the unlikely situation where I have to use two different I2C buses, one per device. However, I2C interface was designed to do the exact opposite thing, allowing several devices to communicate over the same bus (provided each one had a different address of course).

As second detail I have been interested is to speed up the communication, as the current request takes almost 1 millisecond (to read a 16 bit number). It may not seem much but as I wanted to keep a constant frequency of 1Khz on my main loop, that reading time was definitely too long. When using the Wire library I learned that setting TWR=1 will offer me the fastest communication of about 170 microseconds, so that problem was also taken care of. But I still needed to get a I2C second bus running.

There are several Soft I2C libraries for Arduino, but the one that worked for me is the SoftI2CMaster, which I could see is available as simple C library or as C++ class wrapping it all nicely. I settled with the former that hopefully gives me an edge in communication time. It all should had been very simple if somebody told me I should shift left one bit the address value, but because I did not know that, I wasted a couple of hours till I figured that out.

Once set properly, the library allowed me to read one sensor value in 164 microseconds. The code below reads one angle value from the AS5600 sensor using this library.

So now, even if I read two values, one from each sensor, it will take me less that 400 microseconds, leaving room for additional processing while still keeping my 1Khz loop time. Now I only need to figure the same out for other platforms like ESP8266, Nucleo STM32 and MKR1000. 

Thursday, March 24, 2016

Crome 49 broke PDF viewing in Mavericks

A recent update of Chrome brought me some trouble with various web content, including PDF viewing. Apparently some change in how layers are handled makes the viewing of PDF content almost impossible: you see some bars of the underlying PDF file but only as a flicker while you scroll down the document, as if some black layer was on top of it.

A quick check online revealed that many people using OSX versions before El Capitan were complaing about exactly that same thing.  And while Google seemed not to be offering a solution at the moment (and upgrading to El Capitan was not something I would like to do right now) some users suggested that disabling hardware acceleration in the browser would help.

However, disabling hardware acceleration might solve this issue but create other problems with other content or just degrade browsing performance, so I did not want to go that way either.

Finally, another user suggested the install of a browser extension (in fact replacing Chrome's built-in PDF viewer) for PDF content. I selected the most popular one, called Kami, and not I am capable of watching PDF files again. Not ideal but at least it did not take me forever to get a fix.

And if Chrome engineers are listening, please fix this ASAP as PDF viewing is an integral part of most modern browsers.

Unfortunately, there are some videos from a newspaper that are experiencing the same type of problem, luckily most of them are for advertising so I will not miss them, but I know there are other problems related to the same cause that might become a problem soon.

Update: I have just installed Versión 49.0.2623.108 (64-bit) that fixed the problem.