dagnall53 / WiRocS

WiFi Rocnet for esp 32 and 8266
5 stars 4 forks source link

Wiring wirocs #1

Open rifqizain opened 11 months ago

rifqizain commented 11 months ago

Can you share this wiring for your this project, Sir?

dagnall53 commented 11 months ago

This code is superseded by the wio code in rocrail.
but see https://wiki.rocrail.net/doku.php?id=users:dagnall53:description

dagnall53 commented 11 months ago

Ahh. Sorry , that linked page has been deleted as the wirocs project is no longer active and the rocrai WIO is the replacement.

rifqizain commented 11 months ago

can this code still be used with the current rocrail program sir?

dagnall53 commented 11 months ago

Sorry, I think it can but I have not tried. I presume you want to use the sound effects parts? The WIO code has better and easier to set up servo and I/o elements than my code.
so if you just need sensors and I/o use wio.

rifqizain commented 11 months ago

yes sir, I want to try controller sound effects and sync with engine speed without using dcc on the model train. can you help me sir?

dagnall53 commented 11 months ago

Im very sorry, it was a very long time ago that iwrote the code. You should also know that the new WIO code has a built in mobile dcc mode. This means that it can directly drive a cheap dcc sound decoder. This will give better sounds and better motor control than my old wiorocs program. I have tried it with the inexpensive hornby tts sound decoders and it is a much better solution than my old code. But ..I am away at present, but will try to find the wiring diagrams for you if you want to experiment. you will need a motor controller for the motor, (actually this is the same as wio uses to generate dcc!) but the sound effects just need one transistor. i think most of the wiring should be explained if you look at the notes in the code. But i will look and see if i can see where to point you.

dagnall53 commented 11 months ago

I have this but it misses the pictures. I hope it is sufficient to assist. it says use d1 d2 d3 d4 to drive the tb 6612. For the motor. MOBILE DECODER WiRocS can be used as a complete "mobile" Loco controller. It includes the ability to get RocNet protocol loco messages and will respond to speed, direction, lights and sounds commands.

One small mobile sound decoder configuration is to use the WEMOS Mini with a RC servo dc motor controller and the Adafruit DAC. In this configuration, the Battery eliminator in the RC servo DC motor controller powers the WEMOS Mini and the DAC.

The WiRocS can also be used to drive a PWM motor control directly, in which case the RC DC motor controller is replaced by a motor shield with the 293 chip or (much better!) a TB6612FNG Dual DC Stepper Motor Drive Controller Board Module.

The TB6612 has MOS drivers so does not have the losses of the bipolar 293, and I found it runs cool driving my loco motors, where the 293 gets hot. BUT! NOTE that the WEMOS Mini input voltage is limited to 6.5V, so must not be connected directly to a 2S LIPO. A small 5V regulator must therefore be added for this purpose. - Also, to complicate matters, the NodeMCU motor shield has some additional and not well documented circuitry. This makes pins D3 and D4 "direction pins" and Pins D1 and D2 the PWM for the two Motor channels. This makes motor direction code for the Motor Shield very simple, but incompatible with use with other hardware. Because most users will use the "stationary" version of WiRocS I have defaulted the drives to use the "motor shiled" type driving. There are some directives in the code to select other drive options, but I would recommend contacting me if you plan to use the WiRocS to drive a loco using PWM mode.

There is another advantage to the 6612, - you can use one set of drivers to replace the single transistor AudioNODAC drive. Connect RX to one of the PWM inputs, and the loudspeaker (via a 10uf electrolytic) to the output.

I also connected a 100k resistor from 3V3 to the Standby pin, with 10uf from standby to Gnd. This provides a very short delay before the drivers are turned on. Without this, the wheels do a powerful spin on turn on that can be disconcerting or damaging.

The illustration shows a 6612 board with the PWM Channel A driving to the motor, and one half of Channel B to drive the loudspeaker via the electrolytic, (but note that the standby pin did not yet have the Resistor-Capacitor delay added at the time of the photo).

dagnall53 commented 11 months ago

And this about sound. WiRocS Sound There are two options to get sound. You can hear how it works on the Mobile variant here Youtube: Loco running with sound.

The simplest is to use the definition _AudioNODAC. This is the Default and all the available binary files have been compiled with this option.

This creates a Class D amplifier output stage that uses "I2SDAC_DIN" {D9/RX (esp8266) or 22 on ESP32}, to drive a transistor base that then drives the loudspeaker.

I2SDAC_DIN drives the transistor base. I recommend placing resistor {1k to 10k} between I2SDAC_DIN and the NPN transistor base. I2SDAC_LRC is 'LRC' This is set during Audio setup, but released for use as an input later. (?). In this configuration I2SDAC_LRC is initially set as a clock output, but it can be re-used once the DAC has been setup.

