Any switch is made of two conductive mechanical contacts that are either touching each other (closed circuit) or not (open circuit). When they make contact, the contact is not always perfect. For the fraction of s second before the contact is complete, the circuit may make contact and be broken several times. When you read this input on a microcontroller, you’ll see a rapid switching from 0 to 1 over a few milliseconds until the contact is final.
The Cobox Micro can send and receive UDP packets. I haven’t written examples yet. Following are just my notes, from discussions on the Lantronix Xport Yahoo mailing list, and from experimentation.
To send directed UDP packets, you have to put set the connectMode appropriately. Bits 2 and 3 of the ConnectMode register are set to 1 to enable directed UDP. Setting the ConnectMode to 0xCC (hex) will set the Cobox to accept any incoming UDP packets and allow you send UDP packets to the address and port number you set for the remote IP address. Once you’ve set the ConnectMode to 0xCC, set the Datagram Type to 01. With these settings, your cobox will only send to the remote IP specified in your configuration.
It is possible to change the destination address on the fly. It’s undocumented, but the Lantronix folks on the list have been helpful in figuring it out. First, you have to set the ConnectMode to CC and the Datagram type to 00. In this configuration, you have to compose your own outgoing datagrams, as follows:
Continue reading “Sending UDP Datagrams to and from a Cobox, Xport, or WiPort”
A collection of other embedded net processors
(most of which I’ve never tried, and most of which I’ve gotten from others)
This is a perl script that uses DBI to open an SQL database, read all the lines of a table, and print them out in an HTML page. This script assumes you’ve got a table in your database called people_table, and that you’ve got at least two fields, one called firstname and one called lastname.
Everything I know about accessing SQP through perl (which isn’t much) I learned from Chris Sung’s notes, in about half an hour. I copied much of this script from him too.
This example assumes you’re using a DC motor that runs on low voltage DC, in the 5-15V range. Connect leads to its terminals, and run if from a benchtop power supply if you have one. Try changing the voltage on it, and seeing what effect it has. Don’t go over the motor’s rated voltage. Connect a switch in series with the motor and use it to turn on the motor.
This is an example of pulsewidth modulation for the PIC. The value received from an analog input is used to dim an LED, using the PWM command. The LED is on RD2, and the analog in is on RA0.
The PWM command has three parameters: the pin, the duty cycle (a byte), and the number of times to pulse the pin (a word). The duty cycle is how long the pin is on for each cycle. If the duty cycle is 100% (255), then the pin is on all the time. A duty cycle of 50% turns the pin on for half of each cycle, and so forth.
At 4MHz, one on-off cycle is about 5 milliseconds. A higher number of cycles makes for smoother PWMing, but less interactivity, because the PIC does nothing else until it’s finished all the cycles for each PWM command.
This program waits for the Lantronix device to give an acknowledgment of a net connection before it starts to send data. The Lantronix Device has to have its connect mode set to verbose, so that it will send ASCII N when not connected, ASCII D when disconnecting, and ASCII C when a connection is made.
Here’s another simple algorithm for smothing analog values. This one was posted by Brian Taylor on the PicBasic list.
Adjust alpha for more or less smoothing. A large alpha takes much longer to reach final value. 1 = no smoothing. 4 or 5 would typically give good results, but your mileage may vary.
This example for Processing shows how to take in a multi-byte string of serial data and process it byte by byte. In this example, the computer sends an “A” to the microcontroller, and the microcontroller sends three bytes in response. Each byte represents a sensor value.
After sending the “A”, the computer reads each byte in, adding it to a string until it has three bytes in the string. It then parses each byte of the string out into an int, and assigns values to three variables from those bytes.
This example is written for Processing,by Casey Reas and Ben Fry. It was last updated for beta version 115.
This page covers the details of MIDI communication on the BX-24.
To send MIDI out from the BX-24, you use the serial commands. You need to set the baudmode to match MIDI settings. You can’t use COM3 for MIDI, because it can’t reach the required baud rate, so you have to use COM1. Wiring is as follows: