Show Posts
Pages: 1 ... 155 156 [157] 158 159 ... 361
2341  Using Arduino / Project Guidance / Re: comparing an array of inputs on: May 14, 2013, 06:37:46 pm
What TH posted only with more details:

You can keep the status of those 8 pins in a bit array, otherwise known as a byte.

You can use bitRead(), bitWrite(), bitSet() and bitClear() to work with the bits and/or the bitwise operators, the shifts and logic operations. All those are found here:
http://arduino.cc/en/Reference/HomePage

If you have a pattern 11111011 that changes to 11110111 then XOR the two and get 00001100 showing the bits that changed (the 1's in the result) and work it from there.

If you arrange which parts of the mat match which bits then bit position might be something you can use in your algorithm, relating spatial movement to bit movement.

Yes it requires knowing or learning bits and bit logic. Is using a variable-per-sensor array going to be easier because you don't have to learn bits? Well there's not all that much to bits and bit logic and by using those you can compare all 8 sensors in one operation while using arrays will require looping and extra variables.

If you are using an UNO then you can read all 8 sensors in 2 direct Port reads (search on Port Manipulation). All UNO Ports have some pins tied up by default. The MEGA2560 has some ports with all 8 pins (bits) open for use, you can read the whole mat in one operation.

Do some studying and ask questions before you choose a path, and you will be better prepared either way.

2342  Using Arduino / Programming Questions / Re: Strange Characters in Serial Monitor on: May 14, 2013, 10:44:35 am
You set the Arduino serial baudrate to 57600. Did you set Serial Monitor to match?
2343  Using Arduino / Programming Questions / Re: Averaging analog inputs without delay() help needed on: May 14, 2013, 10:38:36 am
Quote
Analog read takes about 105 millis which in itself isn't much but -do- you need to check the battery that often?

Uhh...  Are you sure that's right?  I calculate about 104 micros, which is about 3 orders of magnitude different.


Ooops, yes, micros! I forget if the doc says 104 or 105 or how exact that is.

I go now to edit my screwup above.
2344  Development / Suggestions for the Arduino Project / Is there a project to improve/replace the official examples? on: May 14, 2013, 06:46:05 am
I know they work but in many cases they are teaching new people bad habits that come back in Help! Help! threads. The whole communication set is rife with C++ String use. Blink Without Delay has longs mixed with unsigned longs for time work. Throughout, ints are used where bytes or shorts will do.

These are 8 bit machines with very limited RAM. Awareness of that from the start will result in fewer problems and the examples are not helping.

2345  Using Arduino / Audio / Re: Arduino library for WTV020-SD-16P audio module on: May 14, 2013, 12:27:53 am
Hello!
I have a question!
How to manually change modes on vtv020-sd-16p,all ekys are on/off(loop),key 5 group of voice...
Thanks!!!

I want to ask which control mode module do you use?for example ,If you buy 2-wire series mode can not us key 5 group of voice,control mode is fixed when we program main chip,and you need tell supplier what you want,i think they will give you correct control mode module.

Please. On eBay the supplier tells little. This is typical and notice it says "MP3":
http://www.ebay.com/itm/U-disk-audio-player-SD-card-voice-module-MP3-Sound-module-WTV020-SD-16P-Arduino/310629013078?_trksid=p2045573.m2042&_trkparms=aid%3D111000%26algo%3DREC.CURRENT%26ao%3D1%26asc%3D27%26meid%3D7644561902605214505%26pid%3D100033%26prg%3D1011%26rk%3D2%26sd%3D271024886800%26

Nothing about mode. This one also uses mini-SD I don't find easily, nor adapter mini to micro-SD so this module says 'problems' to me.

I am having problems enough with the VS1003 modules I got. Yes there is software for other modules with the same chip that do almost what I want. In the meantime I have someone who wants dozens of Arduino-controlled sound players.

What I find that "works out of the box" is expensive and the rest are take your chances when buying and see how many hours before you get it to work if ever. Does that sound like any way to sell a lot of anything here?


2346  Using Arduino / Audio / Re: Arduino library for WTV020-SD-16P audio module on: May 13, 2013, 10:55:42 pm
Welcome and you are clear to go. Just be careful about the micro SD card you are using. Got a lot of pain in the b... figuring out why mine did not work from the start.

I hope you share on that later in this thread!
Learning traps to avoid after stepping in so many is why I read so many posts!
2347  Using Arduino / Programming Questions / Re: Averaging analog inputs without delay() help needed on: May 13, 2013, 10:30:25 pm
Code:
   int BatFadeRead = 50;                              //Number of readings to average
    int BA(0);                                         //BA = battery average
    for (int i = 0; i< BatFadeRead; i++) BA += BatFade;

That for loop might as well be:
Code:
   BA += BatFade * BatFadeRead;

I don't see where in that code 50 readings are averaged at all.
There are statistics methods that let you keep one running value that each new data point changes but it's been so long ago for me that I can only remember squares being involved.


You can save a bit on parts like this:
Code:
     if (Photodiode > 25)                             //Display Vent LED status in Serial Monitor
        Serial.println("Vent LEDs are ON");
      else
        Serial.println("Vent LEDs are OFF");

by doing like this:
Code:
     Serial.println("Vent LEDs are ");
      if (Photodiode > 25)                             //Display Vent LED status in Serial Monitor
        Serial.println("ON");
      else
        Serial.println("OFF");

Go over conditions and often you will find prints or commands that are common and can be moved above or below the block they are in. Just checking your code over and working out what can and can't be done and how will not only get you to improve your code but your own code skills as well.
The more aggressive you get with your code, the tighter it will get and the better you will do next time, etc. I've seen Comp-Sci Masters (as in degree holders) that hadn't learned that lesson and High School students that had... back in the 80's! It's a crazy world.

Quote
GoForSmoke, Thanks for your input on that too. I'm actually incorporating most of that code you posted into a different project and it is proving to be very helpful!

I hope you like the state machine and see how simple one can be. If need be you can run code on several state variables but take care that they don't step on each other.

For responsive code you want to make sure that loop() runs fast, always. One thing you do in this sketch is an analog read every time through loop. Analog read takes about 105 millis (edit: MICROS, but still 100 micros is a good while in AVR-land) which in itself isn't much but -do- you need to check the battery that often?

Quote
Edit: Anyone have any ideas why this thread has a crazy amount of views? Glitch? I cant see there really being that many views.

There's been some forum admin work going on. OTOH maybe a lot of people are interested but don't have much to say that hasn't been said. The thread title is interesting in itself.
2348  Using Arduino / Project Guidance / Re: Using Tx and Rx ports with several modules on: May 13, 2013, 10:01:38 pm
Does the tractor have a fuse box?
2349  Community / Website and Forum / If you see this screen again, report it to an administrator. on: May 13, 2013, 07:31:29 pm
Got that database error twice when trying to list replies.

I hope this is where I should report, I dunno where else.

2350  Using Arduino / Programming Questions / Re: Averaging analog inputs without delay() help needed on: May 12, 2013, 11:47:45 pm
If you look in the code I gave you, case 3 uses the blink without delay time check to control the led ON time.

2351  Using Arduino / Programming Questions / Re: Programming question on: May 12, 2013, 12:58:06 pm
As Peter writes, +1.

Until you work through things like this a few times it is not easy.
But until you work through a few of these types of thing you will never gain the skills to tackle the real big or hard things at all, or even other not big or not really hard things like this either. 

2352  Using Arduino / Programming Questions / Re: Removing delay and averaging analog input help needed on: May 12, 2013, 12:50:14 pm
Thanks for the reply!
Unfortunately, that code still uses the delay function and I'm really trying to steer away from that if possible.

If that is in response to what I posted then you have a reading or attention problem.
The only time the word delay appears there is in a commented out line.
It certainly does NOT use delay.

2353  Using Arduino / Programming Questions / Re: Programming question on: May 11, 2013, 06:53:42 pm
Quote
Message layout:
   '
   ' Byte 1: Flag byte:&h00
   ' Byte 2: Address: 1-255; address zero forbidden!
   ' Byte 3: Command: Bit 3 always "1": CCCC.1SHL (CCCC= command, H&L = original databits from Data low/high , S=sign of the Data )
   ' Byte 4: Data Low: &h00-&hFF;  bit0 always 1 : XXXX.XXX1 -> XXXX.XXXL. The H and L bits are save in byte3 and forced to "1"
   ' Byte 5: Data High:&h00-&hFF: bit1 always 1 : XXXX.XX1X -> XXXX.XXHX
   ' Byte 6: End byte:&hFF

Byte 3 bits CCCC1SHL is shown high to low bits. CCCC is command, S is sign.
Byte 3 bit 0 is the 0 bit of the byte 4 data that in byte 4 is replaced with 1.
Byte 3 bit 1 is the 1 bit of the byte 5 data that in byte 5 is replaced with 1.

Byte 4 is the data low byte with bit 0 set to 1. Use this to check the transmitted data.

Byte 5 is the data high byte with bit 1 set to 1. Use this to check the transmitted data.
 
Byte 6 is all bits set, 255, 0xFF .... use this to check the transmitted data.

As has been noted here before: serial transmission has no guarantees.


2354  Using Arduino / Programming Questions / Re: Input from Keyboard on: May 11, 2013, 06:34:07 pm
Example code that doesn't check for, expect or handle input errors. When have I seen that before?

But then the String-happy communication examples are like a big "don't bother" sign anyway.




2355  Using Arduino / Programming Questions / Re: Bluetooth library on: May 11, 2013, 06:17:47 pm
It's not a strange China fail. It's a you fail. Simple serial connections have >always< swapped RX and TX... that's how they work whether TTL or RS-232. It lets both ends be the same.

Chip 1 sends on chip 1 TX and chip 2 receives on chip 2 RX. Transmit on TX, read on RX. Works. 

Consider serial between the 328P and the USB chip on the Arduino as just such a connection, because it is. RX to TX and TX to RX. Then you go add another connect, a third end. You can wire it up but if the BT and the USB chip both try and send to the Arduino at the same time the Arduino RX will get garbage.

SoftwareSerial is EASY to use. Include the library, make a SoftwareSerial object (like the example code shows) and code the same as you would for Serial except with the object name instead of 'Serial' (again with the example code). Wire the BT to the SoftwareSerial pins and tada you can communicate with the PC and the BT separately at the same time.
Pages: 1 ... 155 156 [157] 158 159 ... 361