Fighting with computers

Computers are not always friendly.

Monday, February 01, 2016

Windows 10: Upgrade if you can

Since 2000 I am on a Windows-free diet. But that does not mean that I am totally ignoring Windows,
after all, it is what most people use. So I have a few computers still running XP, Windows 7 and Windows 8.1. Last week a couple of my laptops offer me the chance to upgrade to Windows 10.

A few weeks a friend bought himself a nice Bang & Olufsen laptop equipped with Windows 10. My friend is a long-time Windows sufferer and he seemed to be quite happy with the latest Windows version. So I decided to bite and try the upgrade by myself.

My first system was two years old Toshiba laptop with an i5 and 8 GB of RAM. I started the upgrade and everything went smoothly though terribly slow, the whole process taking perhaps ten hours (not sure exactly how long as I went to bed, bored of waiting. And I do not think download speed is to blame here as I have fast Internet connection at home (apparently a bit more than 2 GBytes are downloaded).

My second system was an older, low performance AMD-based HP laptop with 3GB of RAM. The process started smoothly but after one day I could only see a rotating sign below the Windows icon on the screen while zero hard-disk activity was happening.  Tired of waiting after more than 24h I powered cycle the laptop: on booting up the system crashed and I thought I totally screw it up, but on the second reboot the upgrade was able to continue. But apparently only to keep on doing the same. I left it to its own devices for three more days with no apparent change. So I decided to power-cycle it again. At this point I was really lamenting to have attempted the upgrade and I was thinking I might need to reinstall the system. However, I was pleasantly surprised to see a message on the screen saying that Windows was reverting to the previous Windows version. And twenty minutes later the system was brought back to life from the death.  I, for one, have to congratulate Microsoft people decided to put forward this escape route.

I have not explored Windows 10 deep enough to have an informed opinion but so far I am glad the start menu is back.

Wednesday, January 20, 2016

Wifi DC motor controller?

A few days ago I was talked on G+ by my friend Mauro Manco with an idea that was a bit weird at first: we all have heard about ESP8266 SoC that can bring Wifi happiness to out Arduino projects for a few dollars.

What Mauro suggested is that this same unit might handle the servo code I have written for an Arduino. That was in part possible by the release of an SDK that allow us to program it the same way as a regular Arduino, so code-wise, programs are compatible. In a few attempts Mauro managed to get my code to compile happily for the ESP.  But he wanted me to try it out so he was as kind as sending me a NodeMCU board to my home so I could give it a try.

It just arrived at noon and I could not resist to give it a try, as usual not without some minor problems. The first one was that the NodeMCU did not show up as a serial port in my Macbook. I tried installing the CH340 driver to no avail. After using a magnifying lenses I realised that the USB to serial adapter on my board it was really a Prolific CP2102 chip instead. So just after another driver install, this time the right one, the board showed up in my computer as a serial port and I was able to compile, upload and test the mandatory Blink example :-) all from the familiar Arduino IDE.

Next step was to check whether or not the processor was up to the task of a time-critical interrupt code. I connected the encoder inputs to the module and set my motor at full speed. And I capture some samples of the motor position each second, as shown below:

It seemed it was working ok, but to be sure I needed to do the math, and I prefer the computer to do that for me.

So I could see the motor was running at around 3700 RPM, which was consistent with the no load speed at 12V supply. So my guess is that interrupts are not lost here as that was the worst case scenario for this motor. 

Please note that the business till now is just a change from the b-bit 16 Mhz Atmel 328 or 32u4 processor to the ESP's 32-bit SoC 80Mhz processor. As it was expected the system is clearly much faster and it can handle speeds the Arduino might not reach.

But the next step was to replace the Serial I/O of my program for a TCP communication over wifi so the motor controller could be configured and/or commanded wirelessly. So I did some changes and get it more or less working through wifi using telnet program on the computer side. Still some tidying may be needed but it seems to work ok (EEPROM is not working though it gives no error).

If you use the serial terminal on the ESP side, you will see it prints the IP address it obtains once it logs to your wifi network.

For controlling a motor for a dolly you might want to use your cellphone to create a temporary wifi network so you can send the commands to the motor with your desired timing wirelessly no matter where you are (if you build the program for that I will love to have a copy :-)

Sunday, December 13, 2015

Presentations' clock

I was recently invited by Pablo Murillo to give a talk at Zaragoza Maker Show and I wanted [among other things] to present and hands-on project to the audience, outlining the process I followed to get it done.

I was lucky my friend and fellow "Arduinist" Colin Dooley gave me away a 15-led addressable RGB stripe a while ago. Unfortunately, the Cylon effect (aka Lasrson scanner for those old enough) was already taken as one example from FastLED library, so I had to do something else.

I have chosen the title "Beyond Blink" for my talk, so it would be nice to get something that, while blinking, performed a more useful work. So what I decided was to use the 15-led stripe as some sort of presentations clock, that will help the speaker to know the time elapsed, a new led lit each minute, while of them is blinking each second.

