Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Serial Communication Protocol on: August 30, 2012, 12:18:06 am
Check this out:

Code:
arduino.out(4).blink(100).doFor(hours(1))

Blinks a pin every 100 milliseconds for an hour. And once you execute another statement, that blinking pauses until the next command is done.

Code:
arduino.out(4).analog(127).doFor(minutes(10))

After 10 minutes, the pin goes back to the original blink routine.

2  Using Arduino / Programming Questions / Re: Serial Communication Protocol on: August 30, 2012, 12:14:46 am
I asked because if the data is binary (and can therefore be any value) there's no way I know of to reliably detect a start of frame by just looking at received bytes.

Oh yeah of course it's impossible to know 100%, but being a 1 in 255 chance plus the checksum and other marker bytes, it's pretty safe.

Quote
length (2 byte int)
Expecting a lot of data smiley

Hey if they had made IP addresses more than 32 bits back in the day I wouldn't be paying 2 bucks a month for every site that uses SSL.

Extra byte, I figured why not (the alternative is 255 bytes). Even though the largest command I'll send here is 9 bytes.
3  Using Arduino / Programming Questions / Re: Serial Communication Protocol on: August 29, 2012, 11:10:18 pm
Quote
I just went ahead and threw a very basic one together with a start/length/checksum.
Is the data in binary format? If so how do you detect the start of a frame?

______
Rob

Just a 0 byte right now but I'm planning to change it to something less likely, a random number between 1 and 255.

start byte
length (2 byte int)
data (arbitrary)
checksum (2 byte int, fletcher-16)
end byte

Might put markers inbetween length/data/checksum for quicker identification of malformed data

4  Using Arduino / Programming Questions / Re: Serial Communication Protocol on: August 29, 2012, 04:46:29 pm
I read your whole post, twice, to make sure I didn't miss anything. I don't understand the question, I guess. Where does the "disordered data" originate? The Arduino or the PC?

It could originate from either side, my point is I'm looking for a bit more reliability than just hoping that all of the data sent from PC -> Arduino or Arduino -> PC gets to the other side.

It probably wouldn't be disordered (sending is synchronized on the Scala side), but I could see a byte missing here and there.

What, exactly, does that code cause the Arduino object to send to the serial port? Where is the Arduino code that handles the data that the Arduino object sends?

There are about 9 commands, each with an integer identifier and a couple bytes of data along with them. The arduino gets them, looks at the first 2 bytes, and uses that to identify the command.

Commands are setMode, digitalWrite, digitalRead, etc. Basically the same as the Arduino's C++ functions.

Those are pretty sketchy requirements and nowhere near enough information to design a protocol, but it sounds to me as if your problem is essentially how to detect complete and valid message frames out of a byte stream. You could achieve that by defining start/end flags to denote your message boundary, define a message structure that incorporates a checksum, and if your start/end flags could legitimately appear within the message then also provide a mechanism to escape them.

I don't need anything fancy, just the most basic packet protocol.

I just went ahead and threw a very basic one together with a start/length/checksum.

5  Using Arduino / Programming Questions / Serial Communication Protocol on: August 29, 2012, 12:01:12 am
I'm working on an Arduino -> Scala/Java bridge and am having some issues with serial communication. Right now I have an extremely simple command protocol that will fail upon disordered data.

Any suggestions on what I can use just for the communication? Looking for something like a very primitive version of TCP that works over serial and protects data integrity.

And just for kicks here's how it works (this is all working now perfectly besides the data transfer issues) in Scala code. I'll probably put it out open source. This is a Scala class that listens to a number of input pins and sends out appropriate responses and issues commands directly on the computer it runs on.

Code:

val arduino = Arduino("/dev/ttyACM4", 115200, 1000)

// Create LED Pin Objects
val statusLed = arduino.out(3)
val waitingLed = arduino.out(4)
val errorLed = arduino.out(5)

waitingLed.on

// TODO: Initialize Music Player

waitingLed.off

// Create Music Control Pin Objects

val play = arduino.in(11)
play.listenOn {
  if (isDay()) {
    execute("amixer set \"Master\" toggle")
  }
}

val volume = arduino.in(12)
volume.attachInterrupt(InterruptType.Change)
volume.listenAnalogBelow(127) {
  // Unmute
  // Change Volume
  errorLed.off
}
volume.listenAnalogAbove(128) {
  errorLed.on
}

val mute = arduino.in(10)
mute.listenOn(execute("amixer set \"Master\" toggle"))


