Jump to content

Arduino and Raspberry Pi Projects Thread


gavino200

Recommended Posts

I'm going to try my hand at using Arduinos and/or other mini open source computers for model train applications. My knowledge is very basic, so I'm going to try to use this thread to collect ideas and resources as I learn. At this stage I'll be copying existing projects and modifying them to fit my layout's needs. I'll collect references and resources here below. If anyone has anything they'd like to add or suggest changing, just post below and I'll edit in the info.

 

Sites and blogs related to model rail arduino

 

Model Railroading with Arduino

No much going on with this site. The most interesting project is Dani's sound project. 

 

Posted by stevenh 

https://modelrail.otenko.com/arduino

 

Arduino DC train controller by KenS

http://www.sumidacrossing.org/LayoutControl/TramController/index.html

http://www.sumidacrossing.org/Musings/files/130414_Revisiting_Arduino.php

http://www.sumidacrossing.org/Musings/files/130504_Detecting_Trains_with_IR_Sensors_Part_II.php

 

Posted by Jeff. Blog about Arduino Tiny

 

 

The Arduino section of Dani's Club N Cales Blog.

Lots of excellent, well described projects, including signals, LED, and sound control

 

 

Dani's Club N Caldes github page

 

 

 

Suppliers related to arduino/ components

 

Adafruit - Great source for LED related electronics, OLEDs etc, along with code and instructions. 

 

 

Resource posted by sedril for PCB fabrication

Fritzing

 

Arduino Store

It's generally cheaper to buy from a third party, but the Arduino store gives a good overview of what's available.

 

 

Arduino Nano purchase link.

 

 

I bought a "Make" Arduino beginner kit that came with an Arduino Uno, some components, a bread board, a USB cable, a 5V power supply, and the following book. I don't remember what I paid for it, but the updated version which also contains a second book is quite expensive. 

 

I don't recommend this book. It's not terrible, but it's not great. I think it would be better to just buy the basic hardware and learn how to use them from online sources. 

 

Arduino programming software link

 

 

 

Edited by gavino200
  • Like 2
Link to comment

There have been quite a few threads in the past here, related to various Arduino projects. I'm going to place links to these threads below. 

 

An amazing project from Madsing's Shin-Yukari layout where multiple video displays 

are incorporated into a building, controlled by arduinos.

An arduino used as a train controller.

 

Description from Dani of a station announcement sound project. Excellent. Worth studying.

Dany has links to some excellent resources. 

 

Short discussion mostly about signals and sensors.

 

Short discussion about Arduino Tiny, with blog and purchase links. Resources added above. 

Short conversation about debugging a piece of code. 

 

Some good ideas and general discussion. Resources have been added above.

 

 

 

 

 

 

Edited by gavino200
  • Like 1
Link to comment

Likely any projects that I attempt will have their own thread and a link to that thread here below in this post. Other projects that I find on the forum or the internet, I'll link here below. 

 

List of possible projects with examples and code where possible

 

These are projects that I'm interested in attempting and will hopefully write up in this thread. 

 

Signal Control

OLED displays - small signs

TFT displays - larger signs

Station audio

Train Speed meter - see below

DCC decoder - mainly just to understand decoders better

Level crossing/scenery animation

Building lighting control

Town traffic lights

 

 

 

Edited by gavino200
  • Like 1
Link to comment
gavino200

I received my LED projects book today. It's fairly slim, and the projects look useful. Looking forward to working though it. 

 

wtEmtyv.jpg

 

 

Edit: Review of the book

 

The writing style is clear and simple. 

 

Chapter One is a simple review of electronic components. There's a nice discussion of how a bread board works. I understood this for the first time from the "Make" Arduino book that I read a week or so ago. The discussion in this book was a nice reinforcement. I'm sure breadboards are just intuitive for most people, but for me they weren't. Actually the mystery surrounding them was perhaps the biggest single intimidation factor with getting into electronics. 

 

Chapter Two discusses Chips. Rather than a wikipedia kind of summary. it gives a history of chips from a hobbyist point of view. It was really nice to see where I fit in in the general scheme of hobby electronics. Again, it checks all three of my personal book requirements. Short, simple, and demystifying. 

 

