Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Delta-Wye
Sep 29, 2005

JesusDoesVegas posted:


code:
if (thing = 1 || thing = 2) 
instead of just
code:
if (thing = 1 || 2)
Again, I'm sure these are obvious for most of you, but it took me a bit to figure out. Using the wrong syntax caused a lot of bizarre things to happen that threw me off.
:raise:
I think you want

code:
if (thing == 1 || thing == 2) {
    //do something
}
if you have a series of these, they can be done with a case as well:
code:
switch (thing)
{
case 1:
case 2: 
    //do something if == 1 or 2
    break;
case 3: 
    //do something else if == 3
    break;
case 4:
case 5:
    //do this if == 4 or 5
    break;
default: 
    //or do something by default
    break;
}

Adbot
ADBOT LOVES YOU

huhu
Feb 24, 2006
Time to ask some dumb questions!

What exactly is a ground? I've taken elements of electrical engineering for my mechanical engineering major and we did some circuit stuff but I feel the explanation of what a ground is was completely off. I thought all circuits had to be in a loop but supposedly thee ground can sometimes serve as a completion of the loop?

I set up some code so that 11, 12, and 13, from the Arduino would power three separate LEDs. One of them was much brighter than the other two. I tried moving the LEDs to different spots on the breadboard, changed the LEDs, and changed the Arduino to 10, 11, and 12 and still got the same thing. Thoughts?

How do you go about picking a resistor? Like in the case of 330Ω vs 10kΩ? My kit came with those two values.

UberVexer
Jan 5, 2006

I like trains

Delta-Wye posted:

:raise:
I think you want

code:
if (thing == 1 || thing == 2) {
    //do something
}
if you have a series of these, they can be done with a case as well:
code:
switch (thing)
{
case 1:
case 2: 
    //do something if == 1 or 2
    break;
case 3: 
    //do something else if == 3
    break;
case 4:
case 5:
    //do this if == 4 or 5
    break;
default: 
    //or do something by default
    break;
}

Theoretically
"if(thing1== 1 || thing == 2)" is correct, assuming you have only one statement coming after it, that is
"if(thing1== 1 || thing == 2)
digitalWrite(13,1);"

It is just bad practice.


huhu posted:

Time to ask some dumb questions!

What exactly is a ground? I've taken elements of electrical engineering for my mechanical engineering major and we did some circuit stuff but I feel the explanation of what a ground is was completely off. I thought all circuits had to be in a loop but supposedly thee ground can sometimes serve as a completion of the loop?

I set up some code so that 11, 12, and 13, from the Arduino would power three separate LEDs. One of them was much brighter than the other two. I tried moving the LEDs to different spots on the breadboard, changed the LEDs, and changed the Arduino to 10, 11, and 12 and still got the same thing. Thoughts?

How do you go about picking a resistor? Like in the case of 330Ω vs 10kΩ? My kit came with those two values.

- Ground on AC or DC circuits have different meanings, so I will leave that alone as I don't want you to explode, I'm no expert on that.
- You probably have the Arduino powered by USB, which is relatively low power, try connecting to a 9-12VDC wall wart.
- Ohm's law. V=I*R where I = current, R = Resistance, and V is the voltage. So for the case of an LED you'd use
(Source Volts - LED Volts) / (Current / 1000) = Resistance

Building on that last point about resistors, you might find you get some weird values, if you feel lazy just pick the easiest one to purchase that is closest to your value, if you get 350 ohms, feel free to use a 330, because you can actually find them; or put them in series.

UberVexer fucked around with this message at 06:55 on Nov 24, 2012

Delta-Wye
Sep 29, 2005

UberVexer posted:

Theoretically
"if(thing1== 1 || thing == 2)" is correct, assuming you have only one statement coming after it, that is
"if(thing1== 1 || thing == 2)
digitalWrite(13,1);"

It is just bad practice.
You misunderstood my point. Your previous example was doing assignments (=) instead of comparisons (==). Old programmers trick, always write your comparisons like this so the compiler will catch this typo:
code:
if (1 == thing || 2 == thing) {

}

UberVexer posted:

- Ground on AC or DC circuits have different meanings, so I will leave that alone as I don't want you to explode, I'm no expert on that.
Ground means the same thing in AC and DC circuit analysis, although for electricians they would call 'ground' 'neutral'. All voltages are relative, and ground is selected as a sensible reference point. When you do circuit analysis, you never calculate something absolute voltage, you calculate its relative voltage. For instance, imagine a two 9 volt batteries. If you analyze one battery, you would see it has a + and a - terminal, 9 volts apart. Hooking them up in various ways has the following effects:

a. Call the - terminal ground, the + becomes 9V. Conversely, if you call the + terminal ground, the - terminal becomes -9V. The 9V is relative between the two terminals, not absolute unless you pick an arbitrary zero point (ground).
b. Connect - to +, if we call the leftmost + terminal ground, it's - terminal becomes -9V. The + on the other battery is connected so it is the same (-9V) and the - terminal is 9 volts lower (-18V).
c. Here the middle terminal is ground (0V) so one battery's exposed terminal is 9V and the other is -9V. This configuration is common with things like audio, where you need a bipolar supply.
d. Here the rightmost - terminal is called ground. One battery up is 9V, and one more battery up is 18V.
Keep in mind a-d has different voltage levels, but the same circuit. The voltages contained are all relatively the same, but by changing what we call ground (0V) we change their absolute measurements.
e-g are parallel connections. In this case, you either get 9V or -9V out depending on what you call ground.

if a-d is the same, why do audio guys usually go with -9V and 9V, where something like an RC car (or power tool with a battery pack) is going to call it 18V? Audio guys need a bipolar swing for the audio signal, and calling ground 0V is mathematically convenient and means 0 signal is in the middle and conveniently halfway between the extremes. Something like an RC car is running 18V directly to the motors and calling +18V-0V for doing those calculations mathematically convenient.

The 'ground' in your house is a safety precaution and not the reference, the neutral wire is the reference point. They are usually connected together at the breaker box... blah... GFCI circuits... :words:
Long explanation for 'why is this ground and not this' but I hope it was slightly enlightening.

UberVexer posted:

- You probably have the Arduino powered by USB, which is relatively low power, try connecting to a 9-12VDC wall wart.
3 leds should be able to be ran from USB as long as the current being drawn per LED isn't unreasonable. huhu, are you not using resistors?
http://softsolder.com/2012/11/01/arduino-digital-output-drive-vs-direct-connected-leds/
It may work, but slight manufacturing differences between LEDs and pins will be accentuated. Using a current limiting resistor will help moderate any manufacturing differences.

UberVexer posted:

- Ohm's law. V=I*R where I = current, R = Resistance, and V is the voltage. So for the case of an LED you'd use
(Source Volts - LED Volts) / (Current / 1000) = Resistance
Why are you dividing current by 1000? If current is in mA, you need to multiply by 1000. Otherwise, just use it as is (V=IR) without changing it mysteriously to ( V/(I/1000)=R ).

UberVexer posted:

Building on that last point about resistors, you might find you get some weird values, if you feel lazy just pick the easiest one to purchase that is closest to your value, if you get 350 ohms, feel free to use a 330, because you can actually find them; or put them in series.
The reason for the values that were picked:
http://mightyohm.com/blog/2009/01/eia-resistor-values-explained/

Delta-Wye fucked around with this message at 07:52 on Nov 24, 2012

JesusDoesVegas
Jul 8, 2005

The Funk Ambassador
Lipstick Apathy
Ya, if you look at my code I used ==... I just typoed here.

Would a switch be faster?

babyeatingpsychopath
Oct 28, 2000
Forum Veteran

JesusDoesVegas posted:

Ya, if you look at my code I used ==... I just typoed here.

Would a switch be faster?

It depends on how many comparisons you have and how good your compiler is.
If you have something that you're testing, and only one case can ever be true, you could write:
code:
if () 
   {} 
else if () 
   {} 
else if  () 
   {}
else
   {}