The way it works is that these "listeners" are sent to the arduino with identifiers, the arduino checks the appropriate pins in the loop. If and only if the input from that pin has changed from its previous value, a notification is sent back to the computer which triggers the listener function.

It works with interrupts as well, exactly the same except it uses Arduino's interrupt mechanism and does not check within the loop.
6  Using Arduino / Displays / Wiring up an LCD on: August 25, 2012, 07:27:16 pm
I have this -

What's the best way to wire it up?

Holes seem awfully small, I'd be scared to solder it. Any pre-made 16 pin headers/cables I can hook up to this thing?

7  Using Arduino / Motors, Mechanics, and Power / Re: Using an ATX power supply on: August 24, 2012, 06:26:19 pm
The biggest problem with such a supply is the fact that without modification (not an easy task unless you have a schematic for the supply and are an "expert" in power supply design) you can't set a current limit for a given voltage.

I'm wondering about this though, can't I just stick a current limiter in front of the component?
8  Using Arduino / Motors, Mechanics, and Power / Re: Using an ATX power supply on: August 24, 2012, 03:00:28 am
That's really cool jens.

One of the main attractions for me was the fact that it'd have 12/5v out of the box, but if that's not reliable then I guess it's not much of a benefit. I was trying to avoid doing as much as I could myself, I know power can get pretty difficult and I'm somewhat of a beginner here.

Also a bit worried about the fact that I can't limit amperage, most of my devices are very low amperage, just a couple are a bit higher.

I'll run some tests on mine when it comes in, it's not a dirt cheap one but not the most expensive either.

Luckily a small ITX motherboard has become part of my project, so even if I can't use the PSU for everything else I need it anyway, so nothing wasted.

Thanks for the feedback!


9  Using Arduino / Sensors / Re: Best way to tell if a lid is open. on: August 24, 2012, 02:55:25 am
Certainly using the micro switch/leaver switch is the simplest way.  In case if you don't want to use mechanical approach, you can do this with IR proximity sensor as well.

I'll check that out, thanks.


That is pretty cool, wasn't aware that was possible. Will take a look at that too.

If the lid is a swing style ( doesn't detach completely ) and object doesn't move too much, a mercury switch would be suitable.

Yeah it's a hinged lid, never heard of a mercury switch, I'll look it up.

Thanks for the suggestions everyone.

10  Using Arduino / Motors, Mechanics, and Power / Re: Using an ATX power supply on: August 21, 2012, 11:14:16 pm
Well it usually is solved simply by wiring a lamp mounted inside or onto the PS, or a power resistor of the correct wattage. There is ton of info on the web about utilizing PC supplies in a standalone mode. This is about the cheapest DC power supply per watt available to a hobbyist, often gotten free.

Yeah, I was going to hook up a couple of old hard drives just to toy with it.
11  Using Arduino / Audio / Re: Arduino Volume Control on: August 21, 2012, 10:37:28 pm
Random question. These are car speakers, running them indoors and not too loud, say typical tv volume. Any suggestions on what wattage amp i should get?
12  Using Arduino / Motors, Mechanics, and Power / Re: Using an ATX power supply on: August 21, 2012, 09:57:13 pm
It works pretty well. Watch out for power supplies that have minimum load (current) requirements. If you don't draw at least this amount of current from the various supplies, it will not regulate properly and you could end up toasting something with improper voltage (e.g., the "5v" output ends up at 6.5V or something).

Thanks for the warning. I had heard about minimum load requirements but I wasn't aware I could toast anything if I didn't meet them.
13  Using Arduino / Motors, Mechanics, and Power / Using an ATX power supply on: August 21, 2012, 09:50:22 pm
Any downsides to this? Seems perfect. Cheap, easy to find, has 12v/5v/3.3v outputs out of the box.

Using it for a project in which i need to power an arduino, a set of speakers and a few motors.
14  Using Arduino / Audio / Re: Arduino Volume Control on: August 21, 2012, 07:15:17 pm
Okay I'm getting the impression looking around that most amplifiers do have a built in volume control.
15  Using Arduino / Sensors / Best way to tell if a lid is open. on: August 21, 2012, 06:42:24 pm

I need to notify my arduino when I open the lid of a box, wondering what is the best way to go about this?

I was thinking maybe some type of magnet setup but it would probably be much simpler to just have a button on the box that the lid presses on when it is closed. Any suggestions on the type of button I will need (what it's called)?
Pages: [1] 2