Jump to content

Robin2

Budget Battery Powered 00 Gauge Loco

Recommended Posts

Like Samsung and Boeing?

 

...R

At least they have more money than I do, so have a better chance of being able to deal with the damage :).

 

They probably have experts who could tell me why I can't get a DRV8833 board to work. I'm sure the wiring is right, and so is the software, but nothing happens!

Share this post


Link to post
Share on other sites

I lost quite a bit of time failing to make the DRV8833 motor driver work, so gave up and tried a mini L298 board instead, that worked first time with the same sketch!  Anyway, the MAX471 current reading board works nicely. I haven't got on to reading the motor speed yet, and I want to read the wheel speed too, so I can work out how fast the loco actually runs.

 

I tested it with the Mainline 56xx, and flat out I reckon it would easily beat City of Truro's or even Mallard's record breaking runs! Without being able to check the actual speed, it seems to run at a steady, but rather slow, speed at 3.7v, and what I think may be a satisfactory maximum speed at 5v. It's drawing just under 100mA upside down on the bench with no load. So using the original motor looks promising so far. A 1S battery boosted to 5v may do the job. A quick look on eBay found this, and this, that both look as though they would work. I think this loco could be a suitable first project. If I get the weight out of the bunker, there should be room for a fair sized battery. Most of the boards should fit in the side tanks attached to the chassis. The charger board fits in the cab roof without being visible from normal viewing angles. I've got the roof off, and it should be practical to make it removable, so I'm thinking that I could take it off to plug in a USB cable for charging. More investigation is needed, but maybe my first loco won't be O gauge after all!

Share this post


Link to post
Share on other sites

 

They probably have experts who could tell me why I can't get a DRV8833 board to work. I'm sure the wiring is right, and so is the software, but nothing happens!

Post the code you tried and a diagram showing the connections. The DRV8833 needs one PWM stream for FWD and a different one for REV whereas the L298 can work with a sinlge PWM stream fed to ENABLE and a simple HIGH or LOW for fwd and reverse.

 

...R

Share this post


Link to post
Share on other sites

Post the code you tried and a diagram showing the connections. The DRV8833 needs one PWM stream for FWD and a different one for REV whereas the L298 can work with a sinlge PWM stream fed to ENABLE and a simple HIGH or LOW for fwd and reverse.

 

...R

The mini L298s, the middle one in the photo, don't have an ENABLE, just IN1 and IN2, like the DRV8833

post-7091-0-12101900-1494500034.jpg

 

I hope the following photos make sense. the first two with the L298 that works, and the third with the DRV8833 that doesn't.

post-7091-0-46859800-1499763765.jpg

 

post-7091-0-32020700-1499763767.jpg

 

post-7091-0-01988900-1499763769.jpg

 

Here's the code, cobbled together and heavily adapted from stuff pinched off the web, hence the French comments! There's more code for displaying the current drawn than for controlling the motor.

const int max471In = A1;

int RawValue= 0;
float Current = 0;

#define pinINA1 5 // Moteur A, entrée 1 - Commande en PWM possible
#define pinINA2 6 // Moteur A, entrée 2 - Commande en PWM possible



void setup(){  
  pinMode(max471In, INPUT);
  
   // Initialize les broches de commandes 
  // du moteur A
  pinMode( pinINA1, OUTPUT );
  pinMode( pinINA2, OUTPUT );
  digitalWrite( pinINA1, HIGH );
  digitalWrite( pinINA2, LOW ); 
  
  
  Serial.begin(9600);
}

void loop(){  
  RawValue = analogRead(max471In); 
  Current = (RawValue * 5.0 )/ 1.024; // scale the ADC  
       
  Serial.print("Current = ");
  Serial.print(Current,0); 
  Serial.println(" mA DC"); 
  delay(100);  
}

Share this post


Link to post
Share on other sites

Your photography is good but photographs of hardware are not a good way to convey wiring diagrams. Can you make a simple pencil drawing and post a photo of the drawing.

 

What is the program intended to do?

 

