BasicMicroUK - Forums

www.basicmicro.co.uk
It is currently Thu Apr 26, 2018 12:30 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: Serout with an arduino
PostPosted: Wed Jan 04, 2012 7:02 am 
Offline
New User

Joined: Wed Jan 04, 2012 6:39 am
Posts: 4
Hi,
Having no hair left to pull out, I am wondering if anyone here can help with this.

I have a old robotics kit from mircrobric, the viper. This thing uses the basic atom. I'm trying to use some of the motors with their built in controllers on my arduino. I posted this on the arduino forums and no reply in over two weeks.

Some questions.
Please can someone give a detailed explanation of this line
Serout P4,T2400,["C",150]

and how do I do that on an arduino?

I have been reading and searching and can't figure it out. Here is what I understand so far.

Serout -used to send serial data out on a pin.
p4 - pin4 (on my particular PIC pic16f876a-i/so)
t2400 - baudrate and true output (idle high)
("C",150) - Send out a "C" and a value of 150? This last bit is where I'm confused. If someone can tell me what the thing is sending to the motor control circuit, I think eventually I could recreate it on the arduino.

Thanks


Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Wed Jan 04, 2012 5:45 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
I don't know which Arduino you have and if you are wanting to output this over a hardware serial port or by using SoftwareSerial.

But that only matters for the init. That is for the hardware Serial port you would, have something like:
Code:
Serial.begin(2400)
#define SSCSerial Serial

At the start of your program
For Software Serial you would need to import the library, define an instance of it using 2 IO pins (One input and one output)
Code:
#include <SoftwareSerial.h>
       SoftwareSerial SSCSerial(cSSC_IN, cSSC_OUT);
#define MySerial SSCSerial
       SSCSerial.begin(2400);


OK once you have the serial object init, you can now output to it. Several ways to do it, but for your instance two lines will do it. Note: In the above definitions, For the hardware version I equated SSCSerial with the specific hardware port. I often do this as to allow me to abstract away which hardware port I am using or if I am using a software serial port. In that way I can use it on several different Arduinos or the like without having to change the code... Wish I could do something like that with basic (Slightly off topic)

Code:
   SSCSerial.write("C");
   SSCSerial.write(150);   // simply output a single byte with a value of decimal 150 or hex 96

Note: In many Basic Micro programs, you will see something like:
Code:
serout ... ["This is a string", 13]

The 13 at the end is a Carriage Return. On an Arduino, you often would do this with the println member, like
Code:
SSCSerial.println("This Is a String"]


See the Arduino reference for more details about the Serial class: file:///C:/arduino-1.0/reference/Serial.html


Kurt


Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Wed Jan 04, 2012 7:19 pm 
Offline
Site Admin
User avatar

Joined: Thu Mar 01, 2001 7:00 pm
Posts: 1316
Location: Temecula, CA
If you still have problems after going through Kurst reply let me know. I'm guessing the main confusion was sending a 150 or "150".

_________________
Tech Support
Basic Micro - Robotic Technology Evolved


Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Thu Jan 05, 2012 1:57 am 
Offline
New User

Joined: Wed Jan 04, 2012 6:39 am
Posts: 4
Thanks very much for your quick replies, and the clear explanation.
I am trying it out later tonight and will let you know if it worked.


Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Fri Jan 06, 2012 6:05 am 
Offline
New User

Joined: Wed Jan 04, 2012 6:39 am
Posts: 4
Hi,
I got it to send the "C" and the 150 and I'm able to see it on the serial monitor.

Connected it to the motor/controller but nothing. Is there a way in the atomIDE to output the serout to the debug screen?

What would that serout command with those parameter look like on an oscilloscope?


Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Fri Jan 06, 2012 6:36 pm 
Offline
Master

Joined: Tue Nov 21, 2006 5:34 pm
Posts: 662
I have not worked with microbric so I don't know what their motor controller is expecting for commands. I did do quick look at their site, and it looks like the serouts to the controller are using the baud mode i2400, which is inverted, which may be the problem.

With the hardware serial port I don't know of any way to get an inverted output, except with some external hardware... With the Software Serial you have an optional third parameter on the object definition to inverse the signal...
From my example in previous post:
Code:
SoftwareSerial SSCSerial(cSSC_IN, cSSC_OUT, true);


As for what it looks like under an oscilloscope... An example of an RS232 type signal would look like:
Image(http://en.wikipedia.org/wiki/File:Rs232 ... _trace.svg)
Note: the RS232 is inverted, which is why on the atom the code to output to the S_OUT uses the inverted signal... Like I9600.
For TTL level signals the signals will go from 0V for low to 5V for high (actually there is some voltage below 5V that will register as high and above 0 that will register as low, but...)

Kurt


Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Mon Jan 09, 2012 3:44 am 
Offline
New User

Joined: Wed Jan 04, 2012 6:39 am
Posts: 4
Tried this and motor won't spin yet.

Code:
#include <SoftwareSerial.h>
//SoftwareSerial LABEL(rxPin,txPin)
SoftwareSerial mySerial(2,3,true);

void setup() 
{
  // set the data rate for the SoftwareSerial port
  mySerial.begin(2400);
  mySerial.println("Hello, world?");
}

void loop() // run over and over
{
 digitalWrite(3,HIGH);
    Serial.write(65);
    Serial.write(150);
    delay(5000);
}


I am not very familiar with either MicroBasic or Arduino. I am pretty much a noob. I was going to try to send the serial output (65,150) in binary in the hopes of the motor controller liking it. I do not know what the controller is expecting and I do not know enough to know what happens to the serout command once the AtomIDE compiles it into hex.

I contacted Microbric but they were not much help. I found a blurry schematic of the motor control circuit but I can't make out the components. I requested a clearer image, Microbric said they had none.

Again thanks for your help and advice.


Attachments:
Microbric_viper_motor_control.jpg
Microbric_viper_motor_control.jpg [ 26.15 KiB | Viewed 7668 times ]
Top
 Profile  
 
 Post subject: Re: Serout with an arduino
PostPosted: Tue Feb 07, 2012 5:17 am 
Offline
Citizen

Joined: Thu Oct 14, 2010 2:10 am
Posts: 13
The original code says that you need a delay after pulling the port high. Try adding a 50 microsecond delay as shown below. Also, you say Serial.write and your serial port's name is mySerial. Try changing the port to mySerial as shown below. Finally, that "Hello, world?" may be confusing things. Try getting rid of it that line.


Code:
#include <SoftwareSerial.h>
//SoftwareSerial LABEL(rxPin,txPin)
SoftwareSerial mySerial(2,3,true);

void setup() 
{
  // set the data rate for the SoftwareSerial port
  mySerial.begin(2400);
  // mySerial.println("Hello, world?");
}

void loop() // run over and over
{
    digitalWrite(3,HIGH);
    delayMicroseconds(50);        // pauses for 50 microseconds

    mySerial.write(65);
    mySerial.write(150);
    delay(5000);
}


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group

phpBB SEO