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
Aurium
Oct 10, 2010

cakesmith handyman posted:

Hello thread, I've a project in mind and wondered if an arduino was the right way to go with it. I want to control Lego contraptions without a PC. Years ago I'd have used the RCX controller I got with a mindstorms kit, but it's very limited (3in/3out) and to program it now would require faffing about with Windows 98 and obsolete patches.

All the sensors and motors are 9v and I'm happy to modify cables to connect one system to the other but before I start is an arduino variant the best thing to start with? Can they drive motors in 2 directions natively or do they need external motor driver boards?

An Uno is typically the best to start with. Far and away the most info is out for it, and most hardware is designed for it as well.

And they need an external drivers to run motors. Motors take too much power to drive natively, and the inductive kickback can damage the pins.

Adbot
ADBOT LOVES YOU

cakesmith handyman
Jul 22, 2007

Pip-Pip old chap! Last one in is a rotten egg what what.

Okay, how about this then:

http://www.sniff.org.uk/2016/03/lego-dacta-control-lab-b.html?m=1

The whatsit about half way down the page is basically a Lego IO rack with H-bridge motor drivers, however it's serial controlled via M-F DB9 null modem cable. Is there any way I could control this with arduino?

Aurium
Oct 10, 2010

cakesmith handyman posted:

Okay, how about this then:

http://www.sniff.org.uk/2016/03/lego-dacta-control-lab-b.html?m=1

The whatsit about half way down the page is basically a Lego IO rack with H-bridge motor drivers, however it's serial controlled via M-F DB9 null modem cable. Is there any way I could control this with arduino?

Yes.

There are 2 possible sticking points I can imagine.

You might have a voltage incompatibility. The Arduino is 0-5v only. (Or 3.3 for the due and pro mini) Some serial (TTL serial)is those voltages but the official RS 232 is up to -25 to +25, with typical being +/-12v. There are chips and modules that take care of this.

Another is that you may not know the commands to actually send over the serial connection. There's a good chance someone has documented it, or you could sniff the bus as it runs with the Arduino. (after taking care of the voltage)

cakesmith handyman
Jul 22, 2007

Pip-Pip old chap! Last one in is a rotten egg what what.

I'll do some research then thank you. The final probably saner alternative is just protoboarding a big bunch of relays, but where's the fun in that?

Sagebrush
Feb 26, 2012

cakesmith handyman posted:

Hello thread, I've a project in mind and wondered if an arduino was the right way to go with it. I want to control Lego contraptions without a PC. Years ago I'd have used the RCX controller I got with a mindstorms kit, but it's very limited (3in/3out) and to program it now would require faffing about with Windows 98 and obsolete patches.

All the sensors and motors are 9v and I'm happy to modify cables to connect one system to the other but before I start is an arduino variant the best thing to start with? Can they drive motors in 2 directions natively or do they need external motor driver boards?

If you just need to drive the motors forwards at full power, and not change direction rapidly, you can get a multi-channel relay board for super cheap on Amazon.

https://www.amazon.com/JBtek-Channel-Relay-Arduino-Raspberry/dp/B00KTELP3I/

If you want bidirectional drive or PWM control (variable speed) then you need something with solid-state H-bridges, like these L298 boards:

https://www.amazon.com/C-J-Bridge-Stepper-Controller-arduino/dp/B00XAGRQTO/

each one of those can drive two motors. The L298 isn't a super efficient chip but it should work fine for small LEGO motors. If you need to drive bigger stuff, look for MOSFET-based driver chips/boards instead.

cakesmith handyman
Jul 22, 2007

Pip-Pip old chap! Last one in is a rotten egg what what.

Looks like I need those 298 boards for the Lego, though those relay boards look like they can drive 250VAC? :aaa: I'm sure I can find a few uses for those too.

I assume input 1 & 2 will map to motor 1 forwards and backwards? Simple enough if so.

Thank you, very helpful.

Potato Salad
Oct 23, 2014

nobody cares


cakesmith handyman posted:

Looks like I need those 298 boards for the Lego, though those relay boards look like they can drive 250VAC? :aaa: I'm sure I can find a few uses for those too.

Cakesmith found dead in home in February 2017 over device with following masking tape labels on leads:
"Motor control a"
"motor control B"
"motor control c camera"
"Tazer"
"capacitor bank A"
"capacitor bank B"
"inverter"
"motor control c"
"motor control D"

Sagebrush
Feb 26, 2012

The relay boards can theoretically handle 250 volts, yeah, implying that you could use them to toggle lamps and stuff...but IMHO installing cheap Chinese DIY electronics in your house wiring is a great way to burn it down and then get your insurance denied.

They're great for stuff that you keep an eye on and that won't kill you if they fail.

coyo7e
Aug 23, 2007

by zen death robot
Okay I feel dumb but it's been almost 20 years since I messed around in C - how do I write an exponent, ie "X^Y"?

I'm working on re-inventing the wheel by making a binary clock (eventually I plan to remove the arduino and have it be entirely run off components as a learning exercise but I'm a good way before I reach that point). I want to use a decrementing "for" loop to run modulo on whatever time I have going, so I don't need to write eseentially the same statement several times but I can't remember how to code in C and I dunno where my old reference books are (probably in my family's barn in another city).

edit: aha, the pow() function. And it seems as though there's no need to include the math.h library from C..? :crossarms:

coyo7e fucked around with this message at 03:03 on Jan 3, 2017

Sagebrush
Feb 26, 2012

Yeah, that's the one.

And you don't have to add math.h manually because Arduino.h (the huge macro file that gets inserted at the beginning of every Arduino sketch before it gets punted to the compiler) already includes it.

If you're interested in seeing exactly what makes up the "Arduino language", the file you're looking for is C:\path\to\arduinofolder\hardware\arduino\avr\cores\arduino\Arduino.h

Hobnob
Feb 23, 2006

Ursa Adorandum
Also if all you want to do is integer powers of two (for binary bit twiddling) you'll probably be better off using the left and right bit-shift operators << and >> .

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Hobnob posted:

Also if all you want to do is integer powers of two (for binary bit twiddling) you'll probably be better off using the left and right bit-shift operators << and >> .
Yeah so just to elaborate/clarify a little:
(X << Y) is equivalent to (X * 2^Y)
and
(X >> Y) is equivalent to (X * 2^-Y)

So substitute that in any place you can for integer operations.

gonadic io
Feb 16, 2011

>>=
How does the Zero compare to the MKR zero? It talks about having the same pins (and the data sheets look the same to me), is it literally the same thing except smaller, lighter, and cheaper? Are there any downside to getting it?

gonadic io fucked around with this message at 23:02 on Jan 4, 2017

GobiasIndustries
Dec 14, 2007

Lipstick Apathy
A while back I funded a kickstarter for the Onion Omega2 (onion.io) because it looked nifty. I picked up an Arduino Dock v.2 with it, and they finally showed up a bit ago. The documentation is still scarce and I'm still totally new to all this but after installing the package for the arduino on the omega I can now flash the board via wifi. It's got identical pinouts to the uno so it's supposed to be compatible with all the shields and I should be able to communicate with the omega linux unit via a serial connection. Not as fast as a pi but way more compact, uses even less power, and the omega also has its own gpio ports. Tested a blink sketch last night which worked great because the built-in led is bright and I wanted to see less of it, gonna pull out the breadboard tomorrow and pick up where I left off a while ago with turning on/off leds.

Splode
Jun 18, 2013

put some clothes on you little freak
I used a little Wi-Fi module and an arduino to muck around with web server stuff. Hoping to get it to the point where I can log in to a web page and change stuff on the arduino. It's much easier than I expected, all these pre-programmed AT command gadgets around are fantastic.

A while back I used another arduino and a relay to make a time and temperature based switch for my room heater. I hope to merge the two projects so that I can configure it using a browser.

huhu
Feb 24, 2006
I'm currently leading some workshops in Colombia and we bought parts before we came and we got a 2 pin microphone instead of the 3 pin microphone that's designed to work out of the box with an Arduino. It looks a bit complicated to build a system with the 2 pin microphone. The goal of the workshop is to have lights that turn on when loud sounds are detected. What would be the simplest circuit that could detect loud sounds?

coyo7e
Aug 23, 2007

by zen death robot
A mic with two leads would act as a resistor i believe, so you could probably use something like this http://oomlout.com/a/products/ardx/circ-09/ would probably work if u look up syntax for the mic, and have an LED get brighter or dimmer with room noise.

Wouldn't a 3 prong mic work like a transistor (switch)? That's more complicated by a bit I would think.


http://www.learningaboutelectronics.com/Articles/Arduino-microphone-circuit.php

coyo7e fucked around with this message at 20:37 on Jan 13, 2017

huhu
Feb 24, 2006

coyo7e posted:

A mic with two leads would act as a resistor i believe, so you could probably use something like this http://oomlout.com/a/products/ardx/circ-09/ would probably work if u look up syntax for the mic, and have an LED get brighter or dimmer with room noise.

Wouldn't a 3 prong mic work like a transistor (switch)? That's more complicated by a bit I would think.


http://www.learningaboutelectronics.com/Articles/Arduino-microphone-circuit.php

I tried setting up that first one as a photo resistor with no luck. The second one would work but I was hoping to avoid so many components.

Hadlock
Nov 9, 2004

gonadic io posted:

How does the Zero compare to the MKR zero? It talks about having the same pins (and the data sheets look the same to me), is it literally the same thing except smaller, lighter, and cheaper? Are there any downside to getting it?

The Zero has the traditional form factor, which means it should be mostly compatible with the last decade worth of Arduino shields. That form factor is also a bit more human scale, less cramped, less likely to accidentally short something

MKR is smaller but harder to work with (unless you have Trump sized hands) and only works with specific shields, unless you buy/build some kind of adapter.

Unless you have a specific use case or you live in a tokyo/sf sized apartment I think you're better off with the larger one

evil_bunnY
Apr 2, 2003

gonadic io posted:

How does the Zero compare to the MKR zero? It talks about having the same pins (and the data sheets look the same to me), is it literally the same thing except smaller, lighter, and cheaper? Are there any downside to getting it?
MKR is for stuffin in/onto things. Zero should be your first 'duino

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

Disclaimer that I am a gigantic noob. I bought this Elegoo starter pack and despite my best efforts managed to setup this circuit to control a DC motor.





That worked alright powered through the USB, problem is I'm trying to power this with batteries and my 9V battery pack plugged into the power port on the Arduino is not up for the task. The motors are KNEX motors that can be powered independently with 2 AA batteries (i've tried and it works just wonderfully) but I need to control them programatically. When I tried to naively substitute the 5V and ground in the above diagram for the + and - of my improvised battery pack I got nothing for 2 through 5 batteries (wired in series). The battery pack definitely works for example 3 batteries gave me around +4.5V when tested with a volt meter (each battery is 1.5V). Any ideas? I am aware a motor shield is probably a good idea but I would love it if I could get 'er done with this circuit (or at least the parts in my elegoo starter kit). Thanks!