Chapter Three - Setting up the Arduino. This chapter introduces the Arduino IDE and sketch writing. What I love is that there's a frank discussion of the process of installing drivers for the arduino on PCs. This isn't a simple process. The other material I read didn't mention this. Perhaps they didn't want to discourage people, but there's nothing quite so discouraging as failing miserably at even installing a driver for your Nano. So, cudos to this author for that. The rest of the chapter talks you through a very simple sketch. As it's a printed book you can't just cut/paste. Being forced to write the code is a good exercise, I think, and helps with remembering the process. 

 

The rest of the book is essentially one LED project per chapter

 

Chapter Four - One simple project/sketch - an electronic coin flip. God help me I actually find this interesting!

 

aKeVu7M.jpg

 

 

Chapter 5 - An electronic Dice throw

This was a good lesson. I learned a few things. The sketch built on the last (coin flip) sketch. So instead of writing from scratch, I opened the coin flip sketch and edited it. This sketch was also very repetitive, so I used cut/paste a lot. I'm seeing that using cut/paste in sketches tends to lead to typos and code errors. I'm also seeing that the code won't work unless everything is correct, and that there can be errors that the IDE "verify" function doesn't pick up. The IDE seems only to pick up "grammar" errors. 

 

The second lesson learned in this chapter is that, it's very difficult to trouble shoot a graphical display project/sketch, if the LEDs aren't laid out according to the eventual display. This project was a dice. But for reasons due to space on my breadboard, I laid out the LEDs in a straight line. I also placed the LEDs too close together which made it hard to trouble shoot the physical side of my project. 

 

As I want to eventually use an arduino to control station signals I probably should buy at least one larger breadboard for designing and trouble shooting a spacially oriented LED display. 

 

Chapter 6 - Wheel of fortune project. Similar to the dice sketch. Again I wrote this one by editing the last. This time there are two switches, a start and a stop. I'm beginning to get the logic of the sketches. I'm also seeing how these simple sketches could be used to construct more interesting projects by substituting simple inputs and outputs for more complex ones. 

 

yp0HBK9.jpg

 

Chapter 7 - A very simple sketch. Again building on the preceding code. This time a back and forth array. Like the light in the hood of the "Knight Rider" car. A fun and simple project.

 

Chapter 8 - A fun little project. It's a quiz machine. Six buttons, Six Leds, a buzzer, and a reset switch. It sort of replicates the set of a tv quiz show. Again, the code builds on the previous sketch. 

 

Chapter 9 - A brief but informative of LED arrays such as dot matrix arrays and "Seven segment" (they have eight) arrays - the kind you find in numerical displays.

 

Chapter 10 - A  Seven Segment Display counter project - This is a simple but fun sketch. All you do is program a seven segment array (like the one on an 80s watch or a gas pump) to count from 0 to 9 and then repeat. But for me it's oddly satisfying. These things are everywhere. I never even considered that they were "programmed". I also learned to check if the array I'm buying is a common anode or a common cathode array. Got it wrong and had to wait. Well one more project done. On to the next.

 

Chapter 11 - A two digit display. This is a temp measuring device. But it'll measure anything depending on the sensor.

 

Chapter 12 - A three digit display. This one used a hall effect sensor. I'm using it to measure the magnetic field of my Shinkansen fridge magnet. The sketches for this and the previous project both build directly on the preceding sketch with minimal changes. 

 

jgqIfvb.jpg?1

 

 

The final chapters of the book deal with 8x8 dot matrix dual color LED arrays. There are five sketches. The involve an introduction to basic graphics programming. The concept of a "bitmap" is introduced and well explained. Also shift arrays are introduced. Those are ICs that allow control of more arrays using fewer arduino outputs. These chapters are excellent, but In the 10 years since the publication, dot arrays are obviously less popular. The arrays that the author described as "popular on ebay" are nowhere to be found. Likely because everyone is playing with OLEDs these days. So I didn't actually build these projects but rather studied them instead. 

 

All in all this was an excellent book. I'd recommend it to anyone as a first step. 

Edited by gavino200
  • Like 1
Link to comment
gavino200

