Show Posts
Pages: [1]
1  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial data corrupt on ONE computer.... on: September 22, 2012, 08:02:24 pm
The hardware setup was taken directly from MPGuino, so I know it's pretty solid. I have one arduino putting a test pulse train out on pin 2 - 2ms on, 98ms off, for example (same as 2ms of fuel at 1200 RPMs, since the injector fires every other cycle). Pin 2 on the test signal generator is linked to a 22k resistor to pin 2+3 on the target, with a 5.6v zener to ground (for protection from injector flyback,etc). Ground pin on both boards are linked with a straight jumper, about 4 inches long.

In the car it seems to work fine, so I'm not concerned, but when I have the test generator powered by USB on my PC and the target board powered by USB on a laptop (not even plugged in), it gives weird results.

Again, it works fine in the car, it's just strange.
2  Using Arduino / Project Guidance / Re: Hot water line flusher on: September 21, 2012, 08:37:54 am
Great idea!  Why hasn't anyone else thought of that!

Not trying to take the wind out of your sails, but they do make these commercially.

Don't get me wrong -  I completely understand why you want to do your own (I was thinking about building one myself as well..). Off the shelf means most likely expensive, and obviously not as fun, just wanted to point out they exist.

They recirculate back into the water heater and usually have a sensor so that it shuts off once hot water reaches the farthest point you need it at. No real reason you couldn't time how long it takes and assume that it's always completely cold to skip the temp sensor though.

What I don't understand is why they don't run really small diameter, extra-hot water lines, and a tempering valve at each location to mix it with cold at the far end of the system - that way you get hot water almost instantly because of the size of the line, and since you're storing and transporting a smaller volume, you can insulate it much better for the same price. Smaller tank = less surface area, same amount of insulation to offset the higher temperature differential. Only problem is as the temperature gets lower, the tempering valve would make you consume hot water at a faster rate in an exponential curve, and the temp would just completely drop-off after a certain point. Also not sure about the cost of the tempering valves. Just an idea..
3  Community / Local Groups / Re: Anyone from Pennsylvania still around? on: September 21, 2012, 08:03:23 am
PA as well.. South of allentown.
4  Topics / Science and Measurement / Re: Measuring the velocity on: September 21, 2012, 07:45:09 am
You could use either photodiodes/phototransistors. Doesn't necessarily have to be IR, though. The reason for IR is that you can filter out visible light, and not have to worry as much about whether you're going to use it on a sunny day or in a dark closet, and having your bright/dark transition level moving around. You will probably still need to have an external analog circuit and a potentiometer to adjust the transition level, but using IR instead of visible light will make the dynamic range much lower.
5  Using Arduino / Interfacing w/ Software on the Computer / Re: Need help powering up a keyboard on: September 21, 2012, 07:23:09 am
Not really. Well, yes there is, but practically no. I don't think the keyboard itself processes the caps-lock function - it actually passes the pressing of caps-lock to the computer, the OS keeps track of the current state, then passes back whether the light should be on or off. Easy way to tell for sure if a computer is completely locked up or just temporarily unresponsive is to try to toggle caps-lock or scroll-lock. If the lights don't change, something has gone seriously wrong.

The only thing you could do without interfacing the keyboard to a microcontroller is open up the keyboard, find the wires for the key and indicator light and try to solder in your own toggle circuit (caps-lock is just a momentary switch, not a latched toggle), but any keyboard that was made to the PS2 standard is probably going to be a flex circuit board with those little rubber / carbon switches and probably an epoxy blob IC, so that's going to be hard, if not impossible to modify.

With that being said, it's probably not as hard as you think to interface it to a microcontroller. I've never done it, but I know it's been done before.
6  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial data corrupt on ONE computer.... on: September 20, 2012, 10:11:14 pm
So here's an update - I don't think it was the volatile keyword all along - I was powering the test function generator from a PC while running the datalogger. When they were both plugged into the same computer, it would work fine. I transferred JUST the datalogger to a laptop running off of batteries, and it would start to have corruption issues. When I moved the signal generator to the laptop as well, everything works fine again, so I'm apparently picking up noise on the ground connection even though the laptop is un-grounded. Weird, but at least I have the source.
7  Using Arduino / Interfacing w/ Software on the Computer / Re: Some help with Serial connection on: September 20, 2012, 11:29:55 am
Ahh.. Ok. Yes I've done this in the past - again in VB on windows. I had to find the process ID of the window I was looking for and use a windows API function to activate that window, then the sendkeys() function to send individual keystrokes to the app. Not sure if you can apply the same thing on linux or not, but here's what I did:

