SparkFun Forums 

Where electronics enthusiasts find answers.

Have questions about a SparkFun product or board? This is the place to be.
By StaticDet5
#140301
I definitely want to use EEPROM memory for this project. I'm actually getting ready to map out the EEPROM addresses and the serial command strings for the uOLED displays. If I have enough memory on the system, I want the system to be configurable without an actual PC. I really want to keep the Arduino portion of the build, and because it's more "open source" that way. I love how easy the Arduino is to "pick up and running with". If other people pick this project up to play with, they will do amazing things with it.
Yes, I I can probably knock $20 dollars or more off the final price by going with a plain ATMEGA-something, but I'll lose that very low "knowledge level" needed to tinker with it (and the pre-existing USB support).

It's not ready for the Sparkling homepage. Right now it's not exactly pretty, but and nothing close to integrated. I need my proto-board to come in so I can try hiding it in an AEG.
I should also work on the basic fire control program, and using functions so that it's tidy... Oh yeah.. There's the small matter of the barrel chrony which is going to require interrupts (probably).

A hearty thanks for the vote of confidence, and though!
By dkulinski
#140302
FYI you can always run the Arduino on the ATMega (or even an ATTiny) without putting the whole board in the project. That is what your ICSP header is for. In fact that is how I started the lasertag project until I just ditched the Arduino library all together.

Check out http://blog.kulinski.net if you are interested in my slow progress.
By Mee_n_Mac
#140307
StaticDet5 wrote:That being said, I removed the delay entirely, and everything is functioning just like it should.
Science triumps again ! :dance:

If you had an inkling to know what the motor current looks like over a cycle, I would advise you to setup the 1 msec interrupt and printout mentioned above. Aside from the data collected, it'll be instructive on how to user timers and interrupts and might be a good gearbox and motor diagnostic tool to use in the future as well.

ps - didn't sound like a crackhead to me.
By dkulinski
#140315
I agree with Mee_n_Mac, the more you know the less you are guessing on design. The best would be getting it under an oscilloscope. Perhaps a local hackerspace could be of assistance there? If that is out use the Arduino as a cheap oscilloscope like Mee_n_Mac pointed out.