Edit: This is what I tried to no avail:

awesomeolion fucked around with this message at 04:36 on Jan 14, 2017

Platystemon
Feb 13, 2012

BREADS

You need a shared ground.

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

Platystemon posted:

You need a shared ground.

IT WORKS! Thank you so much!

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

New question for y'all. Now that I've got both motors running on batteries I'm trying to control them using an IR sensor. If I have "irrecv.enableIRIn();" in setup then only one motor runs. If I comment it out both motors run. I know that the IR receiver can block but why would it stop only one motor from working?

code:
#include <IRremote.h>

const int RECV_PIN = 6;
const int RIGHT_WHEEL_PIN = 3;
const int LEFT_WHEEL_PIN = 5;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(RIGHT_WHEEL_PIN, OUTPUT);
  pinMode(LEFT_WHEEL_PIN, OUTPUT);
  
  irrecv.enableIRIn();
}

void loop() {
  analogWrite(RIGHT_WHEEL_PIN, 250);
  analogWrite(LEFT_WHEEL_PIN, 250);
}
Edit: Wow Fritzing is cool! Here's my current setup:

awesomeolion fucked around with this message at 19:00 on Jan 14, 2017

Splode
Jun 18, 2013

put some clothes on you little freak

awesomeolion posted:

New question for y'all. Now that I've got both motors running on batteries I'm trying to control them using an IR sensor. If I have "irrecv.enableIRIn();" in setup then only one motor runs. If I comment it out both motors run. I know that the IR receiver can block but why would it stop only one motor from working?

code:
#include <IRremote.h>

const int RECV_PIN = 6;
const int RIGHT_WHEEL_PIN = 3;
const int LEFT_WHEEL_PIN = 5;

IRrecv irrecv(RECV_PIN);

decode_results results;

void setup()
{
  pinMode(RIGHT_WHEEL_PIN, OUTPUT);
  pinMode(LEFT_WHEEL_PIN, OUTPUT);
  
  irrecv.enableIRIn();
}

void loop() {
  analogWrite(RIGHT_WHEEL_PIN, 250);
  analogWrite(LEFT_WHEEL_PIN, 250);
}
Edit: Wow Fritzing is cool! Here's my current setup:


I may have found your issue
https://forum.arduino.cc/index.php?topic=93994.0

Your arduino might have run out of hardware timers. Apparently that ir library you're using uses one, and analogWrite uses one too.

unpacked robinhood
Feb 18, 2013

by Fluffdaddy
I'm still working on my u8glib editor