Private Function FindApp() As Int32
        ' Loop through process table, return process id of process named 'Notepad.exe'
        Dim proptr() As Process
        Dim Pid As Process
        proptr = Process.GetProcesses()     ' Get an array filled with all process IDs
        For Each Pid In proptr
                If Pid.MainModule.ModuleName = "Notepad.EXE" Then
                    Return Pid.Id           ' Notepad found, return process ID
                End If
            Catch ex As System.ComponentModel.Win32Exception
            Catch ex As InvalidOperationException
            End Try
    End Function

    Private Function ActivateApp() As Boolean
        ' Gives Notepad focus to receive HID keys
       Dim AppID as integer = FindAPP()

        If AppID <> 0 Then ' We found our application!
            Return True
        Else : Return False ' Not running??
        End If
    End Function

To use:
   SendKeys.SendWait("Keys to appear in notepad...")
8  Using Arduino / Interfacing w/ Software on the Computer / Re: Some help with Serial connection on: September 17, 2012, 09:43:26 am
Now he uses a "SATVLTransfer code which does the same thing. I do not understand how it gets into the applications automatically?
Yes I do not use Windows or any silly VB code

Still not quite sure what you're asking, so pardon me if this is obvious - the serial characters come across the usb connection, and the satvltransfer.exe apparently receives them and saves them to a file. Is that the part you're asking about - save them to a file? I would assume they are just taking the data in whatever format it's coming over in, separating out the different variables, and formatting the data into a .csv format, and saving it to a file on your computer. If you're not familiar, .csv stands for comma separated values. You just write a text file that contains all of your data, separated by commas, with a newline character between rows. Rename it to .csv, and you can open it with open office or excel.

Example of the formatting...

9  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial data corrupt on ONE computer.... on: September 17, 2012, 09:20:48 am
I changed the variables that are modified in ISRs to volatile, and it seems to have fixed the issue. It makes sense that the timing might be different between two different computers, but I still don't understand exactly why it would only cause a problem with one computer. Oh well....
10  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial data corrupt on ONE computer.... on: September 12, 2012, 08:29:31 am
...would have worked just fine.
I have no way of knowing why you didn't use the volatile keyword. Perhaps you were aware of it, and had good reasons for not using it. I offered you a change to explain them. If you weren't aware of the volatile keyword, you could google it, or ask here, and we could offer (more) advice.

I don't think I was being condescending. At least, that wasn't my intent.

I assumed it was condescending. My apologies.

Edit: Back to the topic, I'll change that later today and see what happens. I have a feeling that the InjLoopTime variable is having issues because of this - since it's being divided by a constant, and the result is a very large number, I'm guessing that it's being changed, and becoming a single digit number - that's why it's being sent as either a very large, granular value, or zero.
11  Using Arduino / Interfacing w/ Software on the Computer / Re: Some help with Serial connection on: September 12, 2012, 08:26:46 am
An easy route would be to dump it to a comma separated text file - in other words, your microcontroller would print (without line feeds) a value, a comma, a value, a comma, etc, then println(",") to end that row with a comma.

The computer end - You can send that to hyperterminal and write the results to a .txt file, rename it to .csv and import it directly into excel. If you want it to be automated, take a look at Visual Basic 2010 - You should be able to piece together some sample code to write the serial directly to a .csv. You can open them with excel, but you have to open excel first, then open the file from within excel, and it will launch a wizard to import your data.
12  Using Arduino / Interfacing w/ Software on the Computer / Re: Serial data corrupt on ONE computer.... on: September 12, 2012, 08:11:59 am
Bad Output:

Why is that line "bad"?

2nd parameter should have a value - in this case, it should be around 300 (RPM). Interrupts capture a running total of how long the injectors have been open (and number of times opened) since the dawn of time (or power, in this case). The main loop captures a snapshot of those values every x milliseconds (1000, in this case), and compare the current values with the last sample. The difference is how long / how many times it opened during the sample period. Values are as follows:

Total injector on-time during this sample period,
MPH (placeholder for now),
X Axis acceleration,
Y Axis acceleration,
Z Axis acceleration,
Coolant temp placeholder,
Air temperature,
Count of injector events this sample period.

You have two ISRs defined. In those ISRs and in loop(), you reference the same variables, and yet there is nary a volatile keyword in sight. Why would that be?

You are correct. Pin two and three are both being used as interrupts for the injector signal, but on opposite edges. The injector should never open and close quick enough to actually cause a problem, but I hadn't considered asynchronous read access of the main loop as being an issue. I understand that this could be an issue if the values change significantly. FWIW, I've logged literally hours of data and this doesn't seem to be an issue on the desktop.

On a side note, while this might be my first post, I've been reading this forum for a while, and I've noticed a certain tone in a number of your responses. I don't know for certain what your intended tone/attitude is, but keep in mind the audience that you are dealing with. I would be suprised to learn that the majority of users on this forum are experienced, professional programmers. I myself was never formally educated on any high level language, and I take a great deal of pride in my self-inscribed abilities. I appreciate your input, but I still feel that you could have presented it in a format that doesn't carry the risk of sounding condescending.

