Loading ...
Sorry, an error occurred while loading the content.

Re: Velleman USB Experiment Interface Board K8055

Expand Messages
  • Rod
    The board is still available in my local Maplin electronic shop in the UK so too in other parts of the world. For less ambitious folks the board is good fun as
    Message 1 of 14 , Jan 14, 2013
    • 0 Attachment
      The board is still available in my local Maplin electronic shop in the UK so too in other parts of the world. For less ambitious folks the board is good fun as it comes out the box. This code allows Liberty to use all of the .dll functions that ship with the board.

      'This software mimics the control software delivered with the Velleman k8055 board
      'There are no restrictions of any kind on this software
      'As always I used community resources
      'Alyce and Dennis assisted the API calls


      'Set up the environment
      nomainwin
      WindowWidth = 700
      WindowHeight = 410
      UpperLeftX=int((DisplayWidth-WindowWidth)/2)
      UpperLeftY=int((DisplayHeight-WindowHeight)/2)
      struct AtoD1, input1 as long
      struct AtoD2, input2 as long
      struct DtoA,output1 as long, output2 as long
      dim inbyte(5)
      dim outbyte(8)
      dim count(2)
      dim debounce$(5)
      debounce$(1)="0 ms"
      debounce$(2)="2 ms"
      debounce$(3)="10 ms"
      debounce$(4)="1000 ms"
      debounce$(5)="5000 ms"

      'Set up the window controls
      groupbox #main.addressbox, "Card Address", 15, 7, 120, 85
      groupbox #main.dtoabox1, "DA1", 145, 7, 55, 315
      groupbox #main.dtoabox2, "DA2", 210, 7, 55, 315
      groupbox #main.atodbox1, "AD1", 275, 7, 55, 315
      groupbox #main.atodbox2, "AD2", 340, 7, 55, 315
      graphicbox #main.da1, 163,55,20,200
      graphicbox #main.da2, 227,55,20,200
      graphicbox #main.ad1, 290,55,20,200
      graphicbox #main.ad2, 355,55,20,200
      groupbox #main.inputbox, "Inputs", 405, 7, 285, 60
      groupbox #main.outputbox, "Output", 405, 77, 285, 60
      groupbox #main.counterbox1, "Counter 1", 405, 152, 110, 170
      groupbox #main.counterbox2, "Counter 2", 540, 152, 110, 170
      checkbox #main.sk5, "SK5", [null], [null], 30, 27, 49, 25
      checkbox #main.sk6, "SK6", [null], [null], 85, 27, 49, 25
      button #main.connectbutton,"Connect",[connect], UL, 30, 57, 95, 25
      TextboxColor$ = "white"
      textbox #main.cardtext, 15, 112, 120, 25
      button #main.buttonsad, "Set All Digital",[setalldigital], UL, 15, 142, 120, 25
      button #main.buttoncad, "Clear All Digital",[clearalldigital], UL, 15, 172, 120, 25
      button #main.buttonsaa, "Set All Analog",[setallanalog], UL, 15, 202, 120, 25
      button #main.buttoncaa, "Clear All Analog",[clearallanalog], UL, 15, 232, 120, 25
      button #main.buttonout, "Output Test",[outputtest], UL, 15, 262, 120, 25
      button #main.buttonia1, "Inc",[incdtoa1], UL, 150, 25, 45, 25
      button #main.buttonda1, "Dec",[decdtoa1], UL, 150, 262, 45, 25
      button #main.buttonia2, "Inc",[incdtoa2], UL, 215, 25, 45, 25
      button #main.buttonda2, "Dec",[decdtoa2], UL, 215, 262, 45, 25
      button #main.buttoncr1,"Reset",[count1reset], UL, 410, 262, 90, 25
      button #main.buttoncr2,"Reset",[count2reset], UL, 550, 262, 90, 25
      textbox #main.dtoa1text, 150, 292, 45, 25
      textbox #main.dtoa2text, 215, 292, 45, 25
      textbox #main.atod1text, 280, 292, 45, 25
      textbox #main.atod2text, 345, 292, 45, 25
      textbox #main.cntr1text 410, 292, 90, 25
      textbox #main.cntr2text 550, 292, 90, 25
      checkbox #main.rbi1, "1", [null], [null], 410, 30, 32, 25
      checkbox #main.rbi2, "2", [null], [null], 445, 30, 32, 25
      checkbox #main.rbi3, "3", [null], [null], 480, 30, 32, 25
      checkbox #main.rbi4, "4", [null], [null], 515, 30, 32, 25
      checkbox #main.rbi5, "5", [null], [null], 550, 30, 32, 25
      checkbox #main.rbo1, "1", [output1Set], [output1Reset], 410, 100, 32, 25
      checkbox #main.rbo2, "2", [output2Set], [output2Reset], 445, 100, 32, 25
      checkbox #main.rbo3, "3", [output3Set], [output3Reset], 480, 100, 32, 25
      checkbox #main.rbo4, "4", [output4Set], [output4Reset], 515, 100, 32, 25
      checkbox #main.rbo5, "5", [output5Set], [output5Reset], 550, 100, 32, 25
      checkbox #main.rbo6, "6", [output6Set], [output6Reset], 585, 100, 32, 25
      checkbox #main.rbo7, "7", [output7Set], [output7Reset], 620, 100, 32, 25
      checkbox #main.rbo8, "8", [output8Set], [output8Reset], 655, 100, 32, 25
      ComboboxColor$ = "white"
      combobox #main.debounce1, debounce$(, [debounce1], 410, 180, 90, 100
      combobox #main.debounce2, debounce$(, [debounce2], 550, 180, 90, 100

      'Open the window and set up the events to manage the sliders
      open "Velleman K8055 Interface Board" for window_nf as #main
      print #main, "font ms_sans_serif 10"
      print #main, "trapclose [quit]"
      print #main.debounce1, "select 2 ms"
      print #main.debounce2, "select 2 ms"
      print #main.da1, "when leftButtonDown [setda1]"
      print #main.da2, "when leftButtonDown [setda2]"

      'Open the Velleman DLL
      open "k8055d.dll" for dll as #velleman

      'Now wait for the first event
      wait



      [connect]
      print #main.sk5, "value? sk5$"
      print #main.sk6, "value? sk6$"
      if sk5$="set" and sk6$="set" then card =0
      if sk5$="reset" and sk6$="set" then card = 1
      if sk5$="set" and sk6$="reset" then card=2
      if sk5$="reset" and sk6$="reset" then card =3
      card=OpenDevice(card)
      if card>=0 then
      print #main.cardtext, " Card ";str$(card);" found"
      timer 100, [readports]
      else
      print #main.cardtext, " Card not found!"
      wait
      end if

      [readports]
      'ret=ReadAnalogChannel(1)
      'ret=ReadAnalogChannel(2)
      ret=ReadAllAnalog()
      ret=ReadAllDigital()
      ret=WriteAllDigital()
      ret=ReadCounter(1)
      ret=ReadCounter(2)
      gosub [displayupdate]
      wait

      'button and checkbox handlers*********************************************

      [null]
      gosub [displayupdate]
      wait

      [setda1]
      value=min(255,(max(0,int((200-MouseY)/200*255))))
      ret=OutputAnalogChannel(1,value)
      gosub [displayupdate]
      wait

      [setda2]
      value=min(255,(max(0,int((200-MouseY)/200*255))))
      ret=OutputAnalogChannel(2,value)
      gosub [displayupdate]
      wait

      [debounce1]
      print #main.debounce1, "contents? c$"
      select case c$
      case "0 ms"
      debounce=0
      case "2 ms"
      debounce=2
      case "10 ms"
      debounce=10
      case "1000 ms"
      debounce=1000
      case "5000 ms"
      debounce=5000
      case else
      debounce=2
      end select
      ret=SetCounterDebounceTime(1,debounce)
      gosub [displayupdate]
      wait

      [debounce2]
      print #main.debounce2, "contents? c$"
      select case c$
      case "0 ms"
      debounce=0
      case "2 ms"
      debounce=2
      case "10 ms"
      debounce=10
      case "1000 ms"
      debounce=1000
      case "5000 ms"
      debounce=5000
      case else
      debounce=2
      end select
      ret=SetCounterDebounceTime(2,debounce)
      gosub [displayupdate]
      wait

      [count1reset]
      ret=ResetCounter(1)
      gosub [displayupdate]
      wait

      [count2reset]
      ret=ResetCounter(2)
      gosub [displayupdate]
      wait

      [incdtoa1]
      value=min(255,DtoA.output1.struct+1)
      ret=OutputAnalogChannel(1,value)
      gosub [displayupdate]
      wait

      [decdtoa1]
      value=max(0,DtoA.output1.struct-1)
      ret=OutputAnalogChannel(1,value)
      gosub [displayupdate]
      wait

      [incdtoa2]
      value=min(255,DtoA.output2.struct+1)
      ret=OutputAnalogChannel(2,value)
      gosub [displayupdate]
      wait

      [decdtoa2]
      value=max(0,DtoA.output2.struct-1)
      ret=OutputAnalogChannel(2,value)
      gosub [displayupdate]
      wait


      [setallanalog]
      ret=SetAllAnalog()
      gosub [displayupdate]
      wait

      [clearallanalog]
      ret=ClearAllAnalog()
      gosub [displayupdate]
      wait

      [setalldigital]
      ret=SetAllDigital()
      gosub [displayupdate]
      wait

      [clearalldigital]
      ret=ClearAllDigital()
      gosub [displayupdate]
      wait

      [outputtest]
      if test=1 then
      test=0
      ret=ClearAllDigital()
      timer 100,[readports]
      else
      test=1
      timer 200,[output]
      wait
      [output]
      if ledon=0 or ledon=9 then ledon=1 : ledoff=8
      if ledoff=9 then ledoff=1
      ret=SetDigitalChannel(ledon)
      ret=ClearDigitalChannel(ledoff)
      ledon=ledon+1
      ledoff=ledoff+1
      gosub [displayupdate]
      wait
      end if
      gosub [displayupdate]
      wait

      [output1Set]
      outbyte(1)=1
      gosub [displayupdate]
      wait
      [output2Set]
      outbyte(2)=1
      gosub [displayupdate]
      wait
      [output3Set]
      outbyte(3)=1
      gosub [displayupdate]
      wait
      [output4Set]
      outbyte(4)=1
      gosub [displayupdate]
      wait
      [output5Set]
      outbyte(5)=1
      gosub [displayupdate]
      wait
      [output6Set]
      outbyte(6)=1
      gosub [displayupdate]
      wait
      [output7Set]
      outbyte(7)=1
      gosub [displayupdate]
      wait
      [output8Set]
      outbyte(8)=1
      gosub [displayupdate]
      wait

      [output1Reset]
      outbyte(1)=0
      gosub [displayupdate]
      wait
      [output2Reset]
      outbyte(2)=0
      gosub [displayupdate]
      wait
      [output3Reset]
      outbyte(3)=0
      gosub [displayupdate]
      wait
      [output4Reset]
      outbyte(4)=0
      gosub [displayupdate]
      wait
      [output5Reset]
      outbyte(5)=0
      gosub [displayupdate]
      wait
      [output6Reset]
      outbyte(6)=0
      gosub [displayupdate]
      wait
      [output7Reset]
      outbyte(7)=0
      gosub [displayupdate]
      wait
      [output8Reset]
      outbyte(8)=0
      gosub [displayupdate]
      wait

      'Display update ***********************************************************
      [displayupdate]
      print #main.atod1text, AtoD1.input1.struct
      print #main.atod2text, AtoD2.input2.struct
      print #main.dtoa1text, DtoA.output1.struct
      print #main.dtoa2text, DtoA.output2.struct
      print #main.cntr1text, count(1)
      print #main.cntr2text, count(2)
      if inbyte(1)=0 then
      print #main.rbi1,"reset"
      else
      print #main.rbi1,"set"
      end if
      if inbyte(2)=0 then
      print #main.rbi2,"reset"
      else
      print #main.rbi2,"set"
      end if
      if inbyte(3)=0 then
      print #main.rbi3,"reset"
      else
      print #main.rbi3,"set"
      end if
      if inbyte(4)=0 then
      print #main.rbi4,"reset"
      else
      print #main.rbi4,"set"
      end if
      if inbyte(5)=0 then
      print #main.rbi5,"reset"
      else
      print #main.rbi5,"set"
      end if
      if outbyte(1)=0 then
      print #main.rbo1,"reset"
      else
      print #main.rbo1,"set"
      end if
      if outbyte(2)=0 then
      print #main.rbo2,"reset"
      else
      print #main.rbo2,"set"
      end if
      if outbyte(3)=0 then
      print #main.rbo3,"reset"
      else
      print #main.rbo3,"set"
      end if
      if outbyte(4)=0 then
      print #main.rbo4,"reset"
      else
      print #main.rbo4,"set"
      end if
      if outbyte(5)=0 then
      print #main.rbo5,"reset"
      else
      print #main.rbo5,"set"
      end if
      if outbyte(6)=0 then
      print #main.rbo6,"reset"
      else
      print #main.rbo6,"set"
      end if
      if outbyte(7)=0 then
      print #main.rbo7,"reset"
      else
      print #main.rbo7,"set"
      end if
      if outbyte(8)=0 then
      print #main.rbo8,"reset"
      else
      print #main.rbo8,"set"
      end if
      print #main.da1, "discard ; size 6 ; color red ; place 8 200 ; down ; north ; go ";int(DtoA.output1.struct/255*200)
      print #main.da1, "color green ; go ";200-int(DtoA.output1.struct/255*200)
      print #main.da2, "discard ; size 6 ; color red ; place 8 200 ; down ; north ; go "; int(DtoA.output2.struct/255*200)
      print #main.da2, "color green ; go ";200-int(DtoA.output2.struct/255*200)
      print #main.ad1, "discard ; size 6 ; color red ; place 8 200 ; down ; north ; go "; int(AtoD1.input1.struct/255*200)
      print #main.ad1, "color green ; go ";200-int(AtoD1.input1.struct/255*200)
      print #main.ad2, "discard ; size 6 ; color red ; place 8 200 ; down ; north ; go "; int(AtoD2.input2.struct/255*200)
      print #main.ad2, "color green ; go ";200-int(AtoD2.input2.struct/255*200)
      return

      [quit]
      ret=CloseDevice()
      close #velleman
      close #main
      end




      'Velleman K8055D.dll functions
      '*****************************************************************************************************


      function OpenDevice(card)'card 0,1,2,3 depends on SK5 and SK6 (change jumpers then power up.)
      calldll #velleman, "OpenDevice", card as long, ret as long
      OpenDevice=ret
      end function

      function CloseDevice()'use this at the end of the session
      calldll #velleman, "CloseDevice", ret as void
      OpenDevice=-1
      end function

      function ReadAnalogChannel(channel)'fill either AtoD1.input1.struct or AtoD2.input2.struct
      calldll #velleman, "ReadAnalogChannel", channel as long, ret as long
      if channel=1 then
      AtoD1.input1.struct=ret
      else
      AtoD2.input2.struct=ret
      end if
      end function

      function ReadAllAnalog() 'fill AtoD1.input1.struct and AtoD2.input2.struct
      calldll #velleman, "ReadAllAnalog", AtoD1 as struct, AtoD2 as struct, ret as void
      end function

      function OutputAnalogChannel(channel,value) 'channel 1/2 value 0 255 / volts 0.0 to 5,0
      calldll #velleman, "OutputAnalogChannel", channel as long, value as long, ret as void
      if channel=1 then
      DtoA.output1.struct=value
      else
      DtoA.output2.struct=value
      end if
      end function

      function OutputAllAnalog()' outputs DtoA struct
      calldll #velleman, "OutputAllAnalog", DtoA as struct, ret as void
      end function

      function ClearAnalogChannel(channel) ' 1 or 2 set to 0
      calldll #velleman, "ClearAnalogChannel", channel as long, ret as void
      if channel = 1 then
      DtoA.output1.struct=0
      else
      DtoA.output2.struct=0
      end if
      end function

      function ClearAllAnalog()'1 and 2 set to 0
      calldll #velleman, "ClearAllAnalog", ret as void
      DtoA.output1.struct=0
      DtoA.output2.struct=0
      end function

      function SetAnalogChannel(channel)'1 or 2 set to 255
      calldll #velleman, "SetAnalogChannel", ret as void
      if channel=1 then
      DtoA.output1.struct=255
      else
      DtoA.output2.struct=255
      end if
      end function

      function SetAllAnalog() 'set 1 and 2 to 255
      calldll #velleman, "SetAllAnalog", ret as void
      DtoA.output1.struct=255
      DtoA.output2.struct=255
      end function

      function WriteAllDigital() ' 0-255 bitwise set on or off
      byte=outbyte(1)+2*outbyte(2)+4*outbyte(3)+8*outbyte(4)+16*outbyte(5)+32*outbyte(6)+64*outbyte(7)+128*outbyte(8)
      calldll #velleman, "WriteAllDigital", byte as long, ret as void
      end function

      function ClearDigitalChannel(channel) ' 1/8 channel is set off
      outbyte(channel)=0
      calldll #velleman, "ClearDigitalChannel", channel as long, ret as void
      end function

      function ClearAllDigital() ' 1 to 8 are set off
      calldll #velleman, "ClearAllDigital", ret as void
      for n= 1 to 8
      outbyte(n)=0
      next n
      end function

      function SetDigitalChannel(channel)' 1/8 is set on
      outbyte(channel)=1
      calldll #velleman, "SetDigitalChannel", channel as long, ret as void
      end function

      function SetAllDigital() ' 1to8 are set on
      calldll #velleman, "SetAllDigital", ret as void
      for n=1 to 8
      outbyte(n)=1
      next n
      end function

      function ReadDigitalChannel(channel) ' read channel 1/8
      calldll #velleman, "ReadDigitalChannel", channel as long, ret as boolean
      if ret then
      inbyte(channel)=1
      else
      inbyte(channel)=0
      end if
      end function

      function ReadAllDigital()' read byte
      calldll #velleman, "ReadAllDigital", byte as long
      inbyte(5)=int(byte/16)
      inbyte(4)=int((byte-inbyte(5)*16)/8)
      inbyte(3)=int((byte-(inbyte(5)*16)-(inbyte(4)*8))/4)
      inbyte(2)=int((byte-(inbyte(5)*16)-(inbyte(4)*8)-(inbyte(3)*4))/2)
      inbyte(1)=int(byte-(inbyte(5)*16)-(inbyte(4)*8)-(inbyte(3)*4)-(inbyte(2)*2))
      end function

      function ResetCounter(channel)'set counter 1/2 to 0
      calldll #velleman, "ResetCounter", channel as long, ret as void
      count(channel)=0
      end function

      function ReadCounter(channel) 'read counter 1/2
      calldll #velleman, "ReadCounter", channel as long, ret as long
      count(channel)=ret
      end function

      function SetCounterDebounceTime(channel,debounce) 'debounce channel 1/2 to 0-5000ms
      calldll #velleman, "SetCounterDebounceTime", channel as long, debounce as long, ret as void
      ret=ResetCounter(channel) ' counter needs reset before debounce takes effect
      end function
    • Shack
      When I connect my finished k8055 to my computer and run the demo s everything seems to work properly except button 2 counter button. It stays checked on the
      Message 2 of 14 , Aug 19, 2013
      • 0 Attachment
        When I connect my finished k8055 to my computer and run the demo's everything seems to work properly except button 2 counter button. It stays checked on the demo all the time and does not count.
        I would appreciate any help you may give me.
        Thanks - Ballard
      • Rod
        Do you mean the Velleman supplied Windows demo or the Liberty BASIC demos that have been coded by forum members? If it is the Velleman demo you need to check
        Message 3 of 14 , Aug 19, 2013
        • 0 Attachment
          Do you mean the Velleman supplied Windows demo or the Liberty BASIC demos that have been coded by forum members? If it is the Velleman demo you need to check the debounce value and then the solder connections and switch on the board.

          If it is members code you need to identify the specific code causing the problem.



          --- In libertybasic@yahoogroups.com, "Shack" <ballard_shackleford@...> wrote:
          >
          >
          >
          > When I connect my finished k8055 to my computer and run the demo's everything seems to work properly except button 2 counter button. It stays checked on the demo all the time and does not count.
          > I would appreciate any help you may give me.
          > Thanks - Ballard
          >
        Your message has been successfully submitted and would be delivered to recipients shortly.