Now you can edit a picture in gimp and directly load it in my tool. I've been trying to find efficient ways to store those imported binary images on an 8 bit AVR.
So far there's a rudimentary RLE algorithm.

For example


compresses to a 249 elements long array of 8 bit ints

code:
#define IMG_LENGTH 128
#define RLE_BYTES  249
uint8_t img1[RLE_BYTES] = {
0xFF , 0x00 , 0xB3 , 0x0B , 0x75 , 0x08 , 0x77 , 0x07  ,....}
It works really well as long as the array stays under 255 elements long (because I'm on a 8 bit I guess ?)

What's the proper way to use longer arrays, I think I need several ? My problem is I know mostly gently caress all about C

The display code is this
code:
	uint8_t c=0x00,i,j,x=0,y=0;
	for( i = 0; i < RLE_BYTES; i++ ) {//read image byte array
		for (j=0;j<img1[i];j++){//write current byte to screen
			if(x<IMG_LENGTH-1 ){
				if (c==0x01){u8g_DrawPixel(&u8g,x,y);}
				x++;
			} else {
				x=0;
				y++;
			}
		}
		c=c^0x01;
	}

unpacked robinhood fucked around with this message at 20:07 on Jan 15, 2017

awesomeolion
Nov 5, 2007

"Hi, I'm awesomeolion."

Splode posted:

I may have found your issue
https://forum.arduino.cc/index.php?topic=93994.0

Your arduino might have run out of hardware timers. Apparently that ir library you're using uses one, and analogWrite uses one too.

Thanks! After reading that thread I ended up using digital write and that allows everything to play nice together :)

cakesmith handyman
Jul 22, 2007

Pip-Pip old chap! Last one in is a rotten egg what what.

I bought one of those Elegoo starter kits and apart from a couple of slightly bent pins (yes I just grabbed some pliers) mechanically it's been fine, however the tutorials & the code & the accompanying schematics and drawings don't always match, which is frustrating when you're trying to learn something & you have to find where they sent you wrong.

Also I did the shift register tutorials and now I cant get the chip off the breadboard and I'm afraid I'll destroy it. Is there a special tool I need? Hell is there a little toolkit anyone could recommend? I don't have anything at this scale,

Splode
Jun 18, 2013

put some clothes on you little freak

cakesmith handyman posted:

I bought one of those Elegoo starter kits and apart from a couple of slightly bent pins (yes I just grabbed some pliers) mechanically it's been fine, however the tutorials & the code & the accompanying schematics and drawings don't always match, which is frustrating when you're trying to learn something & you have to find where they sent you wrong.

Also I did the shift register tutorials and now I cant get the chip off the breadboard and I'm afraid I'll destroy it. Is there a special tool I need? Hell is there a little toolkit anyone could recommend? I don't have anything at this scale,

There are special tools for that, but they're not always perfect. A small Flathead screwdriver and care is usually just as good.

coyo7e
Aug 23, 2007

by zen death robot

cakesmith handyman posted:

I bought one of those Elegoo starter kits and apart from a couple of slightly bent pins (yes I just grabbed some pliers) mechanically it's been fine, however the tutorials & the code & the accompanying schematics and drawings don't always match, which is frustrating when you're trying to learn something & you have to find where they sent you wrong.

Also I did the shift register tutorials and now I cant get the chip off the breadboard and I'm afraid I'll destroy it. Is there a special tool I need? Hell is there a little toolkit anyone could recommend? I don't have anything at this scale,
how do you mean they were wrong? Are they like the arduino stuff I got from adafruit where it has a cut-out piece of paper that goes over the breadboard, or something else like you're looking at DCDs and they're not working?

My breadboard cutouts were "correct" but they were a little off-scale or something and anyway after the first two or three you should be picking up enough to do them from eyeball, imho. What's giving you trouble? Share a pic or code or something if possible.

cakesmith handyman
Jul 22, 2007

Pip-Pip old chap! Last one in is a rotten egg what what.

coyo7e posted:

how do you mean they were wrong? Are they like the arduino stuff I got from adafruit where it has a cut-out piece of paper that goes over the breadboard, or something else like you're looking at DCDs and they're not working?

My breadboard cutouts were "correct" but they were a little off-scale or something and anyway after the first two or three you should be picking up enough to do them from eyeball, imho. What's giving you trouble? Share a pic or code or something if possible.

I'm at work so I'll share later but the rgb led fade program behaved strangely until I realised it counted up instead of down or vice versa. Some tutorials have drawings and pictures, some have schematics and drawings. Honestly if the schematic is there it's always better, the drawings have been wrong by a pin or two sometimes.

Nothing terrible just annoying.

Splode
Jun 18, 2013

put some clothes on you little freak
I had an issue last night with an arduino clone board: the Vin pin wasn't actually connected to anything. I'm going to have to be more careful about which knock off clones I buy from eBay in future. This one didn't have a test LED either which you really miss when it's gone.

Hadlock
Nov 9, 2004

unpacked robinhood posted:

I'm still working on my u8glib editor

Now you can edit a picture in gimp and directly load it in my tool. I've been trying to find efficient ways to store those imported binary images on an 8 bit AVR.
So far there's a rudimentary RLE algorithm.

For example


compresses to a 249 elements long array of 8 bit ints

code:
#define IMG_LENGTH 128
#define RLE_BYTES  249
uint8_t img1[RLE_BYTES] = {
0xFF , 0x00 , 0xB3 , 0x0B , 0x75 , 0x08 , 0x77 , 0x07  ,....}
It works really well as long as the array stays under 255 elements long (because I'm on a 8 bit I guess ?)

What's the proper way to use longer arrays, I think I need several ? My problem is I know mostly gently caress all about C

The display code is this
code:
	uint8_t c=0x00,i,j,x=0,y=0;
	for( i = 0; i < RLE_BYTES; i++ ) {//read image byte array
		for (j=0;j<img1[i];j++){//write current byte to screen
			if(x<IMG_LENGTH-1 ){
				if (c==0x01){u8g_DrawPixel(&u8g,x,y);}
				x++;
			} else {
				x=0;
				y++;
			}
		}
		c=c^0x01;
	}

This is the best, thanks sir

JawnV6
Jul 4, 2004

So hot ...

unpacked robinhood posted:

It works really well as long as the array stays under 255 elements long (because I'm on a 8 bit I guess ?)

What's the proper way to use longer arrays, I think I need several ? My problem is I know mostly gently caress all about C
You could break it into several arrays, but that's not your problem. This is a fix:

unpacked robinhood posted:

code:
	uint8_t c=0x00,j,x=0,y=0;
        uint16_t i;
	for( i = 0; i < RLE_BYTES; i++ ) {//read image byte array
...
	}
You were declaring the loop index 'i' as a uint8_t. That has a maximum value of 255. When it was incremented from 255, it would wrap to 0, then the comparison to RLE_BYTES would always be true, and I'm guessing you hit an infinite loop there.

Declaring i with a wider width (uint16_t) should fix that issue.

Jamsta
Dec 16, 2006

Oh you want some too? Fuck you!

Talking of u8glib, u8g2 is out now:

https://github.com/olikraus/u8g2

Finally supports Arduino on ESP8xxx. Has framebuffers and lots of other cool stuff too.

Now I can upgrade my homemade Arduino lawn trimmer to be WiFi enabled along with it's OLED screen.

unpacked robinhood
Feb 18, 2013

by Fluffdaddy

JawnV6 posted:

You could break it into several arrays, but that's not your problem. This is a fix:

You were declaring the loop index 'i' as a uint8_t. That has a maximum value of 255. When it was incremented from 255, it would wrap to 0, then the comparison to RLE_BYTES would always be true, and I'm guessing you hit an infinite loop there.

Declaring i with a wider width (uint16_t) should fix that issue.

ffs :doh:

Corrected, thanks à lot !

Splode
Jun 18, 2013

put some clothes on you little freak

Jamsta posted:

Talking of u8glib, u8g2 is out now:

https://github.com/olikraus/u8g2

Finally supports Arduino on ESP8xxx. Has framebuffers and lots of other cool stuff too.

Now I can upgrade my homemade Arduino lawn trimmer to be WiFi enabled along with it's OLED screen.

oooooh cool

Hadlock
Nov 9, 2004

Is there a standard or best wifi data logger (temperature) project for the esp8266? There's about 2000 just doing a cursory look

Sagebrush
Feb 26, 2012

An ESP8266, FTDI programmer, the relevant Arduino cores, a couple of digital sensors (like the DHT22) and thingspeak.io makes it pretty simple.

Adbot
ADBOT LOVES YOU

neogeo0823
Jul 4, 2007

NO THAT'S NOT ME!!

Do any of you guys know of an electronically controlled, adjustable gas valve that can be hooked into an Arduino? Think like the gas valve on your stove, where you turn a dial to adjust the output to exactly what you want, but instead of a dial, it'd be connected directly to the controller. I'm googling around, but I'm having trouble finding anything that looks like it would work.

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