Author Topic: Sending commands from pc  (Read 809 times)

0 Members and 1 Guest are viewing this topic.

Offline BertTopic starter

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
Sending commands from pc
« on: January 13, 2012, 10:39:43 AM »
Hi, I'm brand new to microcontrollers. I basically want to blink an led on my atmega162 by pushing a button on a program running on my pc. How would I do this? How would I do this if I wanted to control 10 leds hooked to different pins?

Thanks

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 744
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Sending commands from pc
« Reply #1 on: January 14, 2012, 05:36:05 PM »
Generally you would have some sort of simple serial connection between your computer and the mcu.  This typically is a connection between the UART on your mcu, and the computer; this can take a lot of forms, hardware-wise.

The way I've done this is using existing code, e.g. the WebbotLib library, which provides most of the code for reading bytes (these include individual letters such as typed on the keyboard) from the hardware.

A bit of pseudocode for what the code that I have to write for this looks like:
Code: [Select]
char key_press = serial.getByte();
if(key_press == 'a'){
    led_on();
}
else if (key_press == 'b'){
    led_off();
}

To send single letters like in the above, from your computer, one typically uses a terminal program like Hyperterminal, Putty, X-Ctu, realterm, etc.  For more advanced stuff, one might write a program that sends specific bytes to a program, but don't worry about that for now....

You'll have to tell us more about your hardware setup for us to give you more information.
I

Offline BertTopic starter

  • Jr. Member
  • **
  • Posts: 8
  • Helpful? 0
Re: Sending commands from pc
« Reply #2 on: January 16, 2012, 01:46:18 AM »
My ultimate goal is to control the microcontroller from a web page hosted on my pc. Happily ive found a guy that has done this. Here's a link to a homemade security camera that is doing exactly what i want to do if you're interested: http://www.instructables.com/id/Web-controlled-Surveillance-Camera/?f=m. It uses php to write some bytes based on user button clicks to a file on the "server" and then calls some other script which i think sends them to the uC. The only part of his source code I don't get/am not familiar with is several lines in the php script that look like this:

system('sudo /etc/init.d/oma status');

I'm pretty sure this is calling some c script that is doing the actual communication with the uart but idk. If this is the case, what would those scripts contain? That's the one part the guy didn't share and I can't figure out myself.

I am working with an atmega162. I guess I'm not really needing help with the uC side of things, just the code on the pc talking to the uart

Offline Gertlex

  • Supreme Robot
  • *****
  • Posts: 744
  • Helpful? 23
  • Nuclear Engineer Roboticist
Re: Sending commands from pc
« Reply #3 on: January 16, 2012, 08:55:52 AM »
Never used PHP, but that line of code you quote is not calling a C program... it's just a command line command that you would enter in a terminal, normally, but system() is presumably a way of using command line features from within php.  'sudo' is a common command (google/wiki it); I don't know what /etc/init.d/oma is pointing to, but it's a path on a unix-based system.
I

Offline ArtBot

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
Re: Sending commands from pc
« Reply #4 on: January 17, 2012, 03:19:41 AM »
The system() is, indeed, making the equivalent of a command-line entry. The 'sudo' means it's calling the command with root privileges (which is slightly worrying for something net-connected). The utils in the path /etc/init.d/ are normally daemons of some kind, often called during start-up. For example, you can call programs in /etc/init.d/ to start or stop processes like servers (Apache, MySQL). So I presume oma is some process, perhaps a home-made one. Just checked on my Debian system and there's definitely no 'oma' in /etc/init.d/, so without more info it's hard to say what it's doing.
Speculatrix - thinking machines and artificial smarts

 


Get Your Ad Here