[SOLVED] Program accepts only text characters but does not reach full 255 range

Hello folks, I am new here so my knowledge or arduino and c++ are limited, but I do have some coding knowledge with other platforms so all knowledge won't be lost on me I promise! I have a simple program that I am writing for a hobby experiment, I purchased a MotorAir V1 (it has a bluetooth but we are just using the usb port) and I am trying to get it to communicate via com port commands, which I have had some success on with powershell in a simple script (The board spins a motor one way or another):

$count = 0

function getnum($a,$b, $c) {
$numbers = [char[]]@($a, $b, $c)
$numbers = -join $numbers
Write-Output($numbers)
return $numbers
}

$port = new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.Open()
$port.WriteLine((getnum 102 255 50))
$port.Close()

In a nutshell, the script takes the numbers values given in the second to last line, converts it into character/text, in this case "fÿ" which seems to be the only type of command the board program will read, because if i send 102 255 or 0x64 0xFF there is no response other than lights. (Nevermind the $C variable the third bite is not read anyways by the code it seems) Here is the board code (straight from OEM)

Now, the issue, when I use this code 102 255 the actual motor speed output is not that, it is more like 102 150ish it seems (first bite is direction second is speed), since when I use the OEM provided "tool" they send out to test connections, it goes much faster than what I am getting at the same settings.

Could there be an issue with how the commands are sent or a probelm in the code?

Here is a link to the board itself, there are example of the OEM program on the page just no source code to bridge the gap

When you open the port the arduino reboots. May be you need to give it a bit of time before you send your data

tried it with a 5 second delay before writing to the port, same result :frowning: shes a little slow

ran advanced serial port number and I got the following result:
script i wrote outputs this "d?<NUL><LF>"
OEM program and other serial senders output this "dÿ"

Alrighty, i got it! turns out the writeLine command defauts to ascii which would make the character set "?? over 127, found on this post

The correct answer was in the powershell code, which has been simpliefied to the following:

$count = 0

$port = new-Object System.IO.Ports.SerialPort COM3,9600,None,8,One
$port.Open()
while ($count -lt 15) {
$port.Write([byte[]] (100), 0, 1) 
$port.Write([byte[]] (255), 0, 1)
$count +=1
Write-Output($count)
Start-Sleep -Milliseconds 100
}
$port.Close()

so yea thats how you use a powershell script to instantly send a timed command or script to a com port, neato.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.