Closed loulouMS closed 1 year ago
Hi Louis,
First, thanks for paying attention to my project. I did not expect this hobby project would really attract readers. :P
When you see "DCC_begin" in the serial monitor, it means the program is ready to read command messages. You can try entering any message introduced in the "Control Messages" section. Make sure the arrows '<' '>' are included. The program will validate the message. If the received message is valid, it will print "ok" or "Error" otherwise.
The Arduino program should work fine without connecting the motor driver/track, as they are passive components in the system. The timer configuration in UNO and Wifi Rev2 are different. This program was written in a way that supports both.
When I write the readme, I assume an H-bridge circuit IC with two direction pins is used. So the connection is to connect pin 11 and pin 12 to those two direction pins. However, the “Arduino Motor Shield” has a different interface. This shield is built requiring only one direction pin (per channel). When mounted, pin 11 is connected to Channel B PWN and Pin 12 is Channel A direction. Fortunately, channel A, which uses pin 12 for direction control, matches the program. So, you can use channel A to try. The program output in Pin 11 and 12 are just opposite signals to facilitate the use of an H-bridge circuit to control the polarity of output voltage. In your case, using pin 12 only is totally fine.
One more thing you need to consider is for the PWM pin on the shield. We don't need PWM, so the PWM pin (pin 3) on the shield should be set to HIGH. Try adding these two lines in setup(). Sorry that I don't have the Arduino Motor Shield to try first.
pinMode(3, OUTPUT);
digitalWrite(3, HIGH);
If you have an oscilloscope, attach the probe to Pin 12 or any side of the output. You should be able to see the DCC signal waveforms. (Be sure not to connect the ground lead to any output pin!)
Hope this helps.
Hi,
In case of my previous message was not sent to the right address.
-------- Message transféré -------- Sujet : Re: [doyleLai/Arduino-DCC-Station] Nothing appears in the monitor (Issue #1) Date : Sun, 21 May 2023 11:18:22 +0200 De : Louis Petiot @.> Pour : doyleLai @.>
Hi,
Thanks a lot for your quick reply.
As I told you, your project is the only one that I see which really manages the Uno Wifi Ref2 board. I could change to a simple Uno but, since I purchased it, I prefer to persist...
First, about the message "DCC_begin", I saw it only one time, when I ran on the 1st time the program. And never after.
Before putting a loco on the track, I prefer to make a test with a lamp which accepts 12V. But I get no light. So, it seems that there is a problem with the connections. I totally discover the boards, the channels, the H-bridge circuits, ... I put the Motor Shield above the Uno board and put cables from A channel (the part with 6 connections by screws and with a B section?) to the track. I tried to make connections as locoduino site recommends : 5 to 13, 10 to 12 (for Uno), or 2 to 13 and 10 to 12 (for Mega). And I tried only one or no connection. Without success.
So what do you think about the connections to make? You say "using pin 12 only is totally fine" but how to use it? What is the connection to make from pin 12?
I made a last test by adding the 2 lines in setup(), without change. And I do not still get "DCC_begin" in the serial monitor.
Another point: I don't see "Control Messages" section in the serail monitor. I imagine that is the textbox in the top with a Send button on the right. True?
Last question at the moment, do you have some experience with the Wifi function of the Wifi Rev2 board?
Louis
Le 21/05/2023 à 07:33, doyleLai a écrit :
Hi Louis,
First, thanks for paying attention to my project. I did not expect this hobby project would really attract readers. :P
When you see "DCC_begin" in the serial monitor, it means the program is ready to read command messages. You can try entering any message introduced in the "Control Messages" section. Make sure the arrows '<' '>' are included. The program will validate the message. If the received message is valid, it will print "ok" or "Error" otherwise.
The Arduino program should work fine without connecting the motor driver/track, as they are passive components in the system. The timer configuration in UNO and Wifi Rev2 are different. This program was written in a way that supports both.
When I write the readme, I assume an H-bridge circuit IC with two direction pins is used. So the connection is to connect pin 11 and pin 12 to those two direction pins. However, the “Arduino Motor Shield” has a different interface. This shield is built requiring only one direction pin (per channel). When mounted, pin 11 is connected to Channel B PWN and Pin 12 is Channel A direction. Fortunately, channel A, which uses pin 12 for direction control, matches the program. So, you can use channel A to try. The program output in Pin 11 and 12 are just opposite signals to facilitate the use of an H-bridge circuit to control the polarity of output voltage. In your case, using pin 12 only is totally fine.
One more thing you need to consider is for the PWM pin on the shield. We don't need PWM, so the PWM pin (pin 3) on the shield should be set to HIGH. Try adding these two lines in setup(). Sorry that I don't have the Arduino Motor Shield to try first.
|pinMode(3, OUTPUT); digitalWrite(3, HIGH); |
If you have an oscilloscope, attach the probe to Pin 12 or any side of the output. You should be able to see the DCC signal waveforms. (Be sure not to connect the ground lead to any output pin!)
Hope this helps.
— Reply to this email directly, view it on GitHub https://github.com/doyleLai/Arduino-DCC-Station/issues/1#issuecomment-1556088426, or unsubscribe https://github.com/notifications/unsubscribe-auth/AKAEKE3TRW2DQVEWGWG3NHDXHGSMLANCNFSM6AAAAAAYI2ZFHA. You are receiving this because you authored the thread.Message ID: @.***>
Hi again,
I got some progress! Now, I always get Dcc_begin when starting and the commands are accepted (with any loco address). I get ok. But at the moment the train doesn't move, the light remains off, ...
On the 1st time I started successfully the program, the train produced sounds during one minute approximatively. Probably the default sounds. But nothing else.
So, does that mean that the loco was recognized and so, its address was set to another value than 3? How to get its address with the command line and the prog track?
Glad to hear that you made some progress.
I have some comments/suggestions.
<F4001>
if the address is 4. (Function 00 refers to the light)By the way, I will rewrite the readme to make it more clear when I have time.
First, do you prefer I post in github issues section or by email?
My loco is new and I have no DCC unit to test it. I assume there is no problem with it. So, its address should be 3. I directly start with DCC with Arduino and the board Uno Wifi Rev2. Maybe it's ambitious... !
I tried the command <S31100>
but the loco doesn't move. Same with <F3001>
for the light.
So, are you sure that the program works with the board Uno Wifi Rev2? Did you test it with this board made by Arduino?
In the meantime, I'll add some debug lines in the code in order to see if my board is really taken into account and how the difference between simple Uno and Uno Wifi is managed. I imagine that mainly concerns the timers. But I'm totally new in DCC. Can you explain fastly the function of the timers in DCC?
That apart, considering WiFi, I think we have to add a stop hard button between the board and the track, or before the board, to prevent any problem with WiFi connections.
The board also includes Bluetooth features. Did you try to communicate by this way to the track?
I saw in the project that there is only one condition on the type of board. It is in DCC_Signal.cpp. I added debug lines in this file to print information in the serial monitor. The code does execute the part starting with #elif defined(ARDUINO_ARCH_MEGAAVR)
.
With the electric power input in the jack port of the Uno, it seems that the track has less than 12V (I have no voltmeter, just a lamp). So, I have to put the input power in the power channel of the Motor Shield. To do that, instead of breaking the cable of my 12V adapter, I should get soon an adapter with nude cables to be inserted in the channel.
Sorry for the multiple posts. I can delete some of them later on.
Finally, I'm able to use your program with success. I didn't make a full test, only a small one with a limited speed on a little track. The problem was due to the configuration of the power. At the moment, 2 configurations are working:
I have to make comparisons between these configurations, but the problem seems definitively solved.
So, your project seems the only DCC project which manages the Uno Wifi Rev2 board !
Later on, I'll take a part of the code to add other functions and mainly to have a user-friendly approach, on an Android smartphone preferably, or a Windows tablet. I'll try to add a topic in Locoduino forum on this subject (with the code to add/modify) and make a reference to your project.
That apart, I made a test with a simple WiFi example (led on/off). It was successfull. So that represents the 2nd step of the development of the DCC station... Bluetooth functions will come after.
Anyway, thanks a lot for your help and your quick replies.
Louis
What was the problem at the beginning? Others may encounter the same problem. It would be best if you could share it with us so they can take note. I can also make notes in the readme.
When the Arduino Motor shield is mounted, the barrel jack on the UNO board and the power channel on the screw terminal on the Motor shield are electronically connected. So there will be no difference if you use either one.
Be careful to add codes to the interrupt handler in DCC_Signal.cpp. Time computational instructions such as Serial.print() will delay the timer counting, which will stretch the waveform of the DCC signal.
Briefly speaking, a hardware timer can do counting at very precise intervals. We use that to generate the DCC waveforms with correct pulse widths. Timer configuration varies across boards, and it is a deep topic. I cannot explain it in detail here. You may need to research it.
There is one more technical point I have overlooked. After checking the schematic of the Arduino Motor shield, I found it is more complicated than expected. The DIRA (Pin 12) connects to IN1 of the L298 IC as expected. But there is an XNOR gate before the IN2 in which the inputs connect the DIRA and BRAKE_A pins (Pin 12 and 9), which I initially thought it is just a simple inverter to invert DIRA.
The signals input to the IN1 and IN2 of the IC are supposed to be complemented (not the same) to set the output to forward or backward mode. If both inputs are the same, the two outputs are shorted to enter the brake mode. Arduino designed the shield in this way to let their customers control the brake using a separate pin instead of manipulating the two IN pins. But we don't need the brake mode since we use the motor driver to generate DCC signal instead of directly driving a motor. So, for this shield, we need to make this XNOR gate act as an inverter (a NOT gate) by setting the BRAKE pin to LOW.
I am not sure what the pin state of an Arduino board is if it is unset. Your success might be by luck :P. To make it stable, add two more lines to setup() to disable the brake mode:
pinMode(3, OUTPUT);
digitalWrite(3, HIGH); // set PWM (EN1 of L298) to HIGH
pinMode(9, OUTPUT);
digitalWrite(9, LOW); // disable the brake, make IN1 and IN2 of L298 not the same
By the way, I will be happy if you further develop my code to make it more interesting.
There are lots of Arduino DCC projects on the internet which provide comprehensive DCC features, but their codes are either hard to read or require extra components such as a keypad or potentiometer to work. So, I did this project to self-learn to build an Arduino DCC station and managed to make it simple by only using the serial port as the user input.
At the first begining, I had a problem with the 220v electric cable before the 12V adapter! The board was supplied with the usb port so I didn't know that the 12V didn't arrive. But that was quickly solved. The main problem was the connection between the pins 10 and 12. I made it because Locoduino (Ma 1ere centrale DCC and other topics) says we have to make it.
But that doesn't work with the config Uno Wifi Rev2+Motor Shield. It seems that no connection between pins must be made. This is the only real cause of the problem.
I had a debug line temporarily, just for a test. Anyway, I'll delete all of them except for errors.
About timers, I know them since as I am, or I was, a developer in softwares (computation programs, databases, ...) in a lot of environments. But I don't know why a timer seems a little bit complex in DCC.
About DIRA, IN pins, ..., I have to say that is totally unclear for me. I hope that I'll never manage them. But I'll try to add the 4 lines you mention.
Later on, I'll post in Locoduino forum, and in this github project if you wish, some comments of my future tasks related to DCC with Uno Wifi Rev2. I repeat, your project seems the only one which successfully manages this board with DCC. Other developers, including DCC-EX, don't want to manage this board because the timers are specific.
So, thanks again!
Just for your information and if you want to update the readme file, I forgot another problem I got. It concerns the COM baud rate. Your program uses 9600 (the default value in Windows I believe) and the Locoduino examples use 115200 I don't why. So, when starting with your project, this value of 115200 was set in the serial monitor.
Anyway, it's strange to see in the compiler comments the value of 115200 instead of the value chosen in the serial monitor.
Just checked the locoduino website that mentioned the use of DCC++. Their program uses pin 10 (for main track) and 5 (for prog track) for signal outputs. That's why you should bridge them to Pin 12 and 13 to work with the Arduino Motor Shield if you use their program.
My program uses Pin 11 and 12 for main track. By coincidence, the Arduino Motor Shield uses Pin 12 as the direction pin. So, you don't need to bridge any pin when you use my program.
For the baud rate setting, the Arduino program and the serial monitor should match. That is, in the program code, you set baud rate value in Serial.begin()
, then compile it and upload it to arduino board. After that, open the serial monitor and set the baud rate to match the one in the program. You should do it manually and the compiler does not know your baud rate setting in the serial monitor. You need to set it manually in the program code.
Your explanation about pins is really good. I keep the information in a safe place!
About the baud rate, I quite well understood how that works but I just mentioned that the compiler comments (in orange color) show the 115200 value somewhere. Maybe because it's the value which is advised?
There was a typo in my previous reply. The code should be digitalWrite(9, LOW)
instead of HIGH.
I have tried compiling the code in the latest IDE with different baud rate settings, in program code and serial monitor as well. I cannot see the compiler comments even if the baud rate in the code and serial monitor are mismatched. I believe it is another problem, so I am closing this issue. Contact me if you need further help.
Enjoy model trains and have fun with it!
About the baud rate which appears in the compiler log, here is an extract of the text:
C:\Users\******\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/bin/avrdude -CC:\Users\******\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf -v -patmega4809 -cxplainedmini_updi -Pusb -b**115200** -e -D -Uflash:w:C:\Users\******\AppData\Local\Temp\arduino_build_806091/Arduino-DCC-Station.ino.hex:i -Ufuse2:w:0x01:m -Ufuse5:w:0xC9:m -Ufuse8:w:0x02:m -Uflash:w:C:\Users\******\AppData\Local\Arduino15\packages\arduino\hardware\megaavr\1.8.8/bootloaders/atmega4809_uart_bl.hex:i
avrdude: Version 6.3-20190619
Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
Copyright (c) 2007-2014 Joerg Wunsch
System wide configuration file is "C:\Users\******\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"
Using Port : usb
Using Programmer : xplainedmini_updi
Overriding Baud Rate : **115200**
Maybe this is due to the version of Arduino IDE. I use the last 32-bits version.
That apart, I have another question concerning the CVs. I have seen that the code exists in your program but it's not activated. I just would like to change the horn, the bell and the master volume. I have the documentation about the changes to do. So, could you tell me if the code is ready to use or the possible changes to do?
Not sure what happened in the compilation. You could try using the latest IDE 2.1 and try again.
For the CV configuration, I made it for changing a loco's address and the code is quite hard-coded. I did not test it for other CV settings. You can uncomment the code to activate it but please use it cautiously.
After a break during one month, I worked on the project a few days and I'm now able to successfully use a same project with a BLE connexion or a COM connexion if there is no BLE. I modified a little bit your project to manage the BLE (like in the LED example) and I created an Android app that I have to improve to get a user's friendly app.
That apart, I also managed the CV changes and that's working fine.
One main task is remaining: I have to modify the project in order to read function and CV values. I hope that the project will not be over the Arduino limits. Because sometimes, an error comes up when adding some lines of code due to the Arduino memory. Maybe some parts of the project can be deleted...
I have a question about the speed. I have a train with 28 speed steps. Do I have to use another signal than the one currently set for 128 steps, or is the signal compatible with 28 steps?
About reading CV values, do you know how to do it?
And is it possible to know the curent speed step of a loco and the state of its functions without keeping the values in program memory? How a DCC unit can display the speed of a loco when selecting another loco?
Sorry for missing your message due to my recent workload.
If your decoder supports 28-speed step mode only (not 28/128), that train will not work in this system as this system only send out 128-step commands.
I know many DCC command stations in the market can read CV values but I have not tried. You can check out DCC++. I have seen that DCC++ can read CV values.
Thanks for your reply. In fact, after a verification, the loco manages 28/128 mode. I thank it didn't because it was a bit slow but that was due to the voltage. I changed it to 15/16V and that's right.
I'll check out DCC+. But do you have an idea about getting the speed of a loco and the on/off state of the functions?
I have another question or maybe an issue to let you know. I try to use, on the same board, the channel B to manage an analogic track. That works but the speed of the analogic loco is high and constant whatever the value sent in the analogicWrite function. I can stop it and change the direction.
I checked the code and I have seen that is due to the timers. If I desactivate the call to SetupTimer, the speed is normal, but, of course, the digital track cannot be used. Could you tell me how the timers can interfere to the channel B?
The Arduino Motor Shield itself connects its Channel B PWM pin to D11, which is already used by this program to output DCC signal. As for getting the speed on/off state of the functions, I have briefly checked the CV tables (https://dccwiki.com/Configuration_Variable) and didn't see them in the table. So, by means of reading CVs is not an option.
Thanks for the info. Now I understand why the track connected to channel B is also powered. Is it possible to use another pin than 11 in the output DCC signal or another pin for channel B PWM?
About speed and functions, I think we have to decode the previous DCC signals. As far as I read info about DCC, the signals are sent on multiple times, so there is a 'history'. But that's not a real and important problem. I can manage the DCC unit without this feature.
I have another question about CVs. You mention in the sketch 'you must reset the arduino after using this command. Otherwise, the CV instruction packet will stay in the pool forever.'. For the time being, I change the CV for the volume, the horn and the bell without making a reset. Do I have to do it everytime even if I turn off the board when I don't use it? What makes exactly the reset with the W command?
Given that you are using Arduino Motor Shield, you don't need an alternative pin for Pin 11 as this shield is already using Pin 12 to receive DCC signal. After using the "hidden" code for changing CV, you should reset the Arduino by pressing the onboard reset button / removing the power. The "W" command can make the same effect.
As pin 11 is used by the board Uno Wifi Rev2 for the channel B (PWM), So, if I want to use the channel B for another purpose, I have to use another pin than 11 (used in SetupPins). Maybe I can use pin 5 or 6 instead of 11? Unfortunately, I cannot test this change at the moment because my loco (I have only one digital) doesn"t work at the moment (problem with the decoder).
About CVs and reset, I understand that this command has to be used in the signal only one time and that's different to other commands like the speed command which are in the packets which are repeated. So, we have to remove it from the signal after sending one time, so with a reset. True?
HI, I'm new in Arduino (and in digital model trains!, but not in software development) and I recently purchased an Arduino Uno Wifi REv2 and an Arduino Motor Shield in order to use DCC. I found some DCC examples which generate error messages about timers, probably because they are different from Uno timers.
Your project is the only one which does not generate compliing errors. So, I would like to really use it and learn how DCC works.
Unfortunately, when I use the serial monitor, nothing happens when I send a command. I just saw 'Dcc_begin' or something like that on the 1st time.
So, could you help me to solve this problem? It may be due to the wiring connection because I don't fully understand the Wiring paragraph and because I'm using the Motor Shield (with a 12V AC-DC adapter). Should the track be set with electricity without sending a command (in order to make a 1st test?
Louis (from France)