If your compiler is good, then it will turn all that into a big JUMP/BRANCH thing in assembly.

If you write
code:
switch ()
{
case :
  break;
case :
  break;
case :
  break;
case :
}
Then you've told the compiler to do it as a JUMP/BRANCH in assembly anyway. You may be smarter than your compiler.
If you wrote
code:
if ()
  {}
if ()
  {}
if ()
  {}
if ()
  {}
then the compiler can't be sure that each and every one of those cases can't run every time through the loop, and you'll get all the tests done. That may be slow.

This is getting into the programming in c of the device more than you probably like, but "small" devices like microcontrollers need a different way of looking at things; they don't have gobs of memory or fast cores, so you, as a programmer, have to know EXACTLY how your code is going to get compiled if you want good performance.

babyeatingpsychopath fucked around with this message at 23:10 on Nov 24, 2012

The junk collector
Aug 10, 2005
Hey do you want that motherboard?
Delta-Wye covered the ground concept pretty well but I want to add,

An ideal ground is a constant unchanging voltage that can absorb as much current as you throw at it. Conversely, if you are using a bipolar signal (the +9V and -9V with ground at 0V example) it should also be able to provide current. In practice, grounds are not ideal and putting lots of power or fast signals can cause them to shift around, but it shouldn't be something that comes up in most Arduino projects.

Also, if you are working with add on boards for your Arduino and you are using the ground for a reference, say driving hobby servos, you will probably need to connect the ground on the Arduino to the ground on the add on board to make sure they have the same voltage. Since signals are commonly referenced against ground, having your grounds not be the exact same can cause problems like oddly performing PWMs, servos that won't sit still, or burnt components.

Bad Munki
Nov 4, 2008

We're all mad here.


It bears pointing out one other potential bonus for using switch statements that if() statements don't do as well, and many people forget: you don't have to use a break after each switch case. If you don't, it'll keep executing the other options until the switch is over or a break is hit. For example:

code:
int j = 0;
switch(n) {
  case 4:
    j++;
  case 3:
    j++;
  case 2:
    j++;
  case 1:
    j++;
}
Now, that's a pretty retarded way to say j=n, but that's usually the case with over-simplified examples. Using it creatively is up to the reader. And you're still only making one comparison here, instead of doing the same structure with a series of if() blocks.

Bad Munki fucked around with this message at 19:21 on Nov 26, 2012

Delta-Wye
Sep 29, 2005

babyeatingpsychopath posted:

This is getting into the programming in c of the device more than you probably like, but "small" devices like microcontrollers need a different way of looking at things; they don't have gobs of memory or fast cores, so you, as a programmer, have to know EXACTLY how your code is going to get compiled if you want good performance.

I would argue this isn't the case for the Arduino platform at all. It has a relatively beefy processor and is sort of setup so the dev doesn't need to know what is happening under the hood. What the hell happens when you do an analogwrite? A print? Why does setting up a servo disable some of the PWM ports? Who knows, who cares?! It just works.

JesusDoesVegas posted:

Ya, if you look at my code I used ==... I just typoed here.

Mostly just taking the piss out of you. Keep an eye out for those typos though as they are easy to do and compile fine; you just get unexpected behavior. It can be a pain to figure out, especially on an embedded platform because it even looks right if you just glance at the code. I've taught a few semesters of introductory programming and its an extremely common mistake. I kind of wish gcc's -Wall option would toss warnings for assignments done in comparison blocks, if for no other reason than to make TAing easier :v:

JesusDoesVegas posted:

Would a switch be faster?

Maybe? Probably not? At this point you should be concerned with readability and maintainability over all. I doubt your project is pushing the '328 to the point a few cycles here and there matter that much.

Bad Munki posted:

It bears pointing out one other potential bonus for using switch statements that if() statements don't do as well, and many people forget: you don't have to use a break after each switch case. If you don't, it'll keep executing the other options until the switch is over or a break is hit.
Hey buddy, my example had fall through :colbert:

Delta-Wye fucked around with this message at 20:25 on Nov 26, 2012

