Tuesday, 12 February 2013

Pi Progress Tidbits and Serial Communications

Installed the Pi Store App. All went smoothly, but nothing very exciting to be found there... at least for me.

Configured the keyboard using the raspi-config program. Find the layout, then hit return to change the locations of the tilde and get the dollar sign instead of pounds sterling.

Apparently there is no root password created by default, so no root access except via sudo from pi.

Added www-data to the /etc/sudoers file. I'm not sure that's a great idea from a security point of view but it does let php run sudo tasks ;-)     sudo adduser www-data dialout didn't make the serial port available, even though /dev/ttyAMA0 belongs to root and group dialout, but sudo adduser www-data tty did let www-data use the serial port without sudo. This means that the web server can run a program that sends data to and from the serial port to control something else external, like an Arduino. It also means I can take www-data out of the /etc/sudoers file and sudo deluser www-data dialout.

Still have problems with the network dropping overnight. Pi was still running and responding to button pushes. Could it be an overnight timeout thing? Failing to renew DHCP? It was more than just dropping an idle terminal session because I couldn't log back in. It didn't repeat the next night, or the next.

sudo apt-get install libi2c-dev to install the I2C support and then installed WiringPi for the familiar Arduino type interface and the ability to run without root privileges. Installed WiringPi-python for the wrapper. Unfortunately the export process is not getting me control of the pins. I'll need linux geek help with this one I think.

Serial Communications: 

The Pi is 3.3V and other serial ports can be 5 V or more. Be careful. For a simple start I edited /etc/inittab to comment out the console getty near the end of the file.

#Spawn a getty on Raspberry Pi serial line
#T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100

minicom -b 57600 -o -D /dev/ttyAMA0

Making a direct, 3 wire (TX/RX/GND) connection to the DUE works bidirectionally at 57600 with minicom and echoing back.  It also works over an XBee link if the XBee is not powered from the Pi. The 3.3V on the Pi is not strong enough to sustain the Nokia display and transmit on the XBee.

sudo apt-get install python-serial to get the serial library for python (API). This code will then read and write stuff to the serial port.

import serial

p = serial.Serial('/dev/ttyAMA0',57600)
while 1:
  s = p.readline()
  print s
  p.write("this is what I think\n")

No comments:

Post a Comment