Show Posts
Pages: 1 ... 52 53 [54] 55 56 ... 115
796  Using Arduino / Programming Questions / Re: SOftware RESET for arduino Demilanove on: January 16, 2013, 10:14:43 am
Simplest way to do it:
Code:
void systemReset(void){
  WDTCR = _BV(WDCE) | _BV(WDE);
 
  WDTCR = _BV(WDE);
  while(1); //will reset in 16ms
}

More complex way (requires I/O pin):

Code:
void setup(void){
  digitalWrite(someIO,HIGH); //enable pullup-resistor
  pinMode(someIO,OUTPUT); //THEN set to output, by doing so, pin is already high when switching to output meaning reset is not tripped.
}

void systemReset(void){
  digitalWrite(someIO,LOW);
  while(1);
}
Just connect one of the Arduino digital pins to the reset pin, and then replace 'someIO' with the number for the pin you chose.
797  Using Arduino / Microcontrollers / Re: Advantages of Arduino Uno over PIC18F4550 on: January 16, 2013, 09:47:31 am
C++ and AVR-GCC.

There is free a C compiler for PIC18 but it doesn't do any sort of optimisation and it is very strict in how it likes you to write code - if you want a compiler which optimises the code you have to pay Microchip many hundreds of pounds. The one thing I have found when working with PICs is that there software is so intermittent in whether or not it works.

The AVR also has better (well more useful) hardware timers (PWM, counters, interrupts etc).
798  Using Arduino / Displays / Re: SOLVED - unable to make it work 1.8 SPI TFT 128x160 on: January 16, 2013, 07:26:53 am
Don't forget that

MOSI > MISO
MISO > MOSI

One devices OUT is another devices IN.


No...

MOSI -> MOSI
MISO -> MISO

MOSI = "Master OUT, Slave IN"
MISO = "Master IN, Slave OUT"

The Slave devices IN pin, connects to the Master devices OUT pin, so the Slave MOSI and Master MOSI must be connected.

This is not UART, its SPI, where data moves around in a loop containing shift registers.
799  Using Arduino / Microcontrollers / Re: Reset pin on attiny85 on: January 14, 2013, 12:04:40 pm
Unless you use a bootloader.

I have had success with an Attiny84 using its internal oscillator with my customised version of optiboot installed on it, and then disabling its reset pin. I can then use UART to upload new programs.

The process should work for the Attiny85 also.

If you download this core:
https://github.com/TCWORLD/ATTinyCore/

Then in the IDE, select "Optiboot Attiny85 @8MHz", and then using ISP, burn the bootloader using the IDE.

Then connect the attiny to a serial port (you can use an arduino board with its processor removed). PB1 is the Tiny RX pin, PB0 is the Tiny TX pin.

If you open the serial monitor at 9600 board, then unplug power for the Attiny and reconnect it again (to reset it), it should print stuff to the serial monitor. If you can't read it dont worry, just keep sending the letter 'x' (lower case) with no line ending. Each time it will print something to the serial monitor. Eventually (maybe 10 to 15 times of sending 'x') it will stop printing stuff. At this point the bootloader is ready and the internal oscillator is calibrated.

You should then be able to upload sketches via the serial port. Once you have confirmed that you can do that, you will need to use avrdude to set the fuses to disable the reset pin making sure not to erase the chip.
800  Development / Other Software Development / Re: Library for Nokia LCD (128x128) on: January 13, 2013, 06:32:15 am
The latest version, V3.3 adds support for rotating the screen 90,180, and 270 degrees (anticlockwise) to allow your nokia display to be mounted in any direction and have the screen the correct way up.
There is also now support for character wrapping, whereby if a string is too long for the screen, it is automatically wrapped onto a new line.
https://github.com/TCWORLD/gLCD-Library
801  Using Arduino / Microcontrollers / Re: stk500_getsync() not in sync resp=0x00 error for arduino uno breadboard on: January 11, 2013, 06:41:26 am
No, the OP was correct in connecting TX->TX and RX->RX. The recieve pin on the Arduino board is labelled with reference to the Atmega chip (So arduino RX=USB-TX). In order to use the onboard USB-Serial chip, you need to make sure the same is the case for the breadboard chip.