I made a first attempt at replicating @Madsing's Speed measuring device. I think the hardware is correct, though likely there's some fiddling and changing to do. I'm having trouble loading the code. When I put the code into my arduino IDE and check it, I get error messages. I get errors for all three codes. I'll work on finding the problem tomorrow. 

 

4B9Atxw.jpg

 

The error message at the bottom is U8g2lib.h: no such file or library

 

su8JfyB.jpg

 

 

Link to comment
gavino200

So I have the U8g2 library installed. The Arduino IDE verifies as far as line 53

 

u8g2.setFont(u8g2_font_inr30_mr); // Choose a font

 

and gives the following error. 

'u8g2' does not name a type. 

 

To sumarize: Git hub has three ,main folders

https://github.com/madsing98/Yukari-Speed-Display

 

First folder: "Tune delay before initializing the display" contains five lines of code that are already included in the main code.

 

Second folder: ".vscode - New TCRT5000 Sensor"   has two files

 

1. a six line code that I don't see in the main program code, but which also doesn't verify by itself. 

Error on the first "{" expected unqualified-id before '{' token

or with @@ -0,0 +1,6 @@ the error is stray '@' in program.

 

2. a 23 line code c_cpp_properties.json, also not in the main code but also doesn't verify by itself.

same error message as above

 

Third Folder - the main code. Currently with error on line 53 as above

 

I'm sure I'm doing something incredibly foolish on a very basic level. I wonder if one of our resident coders could spot what it is? @Sheffie @cteno4, @Martijn Meerts, @Madsing @Kiha66 @chadbag

Edited by gavino200
Link to comment
gavino200

Some progress. I found an error in my code, but comparing it carefully with Madsing's. I placed a couple of lines out of order, presumably as I was copying it into my IDE.  I'm one step closer. 

 

I'm working on some uploading problems now. 

Link to comment
gavino200

I wasn't able to get the Nano drivers installed on my laptop. But it's a Surface Pro and often problematic. I only like it becase it's small and light. I moved everything to my desktop and it recognized the nano with no problems. 

 

But still having problems with the upload. It uploads for a couple of minutes and the green bar goes all the way across, but then it aborts with "problem uploading to board"

 


avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0xba

 

I did a "loopback test" and it was positive meaning there is a problem. 

 

So there must be a problem with one of the following

1 The host computer

2 The hardware driver

3 The USB cable

4 The board's USB to Serial Converter. 

 

It shouldn't be the computer. The arduino UNO communicated fine on both computers.

It's possible that the problem is the cable. I took it from another train related device but I'm not certain about it's function.

By hardware driver I'm assuming they mean the USB drivers. 

 

If it's the board's USB to Serial Converter I take that to mean the Nano is FUBAR and needs to be replaced. 

 

Oh, well, it's still progress. At least the program code is working, and the hardware setup is becoming less mysterious all the time. 

 

Link to comment
Martijn Meerts

I don't really have any experience with Arduino, so can't easily say where they issue might be. It's definitely something that's on my list of things to look into at some point though, but I've just not had a project yet to use it on 🙂

 

 

  • Like 1
Link to comment

The GitHub repository has three files in two folders.

The folder called « .vscode » contains two files that are generated by Visual Studio Code, the editor / IDE that I have used for this application. These two files are « arduino.json » and « c_cpp_properties.json ». You do not need them as you are using the Arduino IDE. Delete them.

Only the file « Yukari_Speed_Display.ino » is useful. This is the source code of the application (also called sketch in the Arduino world).

 

Marc

 

  • Thanks 1
Link to comment

C language is case sensitive.  I don't do Arduino (though I did have it installed at one time to compile modules for some RC controllers) so don't know if the 

Quote

 

So I have the U8g2 library installed. The Arduino IDE verifies as far as line 53

 

u8g2.setFont(u8g2_font_inr30_mr); // Choose a font

 

and gives the following error. 

'u8g2' does not name a type. 

 

 

 

U8g2 vs u8g2 is a problem or just an error in putting it into the forum.  But watch for case sensitivity issues.

Link to comment
gavino200
1 hour ago, chadbag said:

C language is case sensitive.  I don't do Arduino (though I did have it installed at one time to compile modules for some RC controllers) so don't know if the 

 

 

