Showing posts with label Raspberry Pi. Show all posts
Showing posts with label Raspberry Pi. Show all posts

Saturday, 29 November 2014

Network Printer with CUPS in a Raspberry Pi

Short story: I was tired of having to skpe or mail files to the secretary for her to print it in my behalf,  and working in a highly tech-oriented company, it was embarrasing, so the Raspberry Pi came to the rescue once again...

Sources:

Bartbania
Libre Geek

Install CUPS:

sudo apt-get install avahi-daemon cups cups-pdf python-cups
Once installed (it will take a while) add our user to the lpadmin group, in this case I'm assuming the default user "pi".

sudo usermod -a -G lpadmin pi

Install Samba and dependencies to make the Printer accessible over the network:

sudo apt-get install samba libncurses5-dev bridge-utils

Then edit the configuration file to enable network printing and sharing the printer, below are the most interesting lines in my configuration file:

pi@raspberrypi ~ $ sudo cat /etc/cups/cupsd.conf

# Allow remote access
Port 631

# Enable printer sharing and shared printers.
Browsing On
BrowseOrder allow,deny
BrowseAllow all
BrowseRemoteProtocols CUPS dnssd
BrowseAddress 192.168.1.255
BrowseLocalProtocols CUPS dnssd
DefaultAuthType Basic
WebInterface Yes
ServerName 192.168.1.28

<Location />
 Order Deny,Allow
 Deny From All
 Allow From 127.0.0.1
 Allow From 192.168.1.*
</Location>

<Location /admin>
  Order allow,deny
  Allow @Local
</Location>

<Location /admin/conf>
  AuthType Default
  Require user @SYSTEM
  Order allow,deny
  Allow @Local
</Location>

Then either reboot the Raspberry Pi or restart CUPS:

sudo service cups restart

And that should be all, next we need to add the printer connected to the Raspberry Pi over the USB port, the process should be straight-forward.  The CUPS driver provides a webserver accessible over the socket specified by the RPi's IP and Port assigned in the cupsd.conf file.



Create a GIT sandbox server for ad-hoc work

Some months ago I was working out of the office at a client's location and I had to move my development environment there, but due to a tight and restrictive IT policy, me a some colleagues were unable to set up our current GIT repository and share our work (the proposed zip-share-meld was not tempting at all...).  The easiest solution would be to host the repository on my laptop, but then again, setting up our GIT repo in a Raspberry Pi is more fun, specially when you have a video projector available at the office, and a RetroPie running with 2 extra game controllers.

Create a fresh bare repository on the server:
git init --bare newrepo.git
Add it as a remote in our local repo:
git remote add newrepo  git://user@server.com/newrepo.git
Push all branches:
git push --all newrepo

Wednesday, 23 July 2014

Quick note: Raspberry Pi WiFI client configuration (tested with ralink RT5370)

I recently purchased a WiFi dongle as the new addition for my Raspberry Pi, this cheap and amazing piece of work from ebay is a 150M USB WiFi Wireless Adapter LAN, with a 2dBi de-attachable Antenna and the well-known ralink rt5370 Chip, for only 3€ (at the purchase time) what else could you ask for?


OK, it took a while to arrive to Spain as it was sent from China, but the product was worth the wait!



Not only worked flawlessly with the Raspberry Pi (mine is mounted on the wall next to my desk, sometimes I put it behind my monitor as the enclosure is VESA-compatible, see previous post), but also worked out-of-the-box for my LG 47LA640S Smart TV, saving me from having to buy an "official" overpriced WiFI USB dongle (30€, 6 times the value!) or adding yet-another wireless router to connect my TV over ethernet.

To enable the Raspberry Pi to connect to an AP with a static IP address, just add this to your /etc/network/interface file:

allow-hotplug wlan0

auto wlan0


iface wlan0 inet static
address 192.168.1.232
netmask 255.255.255.0
gateway 192.168.1.1

dns-nameserver 8.8.8.8


wpa-ssid "SSID-example-replace-yours-here"

wpa-psk "replace-your-WPA-password"

This will work as long as your AP has WPA/WPA2 security and is not hidden.

A 3D printed Raspberry Pi VESA mount

The Barcelona Activa folks at the Parc Tecnològic Barcelona Nord has opened a 3D printing space, available for the lucky people working in its facilities, featuring the amazingly cheap and cool BCN3D+ printer and the well-known MakerBot.

After a quick lessonand browsing through Thingiverse, I quickly found that the Raspberry Pi was a hot item with plenty of designs available to further enhance the Rpi experience,so I took this thing (a VESA-mount enclosure for the Raspberry Pi) and did a quick test ride.

There are plenty of tutorials and available free available software on 3D printing, so I'm going to skip this and leave a 3D printing walkthrough for a future post.

I ran the .STL file over the GCode Analyzer to see how my case was to be printedand how much time will it take to print (about 2 hours, just the case without the top-lid), and then copy the GCODE into a SD card, put it in the BCN3D+, calibrate (grumble, grumble), and the result is shown below.







The Raspberry Pi fits quite nice in the enclosure, I only had to remove a loose thread or two to connect the HDMI connector, I have not printed the top-cover as I intend to connect many things to the device, so I'm not sure yet what space should I leave for the cabling and maybe use the cover as a base mount for a sensor, etc.

I'm planning on sticking the Rpi behind my monitor and avoid seeing all the cables on top of my desk, also it serves OK to hang on a wall... good thing is that the Raspberry fits in the enclosure, but with little effort it can be pulled off, allowing a quick swap.

Tuesday, 17 June 2014

Enabling USB audio card in Raspberry Pi

