Adventures in Electronics: A betting generator

Adventures in Electronics: A betting generator

In my last update, I’d just written the code in C to randonly create a bet determining the score line by which Liverpool would win a match and who would score either the first or last goal. Having already written it in the (quite frankly much easier) Python, I had come up against some issues getting my LCD screen to work with a Raspberry Pi and so had turned to Arduino, despite my reluctance to attempt to write anything in C.

Having written the code and successfully tested it printing to the console, I logged into the online Arduino IDE and copied the code into a sketch that I had previously used to test the LCD screen. However, when I came to verify it, it failed. Repeatedly. Even though the code worked for the console.

I did some more googling and came across this instructable for Arduino that randomly chose a name from a list and printed it to the LCD.

I downloaded the sketch and tested it with the Arduino which worked fine – although it automatically changed the name every 5 seconds which wasn’t what I wanted, I wanted mine to only generate the information on a button press.  So I set about changing the code gradually. First of all I copied the format for generating the array of names and repeated it twice so I had the scores, timing and player.

So far so good, the information being shown was now random bet information, but it was automatically changing every 5 seconds. I needed to work out a button press so I used the sample digital button sketch and added that to my code, I removed all the remaining code from the previous example and would you believe it? It worked.

Then came the casing.

I measured all the parts, generated a box on box-designer and added some cut outs for the screen, potentiometer and USB cable.

I used 2 bits of protyping board and soldered all the ground wires to one and all the 5V wires to another

I swapped out the male to male jumper wires for male to female and connected the data pins to the Arduino.

And I chose a push button and soldered the LED and the push button pin wire to the positive terminal.

I plugged the Arduino in and nothing. Well, the screen came on but there was no data being pushed to the screen. It was blank. I was devastated. I tried rebuilding it on a breadboard and again, nothing happened. I was gutted,

I took everything home with me with a view to tackling it again over the weekend.

It was about 12:30am while in bed that it hit me – I’d forgotten to ground the RW pin. Maybe that was it. My very understanding other half said “Do you want to to test it?” And 2 minutes later I was enjoying my hot chocolate in bed, watching Brookside surrounded by wires.

Except, I couldn’t tell whether the problem was fixed because actually, the potentiometer was no longer working. I tried a different one, still nothing. I couldn’t adjust the screen contrast to see if the data was being written to the screen.

Another blow. The only thing I could think of, was that the connections on the LCD had been damaged. I would need to try another screen.

So Saturday afternoon, I head over to work, I assemble the whole thing again on a breadboard and again, nothing. So I tried an alternative screen and that worked. My hunch, may have been correct. So after soldering a set of header pins to the screen I reconnected all the wires I’d soldered the day before including an additional ground pin from RW and finally the whole thing worked.

I quickly assembled the box and all the wires before it could somehow change its mind! Throw in a Frank Spencer moment where I squeezed the glue too hard and the whole thing burst over the desk, chair and floor, and you have a faithful account of my bet generator adventure.

The finished make has put me in such a great mood. This is my first make that involved coding, electronics and crafting and I’m so proud of myself I could burst.

If you would like to make your own the full instructions are here.






The importance of finding your people.

The importance of finding your people.

We all have people we’re close to. Siblings, cousins, friends. We might have friends we’ve known for so long they’ve become family. But despite the close connection we might not necessarily have much in common in terms of hobbies and interests.

I love my sister and my niece with all my heart, they’re among my favourite people to socialise with. But I don’t understand their love of reality TV. And I’m fairly sure they look at my  lounge walls covered in Spider-Man comics with a bemusement bordering on horror.

When I was a kid I didn’t really fit in at school. I had little in common with my class mates, and spent most of my break times alone reading a book. It’s only recently that I’ve realised I made the choice to be alone, because I wasn’t interested in my classmates. On the occasions I tried to fit in, I felt uncomfortable and didn’t enjoy taking part in their games and activities.

But I was lonely. And I grew up believing I was weird, stupid and unlikeable. And that stayed with me into adulthood.

For kids like me, university is the first place you find yourself surrounded by people who share your interests. But that’s a long time to have to wait to find your people.

When I started Little Sandbox, it was to provide an environment for nerdy kids to gather and learn and have the freedom to pursue their interests. It was as much about the social aspect as it was about education.

And the feedback we get from kids and parents always includes references to confidence, feeling safe, belonging, and making friends.

Kids need places they can be themselves, where they can do stuff they love with people who understand them. Where they don’t feel judged. Where they can be proud of who they are and what they’re doing.

And so do adults. I’m quite socially anxious. I hate going in to places I’ve never been. I hate meeting new people. I don’t even like making phone calls. And it occurred to me that I’m probably not the only adult that feels this way. So I thought maybe there’s room for a Big Sandbox. A tech club for adults.

And then I discovered makerspaces.

Against all my usual instincts (and after months of putting it off ) I eventually went along to a Maker nights at DoES Liverpool. I didn’t make anything, I just wanted to see what went on there.

And what I found was my people.

I’ve been back a few times, sometimes I make stuff but mostly I just go to hang out. I like being around people that make stuff, I like talking about tech and just feeling like I’m around people that get me.

So that’s why at Little Sandbox we’re developing a makerspace in Norris Green Library – to grow the makerspace community so more adults like me, can find their people.

