embeded/AVR (ATmega,ATtiny)2015. 7. 28. 14:40

ㄷㄷㄷ 한번 돌려볼까?


Can I use C++ on the AVR?

Basically yes, C++ is supported (assuming your compiler has been configured and compiled to support it, of course). Source files ending in .cc, .cpp or .C will automatically cause the compiler frontend to invoke the C++ compiler. Alternatively, the C++ compiler could be explicitly called by the name avr-c++.

However, there's currently no support for libstdc++, the standard support library needed for a complete C++ implementation. This imposes a number of restrictions on the C++ programs that can be compiled. Among them are:

Obviously, none of the C++ related standard functions, classes, and template classes are available.

The operators new and delete are not implemented, attempting to use them will cause the linker to complain about undefined external references. (This could perhaps be fixed.)

Some of the supplied include files are not C++ safe, i. e. they need to be wrapped into

extern"C" { . . . } 

(This could certainly be fixed, too.)

Exceptions are not supported. Since exceptions are enabled by default in the C++ frontend, they explicitly need to be turned off using -fno-exceptions in the compiler options. Failing this, the linker will complain about an undefined external reference to __gxx_personality_sj0.

Constructors and destructors are supported though, including global ones.

When programming C++ in space- and runtime-sensitive environments like microcontrollers, extra care should be taken to avoid unwanted side effects of the C++ calling conventions like implied copy constructors that could be called upon function invocation etc. These things could easily add up into a considerable amount of time and program memory wasted. Thus, casual inspection of the generated assembler code (using the -S compiler option) seems to be warranted.


[링크 : http://www.atmel.com/webdoc/AVRLibcReferenceManual/FAQ_1faq_cplusplus.html]


AVR용 STL ㄷㄷㄷ

[링크 : http://andybrown.me.uk/wk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/]

Posted by 구차니
embeded/AVR (ATmega,ATtiny)2015. 7. 19. 22:25

어드레스 맵 구조 까지 나오는 예제가 있으면 좋으련만...

그나저나 SDA, SCL에 풀업을 꼭 달으라네..


[링크 : http://electronicsdo.tistory.com/entry/I2C-The-I2C-of-ATmega128]

SCL 과 SDA 단자는 오픈 콜렉터 또는 오픈 드레인 방식으로 되어 있어 Wired-AND 기능을 합니다. 이 단자는 외부에 풀업 저항(수 K 오옴) 을 연결해 주어야 합니다.

[링크 : http://cafe.daum.net/_c21_/bbs_search_read?grpid=lH2L&fldid=GSYT&datanum=85]


SDA,SCL핀에 풀업저항을 꼭 달아줍니다.

[링크 : http://openctrl.tistory.com/entry/I2C-TWI]


자체 Pull-Up 저항은

30-50kΩ 정도로 저항치가 좀 높은 편이라서, 실제로 Data 와 Clock 라인에는

4.7kΩ 정도로 따로 Pull-Up 저항을 걸어두는 편이 좋습니다.

[링크 : http://egloos.zum.com/bellona/v/1345440]

'embeded > AVR (ATmega,ATtiny)' 카테고리의 다른 글

USART UBRR error rate  (0) 2015.07.29
avr-libc 8bit AVR C++  (0) 2015.07.28
atmega128 gpio 인터럽트 데이터시트 내용  (0) 2015.07.18
AVR Studio / AVRdude 연동  (0) 2015.03.12
AVRISP 호환 제품 ?  (0) 2015.03.11
Posted by 구차니
embeded/AVR (ATmega,ATtiny)2015. 7. 18. 22:29


PE4/PE5 는 Output Compate (OC3)

PE6은 Timer/counter 3 clk input(T3)

PE7은 Input Capture (IC)

PD쪽은.. 통신을 쓰면 4개 선을 쓰지 못하니

실질적으로 사용가능한 falling edge / rising edge 탐지는 2개 정도 일려나?


결론은.. 핀하나하나 while로 감지 하지 않으려면...

tie-up해서 잡는 수 밖에 없을 것으로 보이네..






External Interrupts

The External Interrupts are triggered by the INT7:0 pins. Observe that, if enabled, the interrupts will trigger even if the INT7:0 pins are configured as outputs. This feature provides a way of generating a software interrupt. The External Interrupts can be triggered by a falling or rising edge or a low level. This is set up as indicated in the specification for the External Interrupt Control Registers – EICRA (INT3:0) and EICRB (INT7:4). When the external interrupt is enabled and is configured as level triggered, the interrupt will trigger as long as the pin is held low. Note that recognition of falling or rising edge interrupts on INT7:4 requires the presence of an I/O clock, described in “Clock Systems and their Distribution” on page 35. Low level interrupts and the edge interrupt on INT3:0 are detected asynchronously. This implies that these interrupts can be used for waking the part also from sleep modes other than Idle mode. The I/O clock is halted in all sleep modes except Idle mode. Note that if a level triggered interrupt is used for wake-up from Power-down mode, the changed level must be held for some time to wake up the MCU. This makes the MCU less sensitive to noise. The changed level is sampled twice by the Watchdog Oscillator clock. The period of the Watchdog Oscillator is 1µs (nominal) at 5.0V and 25°C. The frequency of the Watchdog Oscillator is voltage dependent as shown in the “Electrical Characteristics” on page 318. The MCU will wake up if the input has the required level during this sampling or if it is held until the end of the start-up time. The start-up time is defined by the SUT fuses as described in “Clock Systems and their Distribution” on page 35. If the level is sampled twice by the Watchdog Oscillator clock but disappears before the end of the start-up time, the MCU will still wake up, but no interrupt will be generated. The required level must be held long enough for the MCU to complete the wake up to trigger the level interrupt.


EICRA와 EICRB는 조금 다르게 설명이 적혀있으니 자세히 읽어 봐야 할 듯..

[링크 : http://www.atmel.com/images/doc2467.pdf]

'embeded > AVR (ATmega,ATtiny)' 카테고리의 다른 글

avr-libc 8bit AVR C++  (0) 2015.07.28
avr twi / i2c 예제 및 풀업관련  (0) 2015.07.19
AVR Studio / AVRdude 연동  (0) 2015.03.12
AVRISP 호환 제품 ?  (0) 2015.03.11
SED1520 데이터시트 / Page, Line, Column  (0) 2014.03.27
Posted by 구차니
embeded/raspberry pi2015. 7. 18. 22:16

초음파 관련 루틴을 while로 처리해서

오차가 있을것으로 생각되다 보니..

인터럽트 처리방식 검색...


gpio 유틸에도 존재는 한다.

gpio edge <pin> rising/falling/both/none

This enables the given pin for edge interrupt triggering on the rising, falling or both edges. (Or none which disables it)

[링크 : http://wiringpi.com/the-gpio-utility/] 


python 버전

GPIO.add_event_detect(17, GPIO.FALLING, callback=my_callback, bouncetime=300)  GPIO.add_event_detect(23, GPIO.FALLING, callback=my_callback2, bouncetime=300)  

[링크 : http://raspi.tv/2013/how-to-use-interrupts-with-python-on-the-raspberry-pi-and-rpi-gpio-part-3] 


c 버전

void myInterrupt(void) {

   eventCounter++;

}


int main(void) {

  if (wiringPiSetup () < 0) {

      fprintf (stderr, "Unable to setup wiringPi: %s\n", strerror (errno));

      return 1;

  }


  // set Pin 17/0 generate an interrupt on high-to-low transitions

  // and attach myInterrupt() to the interrupt

  if ( wiringPiISR (BUTTON_PIN, INT_EDGE_FALLING, &myInterrupt) < 0 ) {

      fprintf (stderr, "Unable to setup ISR: %s\n", strerror (errno));

      return 1;

  }


  // display counter value every second.

  while ( 1 ) {

    printf( "%d\n", eventCounter );

    eventCounter = 0;

    delay( 1000 ); // wait 1 second

  }


  return 0;

}

[링크 : http://cs.smith.edu/dftwiki/index.php/Tutorial:_Interrupt-Driven_Event-Counter_on_the_Raspberry_Pi] 



Posted by 구차니
embeded/raspberry pi2015. 7. 17. 10:52

전에 쓴적이 있던가?

아무튼.. 지금글을 보고 있노라니..

국제화 관련 설정에서

gb가 기본값이었던거 같은데..

영국에서 만든게 왜...중국이 기본값이 된걸까?

+

2017.09.12

gb는 영국임. Great Britain



키보드 레이아웃은 집에가서 테스트 해봐야지 ..



[링크 : http://raspberrypi.stackexchange.com/questions/1042/why-is-my-symbol-not-working]


~!@#$%^&*()_+| 를 입력한 화면 확실히 먼가 이상하게 나온다.

프랑이라던가? 이.. 미묘한 기호순서라니!

XKBLAYOUT을 gb에서 us로 바꾸고

pi@raspberrypi ~ $ sudo cat /etc/default/keyboard

# KEYBOARD CONFIGURATION FILE


# Consult the keyboard(5) manual page.


XKBMODEL="pc105"

XKBLAYOUT="gb"

XKBVARIANT=""

XKBOPTIONS=""


BACKSPACE="guess" 


setupcon을 해주면 빠르게 설정이 된다는데 ssh나 터미널로는 안된다

pi@raspberrypi ~ $ sudo setupcon

We are not on the console, the console is left unconfigured. 


pi@raspberrypi ~ $ sudo service lightdm stop

ctrl -alt - f1

pi@raspberrypi ~ $ sudo setupcon


아무튼 리부팅 하고 오니

~!@#$%^&*()_+| 

원하는대로 잘 나온다.



Posted by 구차니
embeded/raspberry pi2015. 7. 13. 23:27

릴레이는 단순하게 HI/LO 입력에 따라 on/off 스위치라 별거 없으니 대충~

당연히(!) 귀차니즘으로 wiring pi 기준 1번 / GPIO18번에 연결


$ gpio mode 1 output

$ gpio write 1 1


$ gpio write 1 0



[링크 : http://www.seeedstudio.com/depot/Grove-Relay-p-769.html]

Posted by 구차니
embeded/raspberry pi2015. 7. 13. 23:14

3.3-5V 이나 5V추천

탐지거리 3cm-4m

[링크 : http://www.seeedstudio.com/depot/Grove-Ultrasonic-Ranger-p-960.html]


다른 소스들의 예제와 다르게 이녀석...

Trigger / Echo가 아닌 Signal 하나 뿐이다


그래서 Trigger로 output 모드 설정후 전송하고 재빠르게

Echo로 input 모드로 설정후 받아 시간을 재도록 수정해야 한다.


포트는 만만한(?) GPIO18번 PWM 포트(wiring pi 기준 1번)으로 설정

흰색 - 5V

검정 - GND

보라 - GPIO18 ->A0




$ cat ultrasonic_1.py

#!/usr/bin/python

#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

#|R|a|s|p|b|e|r|r|y|P|i|-|S|p|y|.|c|o|.|u|k|

#+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

#

# ultrasonic_1.py

# Measure distance using an ultrasonic module

#

# Author : Matt Hawkins

# Date   : 09/01/2013

# -----------------------


# Import required Python libraries

import time

import RPi.GPIO as GPIO


# Use BCM GPIO references

# instead of physical pin numbers

GPIO.setmode(GPIO.BCM)


# Define GPIO to use on Pi

GPIO_TRIGGER = 18

GPIO_ECHO    = 18


print "Ultrasonic Measurement"


# Set pins as output and input

GPIO.setup(GPIO_TRIGGER,GPIO.OUT)  # Trigger


# Set trigger to False (Low)

GPIO.output(GPIO_TRIGGER, False)


# Allow module to settle

time.sleep(0.5)


# Send 10us pulse to trigger

GPIO.output(GPIO_TRIGGER, True)

time.sleep(0.00001)

GPIO.output(GPIO_TRIGGER, False)

start = time.time()


GPIO.setup(GPIO_ECHO,GPIO.IN)      # Echo

while GPIO.input(GPIO_ECHO)==0:

  start = time.time()


while GPIO.input(GPIO_ECHO)==1:

  stop = time.time()


# Calculate pulse length

elapsed = stop-start


# Distance pulse travelled in that time is time

# multiplied by the speed of sound (cm/s)

distance = elapsed * 34300


# That was the distance there and back so halve the value

distance = distance / 2


print "Distance : %.1f" % distance


# Reset GPIO settings

GPIO.cleanup() 


자가 없어서 대충 한뼘(21cm)로 해봤는데 얼추 맞는 기분

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 154.8

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 3.0

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 9.1

pi@raspberrypi ~/src/sonic $ sudo python ultrasonic_1.py

Ultrasonic Measurement

Distance : 26.3 


대충 소스 받아서 수정

[링크 : http://www.raspberrypi-spy.co.uk/2012/12/ultrasonic-distance-measurement-using-python-part-1/]

Posted by 구차니
embeded/raspberry pi2015. 7. 7. 06:54

그냥 쏘고 받고

그 시간 간격재고 끝인가? 굳이.. 몇개의 파형을 안보내는 되는 걸려나..


[링크 : http://www.modmypi.com/blog/hc-sr04-ultrasonic-range-sensor-on-the-raspberry-pi]

[링크 : http://www.raspberrypi-spy.co.uk/2012/12/ultrasonic-distance-measurement-using-python-part-1/]

Posted by 구차니
embeded/raspberry pi2015. 7. 6. 23:40

귀찮아서 여전히 USB to RS232로 하면서 뻔뻔한 제목 ㅋㅋ

땜질 안되어 있는 녀석이라 핀 몇개만 일단 박고 대충 결선하고 테스트!


핀이 하나도 없네?!?!


으쌰으쌰 대충 땜질하자


귀찮으니.. 3.3V를 내줄수 있는 USB to 232를 애용합시다? ㅋㅋ

일단 당연하지만 RX와 TX는 서로 엇갈리게 연결해준다.


232의 RXBT의 TX

232의 TXBT의 RX


전원도 대충~ GND와 3.3V 연결


3.3V 입력

TTL 레벨에 38400 으로 연결하고

명령어를 치면되는데.. \r\n 이라 그냥 입력이 불가능해서

Putty로는 테스트 불가 -_ㅠ


1. Set work mode

\r\n+STWMOD=1\r\n Set work mode Master




[링크 : http://www.seeedstudio.com/wiki/Serial_port_bluetooth_module_(Master/Slave)]

[링크 : http://www.seeedstudio.com/wiki/images/e/e8/BTSoftware_Instruction.pdf]

    [링크 : http://www.seeedstudio.com/wiki/Bluetooth_Shield]


Posted by 구차니
embeded/raspberry pi2015. 7. 6. 18:47

결국은 비표준 통신이라.

GPIO로 쌩 고생을 시켜야하나...


/*

 *  dht11.c:

 * Simple test program to test the wiringPi functions

 * DHT11 test

 */


#include <wiringPi.h>


#include <stdio.h>

#include <stdlib.h>

#include <stdint.h>

#define MAXTIMINGS 85

#define DHTPIN 7

int dht11_dat[5] = { 0, 0, 0, 0, 0 };


void read_dht11_dat()

{

uint8_t laststate = HIGH;

uint8_t counter = 0;

uint8_t j = 0, i;

float f; /* fahrenheit */


dht11_dat[0] = dht11_dat[1] = dht11_dat[2] = dht11_dat[3] = dht11_dat[4] = 0;


/* pull pin down for 18 milliseconds */

pinMode( DHTPIN, OUTPUT );

digitalWrite( DHTPIN, LOW );

delay( 18 );

/* then pull it up for 40 microseconds */

digitalWrite( DHTPIN, HIGH );

delayMicroseconds( 40 );

/* prepare to read the pin */

pinMode( DHTPIN, INPUT );


/* detect change and read data */

for ( i = 0; i < MAXTIMINGS; i++ )

{

counter = 0;

while ( digitalRead( DHTPIN ) == laststate )

{

counter++;

delayMicroseconds( 1 );

if ( counter == 255 )

{

break;

}

}

laststate = digitalRead( DHTPIN );


if ( counter == 255 )

break;


/* ignore first 3 transitions */

if ( (i >= 4) && (i % 2 == 0) )

{

/* shove each bit into the storage bytes */

dht11_dat[j / 8] <<= 1;

if ( counter > 16 )

dht11_dat[j / 8] |= 1;

j++;

}

}


/*

 * check we read 40 bits (8bit x 5 ) + verify checksum in the last byte

 * print it out if data is good

 */

if ( (j >= 40) &&

     (dht11_dat[4] == ( (dht11_dat[0] + dht11_dat[1] + dht11_dat[2] + dht11_dat[3]) & 0xFF) ) )

{

f = dht11_dat[2] * 9. / 5. + 32;

printf( "Humidity = %d.%d %% Temperature = %d.%d *C (%.1f *F)\n",

dht11_dat[0], dht11_dat[1], dht11_dat[2], dht11_dat[3], f );

}else  {

printf( "Data not good, skip\n" );

}

}


int main( void )

{

printf( "Raspberry Pi wiringPi DHT11 Temperature test program\n" );


if ( wiringPiSetup() == -1 )

exit( 1 );


while ( 1 )

{

read_dht11_dat();

delay( 1000 ); /* wait 1sec to refresh */

}


return(0);

}


[링크 : http://www.uugear.com/portfolio/dht11-humidity-temperature-sensor-module/] 


+

2015.07.14

입김불고 얼음대고 온도 변화주기

$ gcc dht11.c -lwiringPi

$ sudo ./a.out

Raspberry Pi wiringPi DHT11 Temperature test program

Humidity = 63.0 % Temperature = 26.0 *C (78.8 *F)

Data not good, skip

...

Humidity = 85.0 % Temperature = 30.0 *C (86.0 *F)

...

Humidity = 80.0 % Temperature = 25.0 *C (77.0 *F)
Humidity = 73.0 % Temperature = 24.0 *C (75.2 *F)
Humidity = 73.0 % Temperature = 23.0 *C (73.4 *F)
Humidity = 71.0 % Temperature = 22.0 *C (71.6 *F)


소스상 GPIO 4 / 7번 핀을 사용하므로 적절하게 연결!


전체구성은 대충 이런 느낌적인 느낌으로



Posted by 구차니