The Raspberry Pi has an on-board audio jack, but the on-board audio is generated by a PWM output with little filtering done, but the sound quality, volume, and recording capabilities can be added by using a USB sound card (these are pretty cheap too).

I bought 4€ USB sound card from Amazon, but pretty much any other can be used, it has a stereo output and has a MIC input, which is perfect for voice-controlled projects (like the one I'm currently working on, remember Jarvis?).  The audio card features an USB 2.0 type A connector and it powers up from the USB 5VDC power supply.  I have not measured the current consumption (yet).


Preparing the installation


I'm running Raspbian-based RetroPie on a USB stick, the following should not change anything from your configured settings, however this installation can be done on any Raspbian-based images.
sudo apt-get update
sudo apt-get upgrade

After 5-10 minutes you should have your OS upgraded and ready to go.


Recognizing the USB audio card


Sources:

ALSA driver by default does not allows the USB audio card to be sound device #0 (default), to change this we need to edit the /etc/modprobe.d/alsa-base.conf (as sudo) and change the following line (normally commented-out):

#options snd-usb-audio index=-2

Remove the comment and change index to 0

options snd-usb-audio index=0

After rebooting or restarting ALSA, the audio card should be listed as the default sound device.

As pointed out in Adafruit, there are different supported chipsets, mine was a C-Media based (CM108).


pi@raspberrypi ~ $ dmesg | grep C-Media
3.352853] usb 1-1.2: Manufacturer: C-Media Electronics Inc. 
3.370053] input: C-Media Electronics Inc. 
USB PnP Sound Device as /devices/platform/bcm2708_usb/usb1/1-1/1-1.2/1-1.2:1.3/input/input0
3.386302] hid-generic 0003:0D8C:013C.0001: input,hidraw0: USB HID v1.00 Device [C-Media Electronics Inc. 
USB PnP Sound Device] on usb-bcm2708_usb-1.2/input3
pi@raspberrypi ~ $ lsusb
Bus 001 Device 002: ID 0424:9512 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp.
Bus 001 Device 004: ID 0d8c:013c C-Media Electronics, Inc. CM108 Audio Controller
Bus 001 Device 005: ID 125f:c13a A-DATA Technology Co., Ltd.
pi@raspberrypi ~ $ cat /proc/asound/cards
0 [Device]: USB-Audio - USB PnP Sound Device
C-Media Electronics Inc. USB PnP Sound Device at usb-bcm2708_usb-1.2, full spee
1 [ALSA]: BRCM bcm2835 ALSbcm2835 ALSA - bcm2835 ALSA bcm2835 ALSA
pi@raspberrypi ~ $ aplay -L
Discard all samples (playback) or generate zero samples (capture)
sysdefault:CARD=Device
USB PnP Sound Device, USB Audio
Default Audio Device
front:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
Front speakers
surround40:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
4.0 Surround output to Front and Rear speakers
surround41:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
4.1 Surround output to Front, Rear and Subwoofer speakers
surround50:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
5.0 Surround output to Front, Center and Rear speakers
surround51:CARD=Device,DEV=0

USB PnP Sound Device, USB Audio
5.1 Surround output to Front, Center, Rear and Subwoofer speakers
surround71:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
7.1 Surround output to Front, Center, Side, Rear and Woofer speakers
iec958:CARD=Device,DEV=0
USB PnP Sound Device, USB Audio
IEC958 (S/PDIF) Digital Audio Output
sysdefault:CARD=ALSA
bcm2835 ALSA, bcm2835 ALSA
Default Audio Device
pi@raspberrypi ~ $ arecord -l
**** List of CAPTURE Hardware Devices ****
card 0: Device [USB PnP Sound Device], device 0: USB Audio [USB Audio]
 Subdevices: 1/1
 Subdevice #0: subdevice #0

The last step is adding the following configuration to the asound.conf file, used by ALSA.
pi@raspberrypi ~ $ cat /etc/asound.conf
pcm.!default {
 type plug
 slave {
   pcm "hw:0,0"
 }
}
ctl.!default {
 type hw
 card 0
}

Testing the setup

I have hooked the USB audio card with a TPA2005D1 audio amplifier (roughly 6€) from Sparkfun and a 0.5 Watt  magnetic speaker.  I have to work on the sound quality to reduce some noise, change the audio amplifier's resistors to increase the gain, maybe throw in a potentiometer to allow changing the volume, and use speakers with a higher wattage.


To test the installation we can use the built-in functions provided by the OS.
pi@raspberrypi ~ $ speaker-test
speaker-test 1.0.25
Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
Playback open error: -16,Device or resource busy
Had to close the emulationstation scripts running, then I was able to hear the sound:


pi@raspberrypi ~ $ speaker-test -c2 -D hw:0,0
speaker-test 1.0.25
Playback device is hw:0,0
Stream parameters are 48000Hz, S16_LE, 2 channels
Using 16 octaves of pink noise
Rate set to 48000Hz (requested 48000Hz)
Buffer size range from 96 to 262144
Period size range from 48 to 131072
Using max buffer size 262144
Periods = 4
was set period_size = 65536
was set buffer_size = 262144
0 - Front Left
1 - Front Right
Time per period = 5.564981
0 - Front Left
1 - Front Right
Time per period = 5.559085
0 - Front Left
1 - Front Right
And to test the recording I just connected a detachable mic from a headset.
pi@raspberrypi ~ $ arecord -d 10 test.wav
Recording WAVE 'test.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono
^CAborted by signal Interrupt...

$ aplay test.wav
Playing WAVE 'test.wav' : Unsigned 8 bit, Rate 8000 Hz, Mono