"You have two ISRs defined. In those ISRs and in loop(), you reference the same variables. You should be using the volatile keyword when declaring them. This prevents the compiler from optimizing them under the assumption that they can't change on their own." would have worked just fine.

13  Using Arduino / Interfacing w/ Software on the Computer / Serial data corrupt on ONE computer.... on: September 11, 2012, 10:32:11 pm
I wrote this application to log vehicle data to a SQL database so that I can analyze my driving habits. The arduino makes a few measurements, and sends them across the USB serial connection in a comma separated, semi-human readable format. I have a VB app that sits on the computer and either logs it to a sql database or caches it in a text file when the sql server is unavailable.

Everything is working great on my development computer - I have another micro generating a sample waveform and it measures it perfectly. But, when I plug it into the laptop that I had intended to use on the road, a FEW of the values are corrupt, but the formatting and all of the delimiters are fine. I know it's not the VB end of things - I can open it in hyperterminal, and it's corrupt there as well. I've tried changing the baud rate, etc, but the results are the same - fine on the desktop, first two values are corrupt on the laptop. And even the WAY that they are corrupt is consistent - should be sending a value of 300, and it will alternate between a few different values - 0.00, 2500000 and 1300000 for example. Not just any random values, particular ones. It's as if the buffer is getting full on the laptop and affecting the calculations on the arduino, but why on one, and why does the baud rate have no effect? Any ideas???

Good Output:

Bad Output:

Code is a little messy, but here it is:

unsigned long InjOpenTime;
unsigned long InjOpenLast;
unsigned long InjCloseTime;
unsigned long InjOpenTotal;
//unsigned long InjCloseTotal;
unsigned long SampleStartTime;
unsigned long SampleStartLast;
unsigned long SampleIntervalLength;
float SampleMillis;
float SampleMinutes;
float SampleHours;
float SampleDistance;
float SampleDistanceOld;
float DistanceChange;

long InjLoopTime;
long InjSampleTime;
long InjSampleLast;
long InjDuty;
long InjCycleOpenTotal;
float RPMs;
long VssPulseCount;
long VssMicro;
long VssLastMicro;
long VssTime;
float MPH;
int distance;
int distanceOld;
int InjCloseCount;
int InjCloseCountOld;
int DeltaInjCloseCount;
boolean VssState;
boolean VssLastState;
boolean Test;

void setup() {
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(15, INPUT);
  attachInterrupt(0, InjOpen, RISING); // Pin 2 interrupt
  attachInterrupt(1, InjClose, FALLING); // Pin 3 interrupt

void loop() {
    SampleStartTime = micros();
    SampleDistance = distance;
    InjSampleTime = InjOpenTotal;
    InjDuty = InjSampleTime - InjSampleLast;
    InjSampleLast = InjSampleTime;
    SampleIntervalLength = SampleStartTime - SampleStartLast;
    SampleStartLast = SampleStartTime;
    DistanceChange = SampleDistance-SampleDistanceOld;
    SampleDistanceOld = SampleDistance;
    SampleMillis = SampleIntervalLength / 1000;
    SampleMinutes = SampleIntervalLength / 60000;
    SampleHours = SampleMinutes/60;
    MPH = DistanceChange*.66 * 5280/SampleIntervalLength;
    DeltaInjCloseCount = InjCloseCount - InjCloseCountOld;
    if (DeltaInjCloseCount < 2)
    // Not Running..
    InjLoopTime = 400002;
    InjCloseCountOld = InjCloseCount;
  if (InjLoopTime > 400000)
    RPMs = 0;
    InjLoopTime = 400000;
    RPMs = InjLoopTime;
    RPMs = 1/RPMs * 60000000;
    Serial.print(InjDuty); // Inj pW
    Serial.print(RPMs);  // RPM
    Serial.print(MPH); // MPH
    Serial.print(analogRead(5)); // AccelX
    Serial.print("5"); // AccelY
    Serial.print(analogRead(4)); // AccelZ
    Serial.print("7"); // CoolantTemp
    Serial.print(analogRead(5)); // AirTemp
    Serial.print(DeltaInjCloseCount); // InjEvents

    delay(1000); // Sampling period

void InjOpen()
  InjOpenTime= micros();

void InjClose()
 InjCloseTime = micros();
 InjCycleOpenTotal =  InjCloseTime - InjOpenTime;
 InjOpenTotal += InjCycleOpenTotal;
 InjLoopTime = InjOpenTime - InjOpenLast;
 InjOpenLast = InjOpenTime;
 //VssState = digitalRead(15);
 //if(VssState != VssLastState)
 //  distance++; // We just went .66 feet
 //  VssLastState = VssState;
 InjCloseCount +=1;

Moderator edit: [code] [/code] tags added.
Pages: [1]