Colin

Colin

Going back to my roots! Heh.

About: Relearning electronics and how to code. Not because I have to but because I can!

New Conversation

Join the discussion

Log in or create an account, and start talking!

Activity

Phase One Success!

So I have successfully managed (barring a couple of school boy errors) to get an access point up and running, installed JMRI and then had trains running on a short piece of test track with an android app! The setup in on an old Raspberry Pi b but it works fine and clearly demonstrated that the system will run on a Raspberry Pi Zero W, which I ordered and has arrived today.

To get to this place I:

  • Installed a USB Wireless NIC
  • Installed Hostapd (Access Point Daemon)
  • Installed DNSMASQ (For DNS server and DHCP which is a requirement for easily connecting to the AP)
  • Allowed routing and Pass through for IPV4 from WLAN0 to ETH0 (when connected) (Not required but may make things easier when attached to the AP and requiring access too the internet from home)
  • Installed JMRI to allow access to the Controller
  • bought a SPROG II controller to program and run trains via JMRI.

Next I need to get the card in my new Zero and test again! To access the internet via the AP I would need a USB Hub and a USB ethernet adaptor when using the SPROG.

One thing, when using the AP as a router, the link speed is low, this is in part due to the spec of the Pi, but also the internal Nic on a standard b, b 2 or b 3 is essentially a USB NIC so shares the same USB channel as the Wireless NIC and the SPROG.

Anyhow, a great evenings work.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Remove the Rubbish

You can of course start with the Raspbian lite installation but I wanted access to the desktop if I needed it, but I didn't need any bloat, sure I'd need Java installed for JMRI but a things like Libre Office just took up space. So I went on a look around.  Libre Office came off first but I also removed Wolfram and Sonic Pi.

If you are or know you are going to be tight on space removal of some desktop apps can free up space on your sd card. If the computer is not going to be run as a desktop PC there is no need for them to be there.  I left Python and a browser because python may be useful and you never know when you may need the web.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Restart

I Had some issues with the SPROGPI board and in the end opted for a SPROG 2 and I think in hindsight this was probably going to be the better option.  I can plug a SPROG 2 into my laptop and run from there as well.  True I could use VNC to run the train from a desktop and do it that way but there may be times when I need to use my laptop directly.

With this in mind I have finally got round to sorting out a Raspberry Pi and SPROG for model train control.