But as many talks are longer than 15 minutes, I repeated the same pattern with changing colours for each next quarter. Red being the last color, since third quarter on. Talks should probably be no longer than 45 minutes anyway.

Later I thought that this contraption may also be of interest for the audience, so they too have some feedback on how time is passing during the talk, so I ended up placing it facing to the public during my talk.

I have made no effort on getting a very accurate time measurement, so I won't be surprised if is the thing is a bit off after half an hour, but if there is shift I assume it would be pretty small. Time starts ticking as soon as you plug it in. I used a USB port on the same laptop used for my presentation and I rushed to finish my talk during the allocated time frame. Looking at it instead of checking your watch during the talk looks likely better too.

I told the audience it would be my Christmas gift for them to post the code, so no matter you celebrate it or not you can grab it from here too.

Hardware-wise you just need three wires to connect the stripe to the Arduino, +5V, GND and data pin. I am using D9 pin as a data pin, but you may change it to any other pin you want. Please note you need FastLED library installed on you Arduino IDE or you get a compile error.  For a portable unit you can use an Arduino Pro Mini and a battery or a Nano or Pro Micro and a USB power bank.

Friday, December 11, 2015

Better accuracy from your encoder without more interrupts

Since I published my DC motor control project on youmagine I have got some feedback from users with 2000 PPR (pulses per revolution) encoders or more where they end up having trouble above 3000 RPM. The reason is that the poor Arduino cannot process the interrupts fast enough and the system becomes unreliably.

While optical encoders are available quite cheaply, some of the magnetic sensors from AMS are very competitive and offer very good accuracy (from 12 to 16 bits). One interesting model (due to its low price) is the AS5600, that provides a 12bit angle measurement for less than $2. Measurement data is read by means of an I2C serial bus and needs no interrupts.

Hopefully those having trouble with interrupts can switch to this type of sensor, but model AS5600 is most likely a bad choice as it is intended to replace manual knobs in hi-fi equipment and it will not work at high RPMs (in fact the manufacturer does not provide the max RPM at all).

But for position control applications maximum speed will not reach more than a few hundred RPM tops and for those this cheap sensor maybe a good fit.

I contacted moti project developer who is using this same sensor for his intelligent servo and he was pleased with it.

While chip manufacturer provided an Arduino library I cut the only piece of code I was interested and copy it to my project as a simple function. Time measurement showed that a standard I2C speed (100Khz) took 0.92 milliseconds, but after pumping up the I2C clock speed I lower it to 0.22 milliseconds.

One additional thing to address if your application uses multiple turns is how you manage the wrap around of the angle measurement. It took me a while to figure it out, but within a certain bound of rotational speeds checking for a gap between previous and current value larger than 3500 did the trick for me.

Below you can see a piece of code to get you started, providing a measurement between 0 and 4095 representing an angle between 0 and 360 degrees.

Sunday, December 06, 2015

Getting dropcutter to work

For my CAM project I was using a 3D offset of the parts to compensate for the tool diameter. But i have recently have incorporated a new feature so 3D assemblies of blocks can be represented in 3D. For the automatic assembly (courtesy of Carlos Sánchez) I cannot use the offset surfaces but I have to use the original meshes.

One way of machining a 3D mesh is dropcutter algorithm, that in a nutshell works by modeling the milling bit and setting the z-depth at each XY location so the model is barely touched by the tool. As meshes are made of triangles, each feature of them is tested for contact: edges, facets and vertices. The feature with the highest z-depth value will set it for that particular location.

I have found a lot of insight and useful information in Anders Wallin blog. Though my initial approach was to adapt his monocam's C# code to Java, I ended up with a buggy result. Anders released later a C++ library, opencamlib, that is most likely a much improved version, but I did not test that. Instead I built from scratch my own Java version that now seems to begin to behave properly.  It was not too hard as I am only implementing the ball-nose cutter (that is why you see the yellow spheres above representing the tip of the cutting bit).

You can can have a better view of the above here:

And in case you are wondering what the hell this part is, you can see where it will fit in:

Wednesday, December 02, 2015

Native 64bit Meshmixer version

I have just noticed there is a new version of Autodesk's Meshmixer software available for Linux but this time is no longer running over wine but it is compiled to run in Ubuntu 14.04 64bit. And the first tests suggest it works reliably (only crashed once when searching on the online 123D library).

It is a great program and it is free to use so I find myself using it from time to time. There are quite interesting but unexpected uses.

It is been a while since I last checked, so do not bash me if this is not new news for you, I now it was released first around March 2015, but I am a bit slow :-)

Thursday, November 26, 2015

Simple schematics on the web

I wanted to create a simple schematic for my students. I could use an electronic CAD system but I needed something simple and quick. I look it up on the Internet and I have found a few choices. The first one was from Digi-Key and it worked nicely for my job as shown below (you may want to click on the image to get it to readable size).

It was documenting the circuit of a simple electrostimulator to be used with an Arduino for creating some pain. One of my students wanted to build an Arts installation will cause him physical pain and this one fits the bill. For the rest of the people, the usual disclaimer is in place: use it at your own risk.