The resistor in the transistor base ensures that the serial programming is still possible!. THe speaker will make squeaks whilst being programmed, but I find this useful to show something is happening.

The transistor collector is connected to the loudspeaker and the emitter to ground. The Loudspeaker is connected to the collector and V+. An electrolytic across V+ to Gnd is recommended to support the high pulse currents. The "NODAC" output system uses oversampling, so to try and prevent timing issues, I limited my sound samples to 11K sample rate, rather than the 44k possible. I have not done tests to find the limits, but I find the sounds very acceptable.

There is a "high quality" option that uses the _AudioDAC definition set, which uses the AdaFruit MAX98357 which provides high quality stereo sound and on-board amplifier. If this option is used, the board needs these connections :

I2SDAC_DIN 9 D9(/rx) Data I2SDAC_LRC 4 D4 used as Left Right Control I2SDAC_CLK 8 D8 used by DAC as clock. This mode is not compatible with the OLED display.

dagnall53 commented 11 months ago

And lastly, this page may give more help to understand what i did.
etting up the Node Software with RocView (Once Programmed) "FIXED" Functionality LOCO HEADLIGHTS CV settings Sound System Speed settings: WiRocS Node Information

Back to WiRocs Description Source Code Node_Setup Troubleshooting Hardware WiRocs NODE SETUP Setting up the Node Software with RocView (Once Programmed)

Full printable documentation for the original ESPMQTTWIFOROCNET code setup, with illustrations is in Node Setup.pdf This should remain largely valid for the updated 'WiRocS' code.

This includes full details on:

Programming the NodeMCU/ESP8266 How Rocrail addresses Ports Wireless Debugging Wireless Updating Updating the code Updating the sounds: Also see Compile Directives to see how the compile directives can be used to select the functionality of each WiRocS node.

Selecting Pins as Inputs or Outputs The code uses settings from BOTH Pi02 and Pi03 settings tables to determine the functionality of each pin.

If Pi02 Is set as "INPUT" then the pin is an input (and automatically has the weak pull-up switched on) If Pi02 is set as "OUTPUT", then the output can be either a Digital, PWM or Servo output, depending on the Pi03 settings. With Pi02 as "Output, if Pi03 "Blink" is set, the output will be PWM. With Pi02 as "Output, if Pi03 "Servo" is set, the output will be a Servo pulse. With Pi02 as "Output, if neither Pi03 "Blink" nor "Servod" are set, the output will digital. Setting "Pio2 Blink" enables a flashing mode, whose rate is determined by the Pio2 "delay".

In PWM and Servo modes, the Pio3 Delay*10ms and Left and Right Steps will determine how fast the servo moves to the new position.

Set Delay = 0 and steps to 0 for the fastest movement.

See this guide for how to use RocView to set up a WiRocS node

"FIXED" Functionality

If you are using the code as a mobile decoder, then some pins will have "fixed" functionality. In this case, changing their functions or characteristics using the rocrail tabs will have no effect. You can confirm that their functionality is fixed by observing the Arduino serial terminal as the device initialises. As the device initialises, it checks its port definitions and sends a summary that looks like this: From it you can see if I/O is "fixed", and why.

(As a very simplistic overview, NodePortType Determines if the port is Input or Output, Pi03_Setting_options determines if the output will be digital, PWM or a servo drive.) See also this guide for how to use RocView to set up a WiRocS node and ESP32 Setup

Mobile Decoder LOCO HEADLIGHTS

When set as a Loco, the code expects LEDS connected to 3v3 and the Back or Frontlight pins (D2 and D5). Currently the "fixed" nodes cannot have their phase altered using the Rocrail Rocnet Programming PI02 tab.

CV settings

Clicking on “Programming” will open the Rocrail CV Programming interface. To make this work, you need to select “POM” and the loco to be programmed in the top left box, and Rocrail will interrogate the set loco address and get the main CV settings:

Changing the Loco address can be done with this interface, but care needs to be taken to ensure the programming interface loco address and the loco address stay in synch.

To change from a Short Loco address to a Long loco address, First set the Loco "long" address to the Current Short address. Then change the Loco so it reads the Long address, and then change the Loco address to the desired Long address.

Sound System

Click here for more details on the Sound System

Speed settings:

WiRocS tries to be NMRA compliant.

Set CV 66 and CV 95 if needed to trim for equal speed forward and reverse.

Set the kick start CV65 to a value so that the motor reliably starts without a visible kick. If it kicks noticeably then lower the value. If it does not start, increase the value.

Set the loco to desired speed and adjust CV5 and CV6 so the loco travels at the speed you want. Or use the speed table to select the speed.

rifqizain commented 10 months ago

OK sir, I will try your instructions. thank you for the direction you gave. this really helped me a lot in my model railroads development.