- 50
- 347 298
Endoor: N Gauge Railway
United Kingdom
Приєднався 24 вер 2022
My venture into the creation of a British N-Gauge railway, sharing musings on playing trains in this gauge, progress on its build and what I've learned so far
0047 Decoding DCC from scratch
I've started on a project to make my own DCC decoders, with the aim of getting much cheaper sound capability on locomotives than buying sound-fitted ones or paying for commercial sound decoders. It will take me a long time to reach that goal, and I might fail, but I'm going to try.
In this video I make a start by getting an understanding of the most basic elements of the DCC control signal, connecting a Raspberry Pi Pico microcontroller and writing some code in Python to capture and interpret the signal from the tracks.
I've spent a lot of time making visualisations to explain what I've learned about the DCC signal - hopefully you'll find it interesting, maybe even useful if you decide to embark on a similar project.
The electrical bits I bought for this, or which I already had and used in the video:
Voltage Regulators, LDO 3.3V
cpc.farnell.com/stmicroelectronics/lf33cv/v-reg-ldo-3-3v-to-220-3/dp/SC08293
Schottky Diodes
cpc.farnell.com/stmicroelectronics/bat48/diode-schottky-small-signal/dp/SC07328
Raspberry Pi Pico, with headers
thepihut.com/products/raspberry-pi-pico?variant=41925332566211
Digital multimeter
www.railwayscenics.com/duratool-hand-held-digital-multimeter-test-leads-p-3492.html?sort=1a&cPath=20_28
In this video I make a start by getting an understanding of the most basic elements of the DCC control signal, connecting a Raspberry Pi Pico microcontroller and writing some code in Python to capture and interpret the signal from the tracks.
I've spent a lot of time making visualisations to explain what I've learned about the DCC signal - hopefully you'll find it interesting, maybe even useful if you decide to embark on a similar project.
The electrical bits I bought for this, or which I already had and used in the video:
Voltage Regulators, LDO 3.3V
cpc.farnell.com/stmicroelectronics/lf33cv/v-reg-ldo-3-3v-to-220-3/dp/SC08293
Schottky Diodes
cpc.farnell.com/stmicroelectronics/bat48/diode-schottky-small-signal/dp/SC07328
Raspberry Pi Pico, with headers
thepihut.com/products/raspberry-pi-pico?variant=41925332566211
Digital multimeter
www.railwayscenics.com/duratool-hand-held-digital-multimeter-test-leads-p-3492.html?sort=1a&cPath=20_28
Переглядів: 10 230
Відео
0046 Solenoid out, servo in!
Переглядів 2,5 тис.2 місяці тому
In the last 9 months one of my solenoid point motors became unreliable again, so I decided to replace it with a servo motor, controlled from a £3.90 Raspberry Pi Pico microcontroller. I cover what was involved, including the wiring, code changes and diagnosing some logic problems along the way. Other related videos: 0033, in which I removed the microswitch from the solenoid: ua-cam.com/video/Sa...
0045 T gauge track laying on The Dawlish T Wall
Переглядів 5 тис.3 місяці тому
I make a start on laying the T gauge flexitrack on the North-Eastern section of my Dawlish T Wall layout. Things of interest I used in this video: 8x self-adhesive cork 21x30cm 1mm cork sheets www.amazon.co.uk/dp/B07S188DRJ Flexitrack: www.tgauge.com/product/317/flexible-grey-track-750mm M1 screws (I got packs of 3mm and 5mm long ones): www.ebay.co.uk/itm/386839328339?var=654097636071 Ultra Fin...
0044 Animating a Ratio Signal in N - part 2 - servo motor
Переглядів 5124 місяці тому
I've been continuing with animating my N gauge Ratio signal kit, getting as far as experiments with motorising it. In this video I talk about the refinements I've made to its assembly, and how I control it with a servo motor from a Raspberry Pi Pico microcontroller. Some of the things I bought that were in this video: Ratio 260 Home Or Distant Signal N Gauge Kit: www.jadlamracingmodels.com/rati...
0043 Fitting DCC to Sonic Models Large Prairie
Переглядів 1,1 тис.5 місяців тому
After a wait of nearly two years the Sonic Models N gauge GWR Large Prairies have arrived! Most of this video is about how I fitted a DCC decoder to the locomotive. After that I give some brief first impressions of how well it runs. The decoder I used is a Bachmann 36-556RA: www.themodelcentre.com/36-556ra-bachmann-e-z-command-90degree-6-pin-dcc-decoder-dc-compatible-back-emf
0042 Scale speed of Dapol HSTs (and a Kato 800)
Переглядів 8645 місяців тому
In my previous video I said Dapol HSTs didn't look fast enough to me, that they didn't look like a real HST at full speed. I wasn't going to actually measure it, but changed my mind and in this video measure it in two different ways. The equipment I used: 5x Infrared Reflective Sensor Modules www.amazon.co.uk/dp/B07TZ782F4/ Raspberry Pi Pico, with headers thepihut.com/products/raspberry-pi-pico...
0041 Trouble with Dapol N gauge HSTs
Переглядів 1,8 тис.5 місяців тому
For years I've had trouble with Dapol N gauge HST dummy power cars not being free-rolling - I show the problem and explain how Dapol handled it when I reported it to them. After a long wait I've received my HST Castle set, so was interested to see if that also has the dummy car issue. In the video I said the Castle set doesn't look like it's going anywhere near a scale 125 Mph at full speed, an...
0040 Animating a Ratio signal in N gauge
Переглядів 2,1 тис.5 місяців тому
Having had it for over a year I finally get started on assembling and animating a Ratio kit of a GWR semaphore signal. At the time of making this video it's still a work in progress. Note: in the video I say I used 0.2mm brass rod, but it's actually 0.3mm - that explains why I couldn't push it into a brass tube of 0.2mm inner diameter! Things I bought during the process of what I show in the vi...
0039 Dawlish T Wall - Building the base
Переглядів 8766 місяців тому
I turn the plans for the railway base into reality, though had to do more sawing myself than I had originally expected to do! I discussed the plans in the previous Dawlish T Wall video: ua-cam.com/video/iPGwTAj06S4/v-deo.html Tools I used in this video: 28-piece small right-angle ratchet screwdriver and mini socket set www.amazon.co.uk/dp/B09J8L9GQV Bosch electric screwdriver www.amazon.co.uk/g...
0038 Using a £3.90 Raspberry Pi Pico to control points
Переглядів 1,5 тис.7 місяців тому
I've put a Raspberry Pi Pico in control of some points on my layout and replaced my Peco point lever latching switches with a more robust non-latching kind. Whilst at it I also made a bit more working space under the layout and tidied some bits of the frame. In this video I cover what I've done with the wiring, talking about some bits and pieces that I've tried. I don't say much at all about th...
0037 Running the new Revolution Trains Class 59
Переглядів 1,7 тис.8 місяців тому
This week I received my pre-order for one of the new Revolution Trains N gauge Class 59s - I wasted no time in trying it out with my rake of JHA wagons! I reference previous videos where I applied fixes to the JHA wagons - those are: 0018 Frame & JHA improvements, and a new Voyager (briefly) - ua-cam.com/video/Q8cCR89NzLo/v-deo.html 0021 JHA final fixes and a new Dapol steam loco - ua-cam.com/v...
0036 The sorry state of N gauge loco quality control
Переглядів 3,4 тис.8 місяців тому
I've had 30 brand new N gauge locomotives - I summarise how many of them had running issues, how Dapol compare to Graham Farish, steam vs diesel, and by the the year in which I received them. I then take a brief look at some cosmetic issues and some rolling stock issues. I ran each of the locos that I didn't send back for refund around the layout in its current state, so there are plenty of new...
0035 Dawlish T Wall - The base, part 1
Переглядів 1,9 тис.9 місяців тому
I've made a start on the baseboards for my T Gauge model railway, The Dawlish T Wall. It's mostly been detailed planning, putting me in a position to order some custom-cut wood - I cover the detail of what I've decided to do. The website I used for the wood is www.woodshopdirect.co.uk/ , but since making the video I've found out that the business closed permanently on the 6th of February. I've ...
0034 Fitting DCC to Graham Farish Class 158
Переглядів 67010 місяців тому
How I fitted a Next18 DCC decoder to a 2023 N gauge Graham Farish Class 158
0033 Two steps forward, one step back
Переглядів 49910 місяців тому
There's been progress on the layout, but there's also been a little bit of a backward step. I cover in more detail some of the terrain and electrical topics that I briefly touched on in the previous video (number 32) - partly because I just didn't want the footage I took to go to waste! I also cover progress since that update in "fixing" point motor power generally, working around one point mot...
0032 General update, with trains running again
Переглядів 1,1 тис.10 місяців тому
0032 General update, with trains running again
0031 T Gauge: ballasts, soldering & train detection
Переглядів 3,5 тис.11 місяців тому
0031 T Gauge: ballasts, soldering & train detection
0030 Point motor control from Raspberry Pi Pico
Переглядів 46211 місяців тому
0030 Point motor control from Raspberry Pi Pico
0029 T Gauge - Getting started - The Dawlish T Wall
Переглядів 21 тис.Рік тому
0029 T Gauge - Getting started - The Dawlish T Wall
0028 Signal & points interlocking with a Pico - part 1
Переглядів 587Рік тому
0028 Signal & points interlocking with a Pico - part 1
0026 Rerouting wires and making more terrain
Переглядів 271Рік тому
0026 Rerouting wires and making more terrain
0025 Making hollow terrain (several ways)
Переглядів 470Рік тому
0025 Making hollow terrain (several ways)
0023 Fitting a DCC decoder to Dapol N gauge Class 43
Переглядів 1,2 тис.Рік тому
0023 Fitting a DCC decoder to Dapol N gauge Class 43
0021 JHA final fixes and a new Dapol steam loco
Переглядів 520Рік тому
0021 JHA final fixes and a new Dapol steam loco
As others mentioned. Micropython is not the best for time sensitive applications. You would be better coding this in ether C or C++. Great effort.
Could probably get away with superglue on the ties to keep the banked angle
It would only have a small area to grab with, and a lot of resistance to work against, so I'd be surprised if it would do it. But I didn't think of trying any, I must admit!
Probably still more reliable than the 1 to 1 scale😊
lol, yes quite possibly! 🤣
As others have said, I'm VERY impressed with your work. To get where you have without an oscilloscope is mind boggling ! I am an electronics engineer and have used the the Pico and I agree with other comments. If I was you I would go for a PIC micro. Microchip provide a free compiler MPLAB X which with your attitude you will easily master. As you say 'C' is by far the best language for real time stuff like this. High-level languages like Python are not good at uS levels. I also would say you should use interrupts, there are loads of timers in the PIC processors like the PIC18F27Q43 that can take most of the timing work away from the CPU. In fact the PIC18F27Q43 has a ZCD (Zero Crossing Detector) feature that I have used to detect the rev signal from an alternator. All you would have to do is put a resistor (50k) in series with the signal line. You can then use a timer to measure the pulse length. I wish you the best of luck. If you need any help with the circuitry let us know! Best of luck, Simon
Hi Simon, thank you for your kind words and for taking the time to write-up those suggestions, and for offering future help - I may well need it! I've made a note of the PIC18F27Q43 as a potential thing to look into, thanks 🙂
looks about the same a z gauge
I don't own any Z myself, but this is half the size.
I don't know the PI2040 as well as AVR microcontrollers but if that MCU has timers and at least one of them has a capture pin¹, then you can let that timer time every transition instead of doing it in code. Then all you have to do is subtract the previously captured value from the current one to get the length, in clock pulses of the bit you're measuring. I've also seen suggestions about optocouplers. They're not fit for the job, they're too slow. Instead you may need signal shaping/debouncing done in hardware - unless the Pico has hardware mechanisms to filter spurious pulses away, of course. Micropython may be too slow even with this approach though. You'll have to assess that as well. ¹ A capture pin is used to copy the current counter value of a timer into specific registers, named capture registers, when a transition occurs on that pin. These transitions may also trigger an interrupt, which is useful to signal the application firmware an event occured.
Thanks for taking the time to write up that extra information, and for reading through the other comments to see what people have said. Interesting about the optocouplers - quite a few people are keen on those. I'll give a few things a go and see what kind of results I get - if the code is successfully getting the instructions I think the controller should be sending, and with enough time to do something with it, then it'll achieve what I'm after 🙂
The multimeter in AC mode will show Vrms, it measures the peak voltage and divides it by the sqrt(2), assuming a sinusodial wave.
Thanks for the info. If it did that wouldn't it end up reading the 13V square wave as being around 9V? 13 / (2^0.5)
@@endoorrailway @endoorrailway Vrms = 13V * 0.707 = ~9V, but that would be for a AC sinusoidal wave, not a bipolar square wave .. The cheap DMM can't make sense of it since it also lacks a true zero crossing. The bipolar square wave isn't referenced to a fixed ground, it's floating. So it's not a true AC signal, where the reference (N) is at a fixed potential. Your measurement in DC mode is just the average it sees over some time, it's simply too slow to measure the signal.
OK thanks .
That'd be great for smaller scale models like models of towns in museums.
Funny you should say that - in the summer I visited Cadbury World at Bournville - in their museum section they have a model of the factory and surrounding town, which at the edge has a railway line. The track looked very much like T gauge track 🙂
I would look into using the PIO on the Pico. You should be able to read data using zero clock cycles on either core. This mean MicroPython is completely viable
Several other people have mentioned PIO too, thanks 🙂
Okey that´s just adorable. BUt I love tiny things they are so fascinating and when it´s this small it´s even something I could own in my small apartment.
Yes there's something fascinating about miniatures 🙂 It's definitely a good size for squeezing a bit of railway into a small space.
this is fascinating, best bit with going from the ground up is you actually know what its doing and why, helps with debugging. I did similar, scalextric digital slot car stuff, way to go is to use interrupts (or the PIO on the RP2040, interrupts are easier). simple IRQ stores a flag. not too hard to get the timing between them in a loop, store it somewhere and use a state machine to process it home made decoders are not generally small, they are however perfect for static decoders
Thanks 🙂 I found writing the code to use interrupts pretty easy to do, though the polling code is also easy. I think I'll start with an interrupt-driven approach when I move to C. I have no idea what I'll actually be able to achieve with the circuit, but I'll have the freedom to make it a non-standard shape to fit the spaces in my locos, so that might help. I feel a long way off that yet though!
I assume that micropython is doing some garbage collection, so you might try force a gc.collect() at a time that makes it suitable for you. Python is not going to be a real time os. You might be better trying to run DMA transfers and processing that instead of trying to poll it.
Thanks. The polling wasn't my first approach, but it was the one that worked best in MicroPython. I'll be moving away from MicroPython for this - I was hoping it would do the job, but it doesn't seem to.
@@endoorrailway At least with python you gave it a try and got to know a bit better about whats happening. Thanks for sharing the video
According to Digitrax each rail is measured separately. Rail A and ground on your command station gives one number for voltage and Rail B and ground should give the same number no matter what system you are using. Try this to see what it is reading. Then adding both readings gives you the voltage output for both rails.
Thanks
Electric interface is not optimal but the bit train is gorgeous
Thanks 🙂
This is a great project. I think you need to be able to measure and see what you are measuring. Please borrow or buy an OSCILLOSCOPE. I have one on my desk at work and without it, you would be guessing. The idea of just using a voltage divider is a great idea. Yes a comparator may work, but you now have to worry about speed and false triggering. There are fast opto couplers available. I use one made by Sharp and has 5 pins, two for the LED inside and three for a 5V, Ground and signal. If memory serves it's called a PC400. Best of luck with this. What I have seen is that when you can reliably trigger on your signal, then the decoding starts to make more sense as you are getting good data,
Thanks 🙂 With the various different suggestions I've been given I may well have to give in and buy an oscilloscope, just to see how the different approaches compare. Thanks for the component code - when I get a chance I'll need to go back through these comments and make a list of the things people have suggested and do some online shopping!
It's great fun to build but a nightmare when things go wrong like getting stuck in a tunnel😢😢😢😂😢😢😢😢
Ah, yes, not much space for fishing them out! I intend to have a tunnel at the South-West end of the layout (Kennaway tunnel) - I'll have to make sure the side is removable.
Your wrist look like they would love some playing and training outside
It's a trick of the camera - they're actually very happy as they are 🙂
Ticket to ride sized!
Haha, yes - I hadn't thought of that, but I've got the USA edition of Ticket to Ride which has the smaller vehicles (compared with other editions I've seen), and they're a very similar size!
thats cool👍🏻!
Enjoyed your video! What about using two diodes instead of the voltage divider or regulator for the input? Connect the catodes to each rail and the anodes to two different inputs of the Pico and perhaps separate pullup resistors between 3.3V and the anode of each diode.
Thanks 🙂 And thanks for the suggestion. The various helpful comments on this video have served to remind me just how little I know about electronics! Diodes just control which direction current can flow in, if my understanding of them is correct, and so I used them to split the signal - but the signal is at 13V, which is far too high for the Pico's (or other microcontrollers') inputs. Is your suggestion that, essentially, only a large enough resistor is needed in order to reliably reduce the voltage from 13V to 3.3V after the diodes? The Pico has internal pull-up and pull-down resistors, which one to use is configured in code, so at this stage I don't need to add any for that purpose as far as I'm aware.
@@endoorrailway With a diodes mounted the way I suggested, the current should only flow to through the diode and pull the input down to 0V when there's 0V on the rail (suggest using similar diodes as the rectifier to have the same voltage drop). When the rail is at 13V the diode blocks and pin is pulled up to 3.3V either internally or with a resistor. Probably not necessary to monitor both rails, then you can use only one diode and input. But I think a setup with an optocoupler as some already suggested is the most optimal way of harversting the signal.
Ah I see, that's neat, thanks!
I do not use the Nano, myself, but one thing that occurs to me is that your assumption on the execution speed for the Nano Pi could be optimistic. As standard, the Pi runs an *interpreted* Python, which is usually regarded as a very slow process. The Pi forums are awash with suggestions to improve the speed, one consistent one being micropython, which seems to be compiled to machine code. One point of discussion is that the Linux operating system is SAID to "take a fair bit of time", although some then say "1% of your CPU time is not a lot". I have seen "news" that the Arduino IDE will program the Nano, but not tried that. There are cheap oscilloscopes on Aliexpress, I use a DSO138, but it seems the DSO152 is better, good enough for Adrian of Adrian's Basement on YT to mend a computer with it. Using an ESP32, which runs a compiled C++ from the Arduino IDE should be even faster, but involves learning C++ and different hardware. Avoid the Arduino itself, an Arduino Uno, for example, has none of the advantages of the newer processors, which are aiming for "computer on a chip" functionality. ESP32 has 2MB of RAM, Wifi, Bluetooth, three UARTs for serial, I2C, SPI, two processors, interruipts, two timers (or is it 3...) as standard.
I've never looked at a Nano Pi before, but it looks much more like a computer than a microntroller - what I used here was the Pi Pico. I don't think there's any option of having standard Python on that - MicroPython is all I've seen - but I've got no idea how it implements Python on the Pico. Without an operating system being present it must be quite different, but to work like Python it must still have various inefficiencies. I know that standard Python gets compiled to bytecode at some point (the .pyc files that appear), but is still an interpreted language. The RP2040 sounds like it's one of the computers on a chip - I'll have to assess more options when I get to the stage of making something small enough to go into a locomotive. I've got no fear of programming in C or C++ - I've done that before - but I've got a lot to learn about doing it with microcontrollers and in some cases even just how to get the code flashed onto a chip seems complicated! All good fun learning it though 🙂 Thanks for you ideas and taking the time to write that up 🙂
i wonder what the proper commercial approach to signal conditioning is? is there anything in the spec that describes appropriate circuits for picking up the signal from the rails? in my opinion voltage regulators and voltage dividers are not going to be enough, and will be noisy. i think you might have better luck with optocouplers. these use a light (or infrared) emitting diode across the input signal to turn on a phototransistor on the output side, and will automatically produce a 3v3 signal that is completely isolated from the rail power. if you install two, and connect one in reverse, across the rails, you can select the polarity you are detecting. because optocouplers more dependant on current than voltage, it should give a much more reliable pickup, i think, and i strongly suggest you look into this. however i really would like to know what the specification expects. as for interrupt driven decoding, you may want to consider that there are different priorities of interrupts and, unless you use the highest priority, your interrupts will be postponed by anything else the system thinks is more important, and this will skew your timing. thank you for introducing me to this topic, it is fascinating.
In what I was reading I didn't come across anything that suggested implementation solutions, it was just specifying what needs to be achieved, but I haven't read through most of the documents - I was just trying to get started somewhere. The various specifications are at www.nmra.org/index-nmra-standards-and-recommended-practices A few other people have suggested optocouplers too - I'll have to take a look at what's available - ultimately I'd like to make something that fits into an N gauge locomotive, so small surface-mount components will be needed. I'm sure there's be optocouplers that fit that constraint though 🙂 There was a nice guide about interrupt programming I read that's part of the MicroPython documentation; I'm not sure what other interrupts would be going on, but it seemed to be saying that all of the same priority would queue up if they overlapped, so I just left them at default. Maybe there are others happening that I don't know about, but I think they'll also be affected by the voltage regulator potentially distorting the timing, so there seem to be a few ways in which I could improve things. Thank you for taking the time to share that useful information 🙂
@@endoorrailway i tried reading the spec, thanks for the link, but it seems they do not concern themselves with the actual interface, and these are proprietary. must first admit my electronics technical degree was a very long time ago, and i am very out of practise, but i think you could use a PC817, with an appropriate current limiting resistor, directly across the track signal, and you could then connect the ouput directly (and safely) to your GPIO pin. if the track voltage changes, though, you would need a different resistor.
It didn't take you long to scan a lot of information there! With a degree like that you'll have forgotten a lot more than I'm likely to learn in this field. Thanks for the suggested component - I'll have to start making a list of the various things that have been suggested.
Absolutely LOVED this video... completely Nerdy and pushed so many of my buttons with reverse engineering, electronic, programming and Picos. I think microPython and Pico PIOs is a good solution. I have a project 'picotimcode' which de/encodes a similarly structured protocol. Use separate PIO blocks running small state-machines to break the capture/decode into several parts. Collate the bits and pass to microPython code via FIFO and interrupts. I use one core to controll PIOs to do decode/encode, and the other core to do UI for controlling the whole lot. Good luck, and thank you for bringing me smiles/entertainment.
Also when thinking about capturing bits, think in terms of time rather than voltage. Quick toggles vs slow toggles.... this should be easy for a PIO block.
Thank you very much 🙂 It's getting a lot more views and comments than is typical for my channel, so I think it's ended up appealing more to the general electronics hobby or pros than to just model train-loving folk! Thanks for mentioning PIO - I haven't spent much time to date working with microcontrollers and hadn't come across it before making this video, but others have since mentioned it too. I'm glad you like Picos too, but ultimately for this project I'm aiming to use something physically smaller than the RP2040 (some kind of ATTiny is what I have in mind), so I don't intend to go down the PIO route because it looks like it's specific to the Picos, but if I were sticking with a Pico then it does look like a good way to go. I'm glad you enjoyed it, thanks for letting me know 🙂
@@endoorrailway there are quite a few _really_ small RP2040 and RP2350 boards, magic word is 'stamp'....
A stamp is too big for a lot of N gauge locomotives. For what they have crammed inside these systems on a chip are a real marvel of engineering, and so cheap for all the wonders they perform, but at 6.5-7mm square the RP2040 takes up a decent amount of space that I'll need for other bits and pieces like optocouplers, resistors, some kind of non-volatile storage, motor driver, amplifier etc. - I know there are less capable but much smaller chips around. I really don't know what will work, ultimately - I may well end up with an RP2040.
smells a little like 12v canbus in a car, your rail 1 would be canH and 2 as canL
This is the first time I've tried to work with a digital signal at this level, so it's all "DCC stuff" to me, but it seems likely the engineers who designed it were familiar with other similar things like canbus and took inspiration. That would also help other engineers understand it and work with it easily as there'd be familiarity.
@@endoorrailway yes true, in fact just about all signalling systems have evolved from another before, no matter how complex they make it once it passes through circuitry it all boils down to just 1's and 0's. this one is fairly basic in that theres no error correction just bad packet skipping, you want an headache, look into a cd players data stream thats designed to cope with random flipped bits from noise/dirt of the disc, its amazing how they even came up with it and I'm glad i'll never have to try to code for it....
At this stage I'm pleased that the error detection is just skipping and not correction! Yes I've been impressed with how well CDs can play even with a decent amount of scratching on them. I think that's going to be at a complexity beyond what I dabble in during my hobby time 😉
Wow! Superb!👍👏👏♥️
Thanks 🙂
Nyquist's sampling theorem applies to your track signals: you must sample at least twice as fast as the shortest pulse, so given shortest = 52us, you have to [be able to] sample at 26us intervals. I would suggest you sample at a faster rate than this though: it's common with UARTs to sample at 16x the baud rate, and while that might not be needed, 4x is probably a good thing to aim for. I would strongly suggest looking at the "PIO" units of the Pico. They are kind-of a dedicated I/O processor, and will be able to sample the input very effectively. You can program them from a high level language and then get the benefit of full speed processing. There are a number of example configurations available in the pico SDK - look for example at the I2C and UART setups for inspiration, as they are doing similar things (sampling a pin and decoding signals on it).
I knew there must be a formula, thanks! With 26μs samples a DCC "one" of 64 could potentially be measured as lasting 78μs, but the shortest a DCC "zero" could be measured at is 104μs. But with a 29μs sampling frequency a similar thing comes out - max One is 87μs, minimum Zero is 116μs. I must admit I keep having thoughts like this, but eventually find a scenario that proves me wrong. So far 29 is the largest I've come up with where (I think) there can't be an overlap in interpreting the longest One and shortest Zero. Thanks for mentioning PIO - it's not something I'd come across before making this video (I've not got a lot of experience with microntrollers), but a few other people have mentioned it since. I think it's specific to the Pico, so I'm not intending to go down that route to start with because there are physically smaller microcontrollers around, so I'm expecting to translate what I learn to another architecture. Thank you for taking the time to explain those things 🙂
I have to preface this comment with me not being a python programmer, the last time I used it was long before I retired and I was forced to use it to allow use of a cellular modem that could only be programmed in python, and that had no development environment or debugger. As you may imagine it wasn't my favourite - any language that uses white space as a syntactical element should be strangled at birth, though its data structures and so on are more than adequate and modern IDEs help to stop the more egregious mistakes. On the whole I prefer to stick with C/C# (I also regard C++ as an abomination, despite having used it for a couple of decades professionally). My own suggestion would be to use the PIO instead of polling for edges (I am not going to comment on the hardware, others have already done so). If you download the Pico python SDK documentation then at the very least you could raise an interrupt on a rising edge using the example from 3.9 that would reduce the load on the python. Further PIO programming could actually accurately decode and pass a series of bits over to the python code where the high level decode of the commands from the resulting bit stream could be done pretty simply. The PIO programs drive state machines and are limited in length but the instructions available are ideal for bit banging applications. I am afraid I can only offer broad suggestions because I do not have the hardware available to test it in any way, not having any DCC gear.
Most of my programming experience has been in Java, but I've done C, C++ and some C#. For the most part Python has come out as my favourite in the last few years, though it heavily depends on what it's being used for 🙂 I've been wanting to avoid going down RP2040-specific avenues, like PIO, but so many people are suggesting it I might have to do it just to see how it goes and report back in a future video. Thanks for taking the time to share your thoughts 🙂
@@endoorrailway I imagine IDEs and debuggers make it easier to deal with these days, though I still dislike white space as a syntactic element - you could severely mess with someone by adding a space before one of their tabs in an if block (though I would hope that the compilers would flag that, they didn't 15 years ago). The unit I was programming was a black box hit and hope - you downloaded the program to it and hit reset, then it either did what you expected or not. I did find a compiler for PC that would at least allow me to test out the processing and data structures in a controlled environment but anything to do with the cellular modem was a wing and a prayer since there wasn't a serial port to pass any response codes from the modem back to a PC for debug. I still shudder with that one, it was a pain to get working reliably wherever in the world it was deployed and it should have been a simple case of slap a local data SIM in and off you go. With regard to the PIO I think you will find it worth looking at as it is pretty simple, especially if you are familiar with assembly. The state machine code is severely limited in size but it would still take quite a load off the main program and you could do the pulse measurement down at what is effectively hardware resolution and pass the bits over to an interrupt handler in Python to handle the protocol. I said I would leave the hardware alone but I have to add one thing: I would sample the second rail to be able to filter out any glitches to ensure reliability, I imagine a railway layout is electrically noisy. My own choice would be to use a pair of optos to interface it to the Pico's power; a couple of resistors and some cheap optos would firmly isolate it from the track power and allow a check to ensure that the two signals were truly complementary. Obviously YMMV.
@@TheOwlman Thanks for you further thoughts and taking the time to write them up for me 🙂 Perhaps I'll find that ultimately I want to measure both rails, but with the commands being repeated I suspect it's not going to be necessary, so keeping the componentry and code that little bit simpler is very appealing. I'm also right at the start of this project so although lots of people such as yourself have kindly provided lots of useful and sensible information, it's too much at this stage for me to be trying to incorporate all of it. Thanks 🙂
I have thought using T scale for a subway line below the city layout/.
That would be nice - it would allow you to make big buildings.
I imagine that if T gauge gets popular enough, Micro Trains will solve the coupler issue at some point.
I think it would be great if it got popular, but regardless of how detailed or well it runs, unless it somehow becomes dirt cheap I think it's just too small for most people to be interested in buying.
I want to see the motor inside
There's no way I'm going to try taking this apart unless I really need to, but I suspect the motor is this one: www.tgauge.com/product/500/motor-with-gearbox
Have you tried running the dummy power cars without the body on? Otherwise could it be overly tight power pickups on the wheels?
Thanks for you ideas. I haven't, not beyond a quick test immediately after fitting a DCC decoder. I know that on several of them the wheels rub against the underside of the chassis. I guess I could try rolling the bogeys along by themselves - that would show how well or not the wheels roll.
The HW is "right". Meaning, the rectifier bridge with the voltage regulator. Don't forget some decoupling capacitors. DCC is in kilohertz square wave. The code must be much more robust. Ideally, in C or assembly, using interrupts and HW timers, not relying on execution speed at all. Good luck :)
Thank you for your thoughts. I'll definitely be moving away from the voltage regulator between the signal and microcontroller inputs! Execution time will always be relevant - even in an efficient language and triggered by interrupts, instructions must still be executed for anything useful to be done. But knowing that C is a lot more efficient, and from what others have commented, I'm expecting switching to that make a big difference. Thanks 🙂
@@endoorrailway Also, get yourself a Pico 2.
@bexhillbob I probably will at some point, partly because I'm interested in trying Rust, but I don't think I need the RP2350 for this project.
I have never heard nor seen "T" scale before!
My dad used to engage but then he's got h for a Christmas tree train
Great video. Two suggestions to vastly improve reliability for you: 1. Opto-couplers (I don't suggest resistor dividers; see below) 2. Interrupt driven GPIO Bonus tip: Oscilloscope 1. Opto-couplers As others have said, a voltage regulator is a terrible solution for this. The regulator will take time to, well, regulate the voltage. This regulation can take time, and, is not really deterministic. So your response time may vary. Also, with the regulator you are coupling the (virtual) ground (the zero volts) on the rails to the ground on the Pi, and by extension your PC. That's not an ideal solution. Others have suggested resistor dividers. That works on a single rail, but can still cause the ground coupling issue, which isn't ideal. Opto couplers are ideal here, because they have diodes built-in, you can use one in one orientation and the other opposite that. Then you can use two GPIO pins to monitor either direction if you want. You'll get ground de-coupling, voltage isolation and a deterministic response time all in one. Opto couplers are perfect for this application. 2. Interrupt driven GPIO Others have mused that a 16MHz Arduino has no trouble decoding DCC, but you're struggling with a 133MHz Pi. The reasons are Micro Python and probably the voltage regulator. To make that more deterministic again and make sure you're not missing pulses, you should switch from polling to interrupt driven GPIO handling. An interrupt allows code to be processed immediately, regardless of what the rest of the processor is up to. You can simply timestamp the pulse then or count it and then resume "normal operations" A quick Google found an article titled "Raspberry Pi Pico Interrupts Tutorial- Examples in MicroPython" that might explain it for you. This will make a big impact on reliable pulse counting. Bonus tip: An oscilloscope would be super handy here. These days, a super basic one can be had for DIRT CHEAP. They won't be great, but absolutely perfect for testing and debugging this kind of issue. The "FNIRSI DSO-152" (no affiliation; just and example) is one example. You can get something like this for well under $30.... Hope this helps.
Thanks for the encouragement and for taking the time to write up that information for me! I've been a bit baffled by ground coupling for a while - often things I buy seem to require it, and the common ground on the electrics of this layout seem to link lots of things. I would much prefer things to have more isolation, so if optocouplers are small enough then I'm in favour of trying them 🙂 I did actually start off with interrupt-driven code, but I couldn't get good results and switched to the polling, which worked better. However, the interrupts will be directly linked to what the voltage regulator is doing, so that could well be a source of issues from what you and others have explained to me. I did actually read through a detailed interrupts tutorial from the MicroPython documentation before writing any code - it gives lots of useful information. I don't think there are other projects I'm going to want an oscilloscope for, so I'll see how far I can get without one - I'm pretty sure the signal at the tracks is going to be good because I've got plenty of trains receiving instructions correctly, but I admit it would help with diagnosing the issues I've had! Based on all the helpful comments like this one, I think a combination of switching to C and for now using a voltage divider (both things I should be able to do soon without doing shopping), are likely to bring much better results 🙂
@@endoorrailway optocouplers can be extremely small. Definitely give it a go. One side behaves exactly like an LED, though you never see the light; the other side is often a PNP or NPN transistor with exposed collector & emitter. There are many, many example circuits on the net.
Great, thanks 🙂
I played around with all this a couple of years ago (for Scalextric Digital, which also uses DCC)... I can wholeheartedly recommend all these suggestions. I know a scope is an investment, but you're doing everything blind without one. I went for a Hantek standalone unit for under £200, but USB ones which use your PC to do a lot of the work are £50 or less.
I had a bit of a look at oscilloscopes today - it looks like they'd need to have megahertz bandwidth, and then it was unclear to me if ones that said they're 1 or 10 MHz can handle square waves at that speed. I'll see how far I can get without one - I can be confident that the signal at the track is OK because 30+ locomotives all respond to commands just fine, and I know from the NMRA specs what the signal for the commands should be, so I'll only need to get an oscilloscope if I get stuck. Thanks for the comment 🙂
My few cents: Stick with a regulator for supplying power to the pico. Use a voltage divider using two resistors for the signal. Have a look at interrups and write the recieved bits into a circular buffer (ring buffer)
Thanks for your thoughts 🙂 I think a regulator from rectified power for the microcontroller would be sensible, and actually the DCC specifications say decoders should be able to work with up to 20V from the track, so I imagine it would help with that. I actually started out using interrupts but got worse results that the polling; however, from what others have said it seems that could be at least partly to do with using the voltage regulator for the signal.
Wow that is tiny. 😂
It’s likely your meter isn’t a true RMS meter, so instead of taking a proper average it just takes the peak and multiplies with 2/3 which would be correct for a sign wave, but is wrong for any other wave like the square wave.
Thanks for the theory; in AC mode it does measure the DCC track voltage (without any of my diodes in place) as the expected 13V, so it must be taking a proper average to get that. The readings where it was 2/3 of full voltage were when it was in DC mode - I don't think it should be doing any kind of RMS (or an approximation) for DC, if nothing else because it would never produce a negative value. In DC mode it does correctly measure normal DC signals, like the supply for my LEDs, or the terminals of a 9V battery, as being at the expected voltages. Maybe I need to put it into AC mode and see what it makes of a single track's signal through the diodes - I didn't do that because the current isn't alternating. This multimeter was about £7, so it's not going to be a fancy one.
@@endoorrailway If you were to give your multimeter on AC a 13V sine wave, the peak voltage is going to be 1.4 times the RMS value, and the meter is calibrated to tell you that the RMS is 13V. This is the cause of your 2/3 and 3/2 values, though they sound like the average, rather than the RMS. Try that AC read on a 9V battery and see what you get, compare the DC and AC readings, that should calibrate the reading in your mind. Most multimeters measure AC by rectifying the AC to DC and then dividing by 1.414, the square root of 2 (or multiply by 0.707, the inverse, it's the same result). This matches the definition for measuring an AC value, that it should come out the same as the DC voltage that would deliver the same POWER. (if you have root 2 times the voltage, you get root 2 times the current, and volts x amps = power.) For most multimeters, your AC range will read 13V RMS AC as being 13V and it will usually do the same for 13V DC, though it may say 18.3V... A smart multimeter will recognise DC and scale itself accordingly, though most simple multimeters are not that smart. You could try this and it will be informative. It would seem that when no instructions are being delivered to the track, it rests at 13V DC. You could tell by putting a DC-only engine on, it should go like Mallard... Multimeters are a black art that I mastered in 1973, but now can't explain very competently. It's been a while...
@neilbarnett3046 thanks for the information. The 9V battery test is odd - in DC it measures 8.5 or -8.5 swapping the leads, so that seems about right. In AC it measures 18.8V with the leads one way, and 0V the other way. I expected about 12V or 13V regardless of which way around the cables were, if it were applying the scaling to get equivalent DC power. I think I'll need to do some proper reading up on multimeters, or maybe buy one that comes with detailed documentation - I'm going around in circles with what I'm understanding of what people are telling me vs what I measured, but thank you for taking the time to try and help me with it!
I was so busy watching, and then you look up and there's the 1991 passenger express - hahahaha random
was going to get a set for my son, priced the same as a full size set😑 why this hobby is no longer accessible for children , target market 45 or above
When I compared with N gauge for controller, track and 7-coach HST, T gauge came out cheaper, and I find N gauge is usually cheaper than OO, and when I've looked at O and Z they've been a lot more expensive. But in real terms T gauge isn't much less expensive even though it's a lot smaller, as you've seen. I don't know the details of the economics of model railways, but I'd certainly have a lot more trains if it was a lot less expensive. Presumably the market demand for toy trains or low-detail models just isn't high enough these days to be viable business for the manufacturers.
@@endoorrailway These companies do not even give young potential hobbyists a chance anymore, there should be a reasonable quality starter set with a bit of everything, scenery some length of track flock, train , trees ect all for under 100 pounds and it , If they were smart would also contain a small catalogue of next steps and teasing pictures of the good stuff to inspire, sure the margins would be tight but this is basic marketing often referred to as a foot in the door. thanks for the reply
It does seem to make logical sense - get people interested when they're young in order to get their business later when they can probably afford more. I have no idea about the economics or how companies measure that eventual pay back, or even if it's possible to measure properly, so I'm neither defending them nor blaming them. As a customer and as a father I do agree it would be good if there were more low-cost options available though, so there was something for everyone. Thanks for the comment 🙂
This looks like a cool and fun project. A couple of suggestions: For input use a comparator rather than the voltage regulator. It will give a digital output depending on where input A is higher than input B, or B is higher than A. Get one suitable input voltage range and 3.3V output and it can safely connect to the Pico. For timings remember the phrase “be strict with what you produce and generous with what you consume”. If your outputting signal make them accurate. If your reading them accept input which is outside spec but which makes sense. For the timings here you basically need to set a cut off time between a short signal and a long one. That will make your code resistant to issues. As for the code itself the PIOs on a Pico are specifically designed for processing serial data like this and they’re way, way faster than Python. Use them if you can. I’m not sure what that would look like here, people on the Raspberry Pi forums can probably give the best advice.
Thanks for your suggestions - they're helpful 🙂 A comparator or voltage divider sounds good - I'll be having a go with some resistors soon for the divider, and comparators look low-cost so might be worth trying too. Eventually I'll need to fit everything onto a circuit board that fits into a locomotive, so if I can get away with a couple of resistors that seems like it might take up less space than an integrated circuit package. Yes a simple cut-off sounds good - I think the signal is likely to be good most of the time, and since commands are repeated it shouldn't matter if the odd one gets mangled somehow. A couple of other people have mentioned PIO on the Pico - I hadn't come across that before. It does sound good, but ultimately I'm expecting to move to something physically smaller than the RP2040, so I don't want to develop things with things that are too Pico-specific.
@@endoorrailway Regarding resistor dividers, I’d be wary of voltage spikes causing damage to the Pico. To avoid that look for something called a protection diode and put in across the bottom resistor of the pair (assuming you’re powering the Pico from the rails. Between GND and the Gipson pin if not). This will prevent the voltage going higher than the diodes rating (which should the 3.3v here).
Thanks - that's worth knowing about - the DCC specifications for decoders state they should be able to work up to something quite high - I think it's 20 Volts - so I should consider it possible the controller could output that. Spikes could also happen for various reasons, so they're worth defending against if possible.
I already thought it was crazy to hear the scale as a number, but to SEE it is another thing entirely. Barely bigger than a pencil and smaller than a lego minifig is wild
Yes, it's surprising it exists and works!
You can fill that rail gap pretty easily, no? Don't use crossheads for the screws. Use torx.
I'm not sure what I'd fill it with - what did you have in mind? Although it stands out in scale terms, it's far too small in real terms to put a tiny slice of rail in. Thanks for the hint about torx 🙂 I'll have to see if I can find suitably tiny ones, and maybe buy some smaller screwdrivers.
@@endoorrailway you could try low melt soldering rod, after shielding the sleepers with tin foil. Or you could use jb steelstik, or any other metal epoxy putty. These work at room temp. Push a tiny bit into the gap and use a craft blade to form it into a shape continuous with the rail. Look at micro electronics (particularly fpv) parts. You'll find tiny torx hardware that will be much less likely to strip.
Awesome pointers, thanks 🙂
1:450 model I thought maybe someone should make layout with hms vanguard battleship there are photos of the ship in Africa and there are trains while the battleship is at the background
The tiny scale of T gauge makes it possible to have models of other things that would otherwise take up too much space in the more popular scales, big ships included 🙂
We found it. The train for ants.
Ants would be about the same size as people at 1:450, so it's just the right size for them 🙂 Not sure which creatures the other scales are for though.
I love the "binary train". Great visualization.
Thanks! Once I'd had the idea, I just had to do it 🙂
I'm glad youtube recommends me this! I've been thinking on doing the same but I'd need to learn quite a lot of stuff and its quite a daunting task. I like the way you explained the dcc protocols and maybe I can replicate your work someday! (I know there are libraries for arduinos, but just like you, I want to know the inner workings of the dcc system as well)
Thanks - it took me a lot more effort to make this video than my usual ones because of the diagrams for the explanations, so I'm glad it's making a difference 🙂 I may make my eventual "production" code public on GitHub, but in a way it's a bit pointless because people like you and I want to do it ourselves from scratch anyway 🤣 I too find this daunting though - I'm comfortable with programming, but there's loads that I don't know about the electronics side. But it looks like there's plenty of community help available - I've been given good advice in comments already 🙂
Same here. I'd LOVE to convert all my locos ( 00 not N , thank goodness! ) to DCC, but the cost of loco modules is SOOO expensive, and then of course, the main controller as well.... I'm definitely looking forward to your solution. One question, is it possible to do it this with Arduino, as I have a spare Nano I can use for test purposes? Cheers.
There are other people who've done it on Arduino - the search phrase "DIY DCC decoder" on Google brings back useful results. I read about some of the things linked from dccwiki.com/Do_It_Yourself#Decoders, but not in depth. I'm a long way off anything that can go into locomotive yet, but it looks like other people have done it already 🙂
@@alanclarke4646 IIRC, for the main controller you can use arduino with "DCC++" Although I've never used it myself
One of the things I find weird is how the pico running at 48Mhz has throuble reliable decoding the DCC packets, while and Arduino running at 16MHz is reliable for decoding the packets. Also, use a voltage devider, not a voltage regulator. a voltage regulator mangles signals like crazy. Even better would be an opto coupler Consider buying an cheap osiloscope to view what you are actually working with
From what I read the Pico is 133 Mhz, so to take 30 microseconds to get a reading of the input means it's executed nearly 4,000 instructions! The fact the Arduinos can do all this reliably makes me think that MicroPython is the issue - before long I'll have a go at this with C, just to see the difference. Several other people have also advised that the voltage regulator isn't the way to go, so I'll also see what resistors I've already got and make a voltage divider instead. It would then be interesting to see how the MicroPython does too after that. I'm not expecting to need an oscilloscope for many things, so I'll see how far I can get along without one, but am open to the possibility I'll need to get one. Thanks for the suggestions 🙂
Python is usually interpreted, whereas C++ (as it roughly is) on the Arduino is compiled. So every Python statement has to be read (often copied to an instruction buffer), taken apart, tokenised, parsed and then starts the execution of a fragment of machine code, and then the next part of the statement has to be... yes, you guessed it. I would normally reckon on interpreted code being 20 times slower than compiled code. Compiled programs tell the processor exactly what to do, at full speed. They are, however, tricky to debug, the Arduino IDE and others have a good go at spotting errors at compile time, but after that, the processor will be on its own. There will be some error trapping, for out of memory access, numbers out of range, trying to put values into an input port and so on, but... A good example, I wrote a fractal program in BASIC (interpreted) in 1988 that took 55 minutes to create the Mandelbrot set on screen. I then found a fractal program that did it using compiled machine code in about a minute. The BASIC was, however, good enough for a printer exerciser that wasn't time-crucial.
@@neilbarnett3046 Yeah, I remember thinking when he said it the budget was 100 instructions per microsecond that it would be fine in C or assembler where I'd expect 10 instructions per bit. But if Python is 10x worse that's 100 instructions and very close to being too slow. Python definitely has its uses in data science type applications but running it in a real time embedded system is not one of them. C is great for that sort of thing and if the C compiler does a bad job on the time critical parts you can just write them in a assembler.
@neilbarnett3046, @user-qf6yt3id3w There's some degree of compiling in Python, but I suppose it's more like caching because it's first done at runtime. But that's normal Python - I've not got any idea how MicroPython is implemented. I fully expect interpreted languages to be slower - really I was just having a go with MicroPython to see how it would turn out, and underestimated just how much work it's needing to do to be like standard Python. Eventually I'll get to trying some C on the Pico. Thanks for your comments 🙂
As an electrical engineer, I'd like to congratulate you on your courage and open-mindedness. An excellent start. I have just one suggestion to make, if I may. Try replacing your voltage regulator with a simple voltage divider. This is just a pair of resistors of fairly liberal values, say 2.7k and 8.2k. You'll get a cleaner signal and, ultimately, fewer headaches.
Thank you for your kind words and this useful information 🙂 A few others have also suggested I should use voltage dividers, or other things besides a voltage regulator, so that message is coming through loud and clear, and I'll be doing some component shopping before the next iteration 🙂
@@endoorrailway A voltage regulator is designed to provide a _stable_ supply voltage, so it's not surprising that it doesn't work that well for an intentionally changing signal.
@mrab4222 - thanks, yes I guess that does make sense because it's going to be trying to counteract fluctuations, so that's likely to add some delay even though the voltage is totally dropping off below what the regulator works with. So far my main limiting factor is that it can take a long time for the MicroPython to take a reading of the input, compare it to one that's in memory, and record the time if there's a flip; none of how long that takes is affected by the voltage regulator. The regulator may well affect what happens in the scenarios where I used interrupts though, since they directly hinge off changes in the signal. I'll be moving to C and, for now at least, some resistors for voltage dividing - it looks like I've already got some at resistances that should work 🙂
@@endoorrailway If you already have a bunch of random resistors laying around, you can connect them in parallels or in series to get the required equivalent resistance. This will be sufficient for a quick prototype.
@barmalini Good point, thanks - putting smaller ones in series could be useful if power through them is too high too, though it looks like that's not going to be an issue in this case.
Regulator is awful solution to match signals voltage levels. Resistor divider will be enough, eventualy optocopuller or specialised level shifting ic (old ones from RS232)or just transistor.
Thanks for the info 🙂 Ah OK - out of curiosity, what makes the regulator so bad for this? I'll definitely need to scale this down though, and I know it's possible to get small surface-mount resistors, presumably also transistors and optocouplers. But wouldn't the resistor approach rely on the track voltage staying the same? In practice it does, but according to the DCC specifications a base station would be allowed to produce a lower voltage, and decoders should be able to cope with it. Plus locos might get poor pickup on occasions even if the track voltage is consistent.
I came here to say the same 🙂 : Nobody uses voltage regs as level shifters. I have not looked at the signal on a scope, but I don't think their startup time/speed will be reliable enough for proper timing. The pico should be plenty fast (I think) for what you are doing. You can try with a resistor divider if you do not want to isolate the track and pico with an optocoupler.
The voltage regulator is not ideal - a step change on the input will result in a slope change on the output. I recommend you use a high speed optocoupler (6N137 is commonly used). This will also protect your PC from any damage. In your final decoder, you can just use a series resistor to limit the current into your microcontroller and rely on its input protection diodes to clip the signal to 3V3 or 5V.
@@endoorrailway I only add some to what colegues wrote. Those regulators work stable when some substantial current is drawn from output and today's microcontroller inputs are not taking current at all almost. Also they have some kind of regulation loop and may became oscilatiors without decopuling and they are not suited for high freqency signals as one write it may generate substantial slopes, especially when load is almost not existent. It may be mitigated partially by pulldown resistor on 3.3v side and some capacitors but sincerely I'm shocked that it works at all 😉
@@CarstenBe about lower voltage - if you do divider 1:4 for example then if input drops 1v then output drops 0.25v also voltage value accepted as logical 1 is quite wide starting from 2V also most microcontrollers will accept more than 3.3v some even 5v without harm, eventually you can add zener diode to for safety. But optocupuler maybe most safe and small solution.
your multimeter is averaging not true rms therefore the real voltage reading should be multiplied by 1,4 to get an actual voltage, if you pass it trough fill bridge rectifier you should get that minus 0,7v i still need to build my n decoder because everything off the shelve is just a bit too big also your instructions don't have to be mesured with any high accuracy, since bit 1 and bit 0 are different length you just need to check every 0,7 of the length of the shorter bit and if value fliped read 0 and if it didn't set 1 and set interupt for another rising edge , then reset timer and do read again
To follow up, averaging RMS meters assume a sine wave amd multiply their measured value by 1.11 to approximate RMS. ( (sqrt(2)/2) / (2/pi) ) So divide by 1.11 to get the average value of your measured signal. Since average and RMS for square are the same, you're done. Should be measuring less than two thirds though, I cant explain that @ 3:55.
Thanks @kokodin5895 and @electrowizard2000 for the information - this afternoon I looked up what RMS is and came to the same conclusion about the square wave, explaining the track output in AC mode. I don't think the multimeter would need to do RMS to measure DC, though - in fact it can't be, else it would never produce a negative reading, so for now I think the two-thirds thing remains a mystery.
@@electrowizard2000 this is not sine though, it is square wave alternating via h bridge from single positive voltage if a meter has small bandwidth even if it is averaging it would measure much less than normal ac, most cheap meters is bandwidth limited to less than 1khz because ac they are ment to measure usually is 50-60 hz, the best way to measure this kind of voltahe is to put full bridge on it and measure dc and better yet use something like texas instruments active bridge rectifier and it would spit out 1/10 of rms voltage as a dc, i made meter like that to measue 14khz pulse voltage used in crt tv's as a heater voltage for the crt