When I have a problem I always try the simplest program possible - such as analogWrite(127) to one driver pin and analogWrite(0) to the other pin. If that MAX thing is measuring current then leave it out altogether until you get the driver working.

 

None of your boards looks like the DRV8833 that I have. Can you post a link to the datasheet for your board?

 

...R

Edited by Robin2

Share this post


Link to post
Share on other sites

This topic has gone very quiet, so I thought I'd better post something!

 

I've given up on the cheap DRV8833 boards for now. I couldn't get another one to work either, so I gave in and spent a fortune on two Pololu boards. I haven't tried them yet though.

 

Anyway, something is happening. I'm building a Tx for testing locos, and have got it talking to an Rx on a breadboard. It's just running the GettingStarted example from the RF24 library, but it works. I'll get adventurous and try running a motor soon! The Rx is a cheap Chinese 3.3v 8MHz Pro Mini, and seems to be OK. As I said earlier, the first programmer board I bought didn't work, as it didn't have a DTR connection, but the new one does, and works fine.

 

post-7091-0-81257400-1501538496.jpg

 

This is the Tx so far. Green buttons are forward and reverse, red is stop, and blue is Inertia on or off. The pot controls speed. The nRF24L01 is soldered in and connected to the pins Robin recommends. The Nokia phone LCD has an 84x48 monochrome graphical display, and will display 6 lines of readable text. I want to add some more buttons up the side of the screen, and when it's all working I'll add batteries and make a case for it. It's built as a shield to fit on top of an Uno.

 

Hopefully I'll have two way communication with the loco, so I can display data from the loco on the screen. I think I've got far enough with playing with bits of this to be fairly sure it will work.

 

post-7091-0-88726700-1501538498.jpg

  • Like 1

Share this post


Link to post
Share on other sites

It's good to see your progress. I've been following this thread as I have been thinking about going wireless for a while, only put off by the cost - even of the Deltang system.

 

Yesterday, my first Arduino Uno (clone) arrived as part of a projects kit, for less than the cost of the Deltang transmitter kit. Ok, so there's going to be a bit of a steep learning curve before I get where I want, but that's half the fun.

 

So many thanks to Robin2 for starting this thread, to MichaelT for his input and to your good self for sharing you successes (and failures). 

Share this post


Link to post
Share on other sites

This topic has gone very quiet, so I thought I'd better post something!

Great to see progress.

 

Can you post a link to where you got the Nokia screen?

And is there a library for controlling it?

 

 

spent a fortune on two Pololu boards.

Does that mean that you bought Pololu DRV8833 boards? Or some other model?

 

...R

Share this post


Link to post
Share on other sites

It's good to see your progress. I've been following this thread as I have been thinking about going wireless for a while, only put off by the cost - even of the Deltang system.

 

Yesterday, my first Arduino Uno (clone) arrived as part of a projects kit, for less than the cost of the Deltang transmitter kit. Ok, so there's going to be a bit of a steep learning curve before I get where I want, but that's half the fun.

 

So many thanks to Robin2 for starting this thread, to MichaelT for his input and to your good self for sharing you successes (and failures). 

Watch out. It gets addictive! I haven't written anything about the Arduino based control systems that I'm working on for my DC layouts yet, including one with infrared control! Then there's the "need" for radio control vehicles for my layouts. I'm also developing a desire for a full size robot lawn mower to help tame an acre or so of real grass and undergrowth!

 

I found getting a starter kit was a great way to get going. While I was waiting for it to arrive I read Arduinos for Dummies (found as a free PDF online), and gained enough knowledge to start ordering more bits. I'm keeping the Chinese electronics industry going single handed at the moment (well maybe not quite!).

  • Like 1

Share this post


Link to post
Share on other sites

Great to see progress.

 

Can you post a link to where you got the Nokia screen?

And is there a library for controlling it?

Search eBay and AliExpress for "Arduino Nokia 5110" and spend ages agonising over the best price and least dodgy supplier! This is where I bought it, as it was cheapest UK supplier I found. If I decide to get more I'll find the cheapest Chinese source. You can get the bare display, as fitted to the phone, or on a board for Arduinos etc. I've got a few 1602 LCDs to use up, and an OLED on the way from China to try. You can get some nice looking larger colour TFT touch screens too, but they're more expensive, and complicated!

 

