Show Posts
Pages: [1]
1  Development / Other Software Development / Re: Software SPI library for Arduino Mega 2560 on: December 05, 2011, 07:19:59 pm
Quote
As CR said bit bashed SPI is just shiftIn/Out, is there a special reason to do another version? Like you need 11 bits or something.

The lib I attached is for 12 bit data and 2 dummy bits, so yea, this is why.
2  Development / Other Software Development / Re: Software SPI library for Arduino Mega 2560 on: December 05, 2011, 04:34:02 am
It's fairly easy to bit bash it.

See attached example of a library that bit bashes the SPI.

The biggest problem is that its speed limited by the arduino clock speed. If you have a hardware SPI you can get it to go much faster.

You will need to read the datasheet for whatever you are interfacing to so that you know how to implement the SPI mode needed.

Hope it helps.
3  Development / Other Software Development / Re: Arduino-1.0 Serial.flush() on: December 05, 2011, 12:50:32 am
And on this, it would seem there was no discussion on this topic in the google code project

See here
http://code.google.com/p/arduino/issues/detail?id=593&can=1&q=serial.flush

and here
http://code.google.com/p/arduino/issues/detail?id=497&can=1&q=flush

Poll time.
4  Development / Other Software Development / Re: Arduino-1.0 Serial.flush() on: December 04, 2011, 10:19:55 pm
Quote
I completely fail to see how this change makes anything slower.
this
_rx_buffer->head = _rx_buffer->tail;
takes just a couple of cycles (or less)

this however
while(Serial.available()>0){Serial.read();}
Could take upto (n? cycles) x (the size of the buffer)

Its slow in the context that accomplishing something very simple, as a user takes more cycles now, depending on how full the buffer is, than it did before.

Quote
You say it is valid and then propose a completely invalid situation.  If you really feel the need to flush the serial buffer so that you only see the "response" you are interested in, you have to write your own flush method anyway.  You would need to flush everything except for tokens that you want to see.
How is it invalid? what rubbish. IMO, it's totally valid. I can point you at a whole hand full of modules that fill the serial buffer with unnecessary information that you either have to parse, or dump. Just dumping it is totally valid!

Quote
If on the other hand you want to just dump whatever is in the Serial Receive buffer, a simple for loop will do that.
SLOW.

Quote
Re-purposing flush to the transmit makes sense now that the transmit buffer is asynchronous.
Maybe to you, and other participants at a developer level - but that's also not likely the majority of users out there....

Arduino is mean't to be eeeeasy for the users.
This change has also perhaps gone and broken a whole bunch of libraries...

This Improvement comes at the sacrifice of something else completely unnecessarily!

5  Development / Other Software Development / Re: Arduino-1.0 Serial.flush() on: December 04, 2011, 04:51:07 pm
Quote
First, the buffer size if only 128 bytes. It wouldn't take that long to read and discard the entire buffer.
It's just poor design to let it be done this way. Ultimately, it's these kind of compromises that will make Arduino get even slower than it already is.
Don't get me wrong, I <3 Arduino. smiley-mr-green smiley-mr-green smiley-mr-green

Quote
Second, there are very few legitimate uses of the flush function.
At a user sketch level its totally valid. If you have a particularly verbose module, it can be constant spewing stuff into the serial port. If you are only interested in query-response, then you would want to be able to flush the serial buffer.
6  Development / Other Software Development / Re: Arduino-1.0 Serial.flush() on: December 01, 2011, 09:06:51 pm
Quote
If there is no serial data, there is nothing to do, so the while loop doesn't get executed. How can you possibly get stuck? Neither Serial.available() or Serial.read() are blocking functions.

Noted. You are right. But that bit of code is still a crummy solution.
7  Development / Other Software Development / Arduino-1.0 Serial.flush() on: December 01, 2011, 05:56:45 pm
Soooo,

Serial.flush()

As detailed in the Arduino 1.0 release notes;
* Serial transmission is now asynchronous - that is, calls to
  Serial.print(), etc. add data to an outgoing buffer which is transmitted
  in the background. Also, the Serial.flush() command has been repurposed
  to wait for outgoing data to be transmitted, rather than dropping
  received incoming data.


This seems really dumb. If one were to make a new function, IT SHOULD HAVE A DIFFERENT NAME! why sacrifice this existing function, to add another one? It's basically ridiculous this change got passed.

It would be of no consequence to have this new function called something like Serial.WaitForTx();


It's simple to resolve this with the standard API calls but here is a slow and dirty method, and frankly unreliable because you can get stuck here!