U8g2 vs u8g2 is a problem or just an error in putting it into the forum.  But watch for case sensitivity issues.

 

Yeah, that was the first thing I checked. I found the problem. I had to transfer the code to the Arduino IDE in pieces due to the way that my Surface Pro functions. The Arduino software checks the code and verifies if it is internally consistent, with proper syntax etc. All seems well now. 

 

The only problem is with uploading the code now. I bought a second Nano and a new cord. If it still won't upload, I'll know it must be a driver problem. 

 

I have to say the Arduino thing is quite fun. 

Link to comment
gavino200

Some interesting YouTube videos. Please ignore this if you're anything but an absolute beginner. 

 

Arduino vs Rasberry Pi. What are they? What are the differences?

 

 

 

How to avoid killing your Arduino. A good thing to know.

 

 

 

A nice introduction to OLEDs

 

 

 

Helpful video about TFT displays

 

 

 

Another TFT video

 

 

Edited by gavino200
Link to comment
gavino200
2 minutes ago, chadbag said:

@gavino200  You seem to have posted the same video twice, and did not post the "how to avoid killing your arduino" one

 

Thanks. I was already fixing it. 

Edited by gavino200
  • Like 1
Link to comment
gavino200

I finally got the Nano programmed. It took quite a while to get the the Nano driver for Windows 10 installed and working. 

 

However, the 128x32-pixel SSD1306-based OLED display. is still not functioning. I soldered it to pins, and it's connected as follows.

GND to arduino GND

VCC to arduino 5v

SCL to arudino A2

SDA to arduino A3

 

The sensors seem to work and give a little flicker as I pass my finger by them. 

Still, this is definitely progress. 

Edited by gavino200
Link to comment
gavino200

I tested the SSD1306 OLED 128 x 32 Display using my Arduino Uno and the following instructions, with the Adafruit library installed. 

https://robojax.com/learn/arduino/?vid=robojax-SSD1306-OLED-128x32

 

So the OLED works, and I've been able to program the Nano. Two small successes. Enough for now. I'll call it a day, and start troubleshooting the speedometer next time. 

 

lqUeYxm.jpg

 

Below is the Yukari speed meter circuit. Or rather how I copied it from a photo on the Shin-Yukari blog. I'm not certain I have all the pins correct, but I should be able to check this by parsing the code. When I first tried this a few days ago I had zero clue what I was connecting. Now I have a decent idea. Amusingly if you look closely you'll see some resistors crossing the midline of the breadboard. From my understanding of how a breadboard works I'm 100% certain these are doing nothing. But they were in the photo so I put them in (just in case). I reminds me of a documentary I saw once of how the soviets made a B29 bomber by copying a downed US plane piece by piece. The even copied a few patches that were placed on the fuselage to cover up some damage, though they were fairly sure they were just repairs. I look forward to someday, building with purpose and not just copying the work of @Madsingand others. 

 

pB29gpU.jpg

Edited by gavino200
Link to comment

On the Arduino Nano, SDA (i2c serial data) is on the pin A4, and SCL (i2c serial clock) is on the pin A5. 

Link to comment
gavino200

Thanks. It lives!!! First successful Arduino project!! I'm super happy. 

 

8WWGVmJ.jpg?1

Edited by gavino200
  • Like 3
Link to comment
gavino200

Making a permanent board and housing for it will be a fun project too. The censor distance will be 9cm according to the sketch. I'm going to wait on the sensor housing until I've decided what scenery or building I'm going to build it into. The Yukari permanent circuit has a capacitor that looks like it's attached to either the 5V or the 0 power supply line. Assuming that will protect from power fluctuations. I'll add that too. 

 

For the moment I'm going to put this project aside and continue learning.

 

Thanks @Madsing for publishing your ideas and techniques!!!

 

  • Like 2
Link to comment

So I finished my LED projects for Arduino book. It was a great exercise. Next up I'm going to start to do projects from the Adafruit website. They're mostly graphics oriented so will also be good training for modeling related projects. 

 

 

  • Like 2
Link to comment
Just now, cteno4 said:

You are not so basic now!

 

jeff

 

Well I'm still pretty basic. But I'm ravenously hungry for some OLED projects to cut my teeth on.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...