Like everything for the Arduino, there's plenty of information to Google for. This is the guide I followed. It uses pins that don't conflict with your wiring of the nRF24L01, and there's a link to the library on Github. Watch out as they're 3.3v devices, so don't like 5v on any of the inputs.

 

This is the other side of the board. I've used the same colour coding as the diagram in the guide linked to above for the LCD. I haven't wired the backlight yet, as I'm waiting for some preset pots. The jumble of pretty pink wires is the nRF24L01. On the right is the wiring for the buttons, that are connected to pin A5 using voltage divider resistors to get a different value for each button. These are the shield boards I'm using. They're quite cheap and simple, and this seems to be about the only supplier.

post-7091-0-72691600-1501585495.jpg

 

Does that mean that you bought Pololu DRV8833 boards? Or some other model?

 

...R

They're DRV8833 boards. If I can't make them work I know who to ask ;). £10 for two including postage is a lot when I'm used to Chinese prices!

  • Like 1

Share this post


Link to post
Share on other sites

More progress, but not as far as getting anything running yet. I've built an Rx for testing the assorted locos and motors I've got. It's also got outputs from the available pins, and a socket for a 16 channel PWM servo board, so I can use it for basic layout control. I'll be adding buttons to the Rx to control this. I think it was worth building it as a proper unit, as it should have a long term use.

 

Below: It uses the components I'm aiming to use in locos, except for an L298 motor driver instead of a DRV8833, plus another Nokia 5110 screen. The boards visible here are the Arduino Pro Mini 3.3v on the right, and nRF24L01 on the left. The external programmer is plugged into the Pro Mini. Below the transceiver is the power socket, and to the right are connectors for one analog and two digital pins that are free, with VCC and ground connections. There are also two more analog pins that have connectors on the end of the Pro Mini board. The horizontal one above them is for a QRE1117 IR wheel speed sensor, that I haven't made yet. On the right are screw terminals for connecting a motor, and a socket to connect it to my test track.

post-7091-0-79397300-1502223057.jpg

 

Below: What's under the removeable boards. Top left is the L298 motor driver, top right is a MAX471 current sensor. Between the header sockets for the Pro Mini is a 3.3v regulator, my first bit of proper electronics rather than just connecting up boards! All of one IC and two capacitors! The socket for the 16 channel servo board is on the left above the power socket. There's also a preset pot for the LCD screen backlight below the MAX471 board.

post-7091-0-10382700-1502223053.jpg

 

Below: What's underneath so far. I haven't finished wiring the output connectors yet.

post-7091-0-68459000-1502223055.jpg

 

Below: Connector on my multi-gauge test track. Input pins in the middle, screw terminals to connect a motor on the left, and connection to rails on the right, with a jumper to disconnect it.

post-7091-0-70346500-1502223059.jpg

 

I'm now doing battle with the software. I think I'm slowly winning!

  • Like 2

Share this post


Link to post
Share on other sites

A techie question for Robin. What are the last six members of the locoData structure? LocoID and LocoDir are obvious, I think locoSpeed is in RPM, and I assume locoSteps controls the tiny movements you talked about. But locoOther onwards baffle me, so maybe I shouldn't ask!

struct lD {
    byte locoID;		// 1
    char locoDir;		// 1
    long locoSpeed;		// 4
    long locoSteps;		// 4
    int locoOther;		// 2  total = 12
    byte kP;			// 1
    byte kI;			// 1
    byte kD;			// 1  total 15
    byte kPScaleFactor;	// 1  total 16
    int accVal;			// 2  total 18
};

Share this post


Link to post
Share on other sites

locoSpeed - the interval between revolutions in microseconds.

 

locoSteps - the number of revolutions that are required - I have the ability to make the loco move a specific distance. You can ignore this.

 

locoOther -  space for future development

 

