Страница 1 из 1
Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 08:26:48
olegue
Заказал эту штуку на алике. Сначала смотрел видосики про нее, а теперь решил и сам попробовать. Практических примеров пока мало. Подключил дисплей по i2c, радиомодуль (применик 315мгц) ,библиотеки
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RCSwitch.h>
все завелось вообще без проблем. Ниже код управления с пульта включением Led на 13 ножке и вывод полученного кода на экран LCД 1602
подключенного по i2c
Код: Выделить всё
//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
lcd.init(); // initialize the lcd
lcd.init();
lcd.backlight();
}
void loop()
{
if (mySwitch.available()) {
lcd.setCursor(0,0);
lcd.print("Received ");
lcd.print( mySwitch.getReceivedValue() );
lcd.print(" / ");
lcd.print( mySwitch.getReceivedBitlength() );
lcd.setCursor(0,1);
lcd.print("bit ");
lcd.print("Protocol: ");
lcd.print( mySwitch.getReceivedProtocol() );
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
mySwitch.resetAvailable();
}
}
а вот настроить заливку скетчей через USBASP почему-то не получилось. Потом уже где-то в интернете читал , что якобы это нельзя.
И , типа есть такой двухпроводной Serial Wire Debug и что при наличии ардуины через него можно прошивать. Это я попробую потом , но пока руки не дошли.
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 08:36:31
electroget
[uquote="olegue",url="/forum/viewtopic.php?p=4255515#p4255515"]а вот настроить заливку скетчей через USBASP почему-то не получилось.[/uquote]
А через USBASP это как? Поясните пожалуйста.
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 08:53:02
olegue
Обзор программатора USBAsp v.2.0
https://robotchip.ru/obzor-programmatory-usbasp-v-2-0/
вот есть такой программатор
Я им шью все свои Атмеги, подключаюсь в к выводам Miso, Mosi, Sck, Reset.
В ардуино IDE выбираю пункт "Загрузить через программатор". Загрузчик поменять если делаю какую-то пользовательскую Атмегу, тоже через него.
К этому чипу тоже подцепился, но загрузка не идет.
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 08:56:07
electroget
olegue,
Теперь понял. Но не совсем понятно, зачем использовать программатор если в эту платку всё нормально заливается через обычный USB при питании 3.3 Вольта.
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 10:53:36
olegue
electroget писал(а):Но не совсем понятно
вот в том то и дело, что мне все понятно. Поэтому и делаю , что бы Usbasp работало.
Добавлено after 1 hour 20 minutes 24 seconds:
полистал avrdude.conf и понял,что пока какой нить разумный человек не добавит туда поддержку usbasp прошивки через usbasp не будет. Т.е остается два варианта, один, самый очевидный костыльный через ch340 на плате, от которого я хотел было уже отряхнутся. Нуи и второй, самый надежный, RX/TX. Третий , Serial Wire Debug , так себе удовольствие (нужна ардуина) - вообще не вариант
Добавлено after 6 minutes 47 seconds:
Интересно вот еще , можно ли этот чип испльзовать самостоятельнол, без ардуино. И чем его тогда шить и как?
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 17:54:07
DimKra
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 06, 2022 23:22:08
olegue
Видать так и есть. swd swc через arduino isp - это и будет прошивка камня в чистую загрузчика Ардуино.
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Вт июл 19, 2022 19:57:01
olegue
пробую с ней дальше экспериментировать
решил проверить библиотеки
воспроизведения звука TMRpcm.h и работы с картой SD.h
Спойлер
Код: Выделить всё
/*
Steps:
1. Edit pcmConfig.h
a: On Uno or non-mega boards, #define buffSize 128. May need to increase.
b: Uncomment #define ENABLE_RECORDING and #define BLOCK_COUNT 10000UL
2. Usage is as below. See https://github.com/TMRh20/TMRpcm/wiki/Advanced-Features#wiki-recording-audio for
additional informaiton.
*/
#include <SD.h>
#include <SPI.h>
#include <TMRpcm.h>
#define SD_ChipSelectPin 4
TMRpcm audio;
int audiofile = 0;
unsigned long i = 0;
bool recmode = 0;
int RecPressed=0;
int StopPressed=0;
void setup() {
pinMode(A0, INPUT);
pinMode(6, OUTPUT);
pinMode(5, INPUT_PULLUP);
//attachInterrupt(0, button, LOW);
SD.begin(SD_ChipSelectPin);
audio.CSPin = SD_ChipSelectPin;
audio.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
Serial.begin(9600);
if (!SD.begin(SD_ChipSelectPin)) { // see if the card is present and can be initialized:
Serial.println("SD fail");
return; // don't do anything more if not
}
audio.play("001251.wav"); //the sound file "music" will play each time the arduino powers up, or is reset
}
void loop() {
if (digitalRead(5)==LOW && RecPressed==0)
{digitalWrite(6, HIGH);StartRec();}
else if (digitalRead(5)==HIGH && RecPressed==1)
{digitalWrite(6, LOW);StopRec();}
}
void StartRec() {
RecPressed=1;
audiofile++;
switch (audiofile) {
case 1: audio.startRecording("1.wav", 16000, A0); break;
}
}
void StopRec() {
RecPressed=0;
recmode = 0;
//digitalWrite(6, LOW);
switch (audiofile) {
case 1: audio.stopRecording("1.wav"); break;
}
}
воспроизведение звука работает , а вот с записью проблема
что интересно, скетч для записи файла на карту тоже отрабатывает как надо
Спойлер
Код: Выделить всё
/*
SD card read/write
This example shows how to read and write data to and from an SD card file
The circuit:
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created Nov 2010
by David A. Mellis
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
File myFile;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initializing SD card...");
if (!SD.begin(4)) {
Serial.println("initialization failed!");
while (1);
}
Serial.println("initialization done.");
// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);
// if the file opened okay, write to it:
if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
// re-open the file for reading:
myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");
// read from the file until there's nothing else in it:
while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}
void loop() {
// nothing happens after setup
}
Добавлено after 17 minutes 38 seconds:
А вот есил оригинальную Arduino Nano втыкаю , то пишет звук - вопросов нет.
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Ср июл 20, 2022 20:59:09
olegue
Попробовал модуль wifi
nRF24L01. Тестовый скетч
scanner тоже отлично отрабатывает и показывает занятость каналов.
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
Спойлер
Код: Выделить всё
/*
Copyright (C) 2011 J. Coliz <maniacbug@ymail.com>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
version 2 as published by the Free Software Foundation.
*/
/**
* Channel scanner
*
* Example to detect interference on the various channels available.
* This is a good diagnostic tool to check whether you're picking a
* good channel for your application.
*
* Inspired by cpixip.
* See http://arduino.cc/forum/index.php/topic,54795.0.html
*/
#include <SPI.h>
#include "nRF24L01.h"
#include "RF24.h"
#include "printf.h"
//
// Hardware configuration
//
// Set up nRF24L01 radio on SPI bus plus pins 7 & 8
RF24 radio(9,10);
//
// Channel info
//
const uint8_t num_channels = 128;
uint8_t values[num_channels];
//
// Setup
//
void setup(void)
{
//
// Print preamble
//
Serial.begin(115200);
printf_begin();
printf("\n\rRF24/examples/scanner/\n\r");
//
// Setup and configure rf radio
//
radio.begin();
radio.setAutoAck(false);
// Get into standby mode
radio.startListening();
radio.stopListening();
// Print out header, high then low digit
int i = 0;
while ( i < num_channels )
{
printf("%x",i>>4);
++i;
}
printf("\n\r");
i = 0;
while ( i < num_channels )
{
printf("%x",i&0xf);
++i;
}
printf("\n\r");
}
//
// Loop
//
const int num_reps = 100;
void loop(void)
{
// Clear measurement values
memset(values,0,sizeof(values));
// Scan all channels num_reps times
int rep_counter = num_reps;
while (rep_counter--)
{
int i = num_channels;
while (i--)
{
// Select this channel
radio.setChannel(i);
// Listen for a little
radio.startListening();
delayMicroseconds(225);
// Did we get a carrier?
if ( radio.testCarrier() ){
++values[i];
}
radio.stopListening();
}
}
// Print out channel measurements, clamped to a single hex digit
int i = 0;
while ( i < num_channels )
{
printf("%x",min(0xf,values[i]&0xf));
++i;
}
printf("\n\r");
}
// vim:ai:cin:sts=2 sw=2 ft=cpp
Re: Китайский аналог ардуины на Lgt8f328
Добавлено: Вт авг 30, 2022 15:47:56
maxlab
Привет! Если еще китайским клоном балуетесь, возможно пригодится эта sdk
https://cloud.mail.ru/public/vks2/LdSatQhEN