Show Posts
Pages: 1 [2] 3 4 ... 11
16  Using Arduino / Interfacing w/ Software on the Computer / Re: processing duemilanova firmata & debugging on: July 24, 2012, 07:11:22 am
SOLVED
.. I had picked the wrong port ;o/
Thanks for looking Paul.
17  Using Arduino / Interfacing w/ Software on the Computer / Re: automatically detect USB port with arduino from the computer on: July 24, 2012, 07:02:46 am

I've seen this work in Processing.
println(Arduino.list());

I was surprised to find that
arduino = new Arduino(this, Arduino.list()[0], 57600);
would need '0' to work. Two other ports are working and the Arduino-port is Port8. Ehmee .. maybe that's why my setup /doesn't/ work ..

See the extensive code I posted in
http://arduino.cc/forum/index.php/topic,115580.0.html
for a workable visual-basic solution.
18  Using Arduino / Interfacing w/ Software on the Computer / Re: processing duemilanova firmata & debugging on: July 24, 2012, 06:50:03 am

Quote
  void Firmata_loop() ;
uups ..
I'm surprised that the sketch would compile with that. It brought some

other errors up, but the graphic output is the same.
Quote
Quote
Goes without saying that the arduino part works.
I don't think it does, really.
Ok, I ment the circuit.
I can controle how long on/off is .. it ought to have had time enough,
but it's certainly a legitimate concern. If it's very slow it's not usable for my intend though.

Code:
I hope that you are aware that you can not modify the Firmata sketch, and expect Processing to still work correctly with it.
The Firmata code is not changed, but it does run along side by side other code.
19  Using Arduino / Interfacing w/ Software on the Computer / Re: easy way to create gui for ardu? on: July 24, 2012, 06:14:40 am
    