kP, kI, kD and kPScalefactor - the factors to be used in the PID speed control code. In many projects they would be built into the Arduino code but I decided to send the values to make it easier to try different values without needing to re-program the loco.

 

accVal - can't remember. I don't think it is used

 

...R

  • Like 1

Share this post


Link to post
Share on other sites

Thanks. I can ignore most of it then, and do my own thing!

 

I just want to send the PWM value for motor speed to start with. I'll also add a simple, probably fixed, Inertia setting to control gradual speed change, that I can toggle on or off from the Tx. On the sort of layouts I'm building I don't think any sophisticated motor speed control is needed. Having had to Google PID to find out what it is, I don't think I need to study it at the moment.

 

However, I would like to be able to set the loco speed in scale MPH, rather than some arbitrary number, so I suppose a simple form of PID will be needed eventually. I want to put a speed sensor on a driving wheel, rather than on the motor, to calculate the scale speed and send it from the Rx to the Tx, so I can display the speed in MPH on the controller. To start with I'll just send a PWM value from the controller, but would like to make provision to send either a PWM value or required MPH for the future.

 

Which leads onto a question I haven't found a clear answer to yet. How do you wire up the QRE1113 sensor? The data sheet has pin numbers, but I couldn't make sense of which is which on the actual sensor. All I can see is that one leg is a different length to the others. Do you add any extra components?

Share this post


Link to post
Share on other sites
However, I would like to be able to set the loco speed in scale MPH, rather than some arbitrary number, so I suppose a simple form of PID will be needed eventually. I want to put a speed sensor on a driving wheel, rather than on the motor, to calculate the scale speed and send it from the Rx to the Tx, so I can display the speed in MPH on the controller. To start with I'll just send a PWM value from the controller, but would like to make provision to send either a PWM value or required MPH for the future.

 

I suggest you think carefully about that. It will be much easier for your Arduino program to work in units of measurement that directly relate to the actions it must take - such as microseconds per revolution. I suggest you just convert from those units to MPH for the purpose of showing stuff on the screen.

 

 

 

Which leads onto a question I haven't found a clear answer to yet. How do you wire up the QRE1113 sensor? The data sheet has pin numbers, but I couldn't make sense of which is which on the actual sensor. All I can see is that one leg is a different length to the others. Do you add any extra components?

Sparkfun have a wiring diagram for using the qre1113 as an analogue device (and as a digital device). It seems to me a strange distinction. What you need to use is their analogue diagram - I know, you will be using it for a digital input - but it works. And the other version won't

 

One corner of the sensor is chamfered so you can identify it.

 

...R

Edited by Robin2

Share this post


Link to post
Share on other sites

I suggest you think carefully about that. It will be much easier for your Arduino program to work in units of measurement that directly relate to the actions it must take - such as microseconds per revolution. I suggest you just convert from those units to MPH for the purpose of showing stuff on the screen.

The MPH will just be calculated using the wheel diameter, Pi and the scale of the loco, to display something meaningful to us inferior humans! I think MPH is such a vague number, I can just store a PWM value for each speed, once I can record it. All my layouts are small and level, and trains won't be very long, so I don't think I need any clever motor controls. After all, real steam loco drivers didn't have a speedo, but had to stick to speed limits, so whatever I do is bound to be more accurate. If I send a MPH figure to the loco, it can pick the matching PWM value from an array.

 

Sparkfun have a wiring diagram for using the qre1113 as an analogue device (and as a digital device). It seems to me a strange distinction. What you need to use is their analogue diagram - I know, you will be using it for a digital input - but it works. And the other version won't

 

One corner of the sensor is chamfered so you can identify it.

 

...R

It's not chamfered in the diagram! Flushed with success at not blowing up the AMS1117 voltage regulator, even though I managed to melt a bit of the casing, I'm hoping not to trash the QRE1113 by getting it he wrong way round :). I've found a side by side comparison of the analogue and digital diagrams here.

 

It's now sunk into my slow moving brain that the Fairchild data sheet shows pin numbers and the chamfer!

Share this post


Link to post
Share on other sites

