Why do you need it to be sent as a string?
Just send a byte value and treat it as so in the Arduino. The serialPort1.Write
method will likely have different overloads for various formats including byte.
If you need to represent a value >255 then you can send it over multiple bytes and concatenate into e.g. an int at the Arduino.
NOTE - you seem to have changed the code in your question since the below was written, but I'll leave it there as the concept is still valid.
EDIT
At the moment you are sending in ASCII format from the PC, so 0 - 0x30, 1 = 0x31 etc. To send in plain binary check the overloads for the method.
Try putting something like:
private void button1_Click(object sender, System.EventArgs e)
{
// Say we want to send 23456 (0x5BA0)
//serialPort1.Write(200); // 200 is "send value" command
//serialPort1.Write(91); // 100 (0x5B) is your upper byte value
//serialPort1.Write(160); // 160 (0xA0) is your lower byte value
// this uses the serialPort1.write overload correctly
// 1st byte is command, 2nd and 3rd are upper and lower bytes of int
byte[] data = new byte[] {200, 91, 160};
serialPort1.Write(data, 0, 3); // 0 is the offset and 3 is the size of array
}
and see if it is recieved correctly at the Arduino (do not read it as a string, e.g. if incoming byte == 200)
Something like the below should work - you will have to adjust accordingly to make it do whatever it is you are trying to do, this is just an example of transferring bytes:
if (incomingByte == 200) {
upper_byte = (unsigned char)Serial.read();
lower_byte = (unsigned char)Serial.read();
// full_value should be 23456
int full_value = (upper_byte << 8) + lower_byte; // reconstruct int
}
Notes:
You can write code to split an int into the two bytes (I just put an example "test value")
Again, there may be overloads for this. Also you can use any multiple byte receive capability in the Serial.read routine.
First do you know if it has been secured ?? If so then its hopeless.
Its been 20 years since I last used HC05. Where from my paper copy of the data sheet. It looks like you can likely use its Standalone Bootstrap mode by appling VPP followed by setting PD5 and PD2 low, along with PD3 and PD4 to high. Then release RESET# and the HC05's bootstrap with start dumping the PROM contents at 4800 baud 8N1 out the SCI(UART) assuming a 2 MgHz crystal, starting with $0020 through $1FFF. You could just convert this to RS232 and send to a PC's Serial Port. No need for an Arduino.
This is all assuming the PROM has not been secured.
Here is an article of someone doing just this for a 7085U. My above datasheet is for the 705C8.
Note, Near the end of the 705's popularity a variety of different models came out, like the "J" and "K" which had cheaper programers. So there may likely be differences. Find the datasheets. There likely is a Standalone Bootstrap for your version that can be triggered to dump out either the SCI(UART) or SPI.
Best Answer
Yes. That should work as long as your Servo motor is rated 6V power (each battery cell contributes 1.5V). The key thing is that the battery pack GNDs be connected together. The servo motor responds to a variable pulse width signal. The Nano will output 5V digital I/O. The servo should be responsive to PWM at those levels, but as always check it's datasheet for maximum limits (or provide a link and we can help).