Code:
Private Sub ReadForm()
        If RadioButton1.Checked Then 'forward
            saveBool(0, currentStepper) = True
        End If
        If RadioButton2.Checked Then 'backwards
            saveBool(1, currentStepper) = True
        End If
        If RadioButton3.Checked Then 'mSingleStep
            saveBool(2, currentStepper) = True
        End If
        If RadioButton4.Checked Then 'full step
            saveBool(3, currentStepper) = True
        End If

        '      forw                         single
        If RadioButton1.Checked And RadioButton3.Checked Then 'forward
            mBytesToSend(0) = 0
            '                                full
        ElseIf RadioButton1.Checked And RadioButton4.Checked Then
            mBytesToSend(0) = 2

            '            backw                single
        ElseIf RadioButton2.Checked And RadioButton3.Checked Then 'backwards
            mBytesToSend(0) = 1

            '            backw                full
        ElseIf RadioButton2.Checked And RadioButton4.Checked Then 'fullStep
            mBytesToSend(0) = 3

        End If
        '----------------------------
        mBytesToSend(1) = StringToByte(TextBox3.Text) ' CType(Repeat, Byte)
        mBytesToSend(2) = StringToByte(TextBox4.Text) ' CType(mWaitTime, Byte)
        saveByteValues(0, currentStepper) = mBytesToSend(1)
        saveByteValues(1, currentStepper) = mBytesToSend(2)
        Dim bts(1) As Byte
        'TextBox1
        Dim stps As Integer = CType(TextBox1.Text, Integer)
        bts = Me.StepsToBytes(stps)
        mBytesToSend(3) = bts(0) 'least significant
        mBytesToSend(4) = bts(1) ' most significant
        saveByteValues(2, currentStepper) = mBytesToSend(3)
        saveByteValues(3, currentStepper) = mBytesToSend(4)

    End Sub




    Private Sub Send4Bytes()
        'Stop
        SerialPort1.Write(mBytesToSend, 0, 5)
    End Sub

    Private Sub SerialPort1_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        'Debug.Print("Data recieved")

        Dim val1, val2 As Byte
        'dataStandard:
        'first byte is code (for the dix)
        'next four is an integer (arduin long)
        'Debug.Print("BytesToRead " & SerialPort1.BytesToRead)
        Debug.Print(" ")
        If SerialPort1.BytesToRead = 3 Then
            code = SerialPort1.ReadByte
            'For i As Integer = 0 To 1
            val1 = CType(SerialPort1.ReadByte, Byte)
            val2 = CType(SerialPort1.ReadByte, Byte)
            ' Next
            If code = 5 Then
                val = CSng(val1 + val2 * 256)
                Me.testRefTable(val) 'Res_2 =
                If data_Initiated Then
                    Me.DataWrite(Res_2)
                End If
                RangeData.Add(Res_2)
            End If
            'recepValue = System.BitConverter.ToInt16(val, 0)
            If code = 4 Then
                Beep()
                Beep()
                'UnDim()
            End If
            Debug.Print(dix(code))
            'Debug.Print("value : " & (val1 + val2 * 256).ToString)
        ElseIf 3 < SerialPort1.BytesToRead Then
            SerialPort1.DiscardInBuffer()
            'Stop
        End If

    End Sub

    'Private Sub UnDim()
    '    Button5.Enabled = True
    '    Button2.Enabled = False
    'End Sub

    Private Sub SerialPort1_ErrorReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialErrorReceivedEventArgs) Handles SerialPort1.ErrorReceived
        Debug.Print("error recieving")
    End Sub

    'stop
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        mBytesToSend(0) = 4
        RangeData.Clear()
        Send4Bytes()
    End Sub

    'datawriting
    Private Sub StartDataWriter()

        Dim Dinf As New IO.DirectoryInfo("H:/ScanFiles")
        Dim nbr As Integer = Dinf.GetFiles.Count
        Dim str As String = TextBox2.Text & (nbr + 1).ToString

        Dim dataFileName As String = "H:/ScanFiles/" & str & ".scn"
        Dim fs As IO.FileStream = New IO.FileStream(dataFileName, IO.FileMode.CreateNew) 'Or IO.FileMode.Open

        binWriter = New IO.BinaryWriter(fs)
        '  dataMark = 0
    End Sub
    Private Sub DataWrite(ByVal value As Single)
        'If binWriter.BaseStream.
        binWriter.Write(value)

    End Sub

    'go
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        If bool_Automate Then
            PrepareRoller()
            Button2.Enabled = False
            Button5.Enabled = True
            ' RangeData.Clear()
        Else
            Me.ReadForm()
        End If

        Send4Bytes()
    End Sub

    ''reset as home
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        mBytesToSend(0) = 5

        Me.Send4Bytes()
    End Sub

    ''go home .
    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        mBytesToSend(0) = 6

        Me.Send4Bytes()
    End Sub

    Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged
        ReadForm()
        If startUpBypass Then
            startUpBypass = False
        Else
            If RadioButton5.Checked Then
                currentStepper = 0
            Else
                currentStepper = 1
            End If
            RadioButton1.Checked = saveBool(0, currentStepper)
            RadioButton2.Checked = saveBool(1, currentStepper)
            RadioButton3.Checked = saveBool(2, currentStepper)
            RadioButton4.Checked = saveBool(3, currentStepper)
            TextBox3.Text = saveByteValues(0, currentStepper).ToString
            TextBox4.Text = saveByteValues(1, currentStepper).ToString
            Dim myI As Integer = saveByteValues(3, currentStepper) * 256 + saveByteValues(2, currentStepper)
            TextBox1.Text = myI.ToString
        End If
    End Sub

    Private Sub PrepareRoller()
        mBytesToSend(0) = 0 'forward single
        mBytesToSend(1) = 144 ' CType(Repeat, Byte)
        mBytesToSend(2) = 10 ' CType(mWaitTime, Byte) ?????

        Dim bts(1) As Byte
        Dim stps As Integer = 1
        bts = Me.StepsToBytes(stps)
        mBytesToSend(3) = bts(0) 'least significant
        mBytesToSend(4) = bts(1) ' most significant
    End Sub

    Private Sub PrepareElevator()
        mBytesToSend(0) = 2 'forward full
        mBytesToSend(1) = 10 ' CType(Repeat, Byte)
        mBytesToSend(2) = 0 'waits 100 milliS

        Dim bts(1) As Byte
        Dim stps As Integer = 96
        bts = Me.StepsToBytes(stps)
        mBytesToSend(3) = bts(0) 'least significant
        mBytesToSend(4) = bts(1) ' most significant
    End Sub '
    'Elevate
    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        PrepareElevator()
        Send4Bytes()
        Button5.Enabled = False
        Button2.Enabled = True
    End Sub

    'automate
    Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
        bool_Automate = CheckBox1.Checked
    End Sub

    'Initiate datacollection
    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        If data_Initiated Then
            binWriter.Close()
            data_Initiated = False
            Button6.Text = "Initiate"
        Else
            data_Initiated = True
            'Button6.Enabled = False
            StartDataWriter()
            Button6.Text = "Stop collecting"
        End If


    End Sub

    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        binWriter.Close()
    End Sub