I've just come across these, which connect an nRF24L01 using I2C, so it only needs two Arduino analog pins. Not much use in a loco, but for a Tx or Rx attached to a layout, it frees up some digital pins, including PWM ones that could be used for servos etc.. I've ordered one to try.

https://www.aliexpress.com/item/ATMEGA48-NRF24L01-wireless-Shield-module-SPI-to-IIC-I2C-TWI-Interface/32586707574.html

 

As one of my uses for radio is to control DC layouts wirelessly, and to have DC control on part of my planned RC layouts, it could be useful, especially as I'm thinking of using I2C to control various Arduinos scattered around the layout.

Share this post


Link to post
Share on other sites

An interesting gadget. One could make the equivalent with an Atmega 328 and some veroboard which leads me to wonder what software is on the Atmega48 and how it compares to (or works with) the nRF24 libraries that we are familiar with.

 

I do realize that the gadget is cheap compared to the work required to make a veroboard version.

 

Maybe the board has the facilities necessary to program the Atmega48 - if so maybe it could be used for all sorts of other things.

 

...R

Share this post


Link to post
Share on other sites

Or just attach a Pro Mini to the I2C bus, dedicated to running the nRF24L01, which would actually be cheaper than this board, and less hassle than programming an Atmega 328!

 

I was reading up on I2C this morning. It looks pretty straightforward to use, and I could just run 4 wires round the layout connected to a mix of Arduinos and other I2C devices, controlling individual modules (like points, turntables, building lighting etc.). I'm working towards being able to build and test everything on my workbench, then install it on the layout when it's perfected. The master Arduino could control the nRF24L01, and send mostly 1 byte codes to the address of the relevant Arduino, that would do all the processing to control the device. When you consider that a Pro Mini and SG90 servo is a fraction of the price of a Peco point motor, it would break the whole system down into very small manageable pieces, and make it more resilient.

 

It would also be pretty cheap to control everything wirelessly, but would use a lot of batteries unless power was provided, so running four wires round the layout instead of two seems to make sense.

 

I'm looking into all of this so I allow for it in my RC system. I think I've got a suitable C++ Structure for two way communication between the controller, and the loco and layout, so everything can be run from a mini handheld version of a traditional DC control panel, but wireless with a few added features.

 

Having a break from writing the software to read the Cameo Layouts book at the moment. Iain Rice doesn't seem to have discovered the benefits of RC yet!

Share this post


Link to post
Share on other sites

I was reading up on I2C this morning. It looks pretty straightforward to use, and I could just run 4 wires round the layout

My understanding is that I2C is a very short range system - inches, rather than feet. Ditto for SPI.

 

I am building a system in which a Mega will be the master and there will be several slaves made with Atmega328s. The Mega will communicate with the slaves using Serial and the Mega will also operate the nRF24 to take data from the hand controllers. My idea is that the slaves will all be identical and the Mega will tell them what to do with each I/O pin - for example operate a servo or an LED.

 

...R

Share this post


Link to post
Share on other sites

My understanding is that I2C is a very short range system - inches, rather than feet. Ditto for SPI.

"For reference, shielded 22 AWG twisted pair cables have capacitance in the range of 100-240 pF/m. So the maximum bus length of an I2C link is about 1 meter at 100 Kbaud, or 10 meters at 10 Kbaud. Unshielded cable typically has much less capacitance, but should only be used within an otherwise shielded enclosure."

http://www.mosaic-industries.com/embedded-systems/sbc-single-board-computers/freescale-hcs12-9s12-c-language/instrument-control/i2c-bus-specifications

Share this post


Link to post
Share on other sites

This is a test. If it works it will be deleted.

 

It worked, but I can't see how to delete it altogether

 

 

...R

Edited by Robin2

Share this post


Link to post
Share on other sites

Hi Robin,

 

I think the only option is to delete the text, you cannot delete the entire post.

 

What  was the test?

 

Frank

Share this post


Link to post
Share on other sites
13 hours ago, fallen said:

What  was the test?

Thanks. I just wanted to check that I could post a reply.

 

...R

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

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

Create an account

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

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.