Adventures in C – A betting generator (take two)

Adventures in C – A betting generator (take two)

My Raspberry Pi powered betting generator hit a bit of a roadblock today. I found a batch of LCD1202 screens and wired one up to the Pi. I found a whole load of tutorials and set up guides for using this screen with a Raspi and python, but no matter how many I tried, I could not get the screen to display anything. The contrast was fine, sometimes it would display a random collection of characters but never what was being generated by the script.

On the second day of piscreen adventures, I learned how to SSH into the Raspi from my laptop because I was finding it difficult to type in code on the Raspi while reading the code on my laptop, the monitor I was using was small and blurry, it wasn’t a fun experience. Still accessing the pi remotely made me feel like some kind of hacker which kept me amused for longer than it should have. Needless to say though, eventually the persistent failure of the screen to play with the Raspi was making me particularly frustrated.

During my travels around the web I found a whole load of tutorials for Arduino too, so I dismantled the Pi and wired up the Arduino instead. Once I got the Arduino IDE installed I found the LiquidCrystal example and sent it to the board… guess what? it worked first time. The LCD screen mocked me with its Hello World and a number displaying how many seconds since the code ran.

Ok so at least we know the screen works.

But my bet generator is written in Python and I do not know C at all. In fact, I was so reluctant to try recreating it in C that I RETURNED TO THE PI.

My head is in my hands even now, wondering why on earth I wasted a further few hours trying to make the pi work.

Eventually, I gave up and decided it was time to at least investigate C. Starting with the standard Hello World and jumping right on up to creating a betting generator. I found a script for creating a random sentence generator and, I suppose, I hacked it 🙂 There was a lot of false starts and errors but eventually it compiled and ran.

The results of the bets are here:

And I’ve already assembled the Arduino, so now I just need to work out how to push the results to the LCD screen instead of the console.

Adventures in Python: A betting generator

Adventures in Python: A betting generator

This week, I was having a discussion with my other half about football and money and the subject came round to betting. Whenever he goes to the match his mates all chip in a few quid and they put a bet on. The bet is usually the final score AND either the first or last goal scorer. Needless to say they never win any money.

We realised that while it is possible to have small windfalls through betting, it is so random, and obviously so stacked against you, otherwise how would bookmakers earn a living, that the amount you have to spend cumulatively far outweighs the amount you might win.

We decided to make that money work for us instead – we will enjoy the excitement of a bet while saving money.

Uh-oh! I feel a maker project coming on… Introducing Ralph & Edna’s Fixed Odds Betting Shop (named after Edna Cross and Ralph Hardwick from Brookside – they loved having a cheeky little bet)!

Both of us will place a £10 bet on a randomly generated final score AND first or last goalscorer. If either of us win, we win £20. If we lose the money goes into a savings box. At the end of the football season we’ll use whatever we have to go on holiday or something. There’s still a small chance one of us will win some money each week, but the house definitely wins most of the time – just in our case the house is ours so we win either way!

The make

Ultimately I want to make a money box that represents the house/betting shop. But I want to include a button that, when pressed, will display the random bet each of us is making.

I’m imagining this will use a Raspberry Pi or Arduino (depending on what we have lying around the makerspace that I can test on) and a 16 character, 2 line LCD screen.

For now though I’ve created a python script that will generate the bet for me.

I initially followed a tutorial for a magic 8 ball (be careful though if you’re trying it – this code is for python 2 but my laptop uses python 3 so there are a few discrepancies in the tutorial namely raw_input has been replaced by input and print now requires parentheses)

I noticed the random module was appearing a lot in the various forums and comments so I had a read about that here

It took a few attempts but eventually I came up with a bit of code (see featured image) which, miraculously worked for me.

Here’s the bets it generated…

Now I just need to learn how to run it from a button press and output it to the LCD screen and I’ll have my bet generator gadget!

Adventures in coding

Adventures in coding

I’ve been learning to code, on and off, for several years. In the 13 years I spent as a web designer, I picked up a thing or two with regards fixing and tweaking code, but mainly just HTML and CSS and if the Instagram memes are anything to go by, they’re not considered coding by any real coders.

Still, I learned how to find bits of code and tweak them, but I couldn’t have built a website from scratch (I am a genius with WordPress though).

I signed up for all manner of online lessons. I tried Javascript, Python, Ruby… but in every course I would get to the same point and give up. I find it hard to follow courses, I tend to learn by doing. Having something I want to make and learning how to make it.

Two of the kids from the kids tech club I run entered the Big Bang NW competition and won a place in the final. Their project, The Kerbinator, aims to make the streets more accessible for wheel chair users by using crowdsourced data to locate drop kerbs/ramps, and adding them to a map so that wheelchair users can plan their routes to include the drop kerbs. It’s a fabulous idea. The plan was to build a gadget that would include a button, which when pressed would write the gps coordinates and upload them to a database which would then be added to the map.
Feedback from the judges at the Big Bang suggested that a mobile app would make it more easily distributed in terms of crowdsourcing and so we decided to work on that for the final.

So now I have a purpose for learning to code. Although we have roped in a volunteer expert programmer who is mentoring the kids, I at least now have a direction for my learning… as well as an expert to help me when I get stuck!

So you can follow my journey as I learn NodeJS and MongoDB… whatever they are!