End Class

'kode(0)
'kode(1)

'forward/backward & singlestep/full : kode(0)

' 0-4 implies start
'forward singlestep                     0
'backwards singlestep                   1
'forward fullStep                       2
'backwards fullStep                     3

'stop                                   4
'reset as home                          5
'go home ... is calculated in arduino   6

'Internal to arduino:
'FirstStepper load variables            10
'second stepper load variables          11
'first stepper save variables           12
'second stepper save variables          13
' det kan forventes at når steper er stoppet
'at der kan ske et skift, altså at ved stop
'bliver variables saved. Ligeledes at et skift
'autoatically implies a stop
'skift stepper                          14

'number of repeats: kode(1)   byte
'wait 100 millis : kode(2)    byte
'number of steps : kode(3) & kode(4)   integer/Long
20  Using Arduino / Interfacing w/ Software on the Computer / Re: easy way to create gui for ardu? on: July 24, 2012, 06:13:25 am
Here you go ;o)
... snipped from an old visual basic project.
It's not usable without the wiring and circuit setup, but it may inspire you on single task .. like communicating and such. Without delving too much into details I faintly recall that the code drives 2 motors that positions an infrared rang-finder to measure 'distances to' an object (effectively taking a 3d picture).


Code:

Public Class Form1

    Private mForward, mBackward, mSingleStep, mStop, mFullTurn As Boolean
    Private mSteps, mWaitTime, mRepeats As Integer
    Private mStepString As String = ""
    Private mWaitString As String = ""
    Private mRepeatString As String = ""

    Private currentStepper As Integer = 0
    ' Private current

    Private saveBool(3, 1) As Boolean
    Private saveByteValues(3, 1) As Byte
    Private startUpBypass As Boolean = True

    Private mBytesToSend(4) As Byte ' 5 bytes

    'Private recievedBytes(4) As Byte

    Private code As Integer
    Private value(3) As Byte
    Private recepValue As Integer

    Private dix As Collections.Generic.List(Of String)

    Private RangeData As Collections.Generic.List(Of Single)
    Private bool_Automate As Boolean = True
    Private val As Single
    Private Res_2 As Single
    Private refTable As New Collections.Generic.List(Of Single)

    Private binWriter As IO.BinaryWriter
    Private data_Initiated As Boolean = False

    'Private ev As ev
    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        For Each p In My.Computer.Ports.SerialPortNames
            If p = "COM15" Then
                SerialPort1 = My.Computer.Ports.OpenSerialPort("COM15")
                SerialPort1.Encoding = New System.Text.ASCIIEncoding
                If Not SerialPort1.IsOpen = True Then
                    SerialPort1.Open()
                End If
            End If
        Next
        saveBool(0, 1) = True
        saveBool(1, 1) = False
        saveBool(2, 1) = True
        saveBool(3, 1) = False
        saveByteValues(0, 1) = 1 'Repeat
        saveByteValues(1, 1) = 10 'wait
        saveByteValues(2, 1) = 1
        saveByteValues(3, 1) = 0



        '0 - first stepper
        '1 - second stepper

        '2 - What's up Doc
        '3 - Pause
        '4 - Done
        dix = New Collections.Generic.List(Of String)
        dix.Add("  forward")
        dix.Add("  backward")

        dix.Add("  What's up Doc?") '2
        dix.Add("  Pause")
        dix.Add("  Done")
        dix.Add("  Measure")
        RangeData = New Collections.Generic.List(Of Single)

        Button5.Enabled = False
        'elBut = Button5
        For x As Integer = 0 To 300 '- 0.002 * x
            Val = CSng((108 * 113 / (x + 2000 / (x * x))))
            refTable.Add(Val)
            '  Debug.Print(x.ToString & ") " & val.ToString)
        Next

    End Sub

    Private Sub testRefTable(ByRef RangeOutput As Single)
        '  Res_1 = 0
        Res_2 = 0
        Dim slvd As Boolean = False
        Dim slv As Boolean = True
        Dim frac As Single
        For x As Integer = 0 To 299

            If slv Then
                If refTable(x + 1) <= RangeOutput And RangeOutput < refTable(x) Then
                    frac = (RangeOutput - refTable(x)) / (refTable(x + 1) - refTable(x))
                    Me.Res_2 = x + frac ' (RangeOutput - refTable(x)) / (refTable(x + 1) - refTable(x)) 'interpolates
                    Debug.Print("res_2 " & Res_2.ToString)
                    Exit For
                End If
            End If
        Next
        'Stop
    End Sub
    'forward
    'kode(0)
    Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
        If RadioButton1.Checked Then
            mForward = True
            mBackward = False
        End If
    End Sub

    'backwards
    'kode(0)
    Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
        If RadioButton2.Checked Then
            mForward = False
            mBackward = True
        End If
    End Sub

    'mSingleStep
    'kode(0)
    Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)
        If RadioButton3.Checked Then
            mSingleStep = True
            mFullTurn = False
        End If
    End Sub

    'kode(0)
    'full step
    Private Sub RadioButton4_CheckedChanged_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged
        If RadioButton4.Checked Then
            mSingleStep = False
            mFullTurn = True
        End If
    End Sub

    Private Function StringToByte(ByVal streng As String) As Byte
        StringToByte = 0
        Try
            StringToByte = CType(streng, Byte)
        Catch ex As Exception
            Debug.Print("StringToNumber error : " & ex.Message)
            StringToByte = 0
        End Try
        Return StringToByte
    End Function

    'number of step/turns
    'kode(3 & 4)
    Private Sub TextBox1_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox1.KeyUp
        mStepString = TextBox1.Text
        If e.KeyCode = Keys.Return Then
            If Not mStepString = "" Then
                mSteps = CType(mStepString, Integer)
                'If 250 < mSteps Then
                '    mSteps = 250
                'ElseIf mSteps < 0 Then
                '    mSteps = 0
                'End If
            End If
        End If
    End Sub

    'number of repeat times
    'kode(1)
    Private Sub TextBox3_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox3.KeyUp
        'Dim str As String
        mRepeatString = TextBox3.Text
        If e.KeyCode = Keys.Return Then
            If Not mRepeatString = "" Then
                mRepeats = CType(mRepeatString, Integer)
                If 250 < mRepeats Then
                    mRepeats = 250
                ElseIf mRepeats < 0 Then
                    mRepeats = 0
                End If
                'doTurns()
            End If
        End If
    End Sub

    'kode(2)
    'rest-time
    Private Sub TextBox4_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles TextBox4.KeyUp
        mWaitString = TextBox4.Text
        If e.KeyCode = Keys.Return Then
            If Not mWaitString = "" Then
                mWaitTime = CType(mWaitString, Integer)
                If 250 < mWaitTime Then
                    mWaitTime = 250
                ElseIf mWaitTime < 0 Then
                    mWaitTime = 0
                End If
                'doTurns()
            End If
        End If
    End Sub
    'mSteps
    Private Sub TextBox1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox1.LostFocus
        If Not mStepString = "" Then
            mSteps = CType(mStepString, Integer)
            'If 250 < mSteps Then
            '    mSteps = 250
            'ElseIf mSteps < 0 Then
            '    mSteps = 0
            'End If
        End If
    End Sub

    Private Function StepsToBytes(ByVal steps As Integer) As Byte()
        Dim litl As Integer = steps
        Dim big As Integer = 0
        Dim res(1) As Byte

        While 255 < litl
            litl = litl - 256
            big = big + 1
        End While
        res(0) = CType(litl, Byte)
        res(1) = CType(big, Byte)

        StepsToBytes = res
    End Function

    'mRepeats:
    Private Sub TextBox3_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox3.LostFocus
        If Not mRepeatString = "" Then
            mRepeats = CType(mRepeatString, Integer)
            If 250 < mRepeats Then
                mRepeats = 250
            ElseIf mRepeats < 0 Then
                mRepeats = 0
            End If
            mBytesToSend(1) = CType(mRepeats, Byte)
        End If
    End Sub
    'mWaitTime
    Private Sub TextBox4_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles TextBox4.LostFocus
        If Not mWaitString = "" Then
            mWaitTime = CType(mWaitString, Integer)
            If 250 < mWaitTime Then
                mWaitTime = 250
            ElseIf mWaitTime < 0 Then
                mWaitTime = 0
            End If
            mBytesToSend(2) = CType(mWaitTime, Byte)
        End If

    End Sub

    Private Sub LoadStepper(ByVal first As Boolean)

    End Sub