OP: Did you remove the Atmega chip from the Arduino when you were using it as a USB-Serial converter?
802  Using Arduino / Displays / Re: Nokia LCD display shield question on: January 10, 2013, 01:17:17 pm
I have now added the ability to rotate the screen either 0, 90, 180 or 270 degrees clockwise. (as of Version 3.4).

It should be noted that doing so reduces the performance of the display in any mode other than 0degrees because the coordinates have to be remapped before being send to the screen.
The impact is mostly confined to text and drawing lines.
Filling areas such as with Clear() or Box() doesn't require remapping so is unaffected.

https://github.com/TCWORLD/gLCD-Library/tree/master/Downloads
803  Using Arduino / Programming Questions / Re: Array of functions (addressing multiple identical sensors) on: January 10, 2013, 06:27:59 am

I've come up with the following, which compiles. Not sure if this is the right way to go, or if it's garbage.
Code:

  Serial.begin(9600);
  for (int i=0; i<(maxDHT-1); i++) {
    Serial.print(i), Serial.print("\n");
    DHT aDHT(i, 11); //define a new DHT at pin i with type 11;
    myDHT[i]=&aDHT; // store pointer to aDHT in array myDHT at index i
  };


The problem with that code is that the aDHT instances go out of scope at the end of the for loop and so the array of pointers will become invalid.
804  Using Arduino / Programming Questions / Re: Array of functions (addressing multiple identical sensors) on: January 10, 2013, 06:17:05 am
You could always try this:
Code:
DHT myDHT[MaxSensors] = {DHT(0, 11),DHT(1, 11),DHT(2, 11),DHT(3, 11),DHT(4, 11)};

EDIT: Sorry, those should have been in Capitals, fixed now.
805  Using Arduino / Programming Questions / Re: Algorithm to rotate data on: January 09, 2013, 02:08:01 pm
Same code again, but working bitwise rather than element wise.

Code:
void setup() {
  // put your setup code here, to run once:
  byte array[8] = { 0b00010000,
                    0b00101000,
                    0b01000100,
                    0b11111110,
                    0b10000010,
                    0b10000010,
                    0b10000010,
                    0b00000000 };
  byte rotatedArray[8] = {0};
  /*
  //rotate 90* anti-clockwise
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      char newI = 7-j;
      char newJ = i;
      byte value = ((array[i] >> j) & 1); //extract the j-th bit of the i-th element
      rotatedArray[newI] |= (value << newJ); //set the newJ-th bit of the newI-th element
    }
  }
  */
  //rotate 90* clockwise
  for (char i = 0; i < 8; i++){
    for (char j = 0; j < 8; j++){
      char newI = j;
      char newJ = 7-i;
      byte value = ((array[i] >> j) & 1); //extract the j-th bit of the i-th element
      rotatedArray[newI] |= (value << newJ); //set the newJ-th bit of the newI-th element
    }
  }
 
 
 
  //It should now be reversed. Quick log to check.
  Serial.begin(115200);
  Serial.println("In");
  for (char i = 0; i < 8; i++){
    for (char j = 0; j < 8; j++){
      Serial.print(((array[i]>>j)&1)?'1':'0');
      Serial.print(' ');
    }
    Serial.println();
  }
  Serial.println();
  Serial.println("Out");
  for (char i = 0; i < 8; i++){
    for (char j = 0; j < 8; j++){
      Serial.print(((rotatedArray[i]>>j)&1)?'1':'0');
      Serial.print(' ');
    }
    Serial.println();
  }
}

void loop() {
  // put your main code here, to run repeatedly:
 
}
806  Using Arduino / Microcontrollers / Re: stk500_getsync() not in sync resp=0x00 error for arduino uno breadboard on: January 09, 2013, 11:51:05 am
If it already has optiboot, you don't need to burn the bootloader, they should just work via UART.

How were you wiring them up to the computer?
807  Using Arduino / Programming Questions / Re: Algorithm to rotate data on: January 09, 2013, 11:45:18 am
After a little bit of playing around with how coordinates map, it is really rather simple:
Code:
void setup() {
  // put your setup code here, to run once:
  const char maxSize = 4; //must be a multiple of 2, e.g. 2,4,6,8
  char array[maxSize][maxSize] = {{'A','B','C','D'},{'E','F','G','H'},{'I','J','K','L'},{'M','N','O','P'}};
  char rotatedArray[maxSize][maxSize];
  /*
  //rotate 90* anti-clockwise
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      char newI = maxSize-1-j;
      char newJ = i;
      rotatedArray[newI][newJ] = array[i][j];
    }
  }
  */
  //rotate 90* clockwise
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      char newI = j;
      char newJ = maxSize-1-i;
      rotatedArray[newI][newJ] = array[i][j];
    }
  }
  
  //It should now be reversed.
  Serial.begin(115200);
  Serial.println("In");
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      Serial.print(array[i][j]);
      Serial.print(' ');
    }
    Serial.println();
  }
  Serial.println();
  Serial.println("Out");
  for (char i = 0; i < maxSize; i++){
    for (char j = 0; j < maxSize; j++){
      Serial.print(rotatedArray[i][j]);
      Serial.print(' ');
    }
    Serial.println();
  }
}

void loop() {
  // put your main code here, to run repeatedly:
  
}
Result:
Code:
In
A B C D
E F G H
I J K L
M N O P

Out
M I E A
N J F B
O K G C
P L H D
808  Using Arduino / Programming Questions / Re: Algorithm to rotate data on: January 09, 2013, 10:03:56 am
One approach would be the following:

1) Map each ring into a line starting at the top left and working clockwise. So:
A B C D
E F G H
I J K L
M N O P
Becomes:
outer ring: ABCDHLPONMIE. Ring size = 4
inner ring: FGKJ. Ring size = 2

2) move the last 'ring size - 1' characters to the beginning of a new array
ABCDHLPON  MIE //extract the last 3 as ring size = 4
-> MIE //new array

FGK  J //extract the last 1 as ring size = 2
-> J //new array

3) concatenate the rest:
MIE  ABCDHLPON
J   FGK

4) shift each line back into a ring (inverse of step 1)
M I E A
N J F B
O K G C
P L H D



As for realising it in code, the difficult bit is going to be extracting each ring. But it is doable. If you design a function to extract a ring of a specified size, then you could call that same function for each of the rings in turn, and it could be scaled up to 8x8 easily that way. It would be also sensible to have the function be able to do the inverse to put the lines back into the ring which would be the same code as extracting them only moving flipping destination and source.
I'll write a few lines of code as a possible hint.
809  Using Arduino / Programming Questions / Re: Help with C++ Serial Port Interface with Arduino on: January 09, 2013, 07:48:40 am
You need to create an instance of Serial in order to call non-static functions.
Code:
Serial mySerial = Serial("COM4"); //Create a serial object.

void main() {
  Bool connected = mySerial.IsConnected();
}


This line works because you are calling a constructor function which is by definition static (it creates an instance of a class, so it doesn't require an instance to call it):
Code:
Serial::Serial("COM4");


'static' functions are also known as class methods. These functions do not require any of the instance variables of the class and so can be called directly.

None static functions are known as instance methods. These require instance variables (for example the line "this->connected" accesses the 'connected' variable declared in the class), which means you have to create an instance of the class in memory in order for the function to know where 'connected' is stored in the memory. The 'this' pointer is the memory address of the current instance.
810  Using Arduino / Displays / Re: Very cheap LCD with spongy thing, how's it work? on: January 08, 2013, 06:50:21 pm
The spongey thing is known as an "Elastomeric connector", and is made up of lots of essentially conductive lines. What that means is that if you compress it slightly and have it oriented correctly, it will only conduct in one direction.
By having a long line of the stuff, you can connect multiple pcb pads to multiple non-solderable traces on a display such as the one you have. Each pad will connect to any pad on the display directly above it in the direction of the conductive material, but not to the adjacent pads as it won't conduct in that direction.

The display does have pads on it, but they are made of a transparent conductive material. I have found that it is possible to use conductive glue to attach wires to the displays rather than using the 'sponge'. You just have to be very careful with the quantity of glue you use and keeping the wires in alignment with the traces on the display.

Here is a good reference, with a picture of what the sponge looks like diagramatically:
http://www.fujipoly.com/products/zebra-elastomeric-connectors.html
Pages: 1 ... 52 53 [54] 55 56 ... 115