Offline
Newbie
Karma: 0
Posts: 20
|
 |
« on: January 31, 2012, 01:10:09 pm » |
Hi everyone,
I want to access data from my laptop through USB and then send it to my Arduino board. For example, I want to get the ASCII whenever I press on the keyboard.
How can I do this?
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #1 on: January 31, 2012, 01:23:51 pm » |
If you want to send characters (ASCII) from your laptop to Arduino through serial port, you will need to write a program, in your language of choice, that runs on the laptop and streams out the characters. Here is an example, in VBscript, of a program that reads from a text file and sends to COM/serial port: Const ForReading = 1 Const ForWriting = 2
'------------------------------------------------------------------------------------------------ ' open USB serial port (COMx); ' ' If the serial monitor in Arduino IDE is open, you will get an "access denied" error. ' Just make sure that the serial monitor is closed (so bytes are not sent by the arduino board). '------------------------------------------------------------------------------------------------
Set fso = CreateObject("Scripting.FileSystemObject") Set com = fso.OpenTextFile("COM7:9600,N,8,1", ForWriting)
Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("C:\TEXTFILE.TXT", ForReading)
MsgBox("Ready to write file content to COM")
Do While objFile.AtEndOfStream <> True strChars = objFile.Read(10) com.Write(strChars) WScript.Sleep(200) Loop
objFile.Close com.Close()
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 47
|
 |
« Reply #2 on: September 21, 2012, 01:43:27 pm » |
hello florinc, i only want sent one character (for example "1") to serial port to switch a LED on or off. i have no idea of VBScript, is their a possibility not to work with a textfile and use a shorter, a more simply script. But i need a VBScript.
Thx a lot Vansen
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 5
Posts: 383
|
 |
« Reply #3 on: September 21, 2012, 01:47:40 pm » |
You could always use windows hyperterminal or similar program to send the characters you want.
|
|
|
|
|
Logged
|
|
|
|
|
St. Augustine, FL
Offline
Newbie
Karma: 1
Posts: 15
|
 |
« Reply #4 on: September 21, 2012, 04:50:20 pm » |
Even better, just use the "Serial Monitor" built into the Arduino IDE
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 47
|
 |
« Reply #5 on: September 21, 2012, 05:05:26 pm » |
hello guys,
no, i need that way. i want to use windows speech recognition macro (with VBScript) to switch an LED on or off. I know the serial monitor or putty, but i have to use VBScript.
Pls, if you know how, tell me the way to send only one charakter in a simple way to the serial port without using serial monitor or putty.
thx a lot
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #6 on: September 21, 2012, 05:22:14 pm » |
I modified the above VBscript for you, to send just one character, "1": Const ForWriting = 2 Set fso = CreateObject("Scripting.FileSystemObject") Set com = fso.OpenTextFile("COM7:9600,N,8,1", ForWriting) MsgBox("Ready to write a character to COM") com.Write("1") com.Close()
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 47
|
 |
« Reply #7 on: September 21, 2012, 05:30:07 pm » |
that was a fast help ;9 thx BUT...
it didnt work. do i make a mistake? i tell you my way. i make a new txt-file, copy your code, and rename the file in serial.vbs
then i can start the file whereever i want? but i get an error. he cant open file in coulum 3, but i change the port to com16 - my port.
what is the mistake?
errorcode: 800A0035
|
|
|
|
« Last Edit: September 21, 2012, 05:37:26 pm by Vansen »
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #8 on: September 21, 2012, 05:36:56 pm » |
Yes, use your port instead of the COM7 I used as example. If you get an error ("cannot open" or such), try a "traditional" COM port (e.g. COM1), listed in the hardware profile. Also, make sure the COM port you use is not already in use, by Hyperterminal, serial monitor or other terminal app.
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #9 on: September 21, 2012, 05:38:31 pm » |
I tested it on my Win XP machine and it seems to be working fine.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 47
|
 |
« Reply #10 on: September 21, 2012, 05:46:06 pm » |
my first try was this code: Sub TestCOMPort Const ForWriting = 2, TriStateFalse = 0 Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.OpenTextFile("COM16:9600,N,8,1", ForWriting, False, TriStateFalse) ' Set f = fso.OpenTextFile("COM16:9600,N,8,1", 2) ' Set f = fso.OpenTextFile("COM16:9600,N,8,1", true)
' Write data to the port f.Write Chr(49) f.Write "1" f.Write (1) f.Write ("1") f.Write Chr(32) f.Write Chr(27) f.Close End Sub
i start the file by pressing enter, i got no error, but nothing happen on the serial port. its the same you wrote, it think. i didnt understand that. errorcode is 800A0035
|
|
|
|
|
Logged
|
|
|
|
|
0
Offline
Edison Member
Karma: 6
Posts: 1399
Arduino rocks
|
 |
« Reply #11 on: September 21, 2012, 07:21:52 pm » |
This is what the error means: http://support.microsoft.com/kb/276011Probably your COM16 does not exist. Can you find it listed in Device manager? If I remove COM7 on my machine, I get the same error 0x800A0035 ("File not found"). As I said, as a syntax test, try COM1 instead of your COM16. And why do you have COM16? Are you using a Bluetooth USB module?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 47
|
 |
« Reply #12 on: September 22, 2012, 06:04:44 am » |
ok, i have a lot of ideas i have to check:
first, i have a lenovo s205 laptop with win7 64 bit SP1. My Comport is 16. Dont no why, serial monitor say 16, a connection with PUTTY on Com16 ist successfully. i can switch an led on and of if i enter a "1" in the putty or serial monitor console.
2. i wrote com1 in the file, the same error
3. behind your link i found a reason (maybe): "FileSystemObject is not looking for the file in the folder that you had expected. By default, if you do not specify a path, FileSystemObject searches the WinNT\System32 folder."
-> your script works with winXp. is it possible, there are changes in win7 64bit? maybe the method to open a COMport isnt in System32 folder?
4. i try the script now on my second win7 pc.
ok, i think number 3 is the best idea.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 2
Posts: 47
|
 |
« Reply #13 on: September 22, 2012, 06:56:39 am » |
argh, on my second pc i have COMport 3, works fine with Serial Monitor and Putty.
but if i start the same script, i got error 800a0046. Access denied.
i tried it as admin and closed putty and serial monitor. mhhh.
--------
now im back on my lenovo. i changed the com settings to COMport 2. Com 3 -15 ared still used. i started the script again. now i got error 800a0046 too, but not 800a0035 anymore.
any ideas? pls help me
|
|
|
|
« Last Edit: September 22, 2012, 07:15:18 am by Vansen »
|
Logged
|
|
|
|
|
|
|
|