21  Using Arduino / Interfacing w/ Software on the Computer / processing duemilanova firmata & debugging on: July 24, 2012, 05:51:10 am
I'll pop this and start reading posts elsewhere in this branch of the forum.
I've set up a Duemilanova, the AllInputFirmata example-code and Processing example-code "arduino-input". It compiles without errors but Processing does not respond with expected graphics.
The board tries to catch a click event from a switch that is flipped by dents on a rolling wheel. To get a clear pulse I've pulled out the big guns and attached interrupts on both the rising and the falling edge. Goes without saying that the arduino part works. I use the pulse to write a tikPin on or off. Can anyone suggest a reason why it shouldn't work together with the AllInputFirmata example-code?

Code:
// Firmata variables:
#include <Firmata.h>

byte pin;

int analogValue;
int previousAnalogValues[TOTAL_ANALOG_PINS];

byte portStatus[TOTAL_PORTS]; // each bit: 1=pin is digital input, 0=other/ignore
byte previousPINs[TOTAL_PORTS];

/* timer variables */
unsigned long currentMillis;     // store the current value from millis()
unsigned long previousMillis;    // for comparison with currentMillis
/* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
   get long, random delays.  So only read analogs every 20ms or so */
int samplingInterval = 19;      // how often to run the main loop (in ms)

