I recently wrote a 7000-word document that should contain everything most developers need to know about Microsoft Windows code and driver signing. You can find it on my website: Practical Windows Code and Driver Signing.
This is my professional blog, where I share interesting new things I have learned about computer programming.
Monday, January 7, 2013
Wednesday, December 19, 2012
Fresh & Easy receipt printer test
Look what I found hanging out of the receipt printer at the self-service checkout at Fresh & Easy (grocery store) the other day:
Some of the screwiness of this image is due to my handheld scanner. The actual receipt was not printed crookedly.
Here's a transcript so people can find this by searching on Google:
--------------------------------------------
NCR 734x-F307 Printer: Thermal Receipt
NCR 71xx Printer/MICR/CD/ChkScan Service
Object
OPOS Spec Compliancy Version: 1.7.000
--------------------------------------------
OPOS POSPrinter Control 1.10.001 [Public,
by CRM/RCS-Dayton]
OPOS Spec Compliancy Version: 1.10.001
--------------------------------------------
NCR Printer Service Object
NCR Release File Version: 2.5.1.50
--------------------------------------------
SH/SW: 0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST
DH/SW: 0123456789:;<=>?@ABCDEFGHIJKLMNOPQRST
SH/DW: 0123456789:;<=>
DH/DW: 0123456789:;<=>
--------------------------------------------
CharacterSet-437
(List-437,737,850,852,858,860,862,863,864,86
5,866,874,932,1252,101); LineChars-44
(List-44,56)
!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJK
LMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvw
xyz{|}~
Monday, December 3, 2012
Getting git 1.8.0 to work with PuTTY/plink/pageant 0.62
I am successfully running the following things together:
- Windows 8
- Git-1.8.0-preview20121022.exe from here
- PuTTY, plink, and pageant, all version 0.62, from here
I'm not sure if the Startup menu exists any more in Windows 8. To make pageant.exe run at startup and load my key, I used regedit to add a registry value under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run. The value is a String, the name can be whatever, and the value should be something like:
"C:\Program Files (x86)\PuTTY\pageant.exe" "C:\your\private\key.ppk"
By default, the version of SSH that ships with msysgit does not try to access pageant. You have to configure git to use plink.exe instead. Lots of people on the internet will tell you that you must set the GIT_SSH environment variable to be the full path to plink.exe, but for some reason that wasn't working for me this time. I'm sure this is not optimal, but my solution was to move plink.exe to "C:\Program Files (x86)\Git\bin\ssh.exe", overwriting the original ssh.exe. (I saved a copy of the of the original ssh.exe just in case I need it later.)
Anyway, it works now so I can continue working on all of my favorite coding projects.
UPDATE: See my new and improved article entitled Git and PuTTY in Windows.
Monday, November 26, 2012
Orientation sensing with the Raspberry Pi and MinIMU-9 v2
The Raspberry Pi is an ideal platform for experimenting with inertial measurement units (IMUs). These IMUs are usually I²C devices, so it is straightforward to access them using the Raspberry Pi's I²C bus. The integrated 3D graphics on the Raspberry Pi are useful for visualizing the results.
I have made some software that allows you to connect the MinIMU-9 v2 from Pololu Robotics & Electronics to your Raspberry Pi and calculate the orientation of the IMU. I also wrote a visualization program that shows the results in 3D. Check out the demo in this video:
The software is open source and I have written a tutorial for it. The only items needed besides your Raspberry Pi setup are:
- A MinIMU-9 v2 from Pololu, or the older MinIMU-9.
- Four female-female jumper wires.
Soldering is required: the male header pins that come with the MinIMU-9 v2 need to be soldered in.
The MinIMU-9 v2 can be conveniently powered from the Raspberry Pi's 3V3 power line. The photos below show how to connect a MinIMU-9 v2 to a Raspberry Pi:
The software consists mainly of two programs, both written in C++. The minimu9-ahrs program reads data from the MinIMU-9's sensors via I²C, calculates the orientation of the IMU, and outputs data to the standard output. Internally, it represents the orientation with a quaternion, but several different output options are available: direction cosine matrix, quaternion, euler angles, and raw sensor data. The ahrs-visualizer program reads direction cosine matrix data from its standard input and displays a 3D representation of the MinIMU-9 v2 using OpenGL. I also used libi2c, libpng, the Boost program_options library, and Eigen. There is a Python script that helps calibrate the magnetometer. For easy installation of the software, I have created Debian packages.
For more information, see the tutorial! I would love to see what people build with this, so please post comments below!
PIC18F14K50 errata: I was right all along
Tuesday, July 10, 2012
Atmel Studio bug caused by --Wl,--gc-sections
--Wl,--gc-sections flag is enabled and the .data section is empty. This makes the RAM variables overlap with memory-mapped SFRs, so they do not function properly.
You can follow these steps to reproduce the bug:
- Make a new project with the GCC C Executable Project template and select the ATmega328P. (I believe this bug affects other parts too.)
- In the project properties, check the "Garbage collect unused sections (-Wl,--gc-sections)" checkbox.
- Write the following in main.c:
#include <avr/io.h> unsigned char foo = 0; int main(void) { while(1){ PORTC = foo++; } } - Build the project.
0x00800060 foo
Unfortunately, address 0x60 is the location of WDTCSR, so putting a variable there does not work well.
The problem goes away if you ensure that the
.data section is non-empty by making a static variable that is initialized to a non-zero value:
static void __attribute__((used)) workaround(void)
{
static volatile unsigned char w = 1;
w++;
}
I believe that Atmel Studio is affected by bug #13697 from GNU binutils.
I hope that the next version of Atmel Studio comes with a patched or updated binutils that does not suffer from this problem. I have reported the bug to Atmel.
Update 2012-07-18: A member of the Atmel AVR Toolchain Team has responded to my bug report. He said: "Thanks. We will have this fix available with our next release."
Wednesday, June 20, 2012
Using I²C on the Raspberry Pi
The first step, of course, is to set up an SD card suitable for the Raspberry Pi. I used the official Debian image from the Raspberry Pi Foundation.
Unfortunately, this official image has no support for I²C! You need to enter Chris's Digital Realm for that. Follow the instructions on Chris Boot's site to upgrade your Raspberry Pi firmware and install his Raspberry Pi kernel, which has drivers for I²C. Now if you run
lsmod you should see a lot of good stuff, such as the i2c_bcm2708 module.Once you are running the new kernel, you will need to run
sudo modprobe i2c_dev. You should also add i2c_dev to the /etc/modules.conf file so that it loads automatically the next time you boot up the Raspberry Pi. Now you should see two I2C devices:pi@raspberrypi:~/$ ls -l /dev/i2c* crw------- 1 root root 89, 0 Dec 31 1969 /dev/i2c-0 crw------- 1 root root 89, 1 Dec 31 1969 /dev/i2c-1
You will need to connect your device to the Raspberry Pi. I used Pololu Female-Female Premium Jumper Wires to make the following connections between the Raspberry Pi's GPIO header and my device:
- Raspberry Pi GND to device GND
- Raspberry Pi SCL to device SCL
- Raspberry Pi SDA to device SDA
- Raspberry Pi 3V3 Power to device's power input. This line can only provide a few tens of milliamps so you should look up how much current your device draws and make sure you can power it at 3.3 V. The Raspberry Pi's 5V power line is also available.
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <linux/i2c-dev.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#define MAG_ADDRESS (0x3C >> 1)
#define LSM303_WHO_AM_I_M (0x0F)
int main()
{
char buf[10];
const char * devName = "/dev/i2c-0";
// Open up the I2C bus
int file = open(devName, O_RDWR);
if (file == -1)
{
perror(devName);
exit(1);
}
// Specify the address of the slave device.
if (ioctl(file, I2C_SLAVE, MAG_ADDRESS) < 0)
{
perror("Failed to acquire bus access and/or talk to slave");
exit(1);
}
// Write a byte to the slave.
buf[0] = LSM303_WHO_AM_I_M;
if (write(file, buf, 1) != 1)
{
perror("Failed to write to the i2c bus");
exit(1);
}
// Read a byte from the slave.
if (read(file,buf,1) != 1)
{
perror("Failed to read from the i2c bus");
exit(1);
}
printf("result: 0x%02X\n", buf[0]);
return 0;
}
When I ran this code, it printed 0x3C which means that it successfully talked to the device! There might be a simpler way to read the register; see the Linux Kernel I2C Documentation.In conclusion, it was not too hard to get I²C working on the Raspberry Pi. The biggest hurdle is that the official Debian image/kernel has no support for it. This is kind of surprising because the Raspberry Pi team purposefully brought the I²C lines out to their GPIO header and the product has been selling for several months now.