Saturday, October 17, 2015

I've controlled character LCD through Web

I've controlled character LCD via command line last time. I will control the LCD via Web this time.

I installed apache2 and php5. Then, I called  /usr/sbin/i2cset and i2cget via exec command from PHP script. i2cset can't run because apache2 run on www-data user by default. /var/log/apache2/error.log shows there is no root privilege.

I added the following lines into /etc/sudoers:

www-data ALL=(ALL) NOPASSWD:/usr/sbin/i2cget
www-data ALL=(ALL) NOPASSWD:/usr/sbin/i2cset

Now I can call "sudo /usr/sbin/i2cset" by exec command. I can access it from Android Tablet by setting PHP URL.

Sunday, October 11, 2015

I've tried AQM1602 16x2 character LCD

I bought character LCD with I2C interface. LCD itself costs 450 yen. I soldered the LCD to 2.54mm pitch pin header. I put resistors and condensers on the bread board.

I connected the LCD into Raspberry Pi2's 3.3V, GND, and SDA signals. I didn't put pull-up resistors because those signals are pulled-up internally by Raspberry Pi 2.

I2C address of the LCD is 0x3E. "i2cdetect" command returns 0x3E correctly.

LCD shows characters by sending commands via I2C according to initialize steps written in the usage manual of the LCD. Sometimes commands failed, but they succeeds if I put long wait time. I found that the command fails if the I2C baud rate is 100000 of default value. If I change it by 50000, command succeeds stably. We can change the baud rate by writing the following lines into /boot/config.txt:

dtparam=i2c_baudrate=50000

Saturday, October 10, 2015

I've tried SG92R: Micro servo motor

It is the first time that I use a servo motor. I hear servo motors are often used for robots. DC motors torn round and round, but servo motors rotate only limited angle. They have different applications.

SG92R have 3 signal lines: 5V, GND, and control signal. 4 AAA battery should be connected to 5V signal. I connected the control signal to Raspberry Pi 2's PWM port. We can control rotate angle by using PWM port.

I used "softServo", which is one of wiringPi library, to control the servo motor. We can download wiringPi by using:

git clone git://git.drogon.net/wiringPi

Running ./build in wiringPi folder will make wiringPi library under /usr/local/lib folder. However, This library doesn't include softServo.c, which is required to control server motor. I have to change Makefile so that it build softServo.c too. wiringPi library have already exist in /usr/lib at NOOBS 1.4.2, so,

gcc -o test test.c -lwiringPi

cause an missing function error because it first search /usr/lib/libwiringPi.xx first. So, I use the following command:

gcc -o test test.c -L/usr/local/lib -lwiringPi

I run the command and the servo motor moved by 120 degree with Brrr-r-r sound.