For the bare minimum this project will need:

  • 1 Raspberry Pi (I'm using a Zero)
  • 1 power supply, SD card etc...
  • 1 wireless adaptor (if not using a zero w or pi3
  • 1 SPROG and USB cable.
  • 1 SPROG power supply
  • 1 Model train with a DCC chip installed
  • track and connecting cables.

The end result here is unless the Pi joins a wireless network it will not be able to get to the internet for updates, this may not be an issue but if the Pi is running as an Access Point and there is still a need to get onto the internet, I'd recommend either using a Pi B or at have a USB Ethernet adaptor if the internet is required.

For a truly independent and portable project the Pi needs to be set up as a wireless point with routing to allow access for connected devices should an internet connection be be needed.  This is to allow a small layout to simply to be plugged in anywhere.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Colin made a post to Evening Projects:

Hacking Christmas Lights

For a quick project I bought a cheap set of battery powered lights.  The lights are multicoloured and have a battery pack with a switch, they can be on or off.

The pack come supplied with 3 AA cells and I put my multi meter and found that  that the short length of light was running at 5v with a current of just over 50mA: perfect!

Using some breadboard, a 3 pin male header, a NPN transistor and a 2.2k Ohm resistor, using the "gpiozero" python library I was very quickly pulsing the lights on an off.  Time for a more permanent solution.

So the who circuit is now mounted to some stripboard. 

So pin2 (5v) plugs into the board and then to the positive terminal of the battery-pack.   The negative terminal is connected to the collector of the transistor.  Pin 11 (GPIO17) is connected to the 2.2Kohm resistor and then onto the base of the transistor.  Finally the emitter is connected to pin6 (Ground).

So I've made an alright thing a little better.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Colin made a post to Evening Projects:

PiBakery

PiBakery is a fantastic utility to create tailored SD cards for booting up a Raspberry Pi

It works in the same way that Scratch does so you can add new different elements. For instance on first boot you can add a wireless network with properties, change the host name, password, set the Pi to start up not logged in on CLI, install tight VNC sever and then reboot. Then on every boot after that run VNC server. Once happy that it is complete it can then be burnt to an SD card (PiBakery downloads a copy of Raspbian when it is installed) or save the "program" as an XML script (warning here it looks like passwords are saved in clear text so don't put anything in here that you wouldn't want to advertise).

This is quite useful especially with Pi Zeros because you can build a card and set it up without having to plug in a hub.

I used it this evening and really like it.

See more information here.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Colin made a post to Evening Projects:

Hacking a Raspberry Pi Model B

I have a board that I need to try. I don't want to try it on my Pi 3 so I thought I could alter an old Model B I have hanging around.

Having contacted the manufacturer I know that the board does not use any pins beyond 26 so there is no reason why the board would not work on an old B except that the Composite Video Out was in the way.

Solution was to set to with a soldering iron, a solder sucker and try to lever it out with a fine flat head screwdriver.

The yellow connector is the one.  It did turn into an epic, my soldering iron has a fine point and there is a lot of solder on the three pins on the bottom of it.  Also there is a lot of metal on the connector so the little point on the iron had a hard time getting the solder hot enough.  However after some perseverance I got the connector off.

As an added bonus it boots up as well!

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Colin made a post to Home Cloud Server:

Raspberry Pi 3 boot direct from USB mass storage

One of the issues with a Raspberry Pi was that it is relatively easy to corrupt an SD card if you had power issues or got lazy when switching off.

The Raspberry Pi 3 has the ability to boot from USB mass storage, it does need an up to date version of Raspbian and either latest version of NOOBS or using apt-get to update the OS and then some configuration changes though.Instructions can be found here.

This does change things somewhat, however my owncloud server is running on a Pi 2 so I will need to press my new Pi 3 into service (New?  My old one blew up!) or buy a new one if I intend to go down that route..

Again I stress it will not work on anything but a Pi 3 B and as far as I can see will not work with any of the A series (unless the A 3 when/if it is released may), B, 2 B either Zeros.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

The latest updates of Raspbian and the Raspberry PI NOOBS download includes the ability for USB Mass Storage and PXE or network boot. That gets the cogs turning :) . Raspberry PI 3 only :( .

Respond

Join the discussion

Log in or create an account, and start talking!

Colin is now following the project Raspberry Pi News

Raspberry Pi News

Colin likes the post RasPi

RasPi

Coming to an end.

I never quite got round to fitting the fan to this Pi and to be honest it has been gathering dust over the last few months while I have been using my new Pi Zero.  With the arrival of the Pi-SPROG 1, I now need the Pi 3.  With the SPROG plugging directly into the GPIO header I may not have space for the Heat-sink, never mind the fan so I will put this project to bed.

If you are interested or curious about model trains and digital command and control please go here for the new project:

https://incredibits.io/project/model-trains-digital-command-and-control

Finally if you have been following this project, thank you and I hope it has been useful.

Many thanks

Colin

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Colin made a post to Home Cloud Server:

Making Apache2 ready for Owncloud.

Installing Apache is really easy.  You can have a functioning web-server up and running in minutes.

sudo apt-get update
sudo apt-get install apache2

However Owncloud prefers that a secure connection is used, for this I  needed to ensure that the SSL module is enabled and that a SSL site is enabled to be able to display the data. This also requires a certificate.

The good news is that a self signed certificate is supplied with Apache called "snake oil". if you want to be clever you can create your own, or you can have a signed certificate created.

Getting a signed certificate will stop your web browser from complaining when you connect to the https but you need to provide proof of ownership of the domain at the very least and it usually has a cost.

I was not bothered about a signed certificate so I simple navigated to the sites-available folder and enabled the site, then enabled the ssl module in Apache and finally restarted the Apache2 service.  I keep forgetting the enabling of the ssl module and spend a few minutes wondering why my server refuses HTTPS connections until the penny drops.

So from CLI:

cd /etc/apache2/sites-available
sudo a2ensite default-ssl.conf
sudo a2enmod ssl
sudo service apache2 restart

Now for the database.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Colin made a post to Home Cloud Server:

Adding an External Hard Disk to a Raspberry PI

If you are adding a USB hard disk to a Raspberry Pi using the graphical interface it is fairly straight forward. This is because the drive will auto mount.  The thing is the disk won't automatically mount when booting on to the command line.  You can mount it manually from within the CLI or BASH but we need to drive to be live from boot so the OwnCloud service can use it.

First I had to prepare the disk. I therefore needed to add a partition, a volume and then format the volume for the new drive.  I chose to do this from the Pi.  I could have done all this from the CLI but I have used GParted in the past and find it works really well. So to install GParted from CLI

sudo apt-get update
sudo apt-get install gparted

This meant that I had to load the GUI. I then formatted the entire disk as ext4.

Mounting the drive to persistently (stay mounted after a reboot) ModMyPi have this nice little guide.  This does assume only one drive will be mounted though.  The RaspberryPi-Spy has another guide to allow for multiple drives to be added.

The only amendments I made were to identify the volume as ext4 and not NTFS and the different path to the drive root. The line now reads:

/dev/sda1 /mnt/usb /ext4 defaults 0 0

As Sudo I created the two folders /mnt/usb. Without these folders the drive will not mount.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

Code as Promised

This is the code driving the environment sensor suit in the Sense HAT.  When it gets the data it sends it to ThingSpeak so I can view nice graphs showing the last 60 samples. It also is driving the LED Matrix showing an high level status in a colour code.  The program just runs once and is triggered by crontab every half hour.

#!/usr/bin/python

# Import libraries
from sense_hat import SenseHat
import thingspeak

# Assign 3 way colour values as variables
red = (255, 0, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
yellow = (255, 255, 0)

# Make the SenseHat function easier to use
sense = SenseHat()

# Assign ThingSpeak write key and channel as a variable
write_key = 'PUT KEY HERE'
channel_id = 'CHANNEL ID GOES HERE'

# Grab the environment sensors and assigns to a variable.
# These probably should be assigned after the functions are defined
# but this program only needs to run once.
temp1 = sense.get_temperature_from_pressure()
temp2 = sense.get_temperature()
pressure = sense.get_pressure()
humidity = sense.get_humidity()

# Function to check temperature and make assigned LED's light to correct colour.
def templed():
    ledcount = 0
    if temp1 >= 30:
        while ledcount < 8:
            sense.set_pixel (0, ledcount, red)
            sense.set_pixel (1, ledcount, red)
            ledcount = ledcount + 1
    ledcount = 0
    if temp1 < 30:
        while ledcount < 8:
            sense.set_pixel (0, ledcount, green)
            sense.set_pixel (1, ledcount, green)
            ledcount = ledcount + 1
    ledcount = 0
    if temp1 <= 20:
        while ledcount < 8:
            sense.set_pixel (0, ledcount, blue)
            sense.set_pixel (1, ledcount, blue)
            ledcount = ledcount + 1
    ledcount = 0

# Function to check Humidity and make assigned LED's light to correct colour.
def humled():
    ledcount = 0
    if humidity >= 60:
        while ledcount < 8:
            sense.set_pixel (3, ledcount, blue)
            sense.set_pixel (4, ledcount, blue)
            ledcount = ledcount + 1
    ledcount = 0
    if humidity < 60:
        while ledcount < 8:
            sense.set_pixel (3, ledcount, green)
            sense.set_pixel (4, ledcount, green)
            ledcount = ledcount + 1
    ledcount = 0
    if humidity <= 20:
        while ledcount < 8:
            sense.set_pixel (3, ledcount, red)
            sense.set_pixel (4, ledcount, red)
            ledcount = ledcount + 1
    ledcount = 0

# Function to check air pressure and make assigned LED's light to correct colour.
def presled():
    ledcount = 0
    if pressure >= 1003:
        while ledcount < 8:
            sense.set_pixel (6, ledcount, green)
            sense.set_pixel (7, ledcount, green)
            ledcount = ledcount + 1
    ledcount = 0
    if pressure < 1003:
        while ledcount < 8:
            sense.set_pixel (6, ledcount, yellow)
            sense.set_pixel (7, ledcount, yellow)
            ledcount = ledcount + 1
    ledcount = 0
    if pressure <= 998:
        while ledcount < 8:
            sense.set_pixel (6, ledcount, red)
            sense.set_pixel (7, ledcount, red)
            ledcount = ledcount + 1
    ledcount = 0

# Open up the channel on ThingsSpeak and then send the sensor data        
channel = thingspeak.Channel(id=channel_id,write_key=write_key)
channel.update({1:temp1, 2:temp2, 3:pressure, 4:humidity})

# Turn the Sense HAT LEDs off and ensure that lowlight is on
sense.clear ()
sense.low_light = True

# Call the 3 defined functions
templed ()
humled ()
presled ()

Please feel free to borrow, I've not been programming with Python for that long so if anyone has a better way to code this, please let me know!

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!

64 Lights and they are all off.....

So the Sense HAT has a 64 or 8x8 RGB LED Pixel matrix.  What if I could use that to give a status display of the temperature, air pressure and humidity?

Every half hour a Python3 script is ran from via crontab that captures the sensor input an uploads it to ThingSpeak. As it grabs the values and then pipes them through the thingspeak library why not grab the values and use them to give a quick overview of the outhouse?

So I look through the door and see the currently temperature LED is red do higher than 30 Deg C.  Also that air pressure is below 998 millibars (Again red) but humidity is okay at above 20% but below 60% I wouldn't want to stay in there to long though.

looks like it is all working just fine.

Comments

Post a Comment!

Join the discussion

Log in or create an account, and start talking!