while(Serial.available()>0)
{
  Serial.read();
}

Or, for those of you a little more enthusiastic, you can modify the Arduino source back to how it used to be!
Open
\arduino-1.0\hardware\arduino\cores\arduino

Add this to HardwareSerial.h within the class definition
virtual void Iflush(void);

Add this to function to HardwareSerial.cpp in the body
void HardwareSerial::Iflush()
{
  _rx_buffer->head = _rx_buffer->tail;
}

Save files and recompile - you can now use Iflush in place of what used to be flush.
Tested and working fine.
8  Using Arduino / Sensors / Re: Parallax RFID Read/Write Module 28440 on: March 29, 2011, 04:24:09 pm
Quote
In UberDude's code above (1st post), he shows the serial number of 2 of the tags he was using (they're commented out) 0800E28C60 and 0800D9E43E.  Both of these serial numbers have 10 digits (5 Bytes) but he is only reading 4 bytes with the code, and the .PDF on the tag states that the tag's serial number is 32 bit (4 bytes).

Fair enough to say, a legacy read gets you the serial number of a legacy tag
header+10 bytes(40 bits)+footer

So if you were using legacy tags, you would need to code for it.

A read of a read/write tag gets you a the data from the specified address (1-33)
status + 4 bytes(32 bits)

Each of the 33 data locations has 4 bytes!
Of these locations, 3-31 are writable!

So you need to write to a tag, before you will see anything meaningful

the status codes all not explicitly mentioned anywhere in the datasheet, are in the stamp example code.
http://www.parallax.com/Portals/0/Downloads/docs/prod/rf/28440-RFIDReadWrite-v1.0.pdf
Page 10 at the top

ERR_OK                   0x01   ' No errors
ERR_LIW                 0x02   ' Did not find a listen window
ERR_NAK                 0x03   ' Received a NAK, could be invalid command
ERR_NAK_OLDPW    0x04   ' Received a NAK sending old password (RFID_SetPass), could be incorrect password
ERR_NAK_NEWPW   0x05   ' Received a NAK sending new password (RFID_SetPass)
ERR_LIW_NEWPW    0x06   ' Did not find a listen window after sending old password (RFID_SetPass)
ERR_PARITY             0x07   ' Parity error when reading data
9  Using Arduino / Sensors / Parallax RFID - Serial Sample code on: March 29, 2011, 07:15:43 am
Hi,

Just thought I'd contribute for once.

I just got one of these
http://www.parallax.com/Store/Microcontrollers/BASICStampModules/tabid/134/txtSearch/28140/List/1/ProductID/114/Default.aspx?SortField=ProductName%2cProductName

I'm making an RFID cat door using a Demilanove with a 328.

The code provided lets you add new tags using a 'Master Tag'. So the idea is you come along, swipe the master tag, and after the door unlocks for 10 seconds, the next tag you swipe within a 10 second period will be stored to the eeprom.

The stored tag will now have access to the door!

The master tag is hardcoded.

If you hold the master tag in front of the reader for 3 cycles (30~40 seconds) it will clear the stored memory of tags.

Enjoy.

Code:
#include <EEPROM.h>
#include <stdlib.h>
#include <NewSoftSerial.h>

int outEnable = 4; // Output enable for RFID

NewSoftSerial Rfid(2,3); 

char inByte = 0;     // incoming serial byte for 'Serial' ports
int i; // pointer for manipulating strings
int j; // pointer for manipulating strings

const char CR = 0x0D; // For GSM module
const char LF = 0x0A;

int unlockTimeout = 0;
int masterReset = 0;
int numberOfTagIDs = 0;

char foundTag[11];
char compareTag[11];
char masterTag[11] = "3D00213579";
const int sizeTag = sizeof(foundTag);