I know I am envious of your project, and none of your posts have come across disjointed. Looking forward to your next step!
By Mee_n_Mac
#140320
Here's a question ... Is the software now parking the gearbox so the spring is not compressed in any way ? or just a little ? Or is it random ? I'm still trying to figure out exactly why the multi-fires were happening and how the higher threshold works.
By Mee_n_Mac
#140321
StaticDet5 wrote:
Code: Select all
    do
    {
      IMain = analogRead(CurrentSensor);  //simply reads the CurrentSensor and stores the value in IMain
      delayMicroseconds(SensorDelay);  //delay between sensor readings  
    }
    while (IMain > LowAmpTrigger);  //This is the conditional exit, the motor needs to stay on 
                                     //until the amperage reads low
  
    if (IMain < LowAmpTrigger) {  //This loop checks to see that the amperage is less, 
                                 //if so it does not allow the motor to
      do                          // be turned on until the trigger is released (and ultimately depressed again)
    {
      buttonState = digitalRead(buttonPin);  //this continually checks the trigger state
      //delay(50);
      analogWrite(MotorPin, 0);  //this turns the motor off    
    }
    while (buttonState == HIGH);  //as long as the trigger is depressed, the loop will continue turning off the motor and checking the trigger state
 
May I ask what the If (IMain < LowAmpTrigger) does above ? I'd say that when the upper do loop is exitted, it's pretty much guaranteed to pass that IF condition. I think I'm missing something simple. :?
By StaticDet5
#140324
Wow! Thanks folks!
I took some time last night to verify that the gearbox is being stopped in a completely uncompressed state. It looks like cutting the current the way I did allows the motor to spin a little bit further. It is not stopping in the same place each time, but it is not compressing the spring at all.

Mee_n_Mac, the loop is not needed, I put it in to be thorough. I haven't experimented with taking it out, yet. I would expect the program to stay the same.

Any suggestions on O-Scopes? I know I need to eventually get one. I don't know what to get, and I'm essentially broke right now. Anyone have any experience with the DSO Nano's?
By Mee_n_Mac
#140333
StaticDet5 wrote:I took some time last night to verify that the gearbox is being stopped in a completely uncompressed state. It looks like cutting the current the way I did allows the motor to spin a little bit further. It is not stopping in the same place each time, but it is not compressing the spring at all.
That's good. Seems there's no need for an active e-brake. But now I'm confused as to why it works. My thinking is thus : The trigger gets read as pressed and the motor started. What's the next gate ? That the motor current is to be less than a threshold. Until then the SW is in a tight loop reading the current. I'd expect that if the gearbox is stopped off-the-spring, then the current would be low shortly after the trigger has been pressed and so pass the test before the spring can be compressed and released. Perhaps the current is, and the fact that a human can't press and release the trigger quickly enough is making the SW turn the motor on, then off, then on ... etc ... until the spring compression makes the current rise above the threshold. Then the trigger may be released and the threshold test subsequently makes the motor stop as desired (after the shot happens). But this would be a lucky sequence of timing that might not always hold.

Or something completely different is happening. :?
By StaticDet5
#140378
I still have (what I'm calling) a "debounce delay" in the code, so that the motor is starting to rev before the sensor is being polled.

I worked a bit on the code this weekend, but my dog was freaking out about the gearbox noise, so I wasn't able to continue. I then made a relatively critical mistake:

I left the LiPo plugged in, all weekend. The 3-Cell LiPo is reading just over 3 volts. I broke it.

Kids, a little lesson about LiPo's: take care of them. They don't tolerate mistakes real well, and sometimes the get downright PISSED.

I'm lucky. The battery pack is simply dead. I've seen the aftermath of a catastrophic LiPo fail, and my basement wouldn't have survived that. I charge LiPo's in a "blast box", but I don't do anything special with them when I'm using them.

Bad news: I don't have any other 11.1v LiPo's. I've loaned a couple out, but I think both of them turned in to "perma-loans". I'm going to work on getting some batteries for this thing, but for now, I'm on hold. It'll be a day or two before I can get back into this.
By dkulinski
#140379
Bummer about the battery, glad it didn't do anything worse than fall below the limit. It may suggest a new feature for your project, low battery cutoff!

Do you mind if I post some code for you that should give you a serial dump of the amperage curve? I think for the moment you can use the Arduino as a simple oscilloscope. I actually thought about this all weekend and did some calculations on just how fast you would need to send updates via serial and it dictates a 115.2kbps rate.

This may get rid of the need of a magic delay number and give you the exact data you are looking for. I was going to try it on my son's broken AEG (broken barrel) but it turns out he fried something else in it while playing around with the innards. He is not his daddy's son at all! :D
By StaticDet5
#140380
PLEASE do!

I'm actually a pretty lazy guy. If someone invents a better wheel, I'm all for it (with attribution, of course).

It's funny about the battery. One of the goals of this project is to incorporate a low-battery cutout. I need to figure out how to make it fail-safe. I'm trying to figure out how to do this, without taking up significant battery power. The obvious way to do this is a low-current triggering automotive relay. As part of the start-up "self-check", it would power the relay on. Then, if the voltage falls below a certain level, the relay would "fall-open". I'm worried about the power requirement of a constantly on relay. I'm also worried about having a secondary power-system (push start) on this thing.

It's on the drawing board as a "primary feature". I'm still puzzling it over.
By dkulinski
#140381
You can also put the arduino to sleep after a significant delay. I don't know how deep a sleep as you need to be able to wake it up (you may be able to do this with the trigger) and how long it takes to wake up. Anyway, ideas for the future. I almost have this code done and I hope it works out. I can't test it as I don't have the same equipment you do but it should be sufficient.

Dan Kulinski
By dkulinski
#140385
Alright, I did this on a lunch break at work, gave me something entertaining to do on that period. Ok, you need to do the following:

Upload the sketch, then open your serial monitor. Set the serial monitor to 38400 bps. This will allow you to capture about 10 samples per motor cycle. If this is not smooth enough there is only one variable and the serial speed to change. You can change the ReadAmpsInterval to 1668 and change the Serial.Begin to 115200. Remember to make this change in your serial monitor. These new settings will dump about 25 records per cycle. I don't know how stable the Arduino is at 115200 though so start slow and ramp up if needed.

Pull the trigger!

You are going to get a series of data that is going to spew in your serial monitor. The data is the amperage sensor level, a tab and then the reading from millis(). Once you have done about a seconds worth, let go of the trigger, paste the data into excel (or google docs if you like), apply any formulas to convert the sensor readings to sensible amperage numbers and graph!
Code: Select all
    /*
      BasicAmperageMonitor-Feb-27-2012
     

     
     The circuit:
     * LED on board at pin 13
     * Motor control on pin 3 (PWM pin)
     * pushbutton attached to pin 7 from +5V
     * 10K resistor attached to pin 7 from ground
     * ADC on analog pin 0
     
     Serial settings:
     Bits per second 38400
     

    */

    #include <TimerOne.h>

    const int buttonPin = 7;  //Trigger switch attached to digital pin 7
    const int ledPin = 13;  //onboard LED on pin 13
    const int MotorPin = 3; //Motor drive pin (on MOSFET) connected to PWM pin at pin 3
    const int CurrentSensor = 0;  //Current flow sensor attached to Analog 0
    const int MotorSpeed = 255;  //PWM value for motor, max 255
    
    int buttonState = 0;  // Trigger button state
    volatile int IMain = 0; // Direct ADC reading from current sensor
    long ReadAmpsInterval = 4167; // This will provide 10 readings per AEG cycle



    void setup() {
      Serial.begin(38400); // High output rate to accept about 25 samples per motor cycle
      pinMode(MotorPin, OUTPUT);  //Set the MotorPin as an output
      analogWrite(MotorPin, 0);  // make sure that the MotorPin is Off
      
      pinMode(ledPin, OUTPUT);  // Set the LED Pin as an output
      pinMode(buttonPin, INPUT);  // set the trigger pin as an input
      
      Timer1.initialize(ReadAmpsInterval);  //set up the interrupt timer to read at the ReadAmpsInterval
      Timer1.attachInterrupt(ReadAmps);  //The function to call every interval
    }


    void loop() {
      
      /* A simple loop to drive the motor while the trigger is held down */
      
       buttonState = digitalRead(buttonPin);
       while(buttonState == HIGH) {
         analogWrite(MotorPin, MotorSpeed);
         digitalWrite(ledPin,HIGH);
       }
       
       analogWrite(MotorPin, 0);
       digitalWrite(ledPin, LOW);
    }


    void ReadAmps()          //this is the interrupt function
    {
      IMain = analogRead(CurrentSensor);   //simply reads the CurrentSensor and stores the value in IMain
      
      /* Write out the sensor reading, MSB then LSB */
      Serial.print(IMain,DEC);
      
      /* Send a tab */
      Serial.write(0x09);
      
      /* Write out the millisecond count (repeats after 50 days of run time) */
      unsigned long currentTime = millis();
      Serial.print(currentTime,DEC);
      
      /* Send a carriage return */
      Serial.write(0x0D);
    }
By Mee_n_Mac
#140399
StaticDet5 wrote:I need to figure out how to make it fail-safe. I'm trying to figure out how to do this, without taking up significant battery power. The obvious way to do this is a low-current triggering automotive relay. As part of the start-up "self-check", it would power the relay on. Then, if the voltage falls below a certain level, the relay would "fall-open". I'm worried about the power requirement of a constantly on relay. I'm also worried about having a secondary power-system (push start) on this thing.

It's on the drawing board as a "primary feature". I'm still puzzling it over.
Sounds like a job for another FET. One of the uses I've seen for a similar circuit is reverse voltage sensing, to make sure the battery is not plugged in backwards. The FET acts just like your motor FET does, as a switch, to prevent the voltage from being applied if wrong. I don't see why a similar, somewhat altered, arrangement couldn't serve as a low battery off switch. Off the top of my head it would work something like this : with the battery in but nothing yet turned on ... the FET is off and prevents voltage/power from everything. A momentary button turns the FET on directly from the battery and then the MCU boots and eventually takes over the task of keeping power on via a digital output pin driving the FET to be on. Then whenever the software commands it (low voltage or ???) the MCU can drive that pin off, shutting off the FET and itself in the process. I don't know that this would save that much juice over a deep sleep of the MCU, that might well depend on what kind of voltage regulator you end up with in your final design, but it should be do-able.
By StaticDet5
#140437
I can't catch a break with these batteries...
I've brought two batteries home, only to find that both have issues. Granted, neither of them have seen any use for a bit, but c'mon!

I like the idea of the low-voltage "cut-out", but I need to work on some issues.
First, the "power-on" button needs to be well located. I like the FET idea because it shouldn't matter if the button is pushed while the AEG computer is already powered up.
Second, and biggest, is making sure spurious "low voltage events" aren't triggering a shut-down. I know the voltage is going to drop while the gearbox is cycling. I'll just keep those events separate (if the voltage state is even read during the cycling, still up in the air). However, I don't want to blow through the low-voltage warning threshold and hit the low-voltage shut-off threshold.

I'm on hold until I can find another battery. I'm eyeing a car battery in the corner, but I'm wondering if that will destroy things... Here's where that lack of electrical confidence comes in to play. At my heart, I know a volt is a volt is a volt (and an amp is an amp is an amp), but hooking that massive brick up to something like this... dunno. Somewhat intimidated.
  • 1
  • 5
  • 6
  • 7
  • 8
  • 9
  • 32