void sendPort(byte portNumber, byte portValue)
{
  portValue = portValue & portStatus[portNumber];
  if(previousPINs[portNumber] != portValue) {
    Firmata.sendDigitalPort(portNumber, portValue);
    previousPINs[portNumber] = portValue;
  }
}
//- end Firmata-variables




//int analogInPin = A0 ;
//int val ;
int tikPin = 11 ;
long oldCtr ;
long ctr=0 ;
boolean tikker;
long lastDebounce ;

long oldCtr2 ;
long ctr2=0 ;
boolean tikker2;
long lastDebounce2 ;

boolean stateOn, stateOnOld ;
boolean aTik ;

long beepCtr = 0 ;
long lastdeb3 ;
boolean beeper ;

void setup() {
  Firmata_setup() ;
  //Serial.begin(9600);
  pinMode(tikPin, OUTPUT);
  attachInterrupt(1, tick, RISING  );
  attachInterrupt(0, tick2, FALLING  );
}// void setup()



void loop() {
  
  void Firmata_loop() ;
 //
  if( oldCtr != ctr ){
    lastDebounce = millis();
    tikker = true ;
  }
  
  if( (lastDebounce - millis()) > 75 ){
    if(tikker &! stateOn){
    tikker=false ;
    turnOn() ;
    oldCtr = ctr ;
    }
  }
  
  
    if( oldCtr2 != ctr2 ){
    lastDebounce2 = millis();
    tikker2 = true ;
  }
  if( (lastDebounce2 - millis()) > 75 ){
    if(tikker2 && stateOn){
    tikker2=false ;
    turnOff() ;
    oldCtr2 = ctr2 ;
    }
  }
  
  
  if( stateOnOld != stateOn ){
    lastdeb3 = millis();
    beeper = true ;
     // Serial.print("tst ") ;
      //Serial.println(beepCtr) ;
   //   delay(5) ;
  }
  
  if( lastdeb3 - millis() > 50 ){
      if(beeper && stateOn){
      // finally
      beepCtr++ ;
      beeper = false ;
//      Serial.print("beep ") ;
//      Serial.println(beepCtr) ;
//      delay(5) ;
      stateOnOld = stateOn ;
      }
  }
  
  
  
//  oldCtr2 = ctr2 ;
//  oldCtr = ctr ;
}// end loop ----------------------------------------------------