//********************************************************************//
// EEPROM address Table
const int NUM_TAG_IDS = 1;
const int TAG_START = 2;
//********************************************************************//
// Status Codes
bool MASTER_UNLOCK = false;
bool DOOR_UNLOCK = false;
bool TAG_STORE = false;
//********************************************************************//
// Initialisation... things that only happen on startup and reset
void setup()
{
// set the output enable for the RFID reader
pinMode(outEnable, OUTPUT);

// start serial at 115200 kbs
Serial.begin(115200);  

// start rfid serial at 2400 kbs
Rfid.begin(2400);

// Get the number of ID's in the table
if (EEPROM.read(NUM_TAG_IDS)!=numberOfTagIDs){
numberOfTagIDs=EEPROM.read(NUM_TAG_IDS);
}

Serial.println("HELLO!");
Serial.println();

if (numberOfTagIDs>0){
Serial.print("TAG LIST:");
Serial.print(numberOfTagIDs);
Serial.println(" Entries");
for (j=0; j<(numberOfTagIDs); j++){
for(i=0; i<(sizeTag-1); i++){
Serial.print(EEPROM.read((TAG_START+i+j*(sizeTag))));
}
Serial.println();
}
Serial.println();
}

digitalWrite(outEnable, LOW); // set output enable for RFID reader

}
//********************************************************************//
// Main loop...
//********************************************************************//
void loop()
{

if (MASTER_UNLOCK == true){ // gives us 10 seconds in which to add
delay(1000); // a new tag
unlockTimeout-=1; // decrement the time out counter
masterReset = 0; // clear the masterReset counter
if(unlockTimeout==0){
MASTER_UNLOCK=false;
Serial.println("New Tag Timeout");
Serial.println();
}
}

if (Rfid.available()>11){ // wait till there is enough data to process
if (getbyteRfid()==LF){ // check this is the start of a tag ID
// If so, get the tag data
for (i=0; i<(sizeTag-1); i++){
foundTag[i]=getbyteRfid();
}

if(getbyteRfid()!=CR){
Serial.println("Error reading Tag");
Serial.println();
}
else{
Serial.println("Found a Tag!");
if (MASTER_UNLOCK == true){
if(strcmp (foundTag,masterTag) != 0){
TAG_STORE = true;
MASTER_UNLOCK = false; // 1 key added, so thats it!
unlockTimeout = 0; // clear the timeout
masterReset = 0; // reset the master reset counter
Rfid.flush(); // clean up
}
else if(strcmp (foundTag,masterTag) == 0){
Serial.println("oooooH the Master Tag!");
unlockTimeout = 10; // reset the timeout
masterReset+=1;
Rfid.flush(); // clean up
DOOR_UNLOCK = true; // this gives us indicated of each cycle
// If we see the master tag 3 times in a row, we wipe the memory...
// sort of...
if (masterReset>=2){
Serial.println("SELFDESTRUCT INITIATED!");
EEPROM.write(NUM_TAG_IDS,0);
masterReset = 0;
MASTER_UNLOCK = false; // no more master stuff
}
}
}
else if(strcmp (foundTag,masterTag) == 0){
Serial.println("oooooH the Master Tag!");
Rfid.flush(); // clean up
MASTER_UNLOCK = true; // we can add a new tag now
DOOR_UNLOCK = true; // also unlock it for me
unlockTimeout = 10;
}
else{
Serial.println(foundTag);
if(searchFoundTag((char*)foundTag,(char*)compareTag)){
Serial.println("Tag is registered");
DOOR_UNLOCK = true;
}
else{
Serial.println("Unknown Tag");
DOOR_UNLOCK = false;
}
}
Serial.println();
}
}
}

if (DOOR_UNLOCK == true){
Serial.println("Unlock the Door");
delay(10000); // wait 10 seconds,
Rfid.flush(); // clean up
DOOR_UNLOCK = false; // door locked now
Serial.println("Lock the Door");
Serial.println();
}

if (TAG_STORE == true){
Serial.print("Storing the Tag...");
if(storeFoundTag((char*)foundTag,(char*)compareTag)){
Serial.println("Success!");
Serial.println();
}
TAG_STORE = false;
}

}
//********************************************************************//
// Function to search the eeprom for the foundTag ID
//********************************************************************//
bool searchFoundTag(char *target, char *compare){

if (numberOfTagIDs>0){
for (j=0; j<(numberOfTagIDs); j++){
for(i=0; i<(sizeTag); i++){
compare[i]=(EEPROM.read((TAG_START+i+j*(sizeTag))));
}
if (strcmp (target,compare) == 0){
return true;
}
}
}
return false;
}

//********************************************************************//
// Function to search the eeprom for the foundTag ID
//********************************************************************//
bool storeFoundTag(char *target, char *compare){

if (numberOfTagIDs>45){ // if we run out of space, no more storage...
// Anything but a Mega basically...
return false;
}

if(!searchFoundTag((char*)target,(char*)compare)){ // check if its already there
// store the tag
for(int i=0; i<(sizeTag); i++){
EEPROM.write((TAG_START+i+numberOfTagIDs*(sizeTag)),target[i]);
}
// check it was stored correctly
for(int i=0; i<(sizeTag); i++){
compare[i]=EEPROM.read((TAG_START+i+numberOfTagIDs*(sizeTag)));
}
// update the number of tags we have
if(strcmp(target,compare) == 0){
numberOfTagIDs+=1;
EEPROM.write(NUM_TAG_IDS,numberOfTagIDs);
return true;
}
else{
// report the problem
return false;
}
}
else{
// we already have it
Serial.print("have it...");
return true;
}
}
//********************************************************************//
// function to grab serial characters, forces us to wait untill more
// data arrives...
//********************************************************************//
char getbyteSerial(){

while (Serial.available() == 0) {
}
return Serial.read();
}
char getbyteRfid(){

while (Rfid.available() == 0) {
}
return Rfid.read();
}
10  Forum 2005-2010 (read only) / Troubleshooting / Re: Unable to use AVRISP MKII to burn bootloader on: December 15, 2010, 04:34:16 pm
Tried installing the libusb drivers clean to no avail.
I'm using on 64bit Win 7, but its has 'lots' of crap on it...

Tried in on a (media PC) 32bit Win 7 machine and it worked fine...

When I toast one this ill try it clean (i.e. no history of AVR Studio, or other dev tools) and it should determine if there is some issue with the 64bit os.

Will post back.
11  Forum 2005-2010 (read only) / Troubleshooting / Re: Unable to use AVRISP MKII to burn bootloader on: December 15, 2010, 04:47:24 am
*Bump*

What is the solution to this!
I've got a custom mega1280 compatible board and want to program with the arduino IDE and a AVRISP mkII

Its all well and good to install AVR Studio, but what the hell is the issue with the arduino IDE?

most the jungo driver be installed?

is the lib usb driver the one here:
..\arduino-0021\hardware\tools\avr\utils\libusb\bin

is there an OS compatibility issue?

i get this message no matter what i try...
avrdude: usbdev_open(): did not find any USB device "usb"
12  Forum 2005-2010 (read only) / Development / Re: Hand solder-able LUFA compatible chip? on: October 10, 2010, 06:51:42 am
8/16/32U2 only come in QFN and TQFP

Get the TQFP
http://parts.digikey.com/1/parts/1846461-mcu-avr-8k-flash-16mhz-32tqfp-atmega8u2-au.html

Then you could get a 32pin TQFP to DIP adapter but you will need to solder the part onto the PCB...  There are lots of different ones here, they are on the expensive side, I'm sure you will find cheaper somewhere on the net, This kind of part only costs $0.3ea to produce in volume, so keep this in mind...
http://www.epboard.com/eproducts/protoadapter1.htm

When you order, better get a 1 spare of the PCB and uC unless your comfortable with fine pitch soldering like this

When you are going to solder to the pcb, get a really fine tip for your soldering iron, really thin gauge solder, and start by tacking down pin1, and then pin17 to get it straight. Once lined up, then solder all the other pins and check for shorts before firing up.

or,
if you've got money and no time
http://parts.digikey.com/1/parts/409179-socket-adapter-tqfp32-sa636.html
13  Forum 2005-2010 (read only) / Development / ArduinoBT with Atmega328 on: October 07, 2010, 12:00:03 am
Hi,

Not sure if I have missed this somewhere, I have searched the forum and release notes for details but no luck, So,

In the latest release of the Arduino IDE it seems there is a board option for the BT with an Atmega328.

I have an application where I need more ram so I if I can use a 328 then this is good news... ;D

So, can anyone confirm if i switch out the 168 with a 328 that it will work? I am guessing yes, otherwise this would not be in there...

I know that I need to reprogram the bootloader over the ISP, but otherwise will the IDE handle the transplant?

Cheers,
Steve.
14  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Recommendations for next iteration of Arduino on: October 10, 2010, 08:24:06 pm
could always put on one of each... or possibly put down the second SMT footprint but don't populate in production - only there for those who really want it

truth be told, where I work we are sticking with the standard B connector because it truly is a robust connector in all aspects...
15  Forum 2005-2010 (read only) / Bugs & Suggestions / Re: Recommendations for next iteration of Arduino on: October 10, 2010, 06:32:25 am
Micro OTG B would be best if looking to converge onto a connector type. This connector is the becoming standard for mobiles.  The main difference between the micro and mini is for lowest profile, i.e. as needed in mobiles.

Regarding the comment about reliability, its my experience that the SMT connectors are unreliable where they solder to the PCB.
This is especially the case with USB seeing as they are unplugged and plugged in again, and again, and again!

So, my top pick would be a Through hole Micro (less preferably Mini) OTG B connector.
Pages: [1]