Bad Munki
Nov 4, 2008

We're all mad here.


Delta-Wye posted:

Hey buddy, my example had fall through :colbert:

Sure, but I wanted it to be obvious what the potential really is there, instead of just an alternative for "if(a || b)". :)

JesusDoesVegas
Jul 8, 2005

The Funk Ambassador
Lipstick Apathy
I'm using an ATtiny84 chip to run my PWM since I just don't feel like figuring out the timer issues I ran into earlier. The datasheet
(http://www.atmel.com/Images/8006s.pdf) says the operating voltage is 2.7v to 5.5v.

What is best practice with these ranges? Should I try to shoot for middle ground, say around 4v or would I be safe just giving it the same 5v I'm giving my Arduino?

Delta-Wye
Sep 29, 2005

JesusDoesVegas posted:

I'm using an ATtiny84 chip to run my PWM since I just don't feel like figuring out the timer issues I ran into earlier. The datasheet
(http://www.atmel.com/Images/8006s.pdf) says the operating voltage is 2.7v to 5.5v.

What is best practice with these ranges? Should I try to shoot for middle ground, say around 4v or would I be safe just giving it the same 5v I'm giving my Arduino?

Give it the same 5v as your arduino is using.

Typically there is a graph in the datasheet with safe operating clock ranges for the various speeds - I haven't looked at that particular device, but often the max clock rate is only available at higher VCC voltages (5V should be enough for max clock). Again, typically, you are more power efficient at lower clock rates and lower voltages although it takes a bit more time to get things done. Finding the sweet spot depends a lot on your workload, low power modes, etc, and isn't something you need to be worried about in your project which is probably USB or wall powered anyways.

makomk
Jul 16, 2011

Bad Munki posted:

It bears pointing out one other potential bonus for using switch statements that if() statements don't do as well, and many people forget: you don't have to use a break after each switch case. If you don't, it'll keep executing the other options until the switch is over or a break is hit.
Note that if you do this it's traditional to leave a comment pointing it out like so:

code:
int j = 0;
switch(n) {
  case 4:
    j++;
    /*fallthrough*/
  case 3:
    j++;
    /*fallthrough*/
  case 2:
    j++;
    /*fallthrough*/
  case 1:
    j++;
}
Otherwise it's very easy not to notice that there isn't a break - especially if only one or two cases from a complex switch statement don't have them - and even if you do, will you be able to remember whether it was intentional a few months down the line if you come back to the project? Trust me, Future-You will thank you for it.

Bad Munki
Nov 4, 2008

We're all mad here.


makomk posted:

Otherwise it's very easy not to notice that there isn't a break - especially if only one or two cases from a complex switch statement don't have them - and even if you do, will you be able to remember whether it was intentional a few months down the line if you come back to the project? Trust me, Future-You will thank you for it.
Be sure to
code:
#define case break;case
for maximum something.

(I have no idea if that would actually "work", might depend on the compiler. Mine didn't complain about the #define itself, anyhow.) :v:

Bad Munki fucked around with this message at 00:41 on Nov 28, 2012

Delta-Wye
Sep 29, 2005

huhu posted:

Time to ask some dumb questions!

What exactly is a ground? I've taken elements of electrical engineering for my mechanical engineering major and we did some circuit stuff but I feel the explanation of what a ground is was completely off. I thought all circuits had to be in a loop but supposedly thee ground can sometimes serve as a completion of the loop?

I set up some code so that 11, 12, and 13, from the Arduino would power three separate LEDs. One of them was much brighter than the other two. I tried moving the LEDs to different spots on the breadboard, changed the LEDs, and changed the Arduino to 10, 11, and 12 and still got the same thing. Thoughts?

How do you go about picking a resistor? Like in the case of 330Ω vs 10kΩ? My kit came with those two values.

Your post made me think of this article: http://spritesmods.com/?art=minimalism

Interesting read.

Sh4
Feb 8, 2009
I'm on the fence about buying a complete arduino kit for a project I have, basically I want to do a digital gauge cluster for my bike, the problem is that except the speedo, every sensor is resistance based, so is an arduino able to measure resistance or do I have to apply tension to the sensors and measure voltage changes ?

Also I would need a bunch of relays, are the arduino outputs able to drive relays ?

Another problem is that LCD screens seems to use a lot of out pins is there a way to have an LCD screen and still have about 10 outputs availlable ?

Thanks

Delta-Wye
Sep 29, 2005

Sh4 posted:

I'm on the fence about buying a complete arduino kit for a project I have, basically I want to do a digital gauge cluster for my bike, the problem is that except the speedo, every sensor is resistance based, so is an arduino able to measure resistance or do I have to apply tension to the sensors and measure voltage changes ?
Not sure what you mean by tension, but here are some lecture notes on how to measure resistance with an ADC:
http://web.cecs.pdx.edu/~eas199/B/howto/thermistorArduino/thermistorArduino.pdf

Some of the information will need some tweaking, such as your fixed resistor and your voltage->resistance->measured quantity calculations, but using an ADC and a resistor divider is a pretty easy way to measure resistance.

Sh4 posted:

Also I would need a bunch of relays, are the arduino outputs able to drive relays ?
I wouldn't drive them directly, but you ought to be able to drive them using a mosfet or transistor. http://blog.makezine.com/2009/02/02/connecting-a-relay-to-arduino/ has a pretty good example. If you are driving more than a few (3 or 4) you may save some space and wiring by using something like an ULN2803 chip, which is basically 8 copies of that circuit in an 18-pin DIP package.

Sh4 posted:

Another problem is that LCD screens seems to use a lot of out pins is there a way to have an LCD screen and still have about 10 outputs availlable ?

What LCD screens are you looking at? There are lots of options for outputs and some of them (SPI interfaces, serial backpacks, etc) don't take that many I/O pins to drive.

rustybikes
Mar 12, 2004

Delta-Wye posted:

What LCD screens are you looking at? There are lots of options for outputs and some of them (SPI interfaces, serial backpacks, etc) don't take that many I/O pins to drive.

This is one of the options I use to reduce the LCD pin requirements to ONE. That's right - one pin to drive the LCD (through SoftwareSerial.h), and it lets you do PWM on the backlight as well. I bought 7 or 8 of these 'cos I use them with pretty much all of my 16x2 character LCDs. Anyway: https://www.sparkfun.com/products/258 - it's stupidly simple to use these, and have minimal overhead with many of the things I work on, 'cos I'm already doing SoftwareSerial for other things.

Word of warning - there are OLED versions of the 16x2 displays (Adafruit carries 'em). The OLEDs are only mostly HD44780 compatible, and won't work with the SerLCD backpack (or even the Adafruit i2c/SPI backpack).

Delta-Wye
Sep 29, 2005

rustybikes posted:

This is one of the options I use to reduce the LCD pin requirements to ONE. That's right - one pin to drive the LCD (through SoftwareSerial.h), and it lets you do PWM on the backlight as well. I bought 7 or 8 of these 'cos I use them with pretty much all of my 16x2 character LCDs. Anyway: https://www.sparkfun.com/products/258 - it's stupidly simple to use these, and have minimal overhead with many of the things I work on, 'cos I'm already doing SoftwareSerial for other things.

Word of warning - there are OLED versions of the 16x2 displays (Adafruit carries 'em). The OLEDs are only mostly HD44780 compatible, and won't work with the SerLCD backpack (or even the Adafruit i2c/SPI backpack).

You're looking at character displays; I'm hoping for a slick OLED graphical display :science:

TVarmy
Sep 11, 2011

like food and water, my posting has no intrinsic value

Sh4 posted:

Also I would need a bunch of relays, are the arduino outputs able to drive relays ?

Not directly. Mechanical relays have two problems for the arduino: They draw more power than the pin can deliver, and they can send back a jolt of current when they switch. This is bad, as either of those things can hurt the pin, or even the whole processor. So, you build a circuit that uses the arduino's pin to switch a transistor, which then draws current from the 5V rail (capable of more amps than the arduino's pin). And a diode prevents that charge from hurting anything.

See the schematic on this page for a description of a circuit for this.

What do you need the relay for, exactly? I'm not questioning your decision, I'm just curious. Are they components from a car that need a 12V battery?

JesusDoesVegas
Jul 8, 2005

The Funk Ambassador
Lipstick Apathy
My creation! It lives!


This jumbled mass of ugly wires is the synthesizer I've been working on.

I plugged everything in and it all worked on the first try... Not sure how that happened.


The LCD display changes colors at a seizure inducing rate, and displays the current note, and the selected scale and key.

Every god damned thing that lights up on this thing changes colors. Seizures are fun. I used LEDs from Sparkfun that change color on their own... I found them as I was ordering my final components and I figured I may as well get ridiculous with it.


As I've stated before, I prototyped this bad boy on my Uno, but I ended up on a Pro Mini 5v. It's super tiny, and has 8 analog inputs.

The LCD backlight PWM is controlled by the offboard ATTINY84 chip on bottom. It worked really well, it was super cheap, and it circumvented the annoying timer issues I encountered with PWM and the interrupt routine.


Off board Space Baby Echo by Wooster Audio. This thing module is what inspired me to start this project.

Next phase is figuring out how to model a case. I'm going to have it printed at Shapeways.com. I'll mave the case done in ABS, and the face in full color sandstone. The design I've come up with should work really well. I'll post video at some point.

JesusDoesVegas fucked around with this message at 09:00 on Dec 14, 2012

Delta-Wye
Sep 29, 2005

JesusDoesVegas posted:

Next phase is figuring out how to model a case. I'm going to have it printed at Shapeways.com. I'll mave the case done in ABS, and the face in full color sandstone. The design I've come up with should work really well. I'll post video at some point.

Please do! I'd love to hear it/see it in action.

rustybikes
Mar 12, 2004

Delta-Wye posted:

You're looking at character displays; I'm hoping for a slick OLED graphical display :science:

Fair enough. Adafruit has a few OLED graphic displays. Just guessing, but I'd think either of these would be close to what you're looking for:

http://www.adafruit.com/products/938
http://www.adafruit.com/products/326

These both use SPI, and the 938 one can do i2c as well. I have the 326 one, and it is absolutely gorgeous. I've the older, non-5V-ready ones, so I have to use an external level-shifter, but as far as the Ardu is concerned, it's just another SPI device.

It's not OLED, but the ST7565 LCDs are another possible option. Again, from Adafruit:

http://www.adafruit.com/products/438

This is an RGB backlit LCD with the same resolution as the OLEDs, but the display itself is much bigger. It's not SPI, but still only uses 5 pins.

JesusDoesVegas
Jul 8, 2005

The Funk Ambassador
Lipstick Apathy
https://www.youtube.com/watch?v=AMo98ELDdVc&feature=youtube_gdata_player

Here's a poo poo video I made while I was messing with it tonight. The lighting, sound, and playing are all awful, but it gives an idea of what I've created here.

Combo
Aug 19, 2003



Its been a very arduino Christmas for me apparently:




Two Unos, two different starter kits, a 4 relay module, and Programming Arduino and Projects for Evil Geniuses, both by Simon Monk.


They're my first crack at this sort of thing, I guess its time to start learning :v:

JesusDoesVegas
Jul 8, 2005

The Funk Ambassador
Lipstick Apathy

Combo posted:

Its been a very arduino Christmas for me apparently:




Two Unos, two different starter kits, a 4 relay module, and Programming Arduino and Projects for Evil Geniuses, both by Simon Monk.


They're my first crack at this sort of thing, I guess its time to start learning :v:

Post back when you've created two uno driven kill bots bent on total huan annihilation. I expect nothing less.

kafkasgoldfish
Jan 26, 2006

God is the sweat running down his back...

JesusDoesVegas posted:

Post back when you've created two uno driven kill bots bent on total huan annihilation. I expect nothing less.

The huan's are a peaceful race, they have done nothing to deserve this :ohdear:

Nerobro
Nov 4, 2005

Rider now with 100% more titanium!
I got a Christmas present from Kickstarter. My Digisparks showed up Monday. A full review will follow. So far.. I've run into two things. First, the documentation isn't immediately obvious, and you need a custom version of the IDE. But... that only set me back half an hour.

Gunktacular posted:

Haha!

I just bought myself a Hitachi V-302 Dual Trace Oscilloscope for less than 10$ brand new in box.

You're all jealous, don't lie.

Damned straight I'm jealous.

Serjeant Buzfuz
Dec 5, 2009

Nerobro posted:


Damned straight I'm jealous.

Finally got to test it out actually, works great on the calibration point. Came with two x10 probes and schematics for all the internal boards and components.

Pompous Rhombus
Mar 11, 2007

Combo posted:

Its been a very arduino Christmas for me apparently:




Two Unos, two different starter kits, a 4 relay module, and Programming Arduino and Projects for Evil Geniuses, both by Simon Monk.


They're my first crack at this sort of thing, I guess its time to start learning :v:

Speaking of this, what starter kits do people recommend? I'm a novice who just wants to try it out and see how I like it/if I have the patience to stick with it.

I came across this thing which looks pretty neat, although maybe a bit limiting. The Sparkfun Inventor's Kit also looked good, as did their Starter Kit. The Fritzing Kit also looks pretty nice.

porktree
Mar 23, 2002

You just fucked with the wrong Mexican.

Pompous Rhombus posted:

Speaking of this, what starter kits do people recommend? I'm a novice who just wants to try it out and see how I like it/if I have the patience to stick with it.

I came across this thing which looks pretty neat, although maybe a bit limiting. The Sparkfun Inventor's Kit also looked good, as did their Starter Kit. The Fritzing Kit also looks pretty nice.
The starter kit and the fritzing kit both look decent - it's more convenience than anything. Get an extra breadboard or two, as you learn you'll want to keep circuits together for a while, at least I did. Anything not in the kit can usually be got from Radio Shack easily enough and most of the components are pretty cheap.

Combo
Aug 19, 2003



Yeah, all of those listed sets are really similar to what I got. Just a small breadboard, bunch of wires, a couple of small servos, assorted LEDs, resistors, capacitors, a buzzer, 9V battery plug, etc.

I also happen to still have my starter kit from my EET 101 class which has similar things plus a larger breadboard.

JesusDoesVegas
Jul 8, 2005

The Funk Ambassador
Lipstick Apathy
I got the kit from Make when I started: http://www.makershed.com/Getting_Started_with_Arduino_Kit_V3_0_p/msgsa.htm

I also got the book. It has a breadboard, a bunch of resisters, photo resisters, buttons, LEDs, and a fuckton of jumpers. I feel like a variety of capacitors and pots would have been handy too, but a few trips to radioshack and a few orders from mouser stocked me up pretty well.

Since components are pretty drat cheap, what I've done is just ordered more than I need when buying from mouser if the component seems fairly common. It helps when you're in the middle of figuring something out and you realize you need a component.

You can also strip old electronics for parts. I use the speaker out of an old alarm clock for breadboarding. I also kept its 7 segment display and its time keeping IC, but I've yet to use them.

n0tqu1tesane
May 7, 2003

She was rubbing her ass all over my hands. They don't just do that for everyone.
Grimey Drawer
My wife got me this one for my birthday at the beginning of December:

http://www.makershed.com/Ultimate_Microcontroller_Pack_p/msump.htm

I've done a few of the intro guides, but haven't really had the time to get too far into it due to work and the holidays.

She also got me this kit for Christmas, which has a lot of other assorted parts that will work nicely with the Arduino:

http://www.thinkgeek.com/product/b80b/?srp=1

porktree
Mar 23, 2002

You just fucked with the wrong Mexican.
Is anyone fuxoring around with XBees? I've got a usb xbee explorer to setup the Xbees but I've only detected them once. On any computer I try I get a message telling me to push the reset button on the Xbee (there isn't one on it or the usb board). I can jump rst and ground to reset, but I'm still not able to write to the Xbee. I'm using a fully updated X-CTU, and everything seems to be right. What are the odds that there's something wrong with the usb adapter board?

ephphatha
Dec 18, 2009




Nerobro posted:

I got a Christmas present from Kickstarter. My Digisparks showed up Monday. A full review will follow. So far.. I've run into two things. First, the documentation isn't immediately obvious, and you need a custom version of the IDE. But... that only set me back half an hour.

Mine arrived on tuesday, I pulled out my parts bin and found I have jack all in the way of useful components (plenty of resistors, capacitors, transistors and unlabelled LEDs of various colours and sizes, but no solid core wire to hook up any of it).

I've so far only bothered modifying the USB2LCD example to autoscroll (ie, move a complete line from the bottom to the top row and start writing on the bottom line) and haven't yet got a daemon running on my pc to send data to it. Eventually I think I'll try make it run standalone with an ethernet module and basic http stack so it can pull data from twitter and display tweets, since that's what all the cool kids seem to do. It'll be interesting to see if I can get that to fit on a digispark solo or if I need to use the eeprom module.

huhu
Feb 24, 2006
So I made this code so that you could enter a value into serial monitor and have it turn that number of steps on a stepper motor. I added the line of
code:
Serial.println(stepval); //test the value of Serial.read
Because I couldn't control the steps and say that 0 would turn it 48, 1 would turn it 49, etc. I tried calibrating it so 0 would give 0 and then ran it again. It's fine now except 10=0, 11=1, 12=2, etc. What is affecting these values?

code:
#include <Stepper.h>

const int stepsPerRevolution = 200; 
Stepper myStepper(stepsPerRevolution,8,9,10,11);            

void setup() {
  myStepper.setSpeed(15);
  Serial.begin(9600);
}

void loop() {
  int stepval;
  if(Serial.available())
  { 
    stepval=Serial.read();
    Serial.println(stepval); //test the value of Serial.read
    if(stepval>0)
    { 
      myStepper.step(stepval);
    }
    else
      myStepper.step(-stepval);
  }
  
}

Delta-Wye
Sep 29, 2005

quote:

Because I couldn't control the steps and say that 0 would turn it 48, 1 would turn it 49, etc.

It appears you are sending characters, not numbers. ASCII '0' is decimal 48. http://www.asciitable.com/

nightchild12
Jan 8, 2005
hi i'm sexy

huhu posted:

So I made this code so that you could enter a value into serial monitor and have it turn that number of steps on a stepper motor. I added the line of

Because I couldn't control the steps and say that 0 would turn it 48, 1 would turn it 49, etc. I tried calibrating it so 0 would give 0 and then ran it again. It's fine now except 10=0, 11=1, 12=2, etc. What is affecting these values?

A couple of problems: Serial.read() only reads one byte at a time before returning. It also doesn't parse it as characters or an int, but reads it as a raw byte. So in your loop it's reading the first byte received, trying to use it as a value, then reading the next byte, trying to use it as a value, etc, rather than interpreting the bytes as a single integer.

You probably want to be using Serial.parseInt(), which will pull characters off the serial stream until it gets a non-integer character, and then turn them into an int value to return. If you do this, be sure to turn on newline in your serial program on your PC, and/or use Serial.setTimeout() to reduce the serial read timeout, or else you will get long pauses if you enter an int value with no trailing non-int characters. This is because it reads until it gets a non-integer character, and doesn't know that you have finished sending the number you want until it either gets a non-int value or times out (I think by default it's a full second).

huhu posted:

It's fine now except 10=0, 11=1, 12=2, etc. What is affecting these values?

As Delta-Wye said, it's because Serial.read() is interpreting the byte value instead of the ASCII value. For something like "10 11 12" it should be spitting out "49 48 49 49 49 50".

nightchild12 fucked around with this message at 19:31 on Jan 24, 2013

Adbot
ADBOT LOVES YOU

huhu
Feb 24, 2006
Success! First program I've made with a purpose. Going to be used for work to replace a $200 setup currently being used.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply