|
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 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 |
# ¿ Jan 24, 2013 19:22 |
|
|
# ¿ May 15, 2024 16:10 |
|
Capntastic posted:I can't really see what sort of project would require a Mega. Something with a lot of inputs/outputs with a design goal of "as few parts as possible"? Or if you're unable to get shift registers, muxes, etc? I can buy a Mega locally in a store, but not the ICs I'd need to get more I/O out of an Uno. Like, I want to drive >2 strings of RGB LEDs independently of each other - the Uno only lets me do 2 (6 PWM channels, 3 per LED string), but the Mega lets me do up to 5 without needing to find and figure out new hardware. Or something along those lines, maybe? edit: Or just something with lots of I/O needed. I have a garden sensor / automatic gardener project I've been kicking around in my head that gets way simpler if I use a Mega vs an Uno. double edit: I refuse to let any one pin have more than one purpose since I think it is an affront to God. nightchild12 fucked around with this message at 01:47 on Jan 31, 2013 |
# ¿ Jan 31, 2013 01:42 |
|
huhu posted:I'm making a basic control system using the following elements: The temp sensors use a 1-wire interface and have unique serials, they can all go on one IO pin. The LCD display needs 11 IO pins, plus GND and +5V (unless I'm misreading the datasheet when I skim it). This is your big pin hog. LEDs need a pin each, Float switches need a pin each. If you are just turning the LEDs on based on the float switches, you probably don't need to run them through a microcontroller, though; just hook the LED up directly to the float switch. That brings you down to 12 pins needed: 11 for the LCD and 1 for the temp sensors, with the float switches and LEDs not connected to any IO pins. edit: You should learn about multiplexing anyways, though. Here's a bit from the Arduino playground on an analog multiplexer/demultiplexer: http://playground.arduino.cc/learning/4051 nightchild12 fucked around with this message at 02:29 on Mar 1, 2013 |
# ¿ Mar 1, 2013 00:44 |
|
Yakattak posted:I have a programming question for the Arduino. We have a keypad that is used to "dial a phone". We got the numbers working perfectly fine, when you hit 1, it means 1. The problem we're having is we can't get it to act like a phone, in the sense that, when you dial 1, and wait like a second or two, it will go and dial that number, but when you hit 1,2 and 3 within that period, it dials 123. Is this possible at all? That is totally possible. Easiest way is probably to use the Metro library as a timer to see if ~200 ms has passed between keypresses. I haven't used it myself so this may not be right, but here's something along the lines of what you want: code:
But that's a basic way you can do it. Run a timer which resets each time a key is pressed, and only output when the timer expires or reaches a certain value. nightchild12 fucked around with this message at 19:57 on Mar 10, 2013 |
# ¿ Mar 10, 2013 19:52 |
|
HATE TROLL TIM posted:I've got some older code here that's calling prog_uchar to store an array of data in PROGMEM, however it seems that prog_uchar is deprecated and the Arduino IDE won't allow me to compile it. The correct data type to use is const unsigned char. The uploadStartScreen() function wants an unsigned char pointer. The relevant function from that library: code:
I think there is a problem other than the data type you are using. Can you get it to display anything meaningful at all? Like, clear the screen and put a few characters without messing around with the start screen or fonts or anything? Strip it down to something like the below and make sure that works, then add pieces back one by one: code:
edit2: I did a little more looking around. prog_uchar is deprecated? I can't find an official source for that. Have you tried including the <avr/pgmspace.h> library? I noticed that the PROGMEM reference page says you need to "#include <avr/pgmspace.h>" in order to use PROGMEM, and that it isn't included anywhere in the DigoleSerial library or example. edit3: OK, prog_uchar is deprecated according to the avr-libc website. Looks like the correct way to do this is: const unsigned char startscreenMV[1024] PROGMEM. Here's the old typedef: typedef unsigned char PROGMEM prog_uchar. nightchild12 fucked around with this message at 00:32 on Mar 27, 2013 |
# ¿ Mar 26, 2013 21:02 |
|
Not directly Arduino, but closely related: I'm doing a thing on an ATtiny2313 with avr-gcc and having problems with progmem. I'm trying to set up a character (and graphics) set for a 5x7 LED matrix. I don't have enough RAM on the ATtiny2313 to hold the whole array of character maps, so I'm trying to store them on flash using progmem. However, when I try to access the data, the progmem array is giving me pointers to someplace before where the data is actually stored. It's storing the data OK, I can see it in the compiled .hex file, but when I try to access it with pgm_read_byte(&(alphanum[ch][c])) it returns the byte at &alphanum[ch-17][c+1]. code:
Compiled like so: avr-gcc tinypendant.c -Os -mmcu=attiny2313 -o tinypendant.hex Uploaded to ATtiny2313 like so: avrdude -p attiny2313 -c usbtiny -U flash:w:tinypendant.hex Could it be the -Os? If I turn that off, it pitches a fit and stops working since I'm using delay functions from avr-libc in other parts of the code. fake edit: for you people that read the Embedded Programming thread, should I cross-post this there? real edit: here's the main loop code:
nightchild12 fucked around with this message at 05:41 on May 15, 2013 |
# ¿ May 15, 2013 05:37 |
|
nightchild12 posted:Not directly Arduino, but closely related: I'm doing a thing on an ATtiny2313 with avr-gcc and having problems with progmem. Turns out it was a problem with WinAVR and/or that version of avr-gcc. I downloaded Atmel Studio and recompiled the exact same code with it and it magically started working, at like a quarter the size of the WinAVR compiled program. The Atmel Studio IDE is quite nice, as well.
|
# ¿ May 18, 2013 05:09 |
|
Sagebrush posted:I think there's also a way to fire a timer interrupt if you need microsecond-precision timing. If you're already using a method like this, ignore and carry on. There is a way to do this, but the standard Arduino library doesn't support it. To use interrupts properly, you have to find another library or poke bits into the AVR registers directly. I prefer to access the AVR registers directly. Keep in mind, if you do stuff with interrupts (especially timer interrupts), you can easily break other Arduino-provided functions (like PWM, since it relies on timer interrupt functions to work). Here's how you set up a timer interrupt on an ATTiny2313, taken from an LED matrix project I'm working on. A quick check of the datasheet shows that this looks like it should work with the ATMega328 as well. Example assumes 1MHz CPU frequency: quote:// The above makes it so that the interrupt fires at 3125Hz and does whatever you have in the ISR. You can change the prescaler and Output Compare A values to change the rate at which the interrupt fires. I believe that the ATMega328 has 3 timers, each with a Compare A and Compare B plus overflow interrupts, which you can be clever with and stretch out to get a whole lot of different interval timer interrupts out of. With the above, assuming a 1MHz clock, if you want a 50ms delay between interrupts firing, you'd want to set the prescaler to /256 [ TCCR0B = 0; TCCR0B |= (1<<CS02); ] and the compare value to 195 (1,000,000Hz / 256 = 3906.25 / 195 = reciprocal of 49.92ms) or 196 (1,000,000Hz / 256 = 3906.25 / 196 = reciprocal of 50.176ms). Or use Timer1 since it's 16 bit and can actually get the exact 50ms timing. To do it with an Arduino running at 16MHz, I think you'd need to use the 16 bit Timer1, since Timer0 and Timer2 are 8 bit and can only get up to 16,000,000Hz / 1024 = 15625Hz / 255 = ~61.275Hz = ~16.32ms max delay between triggering interrupts. Assuming my math isn't off, of course. Possible prescaler values are /1, /8, /64, /256, and /1024. Timer compare values are 8-bit for Timer0 and Timer2 and 16-bit for Timer1 (same size as the timer counters). edit: If you do use interrupts, I believe that it's generally considered best practice to keep the ISR as short as possible so you aren't blocking in the interrupt for longer than necessary. Especially never let an ISR get big enough that another interrupt might trigger during it, unless you really really have to and account for the possibility. nightchild12 fucked around with this message at 05:51 on Apr 5, 2014 |
# ¿ Apr 5, 2014 05:40 |
|
|
# ¿ May 15, 2024 16:10 |
|
Amberskin posted:Wasn't it posible to brick the arduino reprogramming the timer interrupts? I remember to have read something about breaking the bootloader so rendering the Arduino bricked until you can reinstall it. All I can find is this https://forum.sparkfun.com/viewtopic.php?f=32&t=30417 and I'm not sure how that managed to brick an Arduino. Maybe it's possible for an ISR to overwrite part of the bootloader or the bootloader needs those interrupts for something? I've seen a ton of tutorials on using interrupts via an Arduino (like http://www.instructables.com/id/Arduino-Timer-Interrupts/ which looks pretty good) and never seen problems with it breaking the bootloader mentioned.
|
# ¿ Apr 5, 2014 18:24 |