Coder Social home page Coder Social logo

Comments (11)

earlephilhower avatar earlephilhower commented on June 3, 2024

What is the exact board you're using? There is no Waveshare RP2040 Tiny in the boards list.

Are you using the exact, unmodified TalkingToMyself example? I just ran it on a Pico with the 2 jumpers and it's working fine here. If not, post the exact setup() code.

If you've changed the pinouts, then double check the pins are legal. The core will panic if you ask it to use an illegal pin for a HW function.

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

Thanks for such a quick response!

the board i use is this one Waveshare RP2040-Tiny Development Board
the one i'm technically building for is this one RP2040-Zero
as i said earlier the only difference is that this one has no pads on the back for the other GPIO pins and has a external usb board

this is its pinout of the RP2040-Tiny
image
image

this is the code from the example included (only added #include <Arduino.h> void recv(int); void req(); so it doesnt throw compile errors)

// Simple I2C master and slave demo - Earle F. Philhower, III
// Released into the public domain
//
// Using both onboard I2C interfaces, have one master and one slave
// and send data both ways between them
//
// To run, connect GPIO0 to GPIO2, GPIO1 to GPIO3 on a single Pico
#include <Arduino.h>
#include <Wire.h>

void recv(int);
void req();

void setup() {
  Serial.begin(115200);
  delay(5000);
  Wire.setSDA(0);
  Wire.setSCL(1);
  Wire.begin();
  Wire1.setSDA(2);
  Wire1.setSCL(3);
  Wire1.begin(0x30);
  Wire1.onReceive(recv);
  Wire1.onRequest(req);
}

static char buff[100];
void loop() {
  static int p;
  char b[90];

  // Write a value over I2C to the slave
  Serial.println("Sending...");
  Wire.beginTransmission(0x30);
  sprintf(b, "pass %d", p++);
  Wire.write(b, strlen(b));
  Wire.endTransmission();

  // Ensure the slave processing is done and print it out
  delay(1000);
  Serial.printf("buff: '%s'\r\n", buff);

  // Read from the slave and print out
  Wire.requestFrom(0x30, 6);
  Serial.print("\nrecv: '");
  while (Wire.available()) {
    Serial.print((char)Wire.read());
  }
  Serial.println("'");
  delay(1000);
}

// These are called in an **INTERRUPT CONTEXT** which means NO serial port
// access (i.e. Serial.print is illegal) and no memory allocations, etc.

// Called when the I2C slave gets written to
void recv(int len) {
  int i;
  // Just stuff the sent bytes into a global the main routine can pick up and use
  for (i = 0; i < len; i++) {
    buff[i] = Wire1.read();
  }
  buff[i] = 0;
}

// Called when the I2C slave is read from
void req() {

}

this is the verbose build output
https://pastebin.com/QnUsi5EQ

from arduino-pico.

earlephilhower avatar earlephilhower commented on June 3, 2024

Errr, your example code doesn't have anything running on the 2nd core (no loop1) and never replies anything because the req() callback is empty. So I haven't really got any idea what you're trying to do here.

Please run the plain TalkingToMyself with the jumper from GP0->GP2 and GP1->GP3 (note these may not be pins 0-3 on the PCB but they should be labeled)....

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

that is the code from TalkingToMyself.ino though
image
image

and the wires (ive probed them before uploading it by setting 0 & 2 high and then same for 1 & 3)
P_20240319_171127
P_20240319_171135

from arduino-pico.

earlephilhower avatar earlephilhower commented on June 3, 2024

There's nothing in the req() function you listed, so there will never be any data sent back with what you posted. So, somehow you seem to have a modified example code.

If you check the original code it's setting data to return to the other I2C: https://github.com/earlephilhower/arduino-pico/blob/175cbcdcdf6bac39854486315fd514c82c610215/libraries/Wire/examples/TalkingToMyself/TalkingToMyself.ino#L64-70

Also, since it's not running anything on core1 I'm still at a loss why you believe Wire crashes the other core?

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

oh interesting, i will try that one.

Is it possible that PlatformIO has a outdated version of the pico core?

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

hmm ok just tried that one and it works. Well that means my code breaks somewhere... (and got no idea where )

i wonder why the platformIO one is missing part of the code though

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

the weird part is that when i have nothing in yhe req in my code the netire slave is gone form the i2c bus

from arduino-pico.

earlephilhower avatar earlephilhower commented on June 3, 2024

There is no official P.IO support for this or any other RP2040 stuff, AIUI, so you should be using the git or release files as described here.

In any case, looks like were' good here so closing.

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

https://youtu.be/AmeiO_LWxh4
yes im aware there is no official support, iinm i am using the git release

Core 0 runs i2c and handles the strip
Core 1 runs the internal one
unless im doing something very wrong i dont see what could cause this in my code

i have the exact copy from your request callback in mine

#include "Commands.h"
#include "Common.h"
#include <Arduino.h>
#include <Adafruit_NeoPixel.h>
#include "CRC.h"
#include "Wire.h"

#define i2c Wire
int i2cADDR = calcCRC8((uint8_t*)rp2040.getChipID(), sizeof(rp2040.getChipID()));

#define I2C_SDA D0
#define I2C_SCL D1
#define WS2812_EXT D2
#define MUX_EN D3
#define MUX_S4 D4
#define MUX_S3 D5
#define MUX_S2 D6
#define MUX_S1 D7

#if defined(ARDUINO_WAVESHARE_RP2040_ZERO)
#define MUX_SIG A3
#elif defined(ARDUINO_RASPBERRY_PI_PICO)
#define MUX_SIG A2
#endif

#define BUTTON1 D8
#define BUTTON2 D9
#define BUTTON3 D2
#define HAT1_1 D11
#define HAT1_2 D12
#define HAT1_3 D13
#define HAT1_4 D14
#define LMB D15
#define WS2812_INT D16
#define RMB D25
#define SCROLL_1 D26
#define SCROLL_2 D27

#define INT_NUM_PIXELS 1
#define EXT_NUM_PIXELS 12


Adafruit_NeoPixel ext_pixel(EXT_NUM_PIXELS, WS2812_EXT);
Adafruit_NeoPixel int_pixel(INT_NUM_PIXELS, WS2812_INT);

volatile Command* command;
volatile RGBW led;
uint8_t i2cBuffSize = 255;
uint8_t i2cBuffSizeFree = i2cBuffSize;
volatile void* i2cBuff = NULL;
volatile bool NewData = false;

void receive(int len);
void request();
uint16_t readMuxChannel(uint8_t channel);


void setup() {
	if (i2cBuff == NULL) {
		i2cBuff = (uint8_t*)malloc(i2cBuffSize);
	}
	command = (struct Command*)i2cBuff;

	analogReadResolution(11);
	//command.data = &i2cBuff;
#if defined(ARDUINO_RASPBERRY_PI_PICO) // This changes the SMPS to be less efficient but also less noisy
	pinMode(23, OUTPUT);
	digitalWrite(23, HIGH);
#endif	
	Serial.begin(115200);
	ext_pixel.begin();

	i2c.setSDA(I2C_SDA);
	i2c.setSCL(I2C_SCL);
	i2c.setClock(100000);
	i2c.begin(i2cADDR);

	i2c.onReceive(receive);
	i2c.onRequest(request);
}

void loop() {
	if (NewData) {
		switch (command->command_type)
		{
			case SET_LED: {
				Serial.println((uint)command->data);
				led.raw = (uint32_t)command->data;
				Serial.println((uint32_t)command->data);
				ext_pixel.setPixelColor(command->id, led.R, led.G, led.B);
				if (ext_pixel.canShow())
					ext_pixel.show();
				NewData = false;
				break;
			}
			case SET_AXIS: {
				NewData = false;
				break;
			}
			case SET_BUTTON: {
				NewData = false;
				break;
			}
			default: {
				NewData = false;
				break;
			}
		}
	}
}


uint16_t readMuxChannel(uint8_t channel) {
	digitalWriteFast(MUX_S1, bitRead(channel,0));
	digitalWriteFast(MUX_S2, bitRead(channel,1));
	digitalWriteFast(MUX_S3, bitRead(channel,2));
	digitalWriteFast(MUX_S4, bitRead(channel,3));
	digitalWriteFast(MUX_EN, LOW);
	uint16_t read = analogRead(MUX_SIG);
	digitalWriteFast(MUX_EN, HIGH);
	return read;
}


// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receive(int len) {
  i2cBuffSizeFree = i2cBuffSize - i2c.readBytes((byte*)i2cBuff, len);
	NewData = true;
}

// function that executes whenever data is received from master
// Called when the I2C slave is read from
void request() {
  static int ctr = 765;
  char buff[7];
  // Return a simple incrementing hex value
  sprintf(buff, "%06X", (ctr++) % 65535);
  Wire1.write(buff, 6);
}


int i2 = 0;
void setup1() {
	int_pixel.begin();
}

void loop1() {
	if (int_pixel.canShow()) {
		int_pixel.rainbow(i2,1,255,128,true);
		int_pixel.show();
		i2+=10;
		if (i2 > UINT16_MAX)
			i2 = 0;
	}
	delay(1);
}

from arduino-pico.

MNS26 avatar MNS26 commented on June 3, 2024

There is no official P.IO support for this or any other RP2040 stuff, AIUI, so you should be using the git or release files as described here.

In any case, looks like were' good here so closing.

i personally would not consider this closed (yet)
i also checked and yes im running the one from git.

after i said it was working i also said it still dissapears from the bus (yes its not the EXACT demo)
i tried it while i commented the Wire.onRequest() out and it STILL crashes the chip (!)
i also tried reworking the example code you linked but still had it crash

this is the entire project in its current state (i2c breaks)
there are 2 build options one for the USB HID part and one for the i2c slave (node)

(its a 7z since it was the smallest one but file extention set as zip to upload it)
RP2040 HOTAS.7z.zip

ill put the project on halt for the foreseeable future then

from arduino-pico.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.