void turnOn(){
//  Serial.print("on ") ;
//  Serial.println(ctr) ;
//  delay(10) ;
digitalWrite(tikPin,HIGH) ;
  stateOn = true ;
}

void tick(){
  ctr++;
//  Serial.println("on") ;
//  delay(2) ;
}// end turnOn --------------------------------------------------

void tick2(){
  ctr2++;
//  Serial.println("off") ;
//  delay(2) ;
  
}// end turnOn --------------------------------------------------

void turnOff(){
//  Serial.println("off ") ;
//  Serial.println(ctr2) ;
//  delay(10) ;
digitalWrite(tikPin,LOW) ;
  stateOn =false ;
}// end turnOff -------------------------------------------------

//******************************************* firmata code *******************


void Firmata_setup()
{
  byte i, port, status;

  Firmata.setFirmwareVersion(0, 1);

  for(pin = 0; pin < TOTAL_PINS; pin++) {
    if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
  }

  for (port=0; port<TOTAL_PORTS; port++) {
    status = 0;
    for (i=0; i<8; i++) {
      if (IS_PIN_DIGITAL(port * 8 + i)) status |= (1 << i);
    }
    portStatus[port] = status;
  }

  Firmata.begin(57600);
}

void Firmata_loop()
{
  byte i;

  for (i=0; i<TOTAL_PORTS; i++) {
      sendPort(i, readPort(i, 0xff));
  }
  /* make sure that the FTDI buffer doesn't go over 60 bytes, otherwise you
     get long, random delays.  So only read analogs every 20ms or so */
  currentMillis = millis();
  if(currentMillis - previousMillis > samplingInterval) {
    previousMillis += samplingInterval;
    while(Firmata.available()) {
      Firmata.processInput();
    }
    for(pin = 0; pin < TOTAL_ANALOG_PINS; pin++) {
      analogValue = analogRead(pin);
      if(analogValue != previousAnalogValues[pin]) {
        Firmata.sendAnalog(pin, analogValue);
        previousAnalogValues[pin] = analogValue;
      }
    }
  }
}



How do I 'put' serial debug-data on the processing screen?
I'll try to make a minimal setup and listen to only one pin, but with no prior experience and no error or debug info .. it will be frustrating.
22  Using Arduino / Sensors / Re: serate output from sensor on: July 24, 2012, 01:37:06 am
hi sebnil,
I've saved the link.
From a quick look at the FIR.cpp I may get a problem on setting the filter in that the output-frequency is not constant.
I worked on another sensor-output yesterday, one that's less serate, but none the less poses the same problem. It's an isolated project, so I can opt to use brute force: I use both an interrupt on rising and falling edge and uses 'debounsing' on the three 'events' that can be extracted. That's a lot of resources on output from a mechanical switch that is flipped by the dents of a wheel.
.. I admire your flawless syntax ..
23  Using Arduino / Programming Questions / Re: variable not changed ... ? on: July 22, 2012, 10:50:08 am
Nick,
Quote
the scope operator is only used to resolve an ambiguity (eg. base class compared to derived class).
That makes good sense.

About the < and > I'm ready to defend my use of it .. wasn't it for the rule I fell upon a couple of days ago: that the variable is always on the left, and the value always on the right.
/my way/ is using only less than, and I used to put value and variable where they fit according to that. I'm surprisingly obtuse when it comes to a quick understanding of which is what.
But, I'll line up.
24  General Category / General Discussion / on robots .. on: July 22, 2012, 08:08:44 am
For inspiration and intertainment
http://www.ted.com/talks/robert_full_on_engineering_and_evolution.html
25  Using Arduino / General Electronics / Re: measuring board's total amp usage? on: July 22, 2012, 05:38:46 am
Hi Mike,
Quote
Well I am not sure you should have coil resistors in the first place. It is much better to try and get the voltage right in the first place.
I hate the principle of burning energy off in a resistor to get things to work right. I did have some attempts at start, and left with the impression, that I could not switch the analog-in on Enable fast enough.
I recently did find some code that sets pwm width and duration in hardware .. if it responds fast enough I could use a much higher voltage and cut the duration in each step and maybe even think in terms of micro-stepping to give the motors a quiet hum instead of the bangbang when it's not on max-speed.
I do know myself well enough to know that it will not be a left-hand job. And, it's the motors that's at the gunpoint in trial & error.
Maybe worst obstacle is: I've made myself a crucial component of a 3d-scanner .. I'm dying to try it out.
26  Using Arduino / Programming Questions / Re: variable not changed ... ? on: July 22, 2012, 05:08:34 am
Quote
Good luck on your project.
Thanks a lot .. I've got a 3d-scanner on the bedding, so I'm sort of eager to round the 'positioner' off.

Last night I got to think, that poll() could be a right name for stepper.setTime() (and button.Read() ), but it's still slightly off: in an event-perspective I actually sets all boolean variables for all the sub-events and states (of the button). The snag still is, that each boolean value of a sub-event/state has to be polled. pollStep() could leave all doubt behind.

Broadcasting says that summer is comming up in EU (about time ;o/) - it seemed to be stuck on your continent ;o)
27  Using Arduino / Programming Questions / Re: variable not changed ... ? on: July 21, 2012, 09:22:47 am
Paul,
Thank you for looking and giving critique,

I have two habits: One is consistently to use only < to prevent me from any confusion when reading those signs. Recently I realized that the value being compared 'always' is on the left side. I see that I haven't got to correct all.
The other habit is to mark the ending bracket } with at commented hint of where to find the start. I find it useful and supportive, and I'll continue with it; but now you know why and what the comment relates to.

I'm aware of the potential issues that can arise around the init() function. I use it to serve one particular problem: to have the cPen.MaxVelocity() value sat (from the minimum value of one of the two stepper.maxVelocities() if memory serves me right). It's observant of you to catch sight of it.

I have an unreasonable lot of errors from poor conversions between types. Not to get hung up on it in the middle of something else, I've sometimes chosen to insert extra variables. Poor coding.

When I wrote the cButton-class (it was the very first in these programming environments), I hoped that I could delegate all the nitty gritty to it. I should have realized the consequence of polling and interrupts (soo used to the microsoft event-model). One can safely say that that class failed to be of any help.

Before sending the code to you, I erased some of the commented-out lines relating to Serial feed-back. At some time the Serial statements would spawn an error (maybe I was using it in a constructor or before setting Serial.begin() ). Anyway, where I would like to use it (in ie. setTime() ) it is way too slow to keep up with events or it ruins proper execution.

As for the string and String ..  .. the notion of pointers gives me a rash. I have messed around with my first trial & error-code in the read/write to eeprom, so I have probably passed the first difficult barrier to get to learn it. I've begun to think of using it for the position-variable that is the root-problem of this thread.

In spite of stern efforts the setTime() has failed to live up to a must convey intuitive info about what it does/is. I recently met 'check' that could be used instead, but only time (or you) can tell if it's right. The Time() functions stresses me because they are often used where efficient code is of the essence (called often). I chose the name because I would intuitively recognize it as a function that would be called often.
There are two kinds of code in my world: the must be extremely efficient .. and the rest. I love the rest because I can focus on writing something understandable, something that will be recognizable some time in the future too.

You can probably guess, that I all in all has spent a lot of time on programming. This has been a rare opportunity to talk about what I do. Thank you.

Carsten
28  Using Arduino / General Electronics / Re: measuring board's total amp usage? on: July 21, 2012, 08:12:34 am
Do you need to plug one of your meter probes into a different socket to measure up to 10 amps?
Yes
.. reminding me I see, that the probe should be moved as well. Thanks.
29  Using Arduino / General Electronics / Re: measuring board's total amp usage? on: July 21, 2012, 05:59:11 am
Hi Mike,
I'm hesitant on 'touching' the circuits because I havn't found a good implementation of .. not burning the coil-resistors. The new resistors I just changed got a brown-out again, but the driver and motor are unharmed.
It's 'nice' to have a joy-stick that just works whenever you want to move the pen 'by hand' (vs. by code), but it tends to leave stepping in a 'wrong' phase. Anyway, I could use the button of the joy-stick as a quick 'turn-on'-button .. and hope that I'll remember to turn it off after use. Or something more fancy since I hate to 'have to' do something else but a particular task at hand.

As for the current measurement I just did .. It goes off scale on 500 mA, and shows 'nothing' on 10A. I'll have to figure out what's achtually using current (besides the board), when it's in 'passive' mode. I'm very likely to sacrifice all the blinking led-indicators .. they are not implemented well anyway. Or .. I've been to school .. I should /CALCULATE/ the darn thing.
30  Using Arduino / Programming Questions / Re: variable not changed ... ? on: July 21, 2012, 05:23:59 am
Hi Paul,
I've gathered the active code in a .txt at
http://troelsgaard.net/images/ct_Images/Positioner/Arduino.txt

It's largely uncommented and I'll use this thread for that. It's an unforgivable task to look for errors in a pile of junk like that, but I will assume that you may be able to use a proper editor for error-detection or search/find. I have written the class-code in notepad and program-code in the Ardino-editor.
The code is segmented into the class-code and meaningful taps in the Arduino editor (like Setup() & Loop(), Sensors, (Button) commands, Tasks ..)

I've build a line-in button-commander that uses 3 buttons to access and execute code. Conceptually the commands that are executed are 'kept' in what I think of as a table-of-commands. Two buttons controls row and column (selectors), the third executes the selected command. It's using some lengthy switch case: one for popping me a message on which table-entrance I just went into, another for holding the function to execute. The table-functions are (for now) largely for reading and writing to eeprom and SDCard, but it has 'goTo's too.
Two other buttons on the button-commander controls on/off and a pause.

Monitor-input converts input to action (moving steppers). It's been build ad-hoc and is not pretty.
I think of it as an alternative to move the pen by the joystick.

Implementing the joystick meant changing some code in the central stepper.setTime() .. to make it go directly to Step().
I try to make steppers go as fast as possible: they are inherently slow and they make less noise on high speed. But it clutters the code at places.

Skip any error-finding on what concerns blinking leds.

Please ask in on more detailed commenting.

I don't feel skilled enough to use pointers, references and addressOf where it would be advantageous.
Pages